PSA: GRUB fails to detect the fact that / and /boot are LUKS encrypted
So, I decided to try out the LUKS2 support in GRUB 2.06. Tried installing using grub-install , and on reboot it failed to unlock the LUKS encrypted root partition, and dropped to a rescue prompt.
At first, I thought this was due to the LUKS2 support not working properly, but after a few hours of frustration, I discovered that GRUB is failing to add the required cryptomount commands to the EFI image and to grub.cfg .
So if you're using encrypted /boot or / partitions, then think twice before re-installing GRUB, and make sure you have a rescue disk handy.
I was only able to fix it by creating a custom config file (https://wiki.archlinux.org/title/GRUB/Tips_and_tricks#Manual_configuration_of_core_image_for_early_boot) with the necessary commands, manually generating an EFI image and then manually modifying grub.cfg
Edit: The LUKS2 support works fine with the PBKDF2 key type if someone wanted to know. It's just that GRUB fails to add the cryptomount commands, so this would have failed with LUKSv1 too.
Edited 17 Jun 2021. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 19 · 88% up
- Kind
- Text
- ID
- o1opyj
18 comments
There are a couple of things you need to take care of:
1- Grub 2.06 "supports" LUKS2, but currently only pbkdf2, which means when running cryptsetup luksFormat you have to specify pbkdf2 as well:
cryptsetup -y --cipher aes-xts-plain64 --key-size 512 --hash sha512 --pbkdf pbkdf2 --type luks2 luksFormat /dev/device2- When installing grub, you have to specify the modules required to detect/decrypt your root/device(s): Change --efi-directory and btrfs with your filesystem.
grub-install --target=x86_64-efi --efi-directory=/boot/efi --modules="luks2 part_gpt cryptodisk gcry_rijndael pbkdf2 gcry_sha512 btrfs" --bootloader-id=archlinux --recheck3- Generate the bootloader image/config:
a- See https://aur.archlinux.org/packages/grub-git/?O=10&PP=10#comment-769218
You can use the grub-mkluks2-image script, but DO CHANGE the prefix and root variables according to your setup!
b- Run
grub-mkconfig -o /boot/grub/grub.cfgReboot :-)
Hello, linunix! I will be very grateful if you can help me figure it out a little.
I have Manjaro Linux KDE Edition installed on BIOS system without UEFI support on HDD with GPT partition table. My "
/dev/sda" disk has the following partitions:sda1- 1MiB "bios" partition without filesystem with "bios_grub" flag;sda2- 512MiB "boot" partition, it is a separate LUKS2-PBKDF2-encrypted boot partition mounted at "/boot";sda3- 931GiB "root" partition, it is a LUKS2-argon2id-encrypted root partition mounted at "/".Here are my encryption settings for "
boot" partition:--type luks2 --cipher serpent-xts-plain64 --hash whirlpool --key-size 512 --pbkdf pbkdf2 --iter-time 10000 --use-randomHere are my encryption settings for "
root" partition:--type luks2 --cipher serpent-xts-plain64 --hash whirlpool --key-size 512 --pbkdf argon2id --iter-time 10000 --use-randomLUKS keyfiles for both "
boot" and "root" partitions are configured correctly.I have installed GRUB with this commands:
sudo grub-install --target=i386-pc /dev/sda --modules="luks2 part_gpt part_msdos cryptodisk gcry_serpent pbkdf2 gcry_whirlpool btrfs" --rechecksudo grub-mkconfig -o /boot/grub/grub.cfgNow I have run the following script and got GRUB "image" file in my home directory:
#!/bin/bashCONFIG=$(mktemp /tmp/grub-config.XXXXX)cat >"$CONFIG" <<EOFcryptomount -u 24cf2eb3e4c64d8f89e822917f53b5d6set prefix='(crypto0)/grub'set root='(crypto0)'insmod normalnormalEOFgrub-mkimage \-p '(crypto0)/grub' \-O i386-pc \-c "$CONFIG" \-o /home/sexyowl/image \luks2 part_gpt part_msdos cryptodisk gcry_serpent pbkdf2 gcry_whirlpool btrfsrm "$CONFIG"Please tell me which command I need to use to overwrite my existing boot image file with new one? So that it works on my configuration (BIOS, GPT, 1MiB bios_grub partition).
Thank you very much in advance!
P.S. Right now, I can start my system manually by executing the same commands in the "grub rescue" as indicated in the script above, but I need to do it every time when I want to turn on my computer, so I want to make it automatically.
Oh, I really have no idea how to deal with "Bios", since I don't use it and have never tested it with encryption. https://wiki.archlinux.org/title/GRUB/Tips_and_tricks#Manual_configuration_of_core_image_for_early_boot doesn't mention bios, only EFI. I would use (U)EFI if possible.
Deleted before we saved it.
Ah, I didn't know about the pbkdf2 module. That may have been the missing link. I'll see if I can get that to work.
In my experience, both steps are required; the grub-install --modules=... and the grub-mkimage commands. Otherwise grub goes to rescue shell. Good luck
Deleted before we saved it.
I can confirm. I have an encrypted /boot with luks1 and everything works fine. I tried to convert the partition with cryptsetup convert and than reinstalling grub. It doesn't detect the encrypted partition anymore. This really sucks because i was waiting for this feature for a long time...
Deleted before we saved it.
The new version of grub added support to luks2 partition with pbkdf2. It seems they dont have updated grub install tho
No it isn't. This is a bug in GRUB.
Deleted before we saved it.