#1060411 initramfs: can't boot bcachefs storage with multi devices

#1060411#5
Date:
2024-01-10 20:34:18 UTC
From:
To:
Dear Maintainer,
I report a problem encountered with initramfs, relating to the new bcachefs
file system.

To test it, I installed a debian/bookwork server, with kernel 6.7 vannilla
recompiled locally and prepared a storage with bcachefs (1 ssd cache + 2 hdd
for replicas):

disk1/ssd: /dev/sda -> /dev/sda1 for esp (LABEL=NEWEFI)
                                           /dev/sda2 for cache bcachefs
(PARTUUID=ea702a10-728b-41d3-a80f-71cbf705dc28)
disk2/hdd: /dev/sdb -> /dev/sdb1 for storage bcachefs
(PARTUUID=679d2cdd-4dca-4707-83a8-0a86c095b345)
disk2/hdd: /dev/sdc -> /dev/sdc1 for storage bcachefs
(PARTUUID=09d070a2-449d-4c31-b214-cb225a0cbbaa)


I formatted it with command:

bcachefs format -LVMTEST --label=ssd.ssd1 /dev/sdb2 --label=hdd.hdd1 /dev/sdc1
--label=hdd.hdd2 /dev/sdd1 --replicas=2 --foreground_target=ssd
--promote_target=ssd --background_target=hdd


and mounted the root in the "/etc/fstab" file by adding the entries (indicating
"partuuid" of each device):

/dev/disk/by-partuuid/ea702a10-728b-41d3-a80f-71cbf705dc28:/dev/disk/by-
partuuid/679d2cdd-4dca-4707-83a8-0a86c095b345:/dev/disk/by-
partuuid/09d070a2-449d-4c31-b214-cb225a0cbbaa /  bcachefs  defaults,noatime   0
0

LABEL=NEWEFI      /boot/efi          vfat    defaults,noatime           0
0


using systemd loader with this entry:

title NEWTEST
linux /EFI/Linux/vmlinuz
options root=/dev/disk/by-
partuuid/ea702a10-728b-41d3-a80f-71cbf705dc28:/dev/disk/by-
partuuid/679d2cdd-4dca-4707-83a8-0a86c095b345:/dev/disk/by-
partuuid/09d070a2-449d-4c31-b214-cb225a0cbbaa rootfstype=bcachefs quiet
nosplash vga=791 noresume
initrd /EFI/Linux/initrd.img


This didn't work.


The problem is in the file "/usr/share/initramfs-tools/scripts/functions" and
depends on the "get_fstype" and "resolve_device" functions that cannot locate
or determine the file system (since bcachefs uses the form
device:device:device).


I managed to get it working by modifying these functions (see below)


Of course this is only a test, I just wanted to let you know about the issues
I've encountered.


Thanks,
Antonio
---- SIMPLE PATCH:
--- /usr/share/initramfs-tools/scripts/functions 2023-10-04 07:43:51.432542921 +0200 +++ /desktop/functions 2024-01-10 20:52:19.103154941 +0100 @@ -198,6 +198,12 @@ # Return value: indicates if an fs could be recognized get_fstype () { + if [ "$ROOTFSTYPE" == "bcachefs" ]; then + FSTYPE="$ROOTFSTYPE" + echo "$ROOTFSTYPE" + return 0 + fi + local FS FSTYPE FS="${1}" @@ -429,12 +435,16 @@ resolve_device() { DEV="$1" - case "$DEV" in - LABEL=* | UUID=* | PARTLABEL=* | PARTUUID=*) - DEV="$(blkid -l -t "$DEV" -o device)" || return 1 - ;; - esac - [ -e "$DEV" ] && echo "$DEV" + if [ "$ROOTFSTYPE" != "bcachefs" ]; then + case "$DEV" in + LABEL=* | UUID=* | PARTLABEL=* | PARTUUID=*) + DEV="$(blkid -l -t "$DEV" -o device)" || return 1 + ;; + esac + [ -e "$DEV" ] && echo "$DEV" + else + echo "$DEV" + fi } # Check a file system.
#1060411#10
Date:
2024-01-28 10:06:53 UTC
From:
To:
See also #1061525.

I'm a bit unsure how this would work; unless you manually set
rootfstype=bcachefs on the GRUB command line, I think this is autodetected
from fstype (in klibc-utils), which doesn't understand bcachefs right now?

/* Steinar */

#1060411#15
Date:
2024-01-28 11:12:51 UTC
From:
To:
Evidently, blkid does, so that part is fine.

With the attached patch, and bcachefs-tools upgraded to a version with
mount.bcachefs included, I can boot with root=UUID=<foo> using a multi-device
filesystem. grub-mkconfig still errors out, though.

/* Steinar */