From: Laszlo Gombos Date: Sat, 20 Aug 2022 17:50:06 +0000 (+0000) Subject: fix(dmsquash-live): add support for NFS X-Git-Tag: 058~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8caaad4fc2d75982eb87f5ebc72a4c276986f756;p=thirdparty%2Fdracut-ng.git fix(dmsquash-live): add support for NFS Move overlayfs mount out into its own dedicated file so that we can call into it directly for NFS support. Add a new test case for overlayfs on top of NFS. --- diff --git a/modules.d/90dmsquash-live/dmsquash-live-genrules.sh b/modules.d/90dmsquash-live/dmsquash-live-genrules.sh index 8c7cad8fe..afd9924f9 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-genrules.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-genrules.sh @@ -15,4 +15,7 @@ case "$root" in /sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root "${root#live:}" fi ;; + nfs*) + cp /sbin/mount-overlayfs "$hookdir/mount/99-mount-overlayfs.sh" + ;; esac diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh index b0ce506eb..9ace8f705 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-root.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh @@ -425,22 +425,8 @@ if [ -n "$overlayfs" ]; then else ln -sf /run/initramfs/live /run/rootfsbase fi - mkdir -m 0755 -p /run/overlayfs - mkdir -m 0755 -p /run/ovlwork - if [ -n "$reset_overlay" ] && [ -h /run/overlayfs ]; then - ovlfs=$(readlink /run/overlayfs) - info "Resetting the OverlayFS overlay directory." - rm -r -- "${ovlfs:?}"/* "${ovlfs:?}"/.* > /dev/null 2>&1 - fi - if [ -n "$readonly_overlay" ] && [ -h /run/overlayfs-r ]; then - ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase - else - ovlfs=lowerdir=/run/rootfsbase - fi if [ -z "$DRACUT_SYSTEMD" ]; then - printf 'mount -t overlay LiveOS_rootfs -o%s,%s %s\n' "$ROOTFLAGS" \ - "$ovlfs",upperdir=/run/overlayfs,workdir=/run/ovlwork \ - "$NEWROOT" > "$hookdir"/mount/01-$$-live.sh + ln -sf /sbin/mount-overlayfs "$hookdir"/mount/01-$$-live.sh fi else if [ -z "$DRACUT_SYSTEMD" ]; then diff --git a/modules.d/90dmsquash-live/module-setup.sh b/modules.d/90dmsquash-live/module-setup.sh index cf3dfe534..98c2afcf1 100755 --- a/modules.d/90dmsquash-live/module-setup.sh +++ b/modules.d/90dmsquash-live/module-setup.sh @@ -31,6 +31,7 @@ install() { inst_hook pre-pivot 20 "$moddir/apply-live-updates.sh" inst_script "$moddir/dmsquash-live-root.sh" "/sbin/dmsquash-live-root" inst_script "$moddir/iso-scan.sh" "/sbin/iso-scan" + inst_script "$moddir/mount-overlayfs.sh" "/sbin/mount-overlayfs" if dracut_module_included "systemd-initrd"; then inst_script "$moddir/dmsquash-generator.sh" "$systemdutildir"/system-generators/dracut-dmsquash-generator inst_simple "$moddir/checkisomd5@.service" "/etc/systemd/system/checkisomd5@.service" diff --git a/modules.d/90dmsquash-live/mount-overlayfs.sh b/modules.d/90dmsquash-live/mount-overlayfs.sh new file mode 100755 index 000000000..fb2765669 --- /dev/null +++ b/modules.d/90dmsquash-live/mount-overlayfs.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh + +PATH=/usr/sbin:/usr/bin:/sbin:/bin + +getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes" +getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes" +getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay="" + +ROOTFLAGS="$(getarg rootflags)" + +if [ -n "$overlayfs" ]; then + if ! [ -e /run/rootfsbase ]; then + mkdir -m 0755 -p /run/rootfsbase + mount --bind "$NEWROOT" /run/rootfsbase + fi + + mkdir -m 0755 -p /run/overlayfs + mkdir -m 0755 -p /run/ovlwork + if [ -n "$reset_overlay" ] && [ -h /run/overlayfs ]; then + ovlfs=$(readlink /run/overlayfs) + info "Resetting the OverlayFS overlay directory." + rm -r -- "${ovlfs:?}"/* "${ovlfs:?}"/.* > /dev/null 2>&1 + fi + if [ -n "$readonly_overlay" ] && [ -h /run/overlayfs-r ]; then + ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase + else + ovlfs=lowerdir=/run/rootfsbase + fi + + if ! strstr "$(cat /proc/mounts)" LiveOS_rootfs; then + mount -t overlay LiveOS_rootfs -o "$ROOTFLAGS,$ovlfs",upperdir=/run/overlayfs,workdir=/run/ovlwork "$NEWROOT" + fi +fi diff --git a/modules.d/90dmsquash-live/parse-dmsquash-live.sh b/modules.d/90dmsquash-live/parse-dmsquash-live.sh index 8c4423b83..1a316a225 100755 --- a/modules.d/90dmsquash-live/parse-dmsquash-live.sh +++ b/modules.d/90dmsquash-live/parse-dmsquash-live.sh @@ -39,6 +39,9 @@ case "$liveroot" in live:/*.[Ii][Mm][Gg] | /*.[Ii][Mm][Gg]) [ -f "${root#live:}" ] && rootok=1 ;; + live:nfs*) + rootok=1 + ;; esac [ "$rootok" = "1" ] || return 1 diff --git a/test/TEST-20-NFS/test.sh b/test/TEST-20-NFS/test.sh index 5409f2b33..81e5710e7 100755 --- a/test/TEST-20-NFS/test.sh +++ b/test/TEST-20-NFS/test.sh @@ -181,6 +181,10 @@ test_nfsv3() { client_test "NFSv3 root=dhcp DHCP proto:IP:path,options" 52:54:00:12:34:07 \ "root=dhcp" 192.168.50.3 wsize=4096 || return 1 + client_test "NFSv3 Overlayfs root=nfs:..." 52:54:00:12:34:04 \ + "root=nfs:192.168.50.1:/nfs/client rd.live.image rd.live.overlay.overlayfs=1" \ + 192.168.50.1 -wsize=4096 || return 1 + return 0 } @@ -400,7 +404,7 @@ test_setup() { # Make client's dracut image "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ -o "plymouth dash ${OMIT_NETWORK}" \ - -a "debug watchdog ${USE_NETWORK}" \ + -a "dmsquash-live debug watchdog ${USE_NETWORK}" \ --no-hostonly-cmdline -N \ -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1