Skip to content

Commit

Permalink
fix(dmsquash-live): add support for NFS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LaszloGombos authored and aafeijoo-suse committed Nov 7, 2022
1 parent 11eef2c commit 8caaad4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
3 changes: 3 additions & 0 deletions modules.d/90dmsquash-live/dmsquash-live-genrules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 1 addition & 15 deletions modules.d/90dmsquash-live/dmsquash-live-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules.d/90dmsquash-live/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]" "/etc/systemd/system/[email protected]"
Expand Down
35 changes: 35 additions & 0 deletions modules.d/90dmsquash-live/mount-overlayfs.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions modules.d/90dmsquash-live/parse-dmsquash-live.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/TEST-20-NFS/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8caaad4

Please sign in to comment.