]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(dmsquash-live): add support for NFS
authorLaszlo Gombos <laszlo.gombos@gmail.com>
Sat, 20 Aug 2022 17:50:06 +0000 (17:50 +0000)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Mon, 7 Nov 2022 14:51:45 +0000 (15:51 +0100)
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.

modules.d/90dmsquash-live/dmsquash-live-genrules.sh
modules.d/90dmsquash-live/dmsquash-live-root.sh
modules.d/90dmsquash-live/module-setup.sh
modules.d/90dmsquash-live/mount-overlayfs.sh [new file with mode: 0755]
modules.d/90dmsquash-live/parse-dmsquash-live.sh
test/TEST-20-NFS/test.sh

index 8c7cad8fe86433891f2b9fcda469e825e4011135..afd9924f9d2c8927a67a750711fb4a2eba92d1d2 100755 (executable)
@@ -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
index b0ce506ebe582c422910ef5889286a109de5e769..9ace8f7057e1f67f63598d8a700db32cd894748c 100755 (executable)
@@ -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
index cf3dfe5342de194d6ac914d9e3a09bf9ec78fbe6..98c2afcf1a687667e7e10c3630837250c1524867 100755 (executable)
@@ -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 (executable)
index 0000000..fb27656
--- /dev/null
@@ -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
index 8c4423b83ee682dd6b44f611e76bcb9efe23b20a..1a316a22586b865307463ec49b39aa6d1657007b 100755 (executable)
@@ -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
index 5409f2b333792638cfe17a8812ce659f004df979..81e5710e7fca5134eee99844f2e324e4363bde56 100755 (executable)
@@ -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