712866
From 81c9e224820fa284806690fc64ac39c58e8760a3 Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Tue, 25 Feb 2014 12:35:32 +0100
712866
Subject: [PATCH] Add flag to toggle hostonly cmdline storing in the initramfs
712866
712866
--hostonly-cmdline:
712866
    Store kernel command line arguments needed in the initramfs
712866
712866
--no-hostonly-cmdline:
712866
    Do not store kernel command line arguments needed in the initramfs
712866
---
712866
 dracut.8.asc                             |  6 ++++++
712866
 dracut.conf.5.asc                        |  3 +++
712866
 dracut.sh                                | 27 +++++++++++++++++++++------
712866
 modules.d/90crypt/module-setup.sh        |  6 ++++--
712866
 modules.d/90dmraid/module-setup.sh       |  6 ++++--
712866
 modules.d/90lvm/module-setup.sh          |  6 ++++--
712866
 modules.d/90mdraid/module-setup.sh       |  6 ++++--
712866
 modules.d/95rootfs-block/module-setup.sh | 31 ++++++++++++++++++++-----------
712866
 8 files changed, 66 insertions(+), 25 deletions(-)
712866
712866
diff --git a/dracut.8.asc b/dracut.8.asc
5c6c2a
index b2946753..ba125c0d 100644
712866
--- a/dracut.8.asc
712866
+++ b/dracut.8.asc
712866
@@ -294,6 +294,12 @@ provide a valid _/etc/fstab_.
712866
 **-N, --no-hostonly**::
712866
     Disable Host-Only mode
712866
 
712866
+**--hostonly-cmdline**:
712866
+    Store kernel command line arguments needed in the initramfs
712866
+
712866
+**--no-hostonly-cmdline**:
712866
+    Do not store kernel command line arguments needed in the initramfs
712866
+
712866
 **--persistent-policy** _<policy>_::
712866
     Use _<policy>_ to address disks and partitions.
712866
     _<policy>_ can be any directory name found in /dev/disk.
712866
diff --git a/dracut.conf.5.asc b/dracut.conf.5.asc
5c6c2a
index 5c941188..be62da98 100644
712866
--- a/dracut.conf.5.asc
712866
+++ b/dracut.conf.5.asc
712866
@@ -76,6 +76,9 @@ Configuration files must have the extension .conf; other extensions are ignored.
712866
     Host-Only mode: Install only what is needed for booting the local host
712866
     instead of a generic host and generate host-specific configuration.
712866
 
712866
+*hostonly_cmdline*"__{yes|no}__"::
712866
+    If set, store the kernel command line arguments needed in the initramfs
712866
+
712866
 *persistent_policy=*"__<policy>__"::
712866
     Use _<policy>_ to address disks and partitions.
712866
     _<policy>_ can be any directory name found in /dev/disk.
712866
diff --git a/dracut.sh b/dracut.sh
5c6c2a
index c4bf4ebc..1c5e6889 100755
712866
--- a/dracut.sh
712866
+++ b/dracut.sh
712866
@@ -136,6 +136,10 @@ Creates initial ramdisk images for preloading modules
712866
   -H, --hostonly        Host-Only mode: Install only what is needed for
712866
                         booting the local host instead of a generic host.
712866
   -N, --no-hostonly     Disables Host-Only mode
712866
+  --hostonly-cmdline    Store kernel command line arguments needed
712866
+                        in the initramfs
712866
+  --no-hostonly-cmdline Do not store kernel command line arguments needed
712866
+                        in the initramfs
712866
   --persistent-policy [POLICY]
712866
                         Use [POLICY] to address disks and partitions.
712866
                         POLICY can be any directory name found in /dev/disk.
712866
@@ -376,7 +380,8 @@ while :; do
712866
         -a|--add)      push add_dracutmodules_l  "$2"; shift;;
712866
         --force-add)   push force_add_dracutmodules_l  "$2"; shift;;
712866
         --add-drivers) push add_drivers_l        "$2"; shift;;
712866
-        --omit-drivers) push omit_drivers_l      "$2"; shift;;
712866
+        --omit-drivers)
712866
+                       push omit_drivers_l      "$2"; shift;;
712866
         -m|--modules)  push dracutmodules_l      "$2"; shift;;
712866
         -o|--omit)     push omit_dracutmodules_l "$2"; shift;;
712866
         -d|--drivers)  push drivers_l            "$2"; shift;;
