Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mounting dm-init file systems in the initrd #13618

Closed
dm0- opened this issue Sep 22, 2019 · 4 comments
Closed

Support mounting dm-init file systems in the initrd #13618

dm0- opened this issue Sep 22, 2019 · 4 comments
Labels

Comments

@dm0-
Copy link
Contributor

dm0- commented Sep 22, 2019

Is your feature request related to a problem? Please describe.
When using device mapper with dm-mod.create, the kernel only creates /dev/dm-0--not /dev/mapper/$name--so systemd can't mount it due to device path canonicalization (and waiting on the .device unit).

Describe the solution you'd like
I want to be able to specify root=/dev/dm-0 dm-mod.create="..." and have the system successfully boot.

Describe alternatives you've considered
It works by adding a new service to the initrd that runs udevadm trigger to create the nodes, but is dm-mod.create something that could be supported out of the box?

@poettering
Copy link
Member

Not grokking this... For dm related questions its best to get some DM people involved...

@dm0-
Copy link
Contributor Author

dm0- commented Oct 8, 2019

Here is a script to set up an example, if it helps.

# Create a root file system image.
truncate --size=50M root.img
mke2fs -m 0 root.img
sudo mount -o loop,X-mount.mkdir root.img root
sudo mkdir root/bin
sudo cp -t root/bin /sbin/busybox
for cmd in ash echo poweroff sleep
do sudo ln -fns busybox "root/bin/$cmd"
done
sudo tee root/init << 'EOF' > /dev/null
#!/bin/ash -eu
echo 'Successfully booted into the image'
sleep 10
exec poweroff -f
EOF
sudo chmod 0755 root/init
sudo ln -fst root/bin ../init
sudo umount -d root

# Create a verity image.
declare -A verity
while read
do verity[${REPLY%%:*}]=${REPLY#*:}
done < <(veritysetup format root.img sig.img)
cat root.img sig.img > verity.img

# Write kernel arguments using dm-init to set up the root device.
echo > kargs.txt \
    'dm-mod.create="root,,,ro,0' $(( $(stat --format=%s root.img) / 512 )) \
    verity ${verity[Hash type]} /dev/sda /dev/sda \
    ${verity[Data block size]} ${verity[Hash block size]} \
    ${verity[Data blocks]} $(( ${verity[Data blocks]} + 1 )) \
    ${verity[Hash algorithm]} ${verity[Root hash]} \
    ${verity[Salt]} '0"' root=/dev/dm-0

So if you have a kernel with dm-init and dm-verity built into it, you can run qemu-kvm -m 1G -kernel vmlinuz -append "$(<kargs.txt)" verity.img to boot into the verity device. The problem is that if you include a systemd initrd with -initrd initrd.img to handle some other setup, it won't be able to mount the root device. (You can test this part using a kernel like Fedora's without the device mapper drivers as builtins; the modules will be loaded automatically if they are included in the initrd.)

The first issue is that systemd waits forever for dev-dm\x2d0.device to start. The second issue is that it fails to mount the device due to device path canonicalization and /dev/mapper/root not being created by dm-init (i.e. mount would work with the -c/--no-canonicalize option). I don't remember what I set up to get past the first issue but not the second, sorry. A call to udevadm trigger fixes both issues, so my question/request was if something could handle this without having to customize initrds.

@poettering
Copy link
Member

it appears the default DM udev rules don't cover this stuff. please ping the DM folks about this, I doubt there's much to do from our side on this, we just pick up any block device marked to be ready.

@poettering poettering added the udev label Nov 4, 2019
@dm0-
Copy link
Contributor Author

dm0- commented Dec 2, 2019

I e-mailed dm-devel a month ago which was unhelpful, so I'll just close this and continue to carry workarounds until I can look into doing something better.

@dm0- dm0- closed this as completed Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants