Blame 0048-Generate-fallback-mount-unit-for-root-filesystem.patch

Harald Hoyer b94732
From bd44831b825da5bf38f883344c3e25844bee4df7 Mon Sep 17 00:00:00 2001
Harald Hoyer b94732
From: Thorsten Behrens <tbehrens@suse.com>
Harald Hoyer b94732
Date: Thu, 11 Dec 2014 15:46:09 +0100
Harald Hoyer b94732
Subject: [PATCH] Generate fallback mount unit for root filesystem
Harald Hoyer b94732
Harald Hoyer b94732
If kernel cmdline has no root= provided, *and* the initrd carries
Harald Hoyer b94732
a default value, create a systemd mount unit to have it available
Harald Hoyer b94732
in /sysroot
Harald Hoyer b94732
Harald Hoyer b94732
References: bnc#855258
Harald Hoyer b94732
Harald Hoyer b94732
Signed-off-by: Thorsten Behrens <tbehrens@suse.com>
Harald Hoyer b94732
Signed-off-by: Thomas Renninger <trenn@suse.de>
Harald Hoyer b94732
---
Harald Hoyer b94732
 modules.d/98systemd/rootfs-generator.sh | 34 ++++++++++++++++++++++++++++++++-
Harald Hoyer b94732
 1 file changed, 33 insertions(+), 1 deletion(-)
Harald Hoyer b94732
Harald Hoyer b94732
diff --git a/modules.d/98systemd/rootfs-generator.sh b/modules.d/98systemd/rootfs-generator.sh
Harald Hoyer b94732
index 5b06137..f3c7d1f 100755
Harald Hoyer b94732
--- a/modules.d/98systemd/rootfs-generator.sh
Harald Hoyer b94732
+++ b/modules.d/98systemd/rootfs-generator.sh
Harald Hoyer b94732
@@ -35,6 +35,35 @@ generator_wait_for_dev()
Harald Hoyer b94732
     fi
Harald Hoyer b94732
 }
Harald Hoyer b94732
 
Harald Hoyer b94732
+generator_mount_rootfs()
Harald Hoyer b94732
+{
Harald Hoyer b94732
+    local _type=$2
Harald Hoyer b94732
+    local _flags=$3
Harald Hoyer b94732
+    local _name
Harald Hoyer b94732
+
Harald Hoyer b94732
+    [ -z "$1" ] && return 0
Harald Hoyer b94732
+
Harald Hoyer b94732
+    _name=$(dev_unit_name "$1")
Harald Hoyer b94732
+    [ -d /run/systemd/generator ] || mkdir -p /run/systemd/generator
Harald Hoyer b94732
+    if ! [ -f /run/systemd/generator/sysroot.mount ]; then
Harald Hoyer b94732
+        {
Harald Hoyer b94732
+            echo "[Unit]"
Harald Hoyer b94732
+            echo "Before=initrd-root-fs.target"
Harald Hoyer b94732
+            echo "RequiresOverridable=systemd-fsck@${_name}.service"
Harald Hoyer b94732
+            echo "After=systemd-fsck@${_name}.service"
Harald Hoyer b94732
+            echo "[Mount]"
Harald Hoyer b94732
+            echo "Where=/sysroot"
Harald Hoyer b94732
+            echo "What=$1"
Harald Hoyer b94732
+            echo "Options=${_flags}"
Harald Hoyer b94732
+            echo "Type=${_type}"
Harald Hoyer b94732
+        } > /run/systemd/generator/sysroot.mount
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+    if ! [ -L /run/systemd/generator/initrd-root-fs.target.requires/sysroot.mount ]; then
Harald Hoyer b94732
+        [ -d /run/systemd/generator/initrd-root-fs.target.requires ] || mkdir -p /run/systemd/generator/initrd-root-fs.target.requires
Harald Hoyer b94732
+        ln -s ../sysroot.mount /run/systemd/generator/initrd-root-fs.target.requires/sysroot.mount
Harald Hoyer b94732
+    fi
Harald Hoyer b94732
+}
Harald Hoyer b94732
+
Harald Hoyer b94732
 root=$(getarg root=)
Harald Hoyer b94732
 case "$root" in
Harald Hoyer b94732
     block:LABEL=*|LABEL=*)
Harald Hoyer b94732
@@ -61,6 +90,9 @@ case "$root" in
Harald Hoyer b94732
         rootok=1 ;;
Harald Hoyer b94732
 esac
Harald Hoyer b94732
 
Harald Hoyer b94732
-[ "${root%%:*}" = "block" ] && generator_wait_for_dev "${root#block:}" "$RDRETRY"
Harald Hoyer b94732
+if [ "${root%%:*}" = "block" ]; then
Harald Hoyer b94732
+   generator_wait_for_dev "${root#block:}" "$RDRETRY"
Harald Hoyer b94732
+   grep -q 'root=' /proc/cmdline || generator_mount_rootfs "${root#block:}" "$(getarg rootfstype=)" "$(getarg rootflags=)"
Harald Hoyer b94732
+fi
Harald Hoyer b94732
 
Harald Hoyer b94732
 exit 0