Subject: Re: bug#40999: GRUB prevents booting a degraded RAID1 array atop LUKS

From: Maxim Cournoyer <[email-masked]>
Date: Sun, 29 Aug 2021 02:15:20 -0400

Hello Giovanni!

I've finally reboot the machine, so am I sharing the information
requested:

Giovanni Biscuolo <[email-masked]> writes:

> Hi Maxim,
>
> I'd "debug" the issue trying to compare my Debian system config with
> yours since I'm also using a BTRFS RAID1 filesystem on LUKS.

Sounds useful!

[...]

> Please could you also provide the result of "lsblk -f"?

NAME          FSTYPE    FSVER LABEL      UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda
sda1
sda2        crypto_LU                  0792432c-78d8-4dcc-87c5-30200c3d02db
  cryptroot btrfs           my-root    2e97fbbd-fa4e-4858-948b-b3a89278a39b  201.2G    77% /var/lib/dock
sdb
sdb1
sdb2        crypto_LU                  a9aead40-9d01-4f7a-bb83-be70dd192b7b
  cryptroot-mirror
              btrfs           my-root    2e97fbbd-fa4e-4858-948b-b3a89278a39b
sdc
sdc1
sdc2        crypto_LU                  f0afd5c9-da70-46a7-9c6f-5d22913638bf
  cryptroot-mirror2
              btrfs           my-root    2e97fbbd-fa4e-4858-948b-b3a89278a39b
sdd           crypto_LU                  f04928db-90aa-458c-8908-036a620b74f6
luks-f04928db-90aa-458c-8908-036a620b74f6
              btrfs           Seagate2TB 231e9e86-e841-4c97-81f1-013a2b8d99c2    1.6T    12% /media/maxim/
sr0
sr1
zram0         swap                       76423fb7-9d60-47fc-b64c-313f0a7b1f55                [SWAP]
--8<---------------cut here---------------start------------->8---

The Btrfs file system in my case is labeled 'my-root' and composed of 3
drives in a raid1c3 btrfs array (3 copies).  @root is a subvolume on
which the root file system lives.

> This is (part of) my disks layout:
>
>
> sdc
> ..sdc1
> ..sdc2 vfat                      F6D8-67E3                             470.8M     1% /boot/efi
> ..sdc3 crypto_L                  e554b806-19ac-48b2-b521-b4e89839a756
> . ..crypt_swap01
> .      swap                      a43ce70c-dd35-47d8-a2ef-ef9d3c6d0885                [SWAP]
> ..sdc4 crypto_L                  820bfdf7-46f7-46f5-8536-7e1b0f04e70e
>   ..crypt_btrfs01_03
>        btrfs    btrfs_pool01     82afe97a-bb97-4b3d-90cb-93a058185b97
> sdd
> ..sdd1
> ..sdd2
> ..sdd3 crypto_L                  960aa919-182b-4604-a8be-8477c86386cc
> . ..crypt_swap02
> .      swap                      3f8f6974-05a9-4047-993a-c4ccb27eaa1d                [SWAP]
> ..sdd4 crypto_L                  c590c62e-6ac8-418c-9ea7-7ae9c79058c8
>   ..crypt_btrfs01_04
>        btrfs    btrfs_pool01     82afe97a-bb97-4b3d-90cb-93a058185b97  802.3G    57% /mnt/btrfs
>
>
> btrfs_pool01 is my BTRFS RAID1 filesystem, it includes /boot and /
> (root) and is on two ancrypted LUKS partitions, as you can see.
--8<---------------cut here---------------end--------------->8---

> Also, please what's your grub.cfg?

Here it is:

--8<---------------cut here---------------start------------->8---
# This file was generated from your Guix configuration.  Any changes
# will be lost upon reconfiguration.

# Set 'root' to the partition that contains /gnu/store.
search --file --set /@root/gnu/store/wlf9ccsl9pmch1dyv5x8c2gdngwn9m5i-grub-image.png

terminal_output console

insmod png
if background_image /@root/gnu/store/wlf9ccsl9pmch1dyv5x8c2gdngwn9m5i-grub-image.png; then
  set color_normal=light-gray/black
  set color_highlight=yellow/black
else
  set menu_color_normal=cyan/blue
  set menu_color_highlight=white/blue
fi
# Localization configuration.
# search --file --set /@root/gnu/store/q1cf63j2az4wlajg0caqy4nbndp0mvpm-grub-locales/[email-masked]
set locale_dir=/@root/gnu/store/q1cf63j2az4wlajg0caqy4nbndp0mvpm-grub-locales
set lang=en_US
insmod keylayouts
keymap /@root/gnu/store/25s8pbpv2fnidrgir26mn97g0ciq52gz-grub-keymap.dvorak

