Harald Hoyer 7ba020
From 07149fe6bea01026b3ae37afb51b0fa831e9f27a Mon Sep 17 00:00:00 2001
Harald Hoyer 7ba020
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 7ba020
Date: Thu, 7 Jan 2016 09:56:36 +0100
Harald Hoyer 7ba020
Subject: [PATCH] nbd: add missing generator
Harald Hoyer 7ba020
Harald Hoyer 7ba020
---
Harald Hoyer 7ba020
 modules.d/95nbd/nbd-generator.sh | 55 ++++++++++++++++++++++++++++++++++++++++
Harald Hoyer 7ba020
 1 file changed, 55 insertions(+)
Harald Hoyer 7ba020
 create mode 100755 modules.d/95nbd/nbd-generator.sh
Harald Hoyer 7ba020
Harald Hoyer 7ba020
diff --git a/modules.d/95nbd/nbd-generator.sh b/modules.d/95nbd/nbd-generator.sh
Harald Hoyer 7ba020
new file mode 100755
Harald Hoyer 7ba020
index 0000000..de52d11
Harald Hoyer 7ba020
--- /dev/null
Harald Hoyer 7ba020
+++ b/modules.d/95nbd/nbd-generator.sh
Harald Hoyer 7ba020
@@ -0,0 +1,55 @@
Harald Hoyer 7ba020
+#!/bin/sh
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+[ -z "$root" ] && root=$(getarg root=)
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+[ "${root%%:*}" = "nbd" ] || exit 0
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+GENERATOR_DIR="$2"
Harald Hoyer 7ba020
+[ -z "$GENERATOR_DIR" ] && exit 1
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+ROOTFLAGS="$(getarg rootflags)"
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+nroot=${root#nbd:}
Harald Hoyer 7ba020
+nbdserver=${nroot%%:*}; nroot=${nroot#*:}
Harald Hoyer 7ba020
+nbdport=${nroot%%:*}; nroot=${nroot#*:}
Harald Hoyer 7ba020
+nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
Harald Hoyer 7ba020
+nbdflags=${nroot%%:*}
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+if [ "$nbdflags" = "$nbdfstype" ]; then
Harald Hoyer 7ba020
+    unset nbdflags
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
+if [ "$nbdfstype" = "$nbdport" ]; then
Harald Hoyer 7ba020
+    unset nbdfstype
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+[ -n "$nbdflags" ] && ROOTFLAGS="$nbdflags"
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+if getarg "ro"; then
Harald Hoyer 7ba020
+    if [ -n "$ROOTFLAGS" ]; then
Harald Hoyer 7ba020
+        ROOTFLAGS="$ROOTFLAGS,ro"
Harald Hoyer 7ba020
+    else
Harald Hoyer 7ba020
+        ROOTFLAGS="ro"
Harald Hoyer 7ba020
+    fi
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+if [ -n "$nbdfstype" ]; then
Harald Hoyer 7ba020
+    ROOTFSTYPE="$nbdfstype"
Harald Hoyer 7ba020
+else
Harald Hoyer 7ba020
+    ROOTFSTYPE=$(getarg rootfstype=) || unset ROOTFSTYPE
Harald Hoyer 7ba020
+fi
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+{
Harald Hoyer 7ba020
+    echo "[Unit]"
Harald Hoyer 7ba020
+    echo "Before=initrd-root-fs.target"
Harald Hoyer 7ba020
+    echo "[Mount]"
Harald Hoyer 7ba020
+    echo "Where=/sysroot"
Harald Hoyer 7ba020
+    echo "What=/dev/root"
Harald Hoyer 7ba020
+    [ -n "$ROOTFSTYPE" ] && echo "Type=${ROOTFSTYPE}"
Harald Hoyer 7ba020
+    [ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
Harald Hoyer 7ba020
+} > "$GENERATOR_DIR"/sysroot.mount
Harald Hoyer 7ba020
+
Harald Hoyer 7ba020
+exit 0