0

Is there a way to make it so that certain kernel modules, mount points, and boot-time services (in either Systemd or OpenRC) can be enabled or disabled based on boot-time parameters (and/or the type of kernel running)?

And taking it a step further, could init systems be swapped in a similar way? (I am aware of the init=... kernel parameter, but can (for example) both systemd and OpenRC co-exist together in the same installation and swapped out at-will during boot-time)?

For some background (in case anyone is old enough to remember this), my line of thinking stems from the DOS technique of having multiple system profiles in config.sys/autoexec.bat which could be chosen based on a boot-time menu.

So if I (purely for the sake of example) wanted to have three menu entries in GRUB:

  • "Gaming": would load a custom kernel, load proprietary nvidia drivers & enable optimus (or vfio passthrough), and boot into X11;

  • "Work": would load another kernel, load intel video drivers, mount my encrypted work partition, and boot into Wayland;

  • "Server": would load a third (high-latency) kernel, start specific additional background services (i.e. web server, ssh host, vm host), and boot into the text console.

The above are just examples, but hopefully the point comes across.

Is something like this possible in Linux?

1 Answer 1

1

Sure. Depending on your distro, it might be easy or hard, but yes.

For modules, this U&L post mentions the modules_load kernel parameter for loading modules And this other post has a parameter for blocking modules. On Arch Linux, mkinitcpio makes it easy to generate multiple kernel images with different configurations (well, at least for pre-loaded modules and so on, but not build config).

For loading services, mounting volumes, etc., systemd makes it easy by having both be units which can part of dependency chains. So you can create a "target" gaming.target which Wants/Requires or is WantedBy/RequiredBy a service which starts X11, or a work.target which Wants/Requires or is WantedBy/RequiredBy by the mount unit and device units of the encrypted work partition, and a unit which starts Wayland, and so on. Then the target that you want to boot to will be part of the kernel command line using the systemd.unit parameter (say, systemd.unit=gaming.target or systemd.unit=work.target).

Since the target needs to be set in the kernel command line, and possibly the modules to load as well, you will need to update your bootloader configuration to create separate entries for each with corresponding the kernel images and command lines.

Init systems can be swapped - when Ubuntu first introduced systemd, it was possible to swap between Upstart and systemd. I think Gentoo still supports it. For other distros, somebody will have to set up service configuration and so on for the non-default init system (and that somebody will likely be you, entailing a lot of work).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .