Harald Hoyer 87cf60
From 721bec3f143141fe3243e9f9dda9931f99b6b085 Mon Sep 17 00:00:00 2001
Harald Hoyer 87cf60
From: Harald Hoyer <harald@hoyer.xyz>
Harald Hoyer 87cf60
Date: Fri, 18 Aug 2017 09:33:10 +0200
Harald Hoyer 87cf60
Subject: [PATCH] Merge pull request #269 from xlpang/master
Harald Hoyer 87cf60
Harald Hoyer 87cf60
introduce new "--no-hostonly-default-device"  argument
Harald Hoyer 87cf60
---
Harald Hoyer 87cf60
 dracut.8.asc                             |  4 ++++
Harald Hoyer 87cf60
 dracut.sh                                | 11 +++++++++--
Harald Hoyer 87cf60
 modules.d/95rootfs-block/module-setup.sh |  6 ++++++
Harald Hoyer 87cf60
 3 files changed, 19 insertions(+), 2 deletions(-)
Harald Hoyer 87cf60
Harald Hoyer 87cf60
diff --git a/dracut.8.asc b/dracut.8.asc
Harald Hoyer 87cf60
index ca169189..23c53cc4 100644
Harald Hoyer 87cf60
--- a/dracut.8.asc
Harald Hoyer 87cf60
+++ b/dracut.8.asc
Harald Hoyer 87cf60
@@ -323,6 +323,10 @@ provide a valid _/etc/fstab_.
Harald Hoyer 87cf60
 **--no-hostonly-cmdline**:
Harald Hoyer 87cf60
     Do not store kernel command line arguments needed in the initramfs
Harald Hoyer 87cf60
 
Harald Hoyer 87cf60
+**--no-hostonly-default-device**:
Harald Hoyer 87cf60
+    Do not generate implicit host devices like root, swap, fstab, etc.
Harald Hoyer 87cf60
+    Use "--mount" or "--add-device" to explicitly add devices as needed.
Harald Hoyer 87cf60
+
Harald Hoyer 87cf60
 **--hostonly-i18n**:
Harald Hoyer 87cf60
     Install only needed keyboard and font files according to the host configuration (default).
Harald Hoyer 87cf60
 
Harald Hoyer 87cf60
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 87cf60
index 3a136d46..681a6b7a 100755
Harald Hoyer 87cf60
--- a/dracut.sh
Harald Hoyer 87cf60
+++ b/dracut.sh
Harald Hoyer 87cf60
@@ -151,6 +151,10 @@ Creates initial ramdisk images for preloading modules
Harald Hoyer 87cf60
                         in the initramfs
Harald Hoyer 87cf60
   --no-hostonly-cmdline Do not store kernel command line arguments needed
Harald Hoyer 87cf60
                         in the initramfs
Harald Hoyer 87cf60
+  --no-hostonly-default-device
Harald Hoyer 87cf60
+                        Do not generate implicit host devices like root,
Harald Hoyer 87cf60
+                        swap, fstab, etc. Use "--mount" or "--add-device"
Harald Hoyer 87cf60
+                        to explicitly add devices as needed.
Harald Hoyer 87cf60
   --hostonly-i18n       Install only needed keyboard and font files according
Harald Hoyer 87cf60
                         to the host configuration (default).
Harald Hoyer 87cf60
   --no-hostonly-i18n    Install all keyboard and font files available.
Harald Hoyer 87cf60
@@ -345,6 +349,7 @@ rearrange_params()
Harald Hoyer 87cf60
         --long no-host-only \
Harald Hoyer 87cf60
         --long hostonly-cmdline \
Harald Hoyer 87cf60
         --long no-hostonly-cmdline \
Harald Hoyer 87cf60
+        --long no-hostonly-default-device \
Harald Hoyer 87cf60
         --long persistent-policy: \
Harald Hoyer 87cf60
         --long fstab \
Harald Hoyer 87cf60
         --long help \
Harald Hoyer 87cf60
@@ -539,6 +544,8 @@ while :; do
Harald Hoyer 87cf60
                        i18n_install_all_l="yes" ;;
Harald Hoyer 87cf60
         --no-hostonly-cmdline)
Harald Hoyer 87cf60
                        hostonly_cmdline_l="no" ;;
Harald Hoyer 87cf60
+        --no-hostonly-default-device)
Harald Hoyer 87cf60
+                       hostonly_default_device="no" ;;
Harald Hoyer 87cf60
         --persistent-policy)
Harald Hoyer 87cf60
                        persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 87cf60
         --fstab)       use_fstab_l="yes" ;;
Harald Hoyer 87cf60
@@ -1133,7 +1140,7 @@ if (( ${#add_device_l[@]} )); then
Harald Hoyer 87cf60
     push_host_devs "${add_device_l[@]}"
Harald Hoyer 87cf60
 fi
Harald Hoyer 87cf60
 
Harald Hoyer 87cf60
-if [[ $hostonly ]]; then
Harald Hoyer 87cf60
+if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
Harald Hoyer 87cf60
     # in hostonly mode, determine all devices, which have to be accessed
Harald Hoyer 87cf60
     # and examine them for filesystem types
Harald Hoyer 87cf60
 
Harald Hoyer 87cf60
@@ -1300,7 +1307,7 @@ export initdir dracutbasedir \
Harald Hoyer 87cf60
     dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
Harald Hoyer 87cf60
     mods_to_load \
Harald Hoyer 87cf60
     fw_dir drivers_dir debug no_kernel kernel_only \
Harald Hoyer 87cf60
-    omit_drivers mdadmconf lvmconf root_dev \
Harald Hoyer 87cf60
+    omit_drivers mdadmconf lvmconf root_devs \
Harald Hoyer 87cf60
     use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
Harald Hoyer 87cf60
     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
Harald Hoyer 87cf60
     debug host_fs_types host_devs swap_devs sshkey add_fstab \
Harald Hoyer 87cf60
diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh
Harald Hoyer 87cf60
index 2b06bac2..987373b4 100755
Harald Hoyer 87cf60
--- a/modules.d/95rootfs-block/module-setup.sh
Harald Hoyer 87cf60
+++ b/modules.d/95rootfs-block/module-setup.sh
Harald Hoyer 87cf60
@@ -32,6 +32,12 @@ cmdline_journal() {
Harald Hoyer 87cf60
 cmdline_rootfs() {
Harald Hoyer 87cf60
     local _dev=/dev/block/$(find_root_block_device)
Harald Hoyer 87cf60
     local _fstype _flags _subvol
Harald Hoyer 87cf60
+
Harald Hoyer 87cf60
+    # "--no-hostonly-default-device" can result in empty root_devs
Harald Hoyer 87cf60
+    if [ "${#root_devs[@]}" -eq 0 ]; then
Harald Hoyer 87cf60
+        return
Harald Hoyer 87cf60
+    fi
Harald Hoyer 87cf60
+
Harald Hoyer 87cf60
     if [ -e $_dev ]; then
Harald Hoyer 87cf60
         printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$_dev")")"
Harald Hoyer 87cf60
         _fstype="$(find_mp_fstype /)"
Harald Hoyer 87cf60