troglobit / finit

Fast init for Linux. Cookies included
https://troglobit.com/projects/finit/
MIT License
621 stars 61 forks source link

Add finit.config=/etc/custom.conf cmdline (kernel) for different finit.conf file #235

Closed hongkongkiwi closed 1 year ago

hongkongkiwi commented 2 years ago

I would like (for testing) to specify a different /etc/finit.conf file. Is it possible to pass a kernel param to specify what config file init uses?

troglobit commented 2 years ago

Nope, only at configure time using --with-config=/path/to/file. It's sort of like /etc/inittab in SysV init.

troglobit commented 2 years ago

Similar to #224, neat request if finit.config=/path/to/file existed then overrides for tests and similar would be possible.

hongkongkiwi commented 2 years ago

This would be useful to me, if implemented, perhaps we could hardcode allowed filenames at compile time? That way user cannot arbitrarily specify a filename and then when something is passed finit just checks against kv to see if it was allowed at compile time.

Might help to mitigate any possible security issues? Just a thought today about this.

troglobit commented 2 years ago

Good idea, I was a bit concerned about the security aspects as well! Thanks :)

hongkongkiwi commented 2 years ago

What about this?

This works since finit.conf is read first (right?)

troglobit commented 2 years ago

Yes, that would work. (I'm assuming you meant finit.config=/etc/finit.conf, not fstab :)

hongkongkiwi commented 2 years ago

Yep! :)

hongkongkiwi commented 2 years ago

I'm receiving these log messages (I don't have any file named /etc/fstab). The fstab file should be compiled as /etc/fstab.noslot I believe (SIDE NOTE: is there anyway to check what the compiled in vars are? possible to display this info somewhere e.g. initctl ver)

[ ⋯  ] Checking filesystem sysfsWARNING: couldn't open /etc/fstab: No such file or directory
[ OK ]
[ ⋯  ] Checking filesystem sysfsWARNING: couldn't open /etc/fstab: No such file or directory
[ OK ]
[ ⋯  ] Checking filesystem sysfsWARNING: couldn't open /etc/fstab: No such file or directory
[ OK ]
[ ⋯  ] Checking filesystem sysfsWARNING: couldn't open /etc/fstab: No such file or directory
[ OK ]
[ ⋯  ] Checking filesystem sysfsWARNING: couldn't open /etc/fstab: No such file or directory
[ OK ]
[ OK ] Mounting filesystems from /etc/fstab.slot.flash_recovery_rootfs.0
[ OK ] Enabling system swap
swapon: failed to parse /etc/fstab: No such file or directory

My custom fstab file passed via finit.fstab= is correctly mounted though, so these are just warnings.

troglobit commented 2 years ago

Great, thanks for testing this! I'll have a look at what this could be later tonight. When I tested I had the std /etc/fstab, of course ...

Re: side note -- no, not from the tools themselves, only config.log and config.h are available.

troglobit commented 2 years ago

Found two things so far, looking at BusyBox sources:

  1. swapon/swapoff do not take any alt. /etc/fstab argument (not even the util-linux counterparts on std Linux)
  2. turns out the fsck program needs /etc/fstab, or a custom FSTAB_FILE=/etc/fstab.alt environemnt set, this also seems to be supported by the util-linux counterpart

For swap, this was an oversight on my part and I'll see what I can do about fishing out swap partitions and files manually and calling swapon /dev/partition or swapon /swapfile from what I can find.

For fsck, I'll set the environment variable and hope it works since I don't have a system with swap to test on atm. But I'll make note of it and test during the coming weekend. (Which is when I hope to release Finit 4.3)

troglobit commented 2 years ago

Ouch, I see now we both mixed up the issues a bit. Our last three comments above should probably've been on #224 ... oh well. I've pushed a few fixes and additions. Again, the swap fixes have not been tested on a system with swap/swapfile yet.

hongkongkiwi commented 2 years ago

I wanted to clarify this feature request a bit and narrow it down.

  1. Change rcsd dir to be read from finit.conf something like rcsd_dir=/etc/mydir (otherwise fallback to whatever is configured at compile time, or just fail if nothing configured, similar to how fstab works)
  2. Finit conf can be specified from kernel comdline finit.conf=/etc/finit.conf with fallback to compile time value or, finit should drop to rescue shell if no finit.conf passed and no compile time fallback specified.

I think these two changes are very powerful and allow the user to specify completely different sets of scenarios. For example, you might want a factory test mode which you can simply specify that with kernel cmdline finit.conf=/etc/factory_test.conf and a completely specific and special set of behaviour would start.

A similar functionality can be used with runlevels, but your limited to a few scenarios with no way to specifically name each one. Also, there are some hardcoded functionality which cannot be changed with runlevels (e.g. in my above example the rcsd_dir), so being able to specify a different finit.conf (which in turn specifies it's own rcsd_dir) would be extremely powerful.

The above changes (I think) should be backwards compatible, so existing users won't see a difference.

troglobit commented 2 years ago

100% agree from me. Thank you for taking the time to pin this down <3

troglobit commented 1 year ago

There, finally completed! :-)

We now have the following kernel command line option:

-- finit.config=/etc/factory.conf

... and top-level configuration directive (from /etc/factory.conf):

rcsd /etc/factory.d