add parameter --print-cmdline
authorHarald Hoyer <harald@redhat.com>
Thu, 15 Aug 2013 13:52:22 +0000 (15:52 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 15 Aug 2013 14:06:37 +0000 (16:06 +0200)
This prints the kernel command line parameters for the current disk
layout.

$ dracut --print-cmdline
rd.luks.uuid=luks-e68c8906-6542-4a26-83c4-91b4dd9f0471
rd.lvm.lv=debian/root rd.lvm.lv=debian/usr root=/dev/mapper/debian-root
rootflags=rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered
rootfstype=ext4

dracut-bash-completion.sh
dracut-functions.sh
dracut.8.asc
dracut.sh
modules.d/90crypt/module-setup.sh
modules.d/90dmraid/module-setup.sh
modules.d/90lvm/module-setup.sh
modules.d/90mdraid/module-setup.sh
modules.d/95rootfs-block/module-setup.sh

index 0f45f16..66b9bc9 100644 (file)
@@ -34,7 +34,7 @@ _dracut() {
                               --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
                               --xz --no-compress --gzip --list-modules --show-modules --keep
                               --printsize --regenerate-all --noimageifnotneeded --early-microcode
-                              --no-early-microcode'
+                              --no-early-microcode --print-cmdline'
 
                        [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
                               --omit-drivers --modules --omit --drivers --filesystems --install
index 7ee4587..1a73e60 100755 (executable)
@@ -304,6 +304,7 @@ get_persistent_dev() {
     [ -z "$_dev" ] && return
 
     for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
+        [[ $i == /dev/mapper/control ]] && continue
         [[ $i == /dev/mapper/mpath* ]] && continue
         _tmp=$(get_maj_min "$i")
         if [ "$_tmp" = "$_dev" ]; then
@@ -584,6 +585,7 @@ for_each_host_dev_and_slaves()
 check_vol_slaves() {
     local _lv _vg _pv
     for i in /dev/mapper/*; do
+        [[ $i == /dev/mapper/control ]] && continue
         _lv=$(get_maj_min $i)
         if [[ $_lv = $2 ]]; then
             _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
@@ -978,14 +980,14 @@ module_check() {
         $_moddir/check $hostonly
         _ret=$?
     else
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         check() { true; }
         . $_moddir/module-setup.sh
         is_func check || return 0
         [ $_forced -ne 0 ] && unset hostonly
         check $hostonly
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
     fi
     hostonly=$_hostonly
     return $_ret
@@ -1006,12 +1008,12 @@ module_check_mount() {
         mount_needs=1 $_moddir/check 0
         _ret=$?
     else
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         check() { false; }
         . $_moddir/module-setup.sh
         check 0
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
     fi
     unset mount_needs
     return $_ret
@@ -1030,12 +1032,33 @@ module_depends() {
         $_moddir/check -d
         return $?
     else
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         depends() { true; }
         . $_moddir/module-setup.sh
         depends
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
+        return $_ret
+    fi
+}
+
+# module_cmdline <dracut module>
+# execute the cmdline() function of module-setup.sh of <dracut module>
+# or the "cmdline" script, if module-setup.sh is not found
+module_cmdline() {
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _ret
+    [[ -d $_moddir ]] || return 1
+    if [[ ! -f $_moddir/module-setup.sh ]]; then
+        [[ -x $_moddir/cmdline ]] && . "$_moddir/cmdline"
+        return $?
+    else
+        unset check depends cmdline install installkernel
+        cmdline() { true; }
+        . $_moddir/module-setup.sh
+        cmdline
+        _ret=$?
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -1051,12 +1074,12 @@ module_install() {
         [[ -x $_moddir/install ]] && . "$_moddir/install"
         return $?
     else
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         install() { true; }
         . $_moddir/module-setup.sh
         install
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -1072,12 +1095,12 @@ module_installkernel() {
         [[ -x $_moddir/installkernel ]] && . "$_moddir/installkernel"
         return $?
     else
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         installkernel() { true; }
         . $_moddir/module-setup.sh
         installkernel
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
index f5199b0..08af94e 100644 (file)
@@ -225,6 +225,9 @@ example:
 **--no-kernel**::
     do not install kernel drivers and firmware files
 
+**--print-cmdline**::
+    print the kernel command line for the current disk layout
+
 **--mdadmconf**::
     include local _/etc/mdadm.conf_
 
index e690b4e..d3e750b 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
@@ -306,6 +307,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
     --long force \
     --long kernel-only \
     --long no-kernel \
+    --long print-cmdline \
     --long kernel-cmdline: \
     --long strip \
     --long nostrip \
@@ -380,6 +382,7 @@ while :; do
         -f|--force)    force=yes;;
         --kernel-only) kernel_only="yes"; no_kernel="no";;
         --no-kernel)   kernel_only="no"; no_kernel="yes";;
+        --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
         --early-microcode) early_microcode="yes";;
         --no-early-microcode) early_microcode="no";;
         --strip)       do_strip_l="yes";;
@@ -712,12 +715,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 +804,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
@@ -904,7 +909,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
@@ -988,6 +993,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
+
+[[ "$mods_to_load " == *01fips\ * ]] && 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}"
 
@@ -1045,14 +1070,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.
index bb014b9..67bc83d 100755 (executable)
@@ -26,25 +26,27 @@ installkernel() {
     instmods dm_crypt =crypto
 }
 
-install() {
-
-    check_crypt() {
-        local dev=$1 fs=$2 UUID
-
-        [[ $fs = "crypto_LUKS" ]] || return 1
-        UUID=$(blkid -u crypto -o export $dev \
-            | while read line; do
+cmdline() {
+    local dev UUID
+    for dev in "${!host_fs_types[@]}"; do
+        [[ "${host_fs_types[$dev]}" != "crypto_LUKS" ]] && continue
+
+        UUID=$(
+            blkid -u crypto -o export $dev \
+                | while read line; do
                 [[ ${line#UUID} = $line ]] && continue
                 printf "%s" "${line#UUID=}"
                 break
-                done)
-        [[ ${UUID} ]] || return 1
-        if ! [[ $kernel_only ]]; then
-            echo " rd.luks.uuid=luks-${UUID} " >> "${initdir}/etc/cmdline.d/90crypt.conf"
-        fi
-        return 0
-    }
+            done
+        )
+        [[ ${UUID} ]] || continue
+        printf "%s" " rd.luks.uuid=luks-${UUID}"
+    done
+}
+
+install() {
 
+    cmdline >> "${initdir}/etc/cmdline.d/90crypt.conf"
 
     inst_multiple cryptsetup rmdir readlink umount
     inst_script "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
@@ -74,8 +76,6 @@ install() {
         done < /etc/crypttab > $initdir/etc/crypttab
     fi
 
-    for_each_host_dev_fs check_crypt
-
     inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
 
     inst_multiple -o \
index 87465d9..b93db8f 100755 (executable)
@@ -23,13 +23,13 @@ depends() {
     return 0
 }
 
-install() {
-    local _i
-
-    check_dmraid() {
-        local dev=$1 fs=$2 holder DEVPATH DM_NAME majmin
-        [[ "$fs" != *_raid_member ]] && return 1
+cmdline() {
+    local _activated
+    declare -A _activated
 
+    for dev in "${!host_fs_types[@]}"; do
+        local holder DEVPATH DM_NAME majmin
+        [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue
 
         majmin=$(get_maj_min $dev)
         DEVPATH=$(
@@ -45,18 +45,23 @@ install() {
         for holder in "$DEVPATH"/holders/*; do
             [[ -e "$holder" ]] || continue
             dev="/dev/${holder##*/}"
-            DM_NAME="$(/usr/sbin/dmsetup info -c --noheadings -o name "$dev" 2>/dev/null)"
+            DM_NAME="$(dmsetup info -c --noheadings -o name "$dev" 2>/dev/null)"
             [[ ${DM_NAME} ]] && break
         done
 
-        [[ ${DM_NAME} ]] || return 1
-        if ! [[ $kernel_only ]]; then
-            echo " rd.dm.uuid=${DM_NAME} " >> "${initdir}/etc/cmdline.d/90dmraid.conf"
+        [[ ${DM_NAME} ]] || continue
+
+        if ! [[ ${_activated[${DM_NAME}]} ]]; then
+            printf "%s" " rd.dm.uuid=${DM_NAME}"
+            _activated["${DM_NAME}"]=1
         fi
-        return 0
-    }
+    done
+}
+
+install() {
+    local _i
 
-    for_each_host_dev_fs check_dmraid
+    cmdline >> "${initdir}/etc/cmdline.d/90dmraid.conf"
 
     inst_multiple dmraid
     inst_multiple -o kpartx
index 4b774c9..6925039 100755 (executable)
@@ -22,29 +22,42 @@ depends() {
     return 0
 }
 
-install() {
-    local _i
-    local _needthin
+get_host_lvs() {
     local _activated
-    inst lvm
-
-    check_lvm() {
-        local DM_VG_NAME DM_LV_NAME
-
-        eval $(/usr/sbin/dmsetup splitname --nameprefixes --noheadings --rows $1 2>/dev/null)
+    declare -A _activated
+
+    for dev in "${!host_fs_types[@]}"; do
+        [ -e /sys/block/${dev#/dev/}/dm/name ] || continue
+        [ -e /sys/block/${dev#/dev/}/dm/uuid ] || continue
+        uuid=$(</sys/block/${dev#/dev/}/dm/uuid)
+        [[ "${uuid#LVM-}" == "$uuid" ]] && continue
+        dev=$(</sys/block/${dev#/dev/}/dm/name)
+        eval $(dmsetup splitname --nameprefixes --noheadings --rows "$dev" 2>/dev/null)
         [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1
-        if ! [[ " ${_activated[*]} " == *\ ${DM_VG_NAME}/${DM_LV_NAME}\ * ]]; then
-            echo " rd.lvm.lv=${DM_VG_NAME}/${DM_LV_NAME} " >> "${initdir}/etc/cmdline.d/90lvm.conf"
-            push _activated "${DM_VG_NAME}/${DM_LV_NAME}"
-        fi
-        if ! [[ $_needthin ]]; then
-            [[ $(lvs --noheadings -o segtype ${DM_VG_NAME} 2>/dev/null) == *thin* ]] && _needthin=1
+        if ! [[ ${_activated[${DM_VG_NAME}/${DM_LV_NAME}]} ]]; then
+            printf "%s\n" "${DM_VG_NAME}/${DM_LV_NAME} "
+            _activated["${DM_VG_NAME}/${DM_LV_NAME}"]=1
         fi
+    done
+}
 
-        return 0
-    }
+cmdline() {
+    get_host_lvs | while read line; do
+        printf " rd.lvm.lv=$line"
+    done
+}
+
+install() {
+    local _i _needthin
 
-    for_each_host_dev_fs check_lvm
+    inst lvm
+
+    get_host_lvs | while read line; do
+        printf "%s" " rd.lvm.lv=$line"
+        if ! [[ $_needthin ]]; then
+            [[ "$(lvs --noheadings -o segtype ${line%%/*} 2>/dev/null)" == *thin* ]] && _needthin=1
+        fi
+    done >> "${initdir}/etc/cmdline.d/90lvm.conf"
 
     inst_rules "$moddir/64-lvm.rules"
 
@@ -81,7 +94,7 @@ install() {
     inst_libdir_file "libdevmapper-event-lvm*.so"
 
     if [[ $_needthin ]]; then
-        inst_multiple -o thin_dump thin_restore thin_check
+        inst_multiple -o thin_dump thin_restore thin_check thin_repair
     fi
 
 }
index b44ce50..2fe4074 100755 (executable)
@@ -26,32 +26,36 @@ installkernel() {
     instmods =drivers/md
 }
 
+cmdline() {
+    local _activated dev line UUID
+    declare -A _activated
+
+    for dev in "${!host_fs_types[@]}"; do
+        [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue
+
+        UUID=$(
+            /sbin/mdadm --examine --export $dev \
+                | while read line; do
+                [[ ${line#MD_UUID=} = $line ]] && continue
+                printf "%s" "${line#MD_UUID=} "
+            done
+        )
+
+        if ! [[ ${_activated[${UUID}]} ]]; then
+            printf "%s" " rd.md.uuid=${UUID}"
+            _activated["${UUID}"]=1
+        fi
+
+    done
+}
+
 install() {
     inst_multiple cat
     inst_multiple -o mdmon
     inst $(command -v partx) /sbin/partx
     inst $(command -v mdadm) /sbin/mdadm
 
-    check_mdraid() {
-        local dev=$1 fs=$2 holder DEVPATH MD_UUID
-        [[ "$fs" != *_raid_member ]] && return 1
-
-        MD_UUID=$(/sbin/mdadm --examine --export $dev \
-            | while read line; do
-                [[ ${line#MD_UUID} = $line ]] && continue
-                eval "$line"
-                echo $MD_UUID
-                break
-                done)
-
-        [[ ${MD_UUID} ]] || return 1
-        if ! [[ $kernel_only ]]; then
-            echo " rd.md.uuid=${MD_UUID} " >> "${initdir}/etc/cmdline.d/90mdraid.conf"
-        fi
-        return 0
-    }
-
-    for_each_host_dev_fs check_mdraid
+    cmdline  >> "${initdir}/etc/cmdline.d/90mdraid.conf"
 
     inst_rules 64-md-raid.rules
     # remove incremental assembly from stock rules, so they don't shadow
index 32eec4a..6792f1d 100755 (executable)
@@ -10,6 +10,15 @@ depends() {
     echo fs-lib
 }
 
+cmdline() {
+    local dev=/dev/block/$(find_root_block_device)
+    if [ -e $dev ]; then
+        printf " root=%s" $(get_persistent_dev "$dev")
+        printf " rootflags=%s" $(find_mp_fsopts /)
+        printf " rootfstype=%s" $(find_mp_fstype /)
+    fi
+}
+
 install() {
 
     if [[ $hostonly ]]; then