]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dmsquash-live, livenet: Simplify OverlayFS read-only overlay setup.
authorFrederick Grose <fgrose@sugarlabs.org>
Mon, 20 Aug 2018 23:52:53 +0000 (19:52 -0400)
committerHarald Hoyer <harald@hoyer.xyz>
Tue, 21 Aug 2018 08:52:34 +0000 (10:52 +0200)
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
modules.d/90dmsquash-live/dmsquash-live-root.sh
modules.d/90livenet/livenet-generator.sh

index fe190012b517df96035efa28760b595be3ad6ee7..1129ddff3b58349c855dc66dcb8f29c5b7e6d252 100755 (executable)
@@ -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
index 0c5e010ec192aef85b333835dfc2fd676629fe7c..0f3d8f89f7383207b638c670fb20f8fe9d863910 100755 (executable)
@@ -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
index e2b5b6ebf817455387240f6b20ad2842291675d0..f0d128511a6ca6dc6ad71bd79b89e8a3a364746f 100755 (executable)
@@ -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