desultory / ugrd

A minimalistic initramfs generator, designed for FDE
GNU General Public License v2.0
32 stars 11 forks source link

bcachefs support #84

Open alexminder opened 6 days ago

alexminder commented 6 days ago

Add bcachefs rootfs support please.

bcachefs have features wich can be used in initrd:

alexminder commented 6 days ago

There is interesting hook for dracut to checking, if bcachefs device complete:

https://github.com/kode54/dracut-hook-bcachefs/tree/main

desultory commented 6 days ago

I briefly looked into this, I think the main issue I found was the source device notation bcachefs uses. Do you know if that's used by any other system? I'm wondering if I should make it more generic or make a separate parsing method for bcachefs. I've found most common filesystems use slaves in the /sys info for the device.

https://github.com/desultory/ugrd/blob/main/src/ugrd/fs/mounts.py#L215

It does simple parsing by reading /proc/mounts and splitting it, it will see /dev/sdc:/dev/sdb:/dev/sda as the "device" and im not sure if that will potentially break anything. If bcachefs has userspace stuff which just handles this, it's not a big deal, but currently ugrd tries to resolve UUID information (by default) to be later used to mount the correct device. At the least this would have to be disabled for bcachefs, especially with multidevice.

With btrfs multidevice, you can just btrfs device scan then mount one of them by uuid, and it mounts the whole set. I don't really see how that module handles encryption or multidevice stuff, unless the bcachefs tools handle that transparently. https://github.com/kode54/dracut-hook-bcachefs/blob/main/bcachefs_finished.sh#L13

alexminder commented 5 days ago

Do you know if that's used by any other system?

As I know, no other.

With btrfs multidevice, you can just btrfs device scan then mount one of them by uuid, and it mounts the whole set.

From version 2.39 of libblkid it is possible to use UUID="", but with both of source notation systemd (mount generator) have problems.

I've found most common filesystems use slaves in the /sys info for the device.

Yes, /sys/fs/bcachefs/UUID/dev-N are presented as slaves and inside this dirs links exists to real block devices.

The command bcachefs show-super <DEVICE> on any bcachefs device shows all the information about FS and all the slaves (how many slaves, external, internal UUIDs).

If bcachefs has userspace stuff which just handles this,

bcachefs userspace utility from bcachefs-tools can do this.

I don't really see how that module handles encryption or multidevice stuff, unless the bcachefs tools handle that transparently.

This module don't check encryption. It is just try to mount it readonly. If one of slave not available mount will fail and process returns to initqueue for waiting. When udev enumerate all bcachefs type devices and bcachefs_finished.sh mounts success, then unmount and boot continues where itis possibe dracut to mount with UUID or /dev/sdc:/dev/sdb:/dev/sda as source.
For encrypted FS need bcachefs unlock before mounting.

desultory commented 5 days ago

Thanks for that info, I will try to test this soon.

One thing to consider is that ugrd does not use udev, so it would have to do something to manually bring devices online at boot time. It pulls blkid (currently 2.39.4 on gentoo), so using UUID notation for the filesystem may just be the most straightforward method.

If you want to test, you can add bcachefs to binaries in the config and set the "recovery" kernel cmdline arg to get a shell when it fails to boot.

If bcachefs says it's encrypted somewhere in the fs info under sys, it should be easy to make a simple hook that runs bcachefs unlock to handle decryption, and the typical uuid/partuuiid/label based mounting should be able to handle it from there.

alexminder commented 3 days ago

currently I can not build initramfs with ugrd:

ERROR    | Failed to run command: blkid /dev/sdc:/dev/sda
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/ugrd/main.py", line 158, in main
    generator.build()
  File "/usr/lib/python3.12/site-packages/ugrd/initramfs_generator.py", line 87, in build
    self.run_build()
  File "/usr/lib/python3.12/site-packages/ugrd/initramfs_generator.py", line 225, in run_build
    self.run_hook(task, force_exclude=True)
  File "/usr/lib/python3.12/site-packages/ugrd/initramfs_generator.py", line 141, in run_hook
    if function_output := self.run_func(function, *args, **kwargs):
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ugrd/initramfs_generator.py", line 103, in run_func
    if function_output := function(self):
                          ^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/zenlib/util/dict_check.py", line 36, in _contains
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/zenlib/util/dict_check.py", line 36, in _contains
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ugrd/fs/mounts.py", line 491, in autodetect_root
    get_blkid_info(self, root_dev)
  File "/usr/lib/python3.12/site-packages/zenlib/util/dict_check.py", line 36, in _contains
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ugrd/fs/mounts.py", line 212, in get_blkid_info
    blkid_output = self._run(['blkid', device]).stdout.decode().strip()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/ugrd/generator_helpers.py", line 157, in _run
    raise RuntimeError("Failed to run command: %s" % " ".join(cmd.args))
RuntimeError: Failed to run command: blkid /dev/sdc:/dev/sda
desultory commented 3 days ago

Ah, I think you may have to disable hostonly (--no-hostonly or hostonly = false) for this to work without patches. That was the main issue, I try to use blkid to get more device info for detection/validation, but blkid doesn't like that compound device notation. I could possibly just make it split off the first device and use that, but I'm not sure if there is some value in checking all devices.

desultory commented 13 hours ago

pic

Do you know if bcachefs supports mounting multi-device mounts with uuid? I'm only able to get it to work with paths.

I've added some stuff to the dev branch which should help with getting started testing this.