From eb18a1fe29a3ffcd646fe6d25ae2d7d998b63e71 Mon Sep 17 00:00:00 2001 From: Frederick Grose Date: Mon, 20 Aug 2018 19:52:53 -0400 Subject: [PATCH] dmsquash-live, livenet: Simplify OverlayFS read-only overlay setup. Use multiple lower layer directories in a single OverlayFS mount with a transient overlay directory. Tolerate a command line with rd.live.overlay.readonly and NO persistent overlay by reconfiguring the OverlayFS mount options. Use more compatible shell syntax for testing symlinks, and use printf instead of echo -e. --- modules.d/90dmsquash-live/dmsquash-generator.sh | 9 ++++++- modules.d/90dmsquash-live/dmsquash-live-root.sh | 34 ++++++++++++++----------- modules.d/90livenet/livenet-generator.sh | 9 ++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/modules.d/90dmsquash-live/dmsquash-generator.sh b/modules.d/90dmsquash-live/dmsquash-generator.sh index fe190012..1129ddff 100755 --- a/modules.d/90dmsquash-live/dmsquash-generator.sh +++ b/modules.d/90dmsquash-live/dmsquash-generator.sh @@ -54,8 +54,10 @@ GENERATOR_DIR="$2" [ -z "$GENERATOR_DIR" ] && exit 1 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" +getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay="" getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes" [ -e /xor_overlayfs ] && xor_overlayfs="yes" +[ -e /xor_readonly ] && xor_readonly="--readonly" ROOTFLAGS="$(getarg rootflags)" { echo "[Unit]" @@ -64,7 +66,12 @@ ROOTFLAGS="$(getarg rootflags)" echo "Where=/sysroot" if [ "$overlayfs$xor_overlayfs" = "yes" ]; then echo "What=LiveOS_rootfs" - echo "Options=${ROOTFLAGS},lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork" + if [ "$readonly_overlay$xor_readonly" = "--readonly" ]; then + ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase + else + ovlfs=lowerdir=/run/rootfsbase + fi + echo "Options=${ROOTFLAGS},${ovlfs},upperdir=/run/overlayfs,workdir=/run/ovlwork" echo "Type=overlay" _dev=LiveOS_rootfs else diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh index 0c5e010e..0f3d8f89 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-root.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh @@ -137,7 +137,7 @@ do_live_overlay() { fi if [ -n "$overlayfs" ]; then unset -v overlayfs - [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" + [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;" fi setup="yes" else @@ -148,7 +148,7 @@ do_live_overlay() { ln -s /run/initramfs/overlayfs/ovlwork /run/ovlwork$opt if [ -z "$overlayfs" ]; then overlayfs="yes" - [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" + [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;" fi setup="yes" fi @@ -159,7 +159,7 @@ do_live_overlay() { ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork$opt if [ -z "$overlayfs" ]; then overlayfs="yes" - [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" + [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;" fi setup="yes" fi @@ -168,8 +168,7 @@ do_live_overlay() { modprobe overlay if [ $? != 0 ]; then m='OverlayFS is not available; using temporary Device-mapper overlay.' - unset -v overlayfs setup - [ -n "$reloadsysrootmountunit" ] && unset -v reloadsysrootmountunit + unset -v overlayfs setup reloadsysrootmountunit fi fi @@ -181,7 +180,7 @@ do_live_overlay() { m=' Unable to find a persistent overlay; using a temporary one.' m="$m"$'\n All root filesystem changes will be lost on shutdown.' m="$m"$'\n Press [Enter] to continue.' - echo -e "\n\n\n\n${m}\n\n\n" > /dev/kmsg + printf "\n\n\n\n${m}\n\n\n" > /dev/kmsg if [ -n "$DRACUT_SYSTEMD" ]; then if type plymouth >/dev/null 2>&1 && plymouth --ping ; then if getargbool 0 rhgb || getargbool 0 splash ; then @@ -203,6 +202,11 @@ do_live_overlay() { if [ -n "$overlayfs" ]; then mkdir -m 0755 /run/overlayfs mkdir -m 0755 /run/ovlwork + if [ -n "$readonly_overlay" ] && ! [ -h /run/overlayfs-r ]; then + info "No persistent overlay found." + unset -v readonly_overlay + [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="${reloadsysrootmountunit}:>/xor_readonly;" + fi else dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size*1024)) 2> /dev/null if [ -n "$setup" -a -n "$readonly_overlay" ]; then @@ -256,6 +260,7 @@ do_live_overlay() { fi ln -s $BASE_LOOPDEV /dev/live-base } +# end do_live_overlay() # we might have a genMinInstDelta delta file for anaconda to take advantage of if [ -e /run/initramfs/live/${live_dir}/osmin.img ]; then @@ -299,7 +304,7 @@ if [ -e "$SQUASHED" ]; then FSIMG=$SQUASHED if [ -z "$overlayfs" ]; then overlayfs="yes" - [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes" + [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit=":>/xor_overlayfs;" fi else die "Failed to find a root filesystem in $SQUASHED." @@ -366,7 +371,7 @@ if [ -b "$OSMIN_LOOPDEV" ]; then fi if [ -n "$reloadsysrootmountunit" ]; then - > /xor_overlayfs + eval "$reloadsysrootmountunit" systemctl daemon-reload fi @@ -374,21 +379,20 @@ ROOTFLAGS="$(getarg rootflags)" if [ -n "$overlayfs" ]; then mkdir -m 0755 /run/rootfsbase - if [ -n "$reset_overlay" ] && [ -L /run/overlayfs ]; then + 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" ]; then - mkdir -m 0755 /run/rootfsbase-r - mount -r $FSIMG /run/rootfsbase-r - mount -t overlay LiveOS_rootfs-r -oro,lowerdir=/run/overlayfs-r:/run/rootfsbase-r /run/rootfsbase + if [ -n "$readonly_overlay" ] && [ -h /run/overlayfs-r ]; then + ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase else - mount -r $FSIMG /run/rootfsbase + ovlfs=lowerdir=/run/rootfsbase fi + mount -r $FSIMG /run/rootfsbase if [ -z "$DRACUT_SYSTEMD" ]; then printf 'mount -t overlay LiveOS_rootfs -o%s,%s %s\n' "$ROOTFLAGS" \ - 'lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork' \ + "$ovlfs",upperdir=/run/overlayfs,workdir=/run/ovlwork \ "$NEWROOT" > $hookdir/mount/01-$$-live.sh fi else diff --git a/modules.d/90livenet/livenet-generator.sh b/modules.d/90livenet/livenet-generator.sh index e2b5b6eb..f0d12851 100755 --- a/modules.d/90livenet/livenet-generator.sh +++ b/modules.d/90livenet/livenet-generator.sh @@ -43,8 +43,10 @@ GENERATOR_DIR="$2" [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" +getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay="" getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes" [ -e /xor_overlayfs ] && xor_overlayfs="yes" +[ -e /xor_readonly ] && xor_readonly="--readonly" ROOTFLAGS="$(getarg rootflags)" { echo "[Unit]" @@ -53,7 +55,12 @@ ROOTFLAGS="$(getarg rootflags)" echo "Where=/sysroot" if [ "$overlayfs$xor_overlayfs" = "yes" ]; then echo "What=LiveOS_rootfs" - echo "Options=${ROOTFLAGS},lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork" + if [ "$readonly_overlay$xor_readonly" = "--readonly" ]; then + ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase + else + ovlfs=lowerdir=/run/rootfsbase + fi + echo "Options=${ROOTFLAGS},${ovlfs},upperdir=/run/overlayfs,workdir=/run/ovlwork" echo "Type=overlay" _dev=LiveOS_rootfs else