]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(overlayfs): split overlayfs mount in two steps
authorDavid Cassany <dcassany@suse.com>
Fri, 22 Sep 2023 14:28:48 +0000 (16:28 +0200)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Mon, 30 Oct 2023 13:01:40 +0000 (09:01 -0400)
This commit splits the creation of required overlayfs underlaying
directories and the actual overlayfs mount. This way it is still
possible to mount the overlayfs with the generated sysroot.mount that
dmsquash-live creates.

The overlayfs tree is created in a pre-mount hook so it is executed
before sysroot.mount is started. Otherwise sysroot.mount starts and
fails before mount hooks are executed.

Signed-off-by: David Cassany <dcassany@suse.com>
modules.d/90overlayfs/module-setup.sh
modules.d/90overlayfs/mount-overlayfs.sh
modules.d/90overlayfs/prepare-overlayfs.sh [new file with mode: 0755]

index 27aa7cfa585b513a358729eb026dbd3868e4dd07..893e2dc366f751cb3e15797b9129d2d28fa4920d 100755 (executable)
@@ -15,4 +15,5 @@ installkernel() {
 
 install() {
     inst_hook mount 01 "$moddir/mount-overlayfs.sh"
+    inst_hook pre-mount 01 "$moddir/prepare-overlayfs.sh"
 }
index 7e2da1a804e673f9eca80e446e850af4114a9794..e1d23fb443867b7ac7b4449c2ca7163a5d2cef96 100755 (executable)
@@ -3,24 +3,11 @@
 type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
 
 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
-        ovlfsdir=$(readlink /run/overlayfs)
-        info "Resetting the OverlayFS overlay directory."
-        rm -r -- "${ovlfsdir:?}"/* "${ovlfsdir:?}"/.* > /dev/null 2>&1
-    fi
     if [ -n "$readonly_overlay" ] && [ -h /run/overlayfs-r ]; then
         ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase
     else
diff --git a/modules.d/90overlayfs/prepare-overlayfs.sh b/modules.d/90overlayfs/prepare-overlayfs.sh
new file mode 100755 (executable)
index 0000000..87bcc19
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
+getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes"
+
+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
+        ovlfsdir=$(readlink /run/overlayfs)
+        info "Resetting the OverlayFS overlay directory."
+        rm -r -- "${ovlfsdir:?}"/* "${ovlfsdir:?}"/.* > /dev/null 2>&1
+    fi
+fi