18971c
From 4584826e9a25fdddb876f07875423196d9fc8840 Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Mon, 7 Oct 2013 15:06:22 +0200
18971c
Subject: [PATCH] rootfs-block: add support for the rootfallback= kernel
18971c
 cmdline option
18971c
18971c
---
18971c
 dracut.cmdline.7.asc                     |  6 ++++
18971c
 modules.d/95rootfs-block/module-setup.sh |  3 +-
18971c
 modules.d/95rootfs-block/rootfallback.sh | 46 ++++++++++++++++++++++++
18971c
 3 files changed, 54 insertions(+), 1 deletion(-)
18971c
 create mode 100755 modules.d/95rootfs-block/rootfallback.sh
18971c
18971c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
18971c
index 09c47e85..4b2ab035 100644
18971c
--- a/dracut.cmdline.7.asc
18971c
+++ b/dracut.cmdline.7.asc
18971c
@@ -69,6 +69,12 @@ rootfstype=ext3
18971c
     force mounting _/_ and _/usr_ (if it is a separate device) read-write.
18971c
     See also ro option.
18971c
 
18971c
+**rootfallback=**_<path to blockdevice>_::
18971c
+    specify the block device to use as the root filesystem, if the normal root cannot be found.
18971c
+    This can only be a simple block device with a simple file system, for which the filesystem
18971c
+    driver is either compiled in, or added manually to the initramfs.
18971c
+    This parameter can be specified multiple times.
18971c
+
18971c
 **rd.auto** **rd.auto=1**::
18971c
     enable autoassembly of special devices like cryptoLUKS, dmraid, mdraid or lvm.
18971c
     Default is off as of dracut version >= 024.
18971c
diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh
18971c
index f066a79c..7e714eb0 100755
18971c
--- a/modules.d/95rootfs-block/module-setup.sh
18971c
+++ b/modules.d/95rootfs-block/module-setup.sh
18971c
@@ -44,5 +44,6 @@ install() {
18971c
         inst_hook pre-udev 30 "$moddir/block-genrules.sh"
18971c
         inst_hook mount 99 "$moddir/mount-root.sh"
18971c
     fi
18971c
-}
18971c
 
18971c
+    inst_hook initqueue/timeout 99 "$moddir/rootfallback.sh"
18971c
+}
18971c
diff --git a/modules.d/95rootfs-block/rootfallback.sh b/modules.d/95rootfs-block/rootfallback.sh
18971c
new file mode 100755
18971c
index 00000000..246ce9a4
18971c
--- /dev/null
18971c
+++ b/modules.d/95rootfs-block/rootfallback.sh
18971c
@@ -0,0 +1,46 @@
18971c
+#!/bin/sh
18971c
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
18971c
+# ex: ts=8 sw=4 sts=4 et filetype=sh
18971c
+
18971c
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
18971c
+
18971c
+for root in $(getargs rootfallback=); do
18971c
+    case "$root" in
18971c
+        block:LABEL=*|LABEL=*)
18971c
+            root="${root#block:}"
18971c
+            root="$(echo $root | sed 's,/,\\x2f,g')"
18971c
+            root="/dev/disk/by-label/${root#LABEL=}"
18971c
+            ;;
18971c
+        block:UUID=*|UUID=*)
18971c
+            root="${root#block:}"
18971c
+            root="${root#UUID=}"
18971c
+            root="$(echo $root | tr "[:upper:]" "[:lower:]")"
18971c
+            root="/dev/disk/by-uuid/${root#UUID=}"
18971c
+            ;;
18971c
+        block:PARTUUID=*|PARTUUID=*)
18971c
+            root="${root#block:}"
18971c
+            root="${root#PARTUUID=}"
18971c
+            root="$(echo $root | tr "[:upper:]" "[:lower:]")"
18971c
+            root="/dev/disk/by-partuuid/${root}"
18971c
+            ;;
18971c
+        block:PARTLABEL=*|PARTLABEL=*)
18971c
+            root="${root#block:}"
18971c
+            root="/dev/disk/by-partlabel/${root#PARTLABEL=}"
18971c
+            ;;
18971c
+    esac
18971c
+
18971c
+    if ! [ -b "$root" ]; then
18971c
+        warn "Could not find rootfallback $root"
18971c
+        continue
18971c
+    fi
18971c
+
18971c
+    if mount "$root" /sysroot; then
18971c
+        info "Mounted rootfallback $root"
18971c
+        exit 0
18971c
+    else
18971c
+        warn "Failed to mount rootfallback $root"
18971c
+        exit 1
18971c
+    fi
18971c
+done
18971c
+
18971c
+[ -e "$job" ] && rm -f "$job"