712866
@@ -389,7 +394,8 @@ while :; do
712866
         --mount)       push fstab_lines          "$2"; shift;;
712866
         --add-device|--device)
712866
                        push add_device_l         "$2"; shift;;
712866
-        --kernel-cmdline) push kernel_cmdline_l  "$2"; shift;;
712866
+        --kernel-cmdline)
712866
+                       push kernel_cmdline_l  "$2"; shift;;
712866
         --nofscks)     nofscks_l="yes";;
712866
         --ro-mnt)      ro_mnt_l="yes";;
712866
         -k|--kmoddir)  drivers_dir_l="$2"; shift;;
712866
@@ -402,9 +408,12 @@ while :; do
712866
         -f|--force)    force=yes;;
712866
         --kernel-only) kernel_only="yes"; no_kernel="no";;
712866
         --no-kernel)   kernel_only="no"; no_kernel="yes";;
712866
-        --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
712866
-        --early-microcode) early_microcode_l="yes";;
712866
-        --no-early-microcode) early_microcode_l="no";;
712866
+        --print-cmdline)
712866
+                       print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
712866
+        --early-microcode)
712866
+                       early_microcode_l="yes";;
712866
+        --no-early-microcode)
712866
+                       early_microcode_l="no";;
712866
         --strip)       do_strip_l="yes";;
712866
         --nostrip)     do_strip_l="no";;
712866
         --prelink)     do_prelink_l="yes";;
712866
@@ -430,11 +439,16 @@ while :; do
712866
                        hostonly_l="yes" ;;
712866
         -N|--no-hostonly|--no-host-only)
712866
                        hostonly_l="no" ;;
712866
+        --hostonly-cmdline)
712866
+                       hostonly_cmdline_l="yes" ;;
712866
+        --no-hostonly-cmdline)
712866
+                       hostonly_cmdline_l="no" ;;
712866
         --persistent-policy)
712866
                        persistent_policy_l="$2"; shift;;
712866
         --fstab)       use_fstab_l="yes" ;;
712866
         -h|--help)     long_usage; exit 1 ;;
712866
-        -i|--include)  push include_src "$2"
712866
+        -i|--include)
712866
+                       push include_src "$2"
712866
                        shift;;
712866
         --bzip2)       compress_l="bzip2";;
712866
         --lzma)        compress_l="lzma";;
712866
@@ -677,6 +691,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
712866
 [[ $prefix_l ]] && prefix=$prefix_l
712866
 [[ $prefix = "/" ]] && unset prefix
712866
 [[ $hostonly_l ]] && hostonly=$hostonly_l
