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
This commit is contained in:
Marek Marczykowski-Górecki 2017-06-12 13:02:31 +02:00
parent e9b8e5a4d1
commit da3f3cd426
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 5 additions and 24 deletions

View File

@ -87,6 +87,7 @@ EOF
echo "0 `cat /sys/class/block/$ROOT_DEV/size` snapshot /dev/$ROOT_DEV /dev/xvdc2 N 16" | \ 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 --noudevsync create dmroot || die "Qubes: FATAL: cannot create dmroot!"
dmsetup mknodes dmroot
log_end log_end
else else
log_begin "Qubes: Doing R/W setup for TemplateVM..." log_begin "Qubes: Doing R/W setup for TemplateVM..."
@ -99,17 +100,7 @@ EOF
fi fi
while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done
mkswap /dev/xvdc1 mkswap /dev/xvdc1
if [ "$ROOT_DEV" = "xvda1" ]; then printf 'KERNEL=="%s", SYMLINK+="mapper/dmroot"' "$ROOT_DEV" >> \
# grub2-probe for some reason can't parse dm-linear pointing at /etc/udev/rules.d/99-root.rules
# 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; }
log_end log_end
fi fi
dmsetup mknodes dmroot

View File

@ -52,6 +52,7 @@ EOF
echo "0 `cat /sys/class/block/$ROOT_DEV/size` snapshot /dev/$ROOT_DEV /dev/xvdc2 N 16" | \ 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 create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; }
dmsetup mknodes dmroot
echo Qubes: done. echo Qubes: done.
else else
echo "Qubes: Doing R/W setup for TemplateVM..." echo "Qubes: Doing R/W setup for TemplateVM..."
@ -64,20 +65,9 @@ EOF
fi fi
while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done
mkswap /dev/xvdc1 mkswap /dev/xvdc1
if [ "$ROOT_DEV" = "xvda1" ]; then ln -s ../$ROOT_DEV /dev/mapper/dmroot
# 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; }
echo Qubes: done. echo Qubes: done.
fi fi
dmsetup mknodes dmroot
modprobe ext4 modprobe ext4