initramfs: use overlayfs for /lib/modules, if available

If overlay fs is available, use it for /lib/modules. This way the whole
/lib/modules will be writable and changes (like extra modules) will
persist in TemplateVM/StandaloneVM.

In practice, this will allow to conveniently build in-vm kernel modules,
even for dom0-provided kernels.

QubesOS/qubes-issues#2908
This commit is contained in:
Marek Marczykowski-Górecki 2019-06-06 01:28:15 +02:00
parent 90641b0dce
commit 9c6c825691
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 21 additions and 6 deletions

View File

@ -94,15 +94,26 @@ if ! [ -d "$NEWROOT/lib/modules/$kver/kernel" ]; then
echo "Waiting for /dev/xvdd device..." echo "Waiting for /dev/xvdd device..."
while ! [ -e /dev/xvdd ]; do sleep 0.1; done while ! [ -e /dev/xvdd ]; do sleep 0.1; done
# Mount only `uname -r` subdirectory, to leave the rest of /lib/modules writable
mkdir -p /tmp/modules mkdir -p /tmp/modules
mount -n -t ext3 /dev/xvdd /tmp/modules mount -n -t ext3 /dev/xvdd /tmp/modules
if ! [ -d "$NEWROOT/lib/modules/$kver" ]; then if /sbin/modprobe overlay; then
mount "$NEWROOT" -o remount,rw # if overlayfs is supported, use that to provide fully writable /lib/modules
mkdir -p "$NEWROOT/lib/modules/$kver" if ! [ -d "$NEWROOT/lib/.modules_work" ]; then
mount "$NEWROOT" -o remount,ro mount "$NEWROOT" -o remount,rw
mkdir -p "$NEWROOT/lib/.modules_work"
mount "$NEWROOT" -o remount,ro
fi
mount -t overlay none $NEWROOT/lib/modules -o lowerdir=/tmp/modules,upperdir=$NEWROOT/lib/modules,workdir=$NEWROOT/lib/.modules_work
else
# otherwise mount only `uname -r` subdirectory, to leave the rest of
# /lib/modules writable
if ! [ -d "$NEWROOT/lib/modules/$kver" ]; then
mount "$NEWROOT" -o remount,rw
mkdir -p "$NEWROOT/lib/modules/$kver"
mount "$NEWROOT" -o remount,ro
fi
mount --bind "/tmp/modules/$kver" "$NEWROOT/lib/modules/$kver"
fi fi
mount --bind "/tmp/modules/$kver" "$NEWROOT/lib/modules/$kver"
umount /tmp/modules umount /tmp/modules
rmdir /tmp/modules rmdir /tmp/modules
fi fi

View File

@ -9,6 +9,10 @@ depends() {
return 0 return 0
} }
installkernel() {
hostonly='' instmods overlay
}
install() { install() {
inst $moddir/init.sh /init inst $moddir/init.sh /init
inst_multiple \ inst_multiple \