It is as simple with Dracut as I think?

I’m trying to mount some things BEFORE the root partition is mounted during boot. It looks like I can just add a simple custom module to Dracut that can literally just hardcode the setting up and mounting for me during boot. Is it as simple as that?
ADD: and then pass the mounted device as rootfs that’s already been decrypted in grub’s command line?

ZFS has a dracut module that used to work that way.

So, yes, it is possible. You can see at the top of that script that they have since switched to using a systemd generator. But the legacy code is still there and I’m sure you could implement something similar as your own custom rootfs if you wanted to.

Thanks. But I don’t think I can use crypttab if I need to decrypt several partitions before I can even boot, before I decrypt the partitions that lead to rootfs for example? And then I still need to manually add them to crypttab so systemd knows of them and can stop the devices on shutdown?

I’m not familiar with crypttab. Personally, I use ZFS and I only encrypt my home directory.

However, as a generic answer to your questions, whatever you can do from the dracut emergency shell (i.e. the early boot stage you can get an interactive shell in by adding rd.break=pre-mount to the kernel command line) you should be able to script. Dracut has “hooks” wherein you can drop custom scripts that you want to run automatically during the different stages of the boot (cmdline|pre-udev|pre-trigger|initqueue|pre-mount|mount|pre-pivot|cleanup). See here for one example of how you could inject a custom script into your initramfs.

Thank you so much! I was about to play with the dracut emergency shell and was going to google how to get to it. And was wondering about how to get the timing hooks. As for the dracut custom scripting I asked ChatGPT and it gave me a decent reply that makes dracut customization look like a breeze. I will test and will post how to do it if successful.

This is achieved by using Dracut hooks basically. It’s important to use a correct hook, of course. There are good descriptions of Dracut hook stage triggers online. And once embedded into the initramfs along with all the required dracut modules and kernel modules things run great. Rd.break=somehook was helpful in testing but it does drop to the emergency shell if it can’t find/mount the rootfs.