set default=0
set timeout=5
menuentry "GNU with Linux-Libre 5.13.12" {
  search --file --set /@root/gnu/store/hvmyb8maz32dy6ra5g68gr4wd08pzq3r-linux-libre-5.13.12/bzImage
  linux /@root/gnu/store/hvmyb8maz32dy6ra5g68gr4wd08pzq3r-linux-libre-5.13.12/bzImage --root=/dev/mapper/cryptroot --system=/gnu/store/6qa5ga0pkjbmz8ix8gfrpy65zkl16xi7-system --load=/gnu/store/6qa5ga0pkjbmz8ix8gfrpy65zkl16xi7-system/boot quiet snd_hda_intel.dmic_detect=0 modprobe.blacklist=rtl8187
  initrd /@root/gnu/store/kllyldndnazfxxrhkabgifx5zvgyz82q-raw-initrd/initrd.cpio.gz
}

submenu "GNU system, old configurations..." {
menuentry "GNU with Linux-Libre 5.13.11 (#275, 2021-08-23 23:17)" {
  search --file --set /@root/gnu/store/fznnj7bgs46czizzhn186606jgr52qnp-linux-libre-5.13.11/bzImage
  linux /@root/gnu/store/fznnj7bgs46czizzhn186606jgr52qnp-linux-libre-5.13.11/bzImage --root=/dev/mapper/cryptroot --system=/var/guix/profiles/system-275-link --load=/var/guix/profiles/system-275-link/boot quiet snd_hda_intel.dmic_detect=0 modprobe.blacklist=rtl8187
  initrd /@root/gnu/store/g73vj8qy6kfrgmr8gnmmzh2q59cbnf2w-raw-initrd/initrd.cpio.gz
}

[...]

if [ "${grub_platform}" == efi ]; then
  menuentry "Firmware setup" {
    fwsetup
  }
fi

--8<---------------cut here---------------end--------------->8---

> This is the config of a menuentry of mine:
>
>
> menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-82afe97a-bb97-4b3d-90cb-93a058185b97' {
> 	load_video
> 	insmod gzio
> 	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
> 	insmod part_gpt
> 	insmod cryptodisk
> 	insmod luks
> 	insmod gcry_rijndael
> 	insmod gcry_rijndael
> 	insmod gcry_sha256
> 	insmod btrfs
> 	cryptomount -u c590c62e6ac8418c9ea77ae9c79058c8
> 	set root='cryptouuid/c590c62e6ac8418c9ea77ae9c79058c8'
> 	if [ x$feature_platform_search_hint = xy ]; then
> 	  search --no-floppy --fs-uuid --set=root --hint='cryptouuid/c590c62e6ac8418c9ea77ae9c79058c8'  82afe97a-bb97-4b3d-90cb-93a058185b97
> 	else
> 	  search --no-floppy --fs-uuid --set=root 82afe97a-bb97-4b3d-90cb-93a058185b97
> 	fi
> 	echo	'Loading Linux 5.10.0-0.bpo.3-amd64 ...'
> 	linux	/debian_root/boot/vmlinuz-5.10.0-0.bpo.3-amd64 root=UUID=82afe97a-bb97-4b3d-90cb-93a058185b97 ro rootflags=subvol=debian_root ip=10.38.2.2::10.38.2.1:255.255.255.0:anemone:eth0:none quiet
> 	echo	'Loading initial ramdisk ...'
> 	initrd	/debian_root/boot/initrd.img-5.10.0-0.bpo.3-amd64
> }
>
>
> AFAIU this code (from the snippet above):
>
>
> 	if [ x$feature_platform_search_hint = xy ]; then
> 	  search --no-floppy --fs-uuid --set=root --hint='cryptouuid/c590c62e6ac8418c9ea77ae9c79058c8'  82afe97a-bb97-4b3d-90cb-93a058185b97
> 	else
> 	  search --no-floppy --fs-uuid --set=root 82afe97a-bb97-4b3d-90cb-93a058185b97
> 	fi
>
>
> sets [1] the root GRUB env variable to the first found device containing
> the UUID 82afe97a-bb97-4b3d-90cb-93a058185b97, that is the UUID of my
> BTRFS filesystem
>
> AFAIU (but still not tested) this means that if the device with UUID
> c590c62[...] is missing the search ensures that GRUB will find the next
> device containing the BTRFS filesystem identified by UUID 82afe97a[...]
>
> WDYT?

[...]

>>> Can you please provide the output of the "ls" command and the "set"
>>> command from the grub rescue shell?

See the attached screenshot of the result:

I was about to mess around in GRUB to edit the prefix, cmdline and
root values and do `insmod normal`, `normal` to proceed to boot, but
then the init RAM disk failed like so:

So there are more than one things to be adjusted :-).

Thank you, I'll look at the data with a fresh head later, but it seems
to me that we'd need to have GRUB fallback logic for the root devices
when RAID setups are detected.  I'll read on what GRUB has in store for
this kind of thing when I have a chance.

Your Debian GRUB config also has me wondering about the 'btrfs' modules,
and the others than Guix System is not using.

Thank you!

Maxim