Skip to content

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.

19 points13 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
19 · 88% up
Kind
Text
ID
o1opyj

Author

3
posts
1k
comments
0
media
View profile

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/device
2- 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 --recheck
3- 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.cfg
Reboot :-)

3 points

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:

  1. sda1 - 1MiB "bios" partition without filesystem with "bios_grub" flag;

  2. sda2 - 512MiB "boot" partition, it is a separate LUKS2-PBKDF2-encrypted boot partition mounted at "/boot";

  3. 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-random

Here are my encryption settings for "root" partition:

--type luks2 --cipher serpent-xts-plain64 --hash whirlpool --key-size 512 --pbkdf argon2id --iter-time 10000 --use-random

LUKS 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" --recheck

sudo grub-mkconfig -o /boot/grub/grub.cfg

Now I have run the following script and got GRUB "image" file in my home directory:

#!/bin/bash

CONFIG=$(mktemp /tmp/grub-config.XXXXX)

cat >"$CONFIG" <<EOF

cryptomount -u 24cf2eb3e4c64d8f89e822917f53b5d6

set prefix='(crypto0)/grub'

set root='(crypto0)'

insmod normal

normal

EOF

grub-mkimage \

-p '(crypto0)/grub' \

-O i386-pc \

-c "$CONFIG" \

-o /home/sexyowl/image \

luks2 part_gpt part_msdos cryptodisk gcry_serpent pbkdf2 gcry_whirlpool btrfs

rm "$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.

1 points
unknown author

Deleted before we saved it.

1 points

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.

1 points

In my experience, both steps are required; the grub-install --modules=... and the grub-mkimage commands. Otherwise grub goes to rescue shell. Good luck

1 points
unknown author

Deleted before we saved it.

1 points

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...

2 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.