Update to 032
[platform/upstream/dracut.git] / dracut.sh
index 2ac3d8b..117f877 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -91,6 +91,7 @@ Creates initial ramdisk images for preloading modules
                          firmwares, separated by :
   --kernel-only         Only install kernel drivers and firmware files
   --no-kernel           Do not install kernel drivers and firmware files
+  --print-cmdline       Print the kernel command line for the given disk layout
   --early-microcode     Combine early microcode with ramdisk
   --no-early-microcode  Do not combine early microcode with ramdisk
   --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
@@ -131,8 +132,12 @@ Creates initial ramdisk images for preloading modules
                          /usr/lib/dracut/modules.d.
                          Useful when running dracut from a git checkout.
   -H, --hostonly        Host-Only mode: Install only what is needed for
-                         booting the local host instead of a generic host.
+                        booting the local host instead of a generic host.
   -N, --no-hostonly     Disables Host-Only mode
+  --persistent-policy [POLICY]
+                        Use [POLICY] to address disks and partitions.
+                        POLICY can be any directory name found in /dev/disk.
+                        E.g. "by-uuid", "by-label"
   --fstab               Use /etc/fstab to determine the root device.
   --add-fstab [FILE]    Add file to the initramfs fstab
   --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
@@ -306,6 +311,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
     --long force \
     --long kernel-only \
     --long no-kernel \
+    --long print-cmdline \
     --long kernel-cmdline: \
     --long strip \
     --long nostrip \
@@ -326,6 +332,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
     --long host-only \
     --long no-hostonly \
     --long no-host-only \
+    --long persistent-policy: \
     --long fstab \
     --long help \
     --long bzip2 \
@@ -339,6 +346,8 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
     --long printsize \
     --long regenerate-all \
     --long noimageifnotneeded \
+    --long early-microcode \
+    --long no-early-microcode \
     -- "$@")
 
 if (( $? != 0 )); then
@@ -380,8 +389,9 @@ while :; do
         -f|--force)    force=yes;;
         --kernel-only) kernel_only="yes"; no_kernel="no";;
         --no-kernel)   kernel_only="no"; no_kernel="yes";;
-        --early-microcode) early_microcode="yes";;
-        --no-early-microcode) early_microcode="no";;
+        --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
+        --early-microcode) early_microcode_l="yes";;
+        --no-early-microcode) early_microcode_l="no";;
         --strip)       do_strip_l="yes";;
         --nostrip)     do_strip_l="no";;
         --hardlink)    do_hardlink_l="yes";;
@@ -405,6 +415,8 @@ while :; do
                        hostonly_l="yes" ;;
         -N|--no-hostonly|--no-host-only)
                        hostonly_l="no" ;;
+        --persistent-policy)
+                       persistent_policy_l="$2"; shift;;
         --fstab)       use_fstab_l="yes" ;;
         -h|--help)     long_usage; exit 1 ;;
         -i|--include)  push include_src "$2"
@@ -644,6 +656,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $prefix_l ]] && prefix=$prefix_l
 [[ $prefix = "/" ]] && unset prefix
 [[ $hostonly_l ]] && hostonly=$hostonly_l
+[[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
@@ -655,6 +668,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $show_modules_l ]] && show_modules=$show_modules_l
 [[ $nofscks_l ]] && nofscks="yes"
 [[ $ro_mnt_l ]] && ro_mnt="yes"