712866
+[[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
712866
 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
712866
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
712866
 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
712866
diff --git a/modules.d/90crypt/module-setup.sh b/modules.d/90crypt/module-setup.sh
5c6c2a
index 18583915..267d39d5 100755
712866
--- a/modules.d/90crypt/module-setup.sh
712866
+++ b/modules.d/90crypt/module-setup.sh
712866
@@ -46,8 +46,10 @@ cmdline() {
712866
 
712866
 install() {
712866
 
712866
-    cmdline >> "${initdir}/etc/cmdline.d/90crypt.conf"
712866
-    echo >> "${initdir}/etc/cmdline.d/90crypt.conf"
712866
+    if [[ $hostonly_cmdline == "yes" ]]; then
712866
+        cmdline >> "${initdir}/etc/cmdline.d/90crypt.conf"
712866
+        echo >> "${initdir}/etc/cmdline.d/90crypt.conf"
712866
+    fi
712866
 
712866
     inst_multiple cryptsetup rmdir readlink umount
712866
     inst_script "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
712866
diff --git a/modules.d/90dmraid/module-setup.sh b/modules.d/90dmraid/module-setup.sh
5c6c2a
index 11181cf5..b230cb0e 100755
712866
--- a/modules.d/90dmraid/module-setup.sh
712866
+++ b/modules.d/90dmraid/module-setup.sh
712866
@@ -61,8 +61,10 @@ cmdline() {
712866
 install() {
712866
     local _i
712866
 
712866
-    cmdline >> "${initdir}/etc/cmdline.d/90dmraid.conf"
712866
-    echo >> "${initdir}/etc/cmdline.d/90dmraid.conf"
712866
+    if [[ $hostonly_cmdline == "yes" ]]; then
712866
+        cmdline >> "${initdir}/etc/cmdline.d/90dmraid.conf"
712866
+        echo >> "${initdir}/etc/cmdline.d/90dmraid.conf"
712866
+    fi
712866
 
712866
     inst_multiple dmraid
712866
     inst_multiple -o kpartx
712866
diff --git a/modules.d/90lvm/module-setup.sh b/modules.d/90lvm/module-setup.sh
5c6c2a
index f0c9b964..1c962d54 100755
712866
--- a/modules.d/90lvm/module-setup.sh
712866
+++ b/modules.d/90lvm/module-setup.sh
712866
@@ -48,8 +48,10 @@ install() {
712866
 
712866
     inst lvm
712866
 
712866
-    cmdline >> "${initdir}/etc/cmdline.d/90lvm.conf"
712866
-    echo >> "${initdir}/etc/cmdline.d/90lvm.conf"
712866
+    if [[ $hostonly_cmdline == "yes" ]]; then
712866
+        cmdline >> "${initdir}/etc/cmdline.d/90lvm.conf"
712866
+        echo >> "${initdir}/etc/cmdline.d/90lvm.conf"
712866
+    fi
712866
 
712866
     inst_rules "$moddir/64-lvm.rules"
712866
 
712866
diff --git a/modules.d/90mdraid/module-setup.sh b/modules.d/90mdraid/module-setup.sh
5c6c2a
index 34aae1e3..1e03847f 100755
712866
--- a/modules.d/90mdraid/module-setup.sh
712866
+++ b/modules.d/90mdraid/module-setup.sh
712866
@@ -65,8 +65,10 @@ install() {
712866
     inst $(command -v partx) /sbin/partx
712866
     inst $(command -v mdadm) /sbin/mdadm
712866
 
712866
-    cmdline  >> "${initdir}/etc/cmdline.d/90mdraid.conf"
712866
-    echo  >> "${initdir}/etc/cmdline.d/90mdraid.conf"
712866
+    if [[ $hostonly_cmdline == "yes" ]]; then
712866
+        cmdline  >> "${initdir}/etc/cmdline.d/90mdraid.conf"
712866
+        echo  >> "${initdir}/etc/cmdline.d/90mdraid.conf"
712866
+    fi
712866
 
712866
     # 
712866
     inst_rules 64-md-raid.rules
712866
diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh
5c6c2a
index 7e714eb0..5bb704a4 100755
712866
--- a/modules.d/95rootfs-block/module-setup.sh
712866
+++ b/modules.d/95rootfs-block/module-setup.sh
712866
@@ -10,17 +10,8 @@ depends() {
712866
     echo fs-lib
712866
 }
712866
 
712866
-cmdline() {
712866
-    local dev=/dev/block/$(find_root_block_device)
712866
-    if [ -e $dev ]; then
712866
-        printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$dev")")"
712866
-        printf " rootflags=%s" "$(find_mp_fsopts /)"
712866
-        printf " rootfstype=%s" "$(find_mp_fstype /)"
712866
-    fi
712866
-}
712866
-
712866
-install() {
712866
 
712866
+cmdline_journal() {
712866
     if [[ $hostonly ]]; then
712866
         for dev in "${!host_fs_types[@]}"; do
712866
             [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
712866
@@ -32,10 +23,28 @@ install() {
712866
             fi
712866
 
712866
             if [ -n "$journaldev" ]; then
712866
-                printf "%s\n" "root.journaldev=$journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf"
712866
+                printf " root.journaldev=%s" "$journaldev"
712866
             fi
712866
         done
712866
     fi
712866
+    return 0
712866
+}
712866
+
712866
+cmdline() {
712866
+    local dev=/dev/block/$(find_root_block_device)
712866
+    if [ -e $dev ]; then
712866
+        printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$dev")")"
712866
+        printf " rootflags=%s" "$(find_mp_fsopts /)"
712866
+        printf " rootfstype=%s" "$(find_mp_fstype /)"
712866
+    fi
712866
+    cmdline_journal
712866
+}
712866
+
712866
+install() {
712866
+    if [[ $hostonly_cmdline == "yes" ]]; then
712866
+        journaldev=$(cmdline_journal)
712866
+        [[ $journaldev ]] && printf "%s\n" "$journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf"
712866
+    fi
712866
 
712866
     inst_multiple umount
712866
     inst_multiple tr