bb31e7f
From edbd9ca058bcb19f351aca470581db1a67b706d7 Mon Sep 17 00:00:00 2001
bb31e7f
From: Fabian <fvogt@suse.com>
bb31e7f
Date: Fri, 11 Sep 2015 13:35:57 +0200
bb31e7f
Subject: [PATCH] dracut.sh: Support --mount with just mountpoint as parameter
bb31e7f
bb31e7f
Right now the --mount parameter of dracut expects a rather long fstab-like
bb31e7f
line. This makes it possible to invoke dracut with e.g. --mount /boot.
bb31e7f
---
bb31e7f
 dracut.8.asc |  4 ++++
bb31e7f
 dracut.sh    | 16 +++++++++++++++-
bb31e7f
 2 files changed, 19 insertions(+), 1 deletion(-)
bb31e7f
bb31e7f
diff --git a/dracut.8.asc b/dracut.8.asc
bb31e7f
index 5f45ed9..d22c1cb 100644
bb31e7f
--- a/dracut.8.asc
bb31e7f
+++ b/dracut.8.asc
bb31e7f
@@ -338,6 +338,10 @@ provide a valid _/etc/fstab_.
bb31e7f
     The default _<dump frequency>_ is "0".
bb31e7f
     the default _<fsck order>_ is "2".
bb31e7f
 
bb31e7f
+**--mount** "_<mountpoint>_"::
bb31e7f
+    Like above, but _<device>_, _<filesystem type>_ and _<filesystem options>_
bb31e7f
+    are determined by looking at the current mounts.
bb31e7f
+
bb31e7f
 **--add-device** _<device>_ ::
bb31e7f
     Bring up _<device>_ in initramfs, _<device>_ should be the device name.
bb31e7f
     This can be useful in hostonly mode for resume support when your swap is on
bb31e7f
diff --git a/dracut.sh b/dracut.sh
bb31e7f
index fb5d400..52a628a 100755
bb31e7f
--- a/dracut.sh
bb31e7f
+++ b/dracut.sh
bb31e7f
@@ -160,6 +160,8 @@ Creates initial ramdisk images for preloading modules
bb31e7f
   --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
bb31e7f
                         Mount device [DEV] on mountpoint [MP] with filesystem
bb31e7f
                         [FSTYPE] and options [FSOPTS] in the initramfs
bb31e7f
+  --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
bb31e7f
+			determined by looking at the current mounts.
bb31e7f
   --add-device "[DEV]"  Bring up [DEV] in initramfs
bb31e7f
   -i, --include [SOURCE] [TARGET]
bb31e7f
                         Include the files in the SOURCE directory into the
bb31e7f
@@ -1469,9 +1471,21 @@ if [[ $kernel_only != yes ]]; then
bb31e7f
 
bb31e7f
     for line in "${fstab_lines[@]}"; do
bb31e7f
         line=($line)
bb31e7f
-        [ -z "${line[3]}" ] && line[3]="defaults"
bb31e7f
+
bb31e7f
+        if [ -z "${line[1]}" ]; then
bb31e7f
+            # Determine device and mount options from current system
bb31e7f
+            mountpoint -q "${line[0]}" || derror "${line[0]} is not a mount point!"
bb31e7f
+            line=($(findmnt --raw -n --target "${line[0]}" --output=source,target,fstype,options))
bb31e7f
+            dinfo "Line for ${line[1]}: ${line[@]}"
bb31e7f
+        else
bb31e7f
+            # Use default options
bb31e7f
+            [ -z "${line[3]}" ] && line[3]="defaults"
bb31e7f
+        fi
bb31e7f
+
bb31e7f
+        # Default options for freq and passno
bb31e7f
         [ -z "${line[4]}" ] && line[4]="0"
bb31e7f
         [ -z "${line[5]}" ] && line[5]="2"
bb31e7f
+
bb31e7f
         strstr "${line[2]}" "nfs" && line[5]="0"
bb31e7f
         echo "${line[@]}" >> "${initdir}/etc/fstab"
bb31e7f
     done