Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add finit.fstab= kernel cmdline param for finit #224

Closed
hongkongkiwi opened this issue Feb 10, 2022 · 14 comments
Closed

Add finit.fstab= kernel cmdline param for finit #224

hongkongkiwi opened this issue Feb 10, 2022 · 14 comments
Assignees
Milestone

Comments

@hongkongkiwi
Copy link
Contributor

hongkongkiwi commented Feb 10, 2022

I wanted to propose a simple feature for a future version of finit.

This would assist me greatly in my use case.

Basically, I'm using A/B update images and an emmc flash. So depending on which image is flashed, I will mount a particular set of mounts. The slot is set in the kernel cmdline and currently (before starting to use finit) I have a script which handles the correct mounting before any services are run.

For example, if I boot in slot a, then I will run mount -T /etc/fstab.slota instead of the default.

Since finit takes care of a lot of nice stuff such as fsck and mounting, I was wondering if it's possible to have a kernel cmdline which sets which file finit uses for these operations? For example, if nothing is set it would continue to use mount -T /etc/fstab as normal, however if finit.fstab_file=/etc/fstab.slota is set (I can do this in my bootloader script) then finit would instead use this for all mount and related fsck operations.

This would make it really easy to handle different mount configurations dynamically based on slot.

@hongkongkiwi
Copy link
Contributor Author

In the meantime, I plan to have a one-shot shell script that does the mounting and then use the condition <run/emmc-mount/done> in all subsequent services. This is necessary because I'm mounting my logs dir based on slot so everything hangs off of this.

It's a workaround that I think should work, but if it would be really nice if I could just specify the fstab file directly in the kernel cmdline.

@hongkongkiwi hongkongkiwi changed the title Add finit.fstab_file kernel cmdline param Add finit.fstab= kernel cmdline param for finit Feb 14, 2022
@hongkongkiwi
Copy link
Contributor Author

hongkongkiwi commented Feb 14, 2022

I think the change could be simple if not objectionable to make this behaviour configurable, I can see the only reference to the fstab file (currently hardcoded) is in:

fstab = lfopen("/etc/fstab", " \t\n");

So this would need to be read from a kernel cmdline var instead and if missing or blank, default to /etc/fstab .

@hongkongkiwi
Copy link
Contributor Author

I just realise that this should also apply to these two plugins:

  • fastboot
  • fsckfix

@troglobit
Copy link
Owner

This is definitely possible to do, and I understand the use-case. Thanks for taking the time to describe it so clearly!

I don't know when I'll have to to work on this, so a pull request would speed things up considerably. For now, I'm putting this on milestone Future, but only because there's not 4.4 planned yet (busy with 4.3).

@hongkongkiwi
Copy link
Contributor Author

For now, FYR I've worked around this issue by adding a mount helper in the fstab file, which then mounts another fstab file ;)

@troglobit
Copy link
Owner

Aha, clever! Mount helpers are really magic :-)

@troglobit troglobit modified the milestones: FUTURE, 4.3 Apr 19, 2022
@troglobit
Copy link
Owner

Changing target for this again, realizing I might actually have some need for this myself. I'll at least give it a try for the 4.3 release cycle ... as always, no promises! Paying customers and their release cadence takes precedence.

@troglobit
Copy link
Owner

Question for @hongkongkiwi: what would be a good fallback if Finit cannot find /etc/fstab.slota before calling mount -na -T /etc/fstab.slota?

Here's the scene: a custom fstab can be selected at configure time using:

./configure --with-fstab=/mnt/footab

At boot, Finit is started with -- finit.fstab=/etc/fstab.slota, what should Finit do if /etc/fstab.slota is missing?

  1. No fallback, system fails to boot due to failing mount -na -T /etc/fstab.slota
  2. Finit detects missing fstab file and calls sulogin, like on a failing fsck
  3. Finit detetct missing fstab file, replaces it with its configured value, checking for /mnt/footab and continues using alt. 1 or 2 (above)

A third fallback, to the UNIX default /etc/fstab (or $sysconfdir/fstab from configure), could also be added to this mix. Checking for the existence of any of the (three) alternatives until it finds one, and then alt. 1 or 2.

Maybe even exit(1) is an error handling option? In this case Finit would cause the kernel error ... attempted to kill init ..., and the system would then rely on the configured kernel error handling, e.g. reboot.

@hongkongkiwi
Copy link
Contributor Author

hongkongkiwi commented Apr 20, 2022

In my mind, if this is configured the user has specifically hardcoded this:
./configure --with-fstab=/mnt/footab

Then it should fallback to this file that makes sense (I guess the default is /etc/fstab), option (3)

  1. Finit detetct missing fstab file, replaces it with its configured value, checking for /mnt/footab and continues using alt. 1 or 2 (above)

However, maybe not all users will want this, so an easy way to handle it could be if not configured or empty like: ./configure --with-fstab= then I would say log an error and sulogin for recovery like fsck (option 2) since a boot is impossible.

I don't think we should ever fail to boot (1), because this is disastrous on an embedded system. I guess unless sulogin is disabled entirely it should always be there for emergency situations like this to investigate the issue.

@troglobit
Copy link
Owner

Yeah you're right, that's the most logical conclusion, and what I'd expect as well. So to summarize:

  • ./configure --with-fstab=/mnt/footab will fall fall back to /mnt/footab if finit.fstab=/etc/fstab.slota is missing.
  • ./configure --without-fstab would not fall back to anything and requires whatever finit.fstab=file to exist
  • In both cases, if file doesn't exist, and sulogin is available we call sulogin

Additionally I propose:

  • If sulogin is missing, or when exiting from sulogin we call do_shutdown(SHUT_REBOOT);, like the fsck case. If you squint, the mount fail and fsck fail cases are the same, so having the same failure handling seems like a good idea.

I completely agree on your point of bricking embedded systems, yet there have been several different cases where users wanted their systems "parked" (blinking a specific LED pattern) so service personnel could easily see which units to replace, or continuously rebooting so that a service engineer could access the bootloader from a service port. At my old job we ended up with deferring to the kernel and how it was configured to handle oops/bug/init crashes, as I mentioned previously. There are so many use cases out there! :-)

I'll give a good think and see what I can come up with, possibly another configure option, or more documentation around the rescue.conf (did you know about that one?)

@troglobit troglobit self-assigned this Apr 25, 2022
@troglobit
Copy link
Owner

There, done! Took a bit longer to complete than planned -- a bit too much at $DAYJOB atm. Hope it works to your liking 😃

troglobit added a commit that referenced this issue Apr 26, 2022
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
troglobit added a commit that referenced this issue Apr 26, 2022
The swapon and swapoff commands do not support a custom fstab, they
assume /etc/fstab is the only true source of swap devices and files.

This change adds rudimentary (!) support for figuring out any swap
device or file to use from any finit.fstab.  Please note, options are
not supported at the moment.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
@hongkongkiwi
Copy link
Contributor Author

Ahhh, at first I was slightly confused about the swap and I realised that I have this line:
#/dev/mmcblk0p14 /swap swap

It's actually commented out, so it shouldn't try to mount any swap I'm wondering if when your parsing the fstab file you ignore commented lines ;)

@hongkongkiwi
Copy link
Contributor Author

This may need a new issue, but just wanted to get your take on it.

@troglobit
Copy link
Owner

It failed only because Finit calls swapon (and swapoff) if it finds it, and it only understands /etc/fstab. The new code I submitted in 605c489 (last night, CET) uses the getmntent(3) std UNIX C API, which I'm pretty sure skips commented lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants