From da3f3cd426e6c94df499c3813b0d029dd07d313d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 12 Jun 2017 13:02:31 +0200 Subject: [PATCH] initramfs: use symlink for rw root.img, instead of dm-linear Do not add 1:1 dm-linear when root.img (/dev/xvda) is read-write. This was to always have root device at /dev/mapper/dmroot, but unfortunately grub can't parse it properly (fails at looking for partition number of /dev/xvda1). There was a hack specifically for this, but it caused other partitions on xvda unavailable. On the other hand, symlink is enough to be able to mount always the same device. Now, grub detect that root fs is on /dev/xvda1, which is enough to have grub2-install working. Unfortunate effect is that it puts root=/dev/xvda1 at kernel command line, which breaks AppVMs based on this TemplateVM. But it's easier to fix kernel command line, than grub device detection logic. Fixes "initramfs: add support for root.img with partition table" QubesOS/qubes-issues#2557 --- dracut/full-dmroot/qubes_cow_setup.sh | 15 +++------------ dracut/simple/init.sh | 14 ++------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/dracut/full-dmroot/qubes_cow_setup.sh b/dracut/full-dmroot/qubes_cow_setup.sh index 13ef76a..f3b77ab 100644 --- a/dracut/full-dmroot/qubes_cow_setup.sh +++ b/dracut/full-dmroot/qubes_cow_setup.sh @@ -87,6 +87,7 @@ EOF echo "0 `cat /sys/class/block/$ROOT_DEV/size` snapshot /dev/$ROOT_DEV /dev/xvdc2 N 16" | \ dmsetup --noudevsync create dmroot || die "Qubes: FATAL: cannot create dmroot!" + dmsetup mknodes dmroot log_end else log_begin "Qubes: Doing R/W setup for TemplateVM..." @@ -99,17 +100,7 @@ EOF fi while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done mkswap /dev/xvdc1 - if [ "$ROOT_DEV" = "xvda1" ]; then - # grub2-probe for some reason can't parse dm-linear pointing at - # partition device directly, but can when it points at it indirectly - # through base device and offset; lets make life easier for users of - # grub2-install - DM_ROOT="/dev/xvda $(cat /sys/class/block/$ROOT_DEV/start)" - else - DM_ROOT="/dev/$ROOT_DEV 0" - fi - echo "0 `cat /sys/class/block/$ROOT_DEV/size` linear $DM_ROOT" | \ - dmsetup create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; } + printf 'KERNEL=="%s", SYMLINK+="mapper/dmroot"' "$ROOT_DEV" >> \ + /etc/udev/rules.d/99-root.rules log_end fi -dmsetup mknodes dmroot diff --git a/dracut/simple/init.sh b/dracut/simple/init.sh index 58e989f..b09a5d6 100644 --- a/dracut/simple/init.sh +++ b/dracut/simple/init.sh @@ -52,6 +52,7 @@ EOF echo "0 `cat /sys/class/block/$ROOT_DEV/size` snapshot /dev/$ROOT_DEV /dev/xvdc2 N 16" | \ dmsetup create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; } + dmsetup mknodes dmroot echo Qubes: done. else echo "Qubes: Doing R/W setup for TemplateVM..." @@ -64,20 +65,9 @@ EOF fi while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done mkswap /dev/xvdc1 - if [ "$ROOT_DEV" = "xvda1" ]; then - # grub2-probe for some reason can't parse dm-linear pointing at - # partition device directly, but can when it points at it indirectly - # through base device and offset; lets make life easier for users of - # grub2-install - DM_ROOT="/dev/xvda $(cat /sys/class/block/$ROOT_DEV/start)" - else - DM_ROOT="/dev/$ROOT_DEV 0" - fi - echo "0 `cat /sys/class/block/$ROOT_DEV/size` linear $DM_ROOT" | \ - dmsetup create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; } + ln -s ../$ROOT_DEV /dev/mapper/dmroot echo Qubes: done. fi -dmsetup mknodes dmroot modprobe ext4