With this post I am sharing a solution with the community.
I have a Gentoo system installed on a ZFS pool consisting of multiple encrypted devices. It is normally decrypted at boot as described in this post. In the file /etc/default/grub I add to the kernel line:
RUB_CMDLINE_LINUX="dozfs crypt_roots=UUID=aaaaaaaa crypt_roots=UUID=bbbbbbbb ..."
where aaaaaaaa and bbbbbbbb stand for the UUID-s of the encrypted volumes as listed in /dev/disk/by-uuid, but there is an inconvenience: A password must be entered once for each volume. I use full disk encryption and 8 encrypted volumes, which would require 9 password entries on each boot, even though I use the same password for all the volumes. Quite a hassle!
Is it possible to decrypt all volumes with a single password entry?
My initramfs is created via sys-kernel/genkernel-next-69.
I have come up with a patch for genkernel that allows for decrypting multiple volumes with a single password (save the file as
/tmp/genkernel_multicrypt.patch):The patch must be applied to genkernel as root in directory
/usr/share/genkernel:If everything goes right, the patch will be applied and you will not see any error messages.
Usage
First make sure your disks can be decrypted using the same password!!!
The patch modifies genkernel's initial ramdisks to support the following additional input parameters:
In the above example you can freely choose how many types you want to have, I used 3:
boot,root,tank. For each type you can have one or more volume UUIDs as shown above.Make sure the UUIDs are present in
/dev/disk/by-uuid. Make sure the UUIDs are exact! Typos can lead to an unbootable system!The devices will be added to the device mapper as
boot0,root0,root1, etc.Now, the kernel line must be modified as follows (simply append all parameters mentioned above to the kernel line along with your regular ones, for example
dolvm,dozfs, etc.).Do not delete your original kernel line yet, simply comment it out in case you want to revert.
When this chore is done, we can call genkernel do generate the new initramfs. Make sure you make a backup copy of your old one to enable easy recovery if something goes wrong. Compiling kernel and modules is not necessary.
Also, write down your original kernel line on a piece of paper, so that you can type it in Grub in case the system can't boot properly.
Your shiny new initramfs is installed in
/boot. Now for the final touch - GRUB's configuration file must be generated to activate the new parameters:At the time of writing grub-mkconfig generates an incorrect file that needs to be patched manually if your root is on ZFS. In the file
/boot/grub/grub.cfgmy root dataset is incorrectly specified as/ROOT/gentooinstead ofzroot/ROOT/gentooso I need to insertzrootin multiple locations. This should not be necessary once that particular bug is fixed.Done! After rebooting the following prompt will be shown:
Enter your password and (fingers crossed) all volumes should decrypt.
Troubleshooting
If your system becomes unbootable, you can use your old initramfs that we saved. When the Grub menu is shown, hit
Eand retype your original kernel line, appending "--saved" to your initramfs filename. This should boot your system as it was before.If you are not satisfied with the patch, restore your original genkernel from
/root/genkernel-backupto/usr/share/genkernel, then restore your original kernel line in/etc/default/gruband call genkernel and grub-mkconfig again:Caveat
For I use a full disk encryption, I still need to enter my password twice at boot. First, to decrypt
/bootand load the kernel, then a second time to decrypt all other volumes. I am not aware of any solution for this.State 17.02.2022