+[[ $early_microcode_l ]] && early_microcode=$early_microcode_l
+[[ $early_microcode ]] || early_microcode=no
 # eliminate IFS hackery when messing with fw_dir
 fw_dir=${fw_dir//:/ }
 
@@ -712,12 +727,14 @@ else
     exit 1
 fi
 
-inst /bin/sh
-if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
-    unset DRACUT_RESOLVE_LAZY
-    export DRACUT_RESOLVE_DEPS=1
+if ! [[ $print_cmdline ]]; then
+    inst /bin/sh
+    if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
+        unset DRACUT_RESOLVE_LAZY
+        export DRACUT_RESOLVE_DEPS=1
+    fi
+    rm -fr -- ${initdir}/*
 fi
-rm -fr -- ${initdir}/*
 
 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
     . $dracutbasedir/dracut-version.sh
@@ -799,7 +816,7 @@ if [[ -d $srcmods ]]; then
     }
 fi
 
-if [[ -f $outfile && ! $force ]]; then
+if [[ -f $outfile && ! $force && ! $print_cmdline ]]; then
     dfatal "Will not override existing initramfs ($outfile) without --force"
     exit 1
 fi
@@ -828,10 +845,6 @@ if [[ $hostonly ]]; then
             unset hostonly
         fi
     done
-    if ! [[ -d /run/udev/data ]]; then
-        dwarning "Turning off host-only mode: udev database not found!"
-        unset hostonly
-    fi
 fi
 
 declare -A host_fs_types
@@ -872,6 +885,11 @@ if [[ $hostonly ]]; then
         "/sbin" \
         "/lib" \
         "/lib64" \
+        "/usr" \
+        "/usr/bin" \
+        "/usr/sbin" \
+        "/usr/lib" \
+        "/usr/lib64" \
         "/boot";
     do
         mp=$(readlink -f "$mp")
@@ -892,7 +910,8 @@ if [[ $hostonly ]]; then
             while read _d _m _t _o _r; do
                 [[ "$_d" == \#* ]] && continue
                 [[ $_d ]] || continue
-                [[ $_t != "swap" ]] || [[ $_m != "swap" ]] && continue
+                [[ $_t != "swap" ]] && continue
+                [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
                 [[ "$_o" == *noauto* ]] && continue
                 [[ "$_d" == UUID\=* ]] && _d="/dev/disk/by-uuid/${_d#UUID=}"
                 [[ "$_d" == LABEL\=* ]] && _d="/dev/disk/by-label/$_d#LABEL=}"
@@ -903,7 +922,7 @@ if [[ $hostonly ]]; then
                         [[ $_mapper = \#* ]] && continue
                         [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
                         [[ "$_o" ]] || _o="$_p"
-                # skip mkswap swap
+                        # skip mkswap swap
                         [[ $_o == *swap* ]] && continue 2
                     done < /etc/crypttab
                 fi
@@ -937,6 +956,22 @@ for dev in ${host_devs[@]}; do
     check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
 done
 
+for dev in "${!host_fs_types[@]}"; do
+    [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
+    rootopts=$(find_dev_fsopts "$dev")
+    if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
+        journaldev=$(fs_get_option $rootopts "jdev")
+    elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
+        journaldev=$(fs_get_option $rootopts "logdev")
+    fi
+    if [[ $journaldev ]]; then
+        dev="$(readlink -f "$dev")"
+        push host_devs "$dev"
+        _get_fs_type "$dev"
+        check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
+    fi
+done
+
 [[ -d $udevdir ]] \
     || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
 if ! [[ -d "$udevdir" ]]; then
@@ -971,6 +1006,26 @@ export initdir dracutbasedir dracutmodules \
     DRACUT_VERSION udevdir prefix filesystems drivers \
     systemdutildir systemdsystemunitdir systemdsystemconfdir
 
+mods_to_load=""
+# check all our modules to see if they should be sourced.
+# This builds a list of modules that we will install next.
+for_each_module_dir check_module
+for_each_module_dir check_mount
+
+dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
+
+if [[ $print_cmdline ]]; then
+    modules_loaded=" "
+    # source our modules.
+    for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
+        _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
+        module_cmdline "$_d_mod"
+    done
+    unset moddir
+    printf "\n"
+    exit 0
+fi
+
 # Create some directory structure first
 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
 
@@ -1028,14 +1083,6 @@ if [[ $kernel_only != yes ]]; then
     fi
 fi
 
-mods_to_load=""
-# check all our modules to see if they should be sourced.
-# This builds a list of modules that we will install next.
-for_each_module_dir check_module
-for_each_module_dir check_mount
-
-[[ "$mods_to_load " == *01fips\ * ]] && export DRACUT_FIPS_MODE=1
-
 _isize=0 #initramfs size
 modules_loaded=" "
 # source our modules.