]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - dracut-functions.sh
Merge pull request #172 from haraldh/RHEL-7
[thirdparty/dracut.git] / dracut-functions.sh
index 3f56316763a2b0f119c6fe0eece8d12be75519ee..61726e44e7f38c96d1b3598bd68263bea6530a79 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-export LC_ALL=C
+export LC_MESSAGES=C
 
 if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
-    if [[ -d "$initdir/.kernelmodseen" ]]; then
-        mkdir -p "$initdir/.kernelmodseen"
+    if [[ -d "$initdir/.kernelmodseen" ]]; then
+        DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
     fi
-    DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
-fi
-
-if [[ $initdir ]] && ! [[ -d $initdir ]]; then
-    mkdir -p "$initdir"
 fi
 
 # Generic substring function.  If $2 is in $1, return 0.
 strstr() { [[ $1 = *$2* ]]; }
+# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
+str_starts() { [ "${1#"$2"*}" != "$1" ]; }
+# returns OK if $1 contains literal string $2 at the end, and isn't empty
+str_ends() { [ "${1%*"$2"}" != "$1" ]; }
+
+# helper function for check() in module-setup.sh
+# to check for required installed binaries
+# issues a standardized warning message
+require_binaries() {
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    if [[ "$1" = "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for cmd in "$@"; do
+        if ! find_binary "$cmd" &>/dev/null; then
+            dinfo "dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
+            ((_ret++))
+        fi
+    done
+    return $_ret
+}
+
+require_any_binary() {
+    local _module_name="${moddir##*/}"
+    local _ret=1
+
+    if [[ "$1" = "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for cmd in "$@"; do
+        if find_binary "$cmd" &>/dev/null; then
+            _ret=0
+            break
+        fi
+    done
+
+    if (( $_ret != 0 )); then
+        dinfo "$_module_name: Could not find any command of '$@'!"
+        return 1
+    fi
+
+    return 0
+}
 
 # find a binary.  If we were not passed the full path directly,
 # search in the usual places to find the binary.
 find_binary() {
     if [[ -z ${1##/*} ]]; then
-        if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; };  then
-            echo $1
+        if [[ -x $1 ]] || { [[ "$1" == *.so* ]] && ldd "$1" &>/dev/null; };  then
+            printf "%s\n" "$1"
             return 0
         fi
     fi
 
-    type -P $1
+    type -P "${1##*/}"
 }
 
 if ! [[ $dracutbasedir ]]; then
@@ -55,17 +99,14 @@ if ! [[ $dracutbasedir ]]; then
     dracutbasedir="$(readlink -f $dracutbasedir)"
 fi
 
-if ! [[ $DRACUT_INSTALL ]]; then
-    DRACUT_INSTALL=$(find_binary dracut-install)
-fi
-
-if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
-    DRACUT_INSTALL=$dracutbasedir/dracut-install
-fi
+ldconfig_paths()
+{
+    ldconfig -pN 2>/dev/null | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | sed -n 's,.* => \(.*\)/.*,\1,p' | sort | uniq
+}
 
 # Detect lib paths
 if ! [[ $libdirs ]] ; then
-    if strstr "$(ldd /bin/sh)" "/lib64/" &>/dev/null \
+    if [[ "$(ldd /bin/sh)" == */lib64/* ]] &>/dev/null \
         && [[ -d /lib64 ]]; then
         libdirs+=" /lib64"
         [[ -d /usr/lib64 ]] && libdirs+=" /usr/lib64"
@@ -73,6 +114,9 @@ if ! [[ $libdirs ]] ; then
         libdirs+=" /lib"
         [[ -d /usr/lib ]] && libdirs+=" /usr/lib"
     fi
+
+    libdirs+=" $(ldconfig_paths)"
+
     export libdirs
 fi
 
@@ -81,39 +125,6 @@ if ! [[ $kernel ]]; then
     export kernel
 fi
 
-srcmods="/lib/modules/$kernel/"
-[[ $drivers_dir ]] && {
-    if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
-        dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
-        exit 1
-    fi
-    srcmods="$drivers_dir"
-}
-export srcmods
-
-if ! type dinfo >/dev/null 2>&1; then
-    . "$dracutbasedir/dracut-logger.sh"
-    dlog_init
-fi
-
-if ! [[ $initdir ]]; then
-    dfatal "initdir not set"
-    exit 1
-fi
-
-# export standard hookdirs
-[[ $hookdirs ]] || {
-    hookdirs="cmdline pre-udev pre-trigger netroot "
-    hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
-    hookdirs+="pre-mount pre-pivot cleanup mount "
-    hookdirs+="emergency shutdown-emergency shutdown "
-    export hookdirs
-}
-
-# Create all subdirectories for given path without creating the last element.
-# $1 = path
-mksubdirs() { [[ -e ${1%/*} ]] || mkdir -m 0755 -p ${1%/*}; }
-
 # Version comparision function.  Assumes Linux style version scheme.
 # $1 = version a
 # $2 = comparision op (gt, ge, eq, le, lt, ne)
@@ -141,10 +152,54 @@ vercmp() {
     esac
 }
 
+srcmods="/lib/modules/$kernel/"
+
+[[ $drivers_dir ]] && {
+    if ! command -v kmod &>/dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
+        dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
+        exit 1
+    fi
+    srcmods="$drivers_dir"
+}
+export srcmods
+
 # is_func <command>
 # Check whether $1 is a function.
 is_func() {
-    [[ $(type -t $1) = "function" ]]
+    [[ "$(type -t "$1")" = "function" ]]
+}
+
+if ! is_func dinfo >/dev/null 2>&1; then
+    . "$dracutbasedir/dracut-logger.sh"
+    dlog_init
+fi
+
+if ! [[ $initdir ]]; then
+    dfatal "initdir not set"
+    exit 1
+fi
+
+# export standard hookdirs
+[[ $hookdirs ]] || {
+    hookdirs="cmdline pre-udev pre-trigger netroot "
+    hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
+    hookdirs+="pre-mount pre-pivot cleanup mount "
+    hookdirs+="emergency shutdown-emergency pre-shutdown shutdown "
+    export hookdirs
+}
+
+dracut_need_initqueue() {
+    >"$initdir/lib/dracut/need-initqueue"
+}
+
+dracut_module_included() {
+    [[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
+}
+
+# Create all subdirectories for given path without creating the last element.
+# $1 = path
+mksubdirs() {
+    [[ -e ${1%/*} ]] || mkdir -m 0755 -p -- "${1%/*}"
 }
 
 # Function prints global variables in format name=value line by line.
@@ -152,10 +207,10 @@ is_func() {
 print_vars() {
     local _var _value
 
-    for _var in $@
+    for _var in "$@"
     do
-        _value=$(eval echo \$$_var)
-        [[ ${_value} ]] && echo "${_var}=\"${_value}\""
+        eval printf -v _value "%s" \""\$$_var"\"
+        [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
     done
 }
 
@@ -169,7 +224,7 @@ normalize_path() {
     shopt -q -s extglob
     set -- "${1//+(\/)//}"
     shopt -q -u extglob
-    echo "${1%/}"
+    printf "%s\n" "${1%/}"
 }
 
 # convert_abs_rel <from> <to>
@@ -185,10 +240,10 @@ convert_abs_rel() {
     set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
 
     # corner case #1 - self looping link
-    [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
+    [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
 
     # corner case #2 - own dir link
-    [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
+    [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
 
     IFS="/" __current=($1)
     IFS="/" __absolute=($2)
@@ -196,7 +251,7 @@ convert_abs_rel() {
     __abssize=${#__absolute[@]}
     __cursize=${#__current[@]}
 
-    while [[ ${__absolute[__level]} == ${__current[__level]} ]]
+    while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
     do
         (( __level++ ))
         if (( __level > __abssize || __level > __cursize ))
@@ -223,10 +278,10 @@ convert_abs_rel() {
         __newpath=$__newpath${__absolute[__i]}
     done
 
-    echo "$__newpath"
+    printf "%s\n" "$__newpath"
 }
 
-if strstr "$(ln --help)" "--relative"; then
+if [[ "$(ln --help)" == *--relative* ]]; then
     ln_r() {
         ln -sfnr "${initdir}/$1" "${initdir}/$2"
     }
@@ -235,40 +290,31 @@ else
         local _source=$1
         local _dest=$2
         [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
-        ln -sfn $(convert_abs_rel "${_dest}" "${_source}") "${initdir}/${_dest}"
+        ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
     }
 fi
 
 # get_fs_env <device>
-# Get and set the ID_FS_TYPE and ID_FS_UUID variable from udev for a device.
+# Get and the ID_FS_TYPE variable from udev for a device.
 # Example:
-# $ get_fs_env /dev/sda2; echo $ID_FS_TYPE; echo $ID_FS_UUID
+# $ get_fs_env /dev/sda2
 # ext4
-# 551a39aa-4ae9-4e70-a262-ef665cadb574
 get_fs_env() {
     local evalstr
     local found
 
     [[ $1 ]] || return
     unset ID_FS_TYPE
-    unset ID_FS_UUID
-    if evalstr=$(udevadm info --query=env --name=$1 \
-        | { while read line; do
-            strstr "$line" "DEVPATH" && found=1;
-            strstr "$line" "ID_FS_TYPE=" && { echo $line; exit 0;}
-            done; [[ $found ]] && exit 0; exit 1; }) ; then
-        eval $evalstr
-        [[ $ID_FS_TYPE ]] && return 0
-        return 1
-    fi
-
-    # Fallback, if we don't have udev information
-    if find_binary blkid >/dev/null; then
-        eval $(blkid -o udev $1 \
-            | while read line; do
-                strstr "$line" "ID_FS_TYPE=" && echo $line;
-                done)
-        [[ $ID_FS_TYPE ]] && return 0
+    ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
+        | while read line; do
+            if [[ "$line" == TYPE\=* ]]; then
+                printf "%s" "${line#TYPE=}";
+                exit 0;
+            fi
+            done)
+    if [[ $ID_FS_TYPE ]]; then
+        printf "%s" "$ID_FS_TYPE"
+        return 0
     fi
     return 1
 }
@@ -279,10 +325,94 @@ get_fs_env() {
 # $ get_maj_min /dev/sda2
 # 8:2
 get_maj_min() {
-    local _dev
-    _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
-    _dev=$(eval "echo $_dev")
-    echo $_dev
+    local _maj _min _majmin
+    _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
+    printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
+}
+
+
+# get_devpath_block <device>
+# get the DEVPATH in /sys of a block device
+get_devpath_block() {
+    local _majmin _i
+    _majmin=$(get_maj_min "$1")
+
+    for _i in /sys/block/*/dev /sys/block/*/*/dev; do
+        [[ -e "$_i" ]] || continue
+        if [[ "$_majmin" == "$(<"$_i")" ]]; then
+            printf "%s" "${_i%/dev}"
+            return 0
+        fi
+    done
+    return 1
+}
+
+# get a persistent path from a device
+get_persistent_dev() {
+    local i _tmp _dev
+
+    _dev=$(get_maj_min "$1")
+    [ -z "$_dev" ] && return
+
+    for i in \
+        /dev/mapper/* \
+        /dev/disk/${persistent_policy:-by-uuid}/* \
+        /dev/disk/by-uuid/* \
+        /dev/disk/by-label/* \
+        /dev/disk/by-partuuid/* \
+        /dev/disk/by-partlabel/* \
+        /dev/disk/by-id/* \
+        /dev/disk/by-path/* \
+        ; do
+        [[ -e "$i" ]] || continue
+        [[ $i == /dev/mapper/control ]] && continue
+        [[ $i == /dev/mapper/mpath* ]] && continue
+        _tmp=$(get_maj_min "$i")
+        if [ "$_tmp" = "$_dev" ]; then
+            printf -- "%s" "$i"
+            return
+        fi
+    done
+}
+
+expand_persistent_dev() {
+    local _dev=$1
+
+    case "$_dev" in
+        LABEL=*)
+            _dev="/dev/disk/by-label/${_dev#LABEL=}"
+            ;;
+        UUID=*)
+            _dev="${_dev#UUID=}"
+            _dev="${_dev,,}"
+            _dev="/dev/disk/by-uuid/${_dev}"
+            ;;
+        PARTUUID=*)
+            _dev="${_dev#PARTUUID=}"
+            _dev="${_dev,,}"
+            _dev="/dev/disk/by-partuuid/${_dev}"
+            ;;
+        PARTLABEL=*)
+            _dev="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
+            ;;
+    esac
+    printf "%s" "$_dev"
+}
+
+shorten_persistent_dev() {
+    local _dev="$1"
+    case "$_dev" in
+        /dev/disk/by-uuid/*)
+            printf "%s" "UUID=${_dev##*/}";;
+        /dev/disk/by-label/*)
+            printf "%s" "LABEL=${_dev##*/}";;
+        /dev/disk/by-partuuid/*)
+            printf "%s" "PARTUUID=${_dev##*/}";;
+        /dev/disk/by-partlabel/*)
+            printf "%s" "PARTLABEL=${_dev##*/}";;
+        *)
+            printf "%s" "$_dev";;
+    esac
 }
 
 # find_block_device <mountpoint>
@@ -296,37 +426,83 @@ get_maj_min() {
 # $ find_block_device /usr
 # 8:4
 find_block_device() {
-    local _x _mpt _majmin _dev _fs _maj _min
+    local _majmin _dev _majmin _find_mpt
+    _find_mpt="$1"
     if [[ $use_fstab != yes ]]; then
-        while read _x _x _majmin _x _mpt _x _x _fs _dev _x; do
-            [[ $_mpt = $1 ]] || continue
-            [[ $_fs = nfs ]] && { echo $_dev; return 0;}
-            [[ $_fs = nfs3 ]] && { echo $_dev; return 0;}
-            [[ $_fs = nfs4 ]] && { echo $_dev; return 0;}
-            [[ $_fs = btrfs ]] && {
-                get_maj_min $_dev
-                return 0;
-            }
-            if [[ ${_majmin#0:} = $_majmin ]]; then
-                echo $_majmin
-                return 0 # we have a winner!
-            fi
-        done < /proc/self/mountinfo
+        [[ -d $_find_mpt/. ]]
+        findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
+            while read _majmin _dev; do
+                if [[ -b $_dev ]]; then
+                    if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
+                        _majmin=$(get_maj_min $_dev)
+                    fi
+                    if [[ $_majmin ]]; then
+                        printf "%s\n" "$_majmin"
+                    else
+                        printf "%s\n" "$_dev"
+                    fi
+                    return 0
+                fi
+                if [[ $_dev = *:* ]]; then
+                    printf "%s\n" "$_dev"
+                    return 0
+                fi
+            done; return 1; } && return 0
     fi
     # fall back to /etc/fstab
-    while read _dev _mpt _fs _x; do
-        [ "${_dev%%#*}" != "$_dev" ] && continue
-
-        if [[ $_mpt = $1 ]]; then
-            [[ $_fs = nfs ]] && { echo $_dev; return 0;}
-            [[ $_fs = nfs3 ]] && { echo $_dev; return 0;}
-            [[ $_fs = nfs4 ]] && { echo $_dev; return 0;}
-            [[ $_dev != ${_dev#UUID=} ]] && _dev=/dev/disk/by-uuid/${_dev#UUID=}
-            [[ $_dev != ${_dev#LABEL=} ]] && _dev=/dev/disk/by-label/${_dev#LABEL=}
-            [[ -b $_dev ]] || return 1 # oops, not a block device.
-            get_maj_min "$_dev" && return 0
-        fi
-    done < /etc/fstab
+
+    findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
+        while read _majmin _dev; do
+            if ! [[ $_dev ]]; then
+                _dev="$_majmin"
+                unset _majmin
+            fi
+            if [[ -b $_dev ]]; then
+                [[ $_majmin ]] || _majmin=$(get_maj_min $_dev)
+                if [[ $_majmin ]]; then
+                    printf "%s\n" "$_majmin"
+                else
+                    printf "%s\n" "$_dev"
+                fi
+                return 0
+            fi
+            if [[ $_dev = *:* ]]; then
+                printf "%s\n" "$_dev"
+                return 0
+            fi
+        done; return 1; } && return 0
+
+    return 1
+}
+
+# find_mp_fstype <mountpoint>
+# Echo the filesystem type for a given mountpoint.
+# /proc/self/mountinfo is taken as the primary source of information
+# and /etc/fstab is used as a fallback.
+# No newline is appended!
+# Example:
+# $ find_mp_fstype /;echo
+# ext4
+find_mp_fstype() {
+    local _fs
+
+    if [[ $use_fstab != yes ]]; then
+        findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \
+            while read _fs; do
+                [[ $_fs ]] || continue
+                [[ $_fs = "autofs" ]] && continue
+                printf "%s" "$_fs"
+                return 0
+            done; return 1; } && return 0
+    fi
+
+    findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \
+        while read _fs; do
+            [[ $_fs ]] || continue
+            [[ $_fs = "autofs" ]] && continue
+            printf "%s" "$_fs"
+            return 0
+        done; return 1; } && return 0
 
     return 1
 }
@@ -340,48 +516,96 @@ find_block_device() {
 # $ find_dev_fstype /dev/sda2;echo
 # ext4
 find_dev_fstype() {
-    local _x _mpt _majmin _dev _fs _maj _min
-    while read _x _x _majmin _x _mpt _x _x _fs _dev _x; do
-        [[ $_dev = $1 ]] || continue
-        echo -n $_fs;
-        return 0;
-    done < /proc/self/mountinfo
+    local _find_dev _fs
+    _find_dev="$1"
+    if ! [[ "$_find_dev" = /dev* ]]; then
+        [[ -b "/dev/block/$_find_dev" ]] && _find_dev="/dev/block/$_find_dev"
+    fi
 
-    # fall back to /etc/fstab
-    while read _dev _mpt _fs _x; do
-        [[ $_dev = $1 ]] || continue
-        echo -n $_fs;
-        return 0;
-    done < /etc/fstab
+    if [[ $use_fstab != yes ]]; then
+        findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
+            while read _fs; do
+                [[ $_fs ]] || continue
+                [[ $_fs = "autofs" ]] && continue
+                printf "%s" "$_fs"
+                return 0
+            done; return 1; } && return 0
+    fi
+
+    findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
+        while read _fs; do
+            [[ $_fs ]] || continue
+            [[ $_fs = "autofs" ]] && continue
+            printf "%s" "$_fs"
+            return 0
+        done; return 1; } && return 0
 
     return 1
 }
 
+# find_mp_fsopts <mountpoint>
+# Echo the filesystem options for a given mountpoint.
+# /proc/self/mountinfo is taken as the primary source of information
+# and /etc/fstab is used as a fallback.
+# No newline is appended!
+# Example:
+# $ find_mp_fsopts /;echo
+# rw,relatime,discard,data=ordered
+find_mp_fsopts() {
+    if [[ $use_fstab != yes ]]; then
+        findmnt -e -v -n -o 'OPTIONS' --target "$1" 2>/dev/null && return 0
+    fi
+
+    findmnt --fstab -e -v -n -o 'OPTIONS' --target "$1"
+}
+
+# find_dev_fsopts <device>
+# Echo the filesystem options for a given device.
+# /proc/self/mountinfo is taken as the primary source of information
+# and /etc/fstab is used as a fallback.
+# Example:
+# $ find_dev_fsopts /dev/sda2
+# rw,relatime,discard,data=ordered
+find_dev_fsopts() {
+    local _find_dev _opts
+    _find_dev="$1"
+    if ! [[ "$_find_dev" = /dev* ]]; then
+        [[ -b "/dev/block/$_find_dev" ]] && _find_dev="/dev/block/$_find_dev"
+    fi
+
+    if [[ $use_fstab != yes ]]; then
+        findmnt -e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev/null && return 0
+    fi
+
+    findmnt --fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
+}
+
+
 # finds the major:minor of the block device backing the root filesystem.
 find_root_block_device() { find_block_device /; }
 
 # for_each_host_dev_fs <func>
-# Execute "<func> <dev> <filesystem>" for every "<dev>|<fs>" pair found
+# Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
 # in ${host_fs_types[@]}
 for_each_host_dev_fs()
 {
     local _func="$1"
     local _dev
-    local _fs
     local _ret=1
-    for f in ${host_fs_types[@]}; do
-        OLDIFS="$IFS"
-        IFS="|"
-        set -- $f
-        IFS="$OLDIFS"
-        _dev="$1"
-        [[ -b "$_dev" ]] || continue
-        _fs="$2"
-        $_func $_dev $_fs && _ret=0
+
+    [[ "${!host_fs_types[@]}" ]] || return 0
+
+    for _dev in "${!host_fs_types[@]}"; do
+        $_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
     done
     return $_ret
 }
 
+host_fs_all()
+{
+    printf "%s\n" "${host_fs_types[@]}"
+}
+
 # Walk all the slave relationships for a given block device.
 # Stop when our helper function returns success
 # $1 = function to call on every found block device
@@ -389,15 +613,66 @@ for_each_host_dev_fs()
 check_block_and_slaves() {
     local _x
     [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
-    "$1" $2 && return
+    if ! lvm_internal_dev $2; then "$1" $2 && return; fi
     check_vol_slaves "$@" && return 0
     if [[ -f /sys/dev/block/$2/../dev ]]; then
-        check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
+        check_block_and_slaves $1 $(<"/sys/dev/block/$2/../dev") && return 0
     fi
     [[ -d /sys/dev/block/$2/slaves ]] || return 1
     for _x in /sys/dev/block/$2/slaves/*/dev; do
         [[ -f $_x ]] || continue
-        check_block_and_slaves $1 $(cat "$_x") && return 0
+        check_block_and_slaves $1 $(<"$_x") && return 0
+    done
+    return 1
+}
+
+check_block_and_slaves_all() {
+    local _x _ret=1
+    [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
+    if ! lvm_internal_dev $2 && "$1" $2; then
+        _ret=0
+    fi
+    check_vol_slaves_all "$@" && return 0
+    if [[ -f /sys/dev/block/$2/../dev ]]; then
+        check_block_and_slaves_all $1 $(<"/sys/dev/block/$2/../dev") && _ret=0
+    fi
+    [[ -d /sys/dev/block/$2/slaves ]] || return 1
+    for _x in /sys/dev/block/$2/slaves/*/dev; do
+        [[ -f $_x ]] || continue
+        check_block_and_slaves_all $1 $(<"$_x") && _ret=0
+    done
+    return $_ret
+}
+# for_each_host_dev_and_slaves <func>
+# Execute "<func> <dev>" for every "<dev>" found
+# in ${host_devs[@]} and their slaves
+for_each_host_dev_and_slaves_all()
+{
+    local _func="$1"
+    local _dev
+    local _ret=1
+
+    [[ "${host_devs[@]}" ]] || return 0
+
+    for _dev in ${host_devs[@]}; do
+        [[ -b "$_dev" ]] || continue
+        if check_block_and_slaves_all $_func $(get_maj_min $_dev); then
+            _ret=0
+        fi
+    done
+    return $_ret
+}
+
+for_each_host_dev_and_slaves()
+{
+    local _func="$1"
+    local _dev
+
+    [[ "${host_devs[@]}" ]] || return 0
+
+    for _dev in ${host_devs[@]}; do
+        [[ -b "$_dev" ]] || continue
+        check_block_and_slaves $_func $(get_maj_min $_dev) && return 0
     done
     return 1
 }
@@ -411,11 +686,12 @@ check_block_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)
             # strip space
-            _vg=$(echo $_vg)
+            _vg="${_vg//[[:space:]]/}"
             if [[ $_vg ]]; then
                 for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
                 do
@@ -427,253 +703,120 @@ check_vol_slaves() {
     return 1
 }
 
-if [[ $DRACUT_INSTALL ]]; then
-    [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
-    inst_dir() {
-        [[ -e ${initdir}/"$1" ]] && return 0  # already there
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" || :
-    }
-
-    inst() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        #dinfo "$DRACUT_INSTALL -l $@"
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    inst_simple() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -e $1 ]] || return 1  # no source
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" || :
-    }
-
-    inst_symlink() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -L $1 ]] || return 1
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    dracut_install() {
-        #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
-
-    inst_library() {
-        [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-        [[ -e $1 ]] || return 1  # no source
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
+check_vol_slaves_all() {
+    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)
+            # strip space
+            _vg="${_vg//[[:space:]]/}"
+            if [[ $_vg ]]; then
+                for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
+                do
+                    check_block_and_slaves_all $1 $(get_maj_min $_pv)
+                done
+                return 0
+            fi
+        fi
+    done
+    return 1
+}
 
-    inst_binary() {
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
 
-    inst_script() {
-        $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@"
-        (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l}  ${DRACUT_FIPS_MODE+-H} "$@" || :
-    }
 
-else
+# fs_get_option <filesystem options> <search for option>
+# search for a specific option in a bunch of filesystem options
+# and return the value
+fs_get_option() {
+    local _fsopts=$1
+    local _option=$2
+    local OLDIFS="$IFS"
+    IFS=,
+    set -- $_fsopts
+    IFS="$OLDIFS"
+    while [ $# -gt 0 ]; do
+        case $1 in
+            $_option=*)
+                echo ${1#${_option}=}
+                break
+        esac
+        shift
+    done
+}
 
-    # Install a directory, keeping symlinks as on the original system.
-    # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
-    # will create ${initdir}/lib64, ${initdir}/lib64/file,
-    # and a symlink ${initdir}/lib -> lib64.
-    inst_dir() {
-        [[ -e ${initdir}/"$1" ]] && return 0  # already there
-
-        local _dir="$1" _part="${1%/*}" _file
-        while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
-            _dir="$_part $_dir"
-            _part=${_part%/*}
-        done
 
-        # iterate over parent directories
-        for _file in $_dir; do
-            [[ -e "${initdir}/$_file" ]] && continue
-            if [[ -L $_file ]]; then
-                inst_symlink "$_file"
-            else
-            # create directory
-                mkdir -m 0755 -p "${initdir}/$_file" || return 1
-                [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
-                chmod u+w "${initdir}/$_file"
-            fi
-        done
-    }
+if ! [[ $DRACUT_INSTALL ]]; then
+    DRACUT_INSTALL=$(find_binary dracut-install)
+fi
 
-    # $1 = file to copy to ramdisk
-    # $2 (optional) Name for the file on the ramdisk
-    # Location of the image dir is assumed to be $initdir
-    # We never overwrite the target if it exists.
-    inst_simple() {
-        [[ -f "$1" ]] || return 1
-        strstr "$1" "/" || return 1
-        local _src=$1 _target="${2:-$1}"
-
-        [[ -L $_src ]] && { inst_symlink $_src $_target; return $?; }
-
-        if ! [[ -d ${initdir}/$_target ]]; then
-            [[ -e ${initdir}/$_target ]] && return 0
-            [[ -L ${initdir}/$_target ]] && return 0
-            [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
-        fi
-        if [[ $DRACUT_FIPS_MODE ]]; then
-            # install checksum files also
-            if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
-                inst "${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
-            fi
-        fi
-        ddebug "Installing $_src"
-        cp --reflink=auto --sparse=auto -pfL "$_src" "${initdir}/$_target"
-    }
+if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
+    DRACUT_INSTALL=$dracutbasedir/dracut-install
+fi
 
-    # same as above, but specialized for symlinks
-    inst_symlink() {
-        local _src=$1 _target=${2:-$1} _realsrc
-        strstr "$1" "/" || return 1
-        [[ -L $1 ]] || return 1
-        [[ -L $initdir/$_target ]] && return 0
-        _realsrc=$(readlink -f "$_src")
-        if ! [[ -e $initdir/$_realsrc ]]; then
-            if [[ -d $_realsrc ]]; then
-                inst_dir "$_realsrc"
-            else
-                inst "$_realsrc"
-            fi
-        fi
-        [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
+if ! [[ -x $DRACUT_INSTALL ]]; then
+    dfatal "dracut-install not found!"
+    exit 10
+fi
 
-        ln_r "${_realsrc}" "${_target}"
-    }
+[[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
+inst_dir() {
+    [[ -e ${initdir}/"$1" ]] && return 0  # already there
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" || :
+}
 
-    # Same as above, but specialized to handle dynamic libraries.
-    # It handles making symlinks according to how the original library
-    # is referenced.
-    inst_library() {
-        local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
-        strstr "$1" "/" || return 1
-        [[ -e $initdir/$_dest ]] && return 0
-        if [[ -L $_src ]]; then
-            if [[ $DRACUT_FIPS_MODE ]]; then
-                # install checksum files also
-                if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
-                    inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
-                fi
-            fi
-            _reallib=$(readlink -f "$_src")
-            inst_simple "$_reallib" "$_reallib"
-            inst_dir "${_dest%/*}"
-            ln_r "${_reallib}" "${_dest}"
-        else
-            inst_simple "$_src" "$_dest"
-        fi
+inst() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+        #dinfo "$DRACUT_INSTALL -l $@"
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
 
-        # Create additional symlinks.  See rev_symlinks description.
-        for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
-            [[ ! -e $initdir/$_symlink ]] && {
-                ddebug "Creating extra symlink: $_symlink"
-                inst_symlink $_symlink
-            }
-        done
-    }
+inst_simple() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" || :
+}
 
-    # Same as above, but specialized to install binary executables.
-    # Install binary executable, and all shared library dependencies, if any.
-    inst_binary() {
-        local _bin _target
-        _bin=$(find_binary "$1") || return 1
-        _target=${2:-$_bin}
-        [[ -e $initdir/$_target ]] && return 0
-        local _file _line
-        local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
-        # I love bash!
-        LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
-            [[ $_line = 'not a dynamic executable' ]] && break
-
-            if [[ $_line =~ $_so_regex ]]; then
-                _file=${BASH_REMATCH[1]}
-                [[ -e ${initdir}/$_file ]] && continue
-                inst_library "$_file"
-                continue
-            fi
+inst_symlink() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -L $1 ]] || return 1
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
 
-            if [[ $_line =~ not\ found ]]; then
-                dfatal "Missing a shared library required by $_bin."
-                dfatal "Run \"ldd $_bin\" to find out what it is."
-                dfatal "$_line"
-                dfatal "dracut cannot create an initrd."
-                exit 1
-            fi
-        done
-        inst_simple "$_bin" "$_target"
-    }
+inst_multiple() {
+    local ret
+        #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@"
+    ret=$?
+    (($ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@" || :
+    return $ret
+}
 
-    # same as above, except for shell scripts.
-    # If your shell script does not start with shebang, it is not a shell script.
-    inst_script() {
-        local _bin
-        _bin=$(find_binary "$1") || return 1
-        shift
-        local _line _shebang_regex
-        read -r -n 80 _line <"$_bin"
-        # If debug is set, clean unprintable chars to prevent messing up the term
-        [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
-        _shebang_regex='(#! *)(/[^ ]+).*'
-        [[ $_line =~ $_shebang_regex ]] || return 1
-        inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
-    }
+dracut_install() {
+    inst_multiple "$@"
+}
 
-    # general purpose installation function
-    # Same args as above.
-    inst() {
-        local _x
-
-        case $# in
-            1) ;;
-            2) [[ ! $initdir && -d $2 ]] && export initdir=$2
-                [[ $initdir = $2 ]] && set $1;;
-            3) [[ -z $initdir ]] && export initdir=$2
-                set $1 $3;;
-            *) dfatal "inst only takes 1 or 2 or 3 arguments"
-                exit 1;;
-        esac
-        for _x in inst_symlink inst_script inst_binary inst_simple; do
-            $_x "$@" && return 0
-        done
-        return 1
-    }
+inst_library() {
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
 
-    # dracut_install [-o ] <file> [<file> ... ]
-    # Install <file> to the initramfs image
-    # -o optionally install the <file> and don't fail, if it is not there
-    dracut_install() {
-        local _optional=no
-        if [[ $1 = '-o' ]]; then
-            _optional=yes
-            shift
-        fi
-        while (($# > 0)); do
-            if ! inst "$1" ; then
-                if [[ $_optional = yes ]]; then
-                    dinfo "Skipping program $1 as it cannot be found and is" \
-                        "flagged to be optional"
-                else
-                    dfatal "Failed to install $1"
-                    exit 1
-                fi
-            fi
-            shift
-        done
-    }
+inst_binary() {
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
 
-fi
+inst_script() {
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
 
 # find symlinks linked to given library file
 # $1 = library file
@@ -690,7 +833,7 @@ rev_lib_symlinks() {
 
     local fn="$1" orig="$(readlink -f "$1")" links=''
 
-    [[ ${fn} =~ .*\.so\..* ]] || return 1
+    [[ ${fn} == *.so.* ]] || return 1
 
     until [[ ${fn##*.} == so ]]; do
         fn="${fn%.*}"
@@ -706,51 +849,77 @@ inst_rule_programs() {
 
     if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
         for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
+            _bin=""
             if [ -x ${udevdir}/$_prog ]; then
                 _bin=${udevdir}/$_prog
-            else
+            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
                 _bin=$(find_binary "$_prog") || {
-                    dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
+                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                     continue;
                 }
             fi
 
-            #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
-            dracut_install "$_bin"
+            [[ $_bin ]] && inst_binary "$_bin"
         done
     fi
-    if grep -qE 'RUN==?"[^ "]+' "$1"; then
-        for _prog in $(grep -E 'RUN==?"[^ "]+' "$1" | sed -r 's/.*RUN==?"([^ "]+).*/\1/'); do
+    if grep -qE 'RUN[+=]=?"[^ "]+' "$1"; then
+        for _prog in $(grep -E 'RUN[+=]=?"[^ "]+' "$1" | sed -r 's/.*RUN[+=]=?"([^ "]+).*/\1/'); do
+            _bin=""
             if [ -x ${udevdir}/$_prog ]; then
                 _bin=${udevdir}/$_prog
-            else
+            elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
                 _bin=$(find_binary "$_prog") || {
-                    dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
+                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                     continue;
                 }
             fi
 
-            #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
-            dracut_install "$_bin"
+            [[ $_bin ]] && inst_binary "$_bin"
         done
     fi
-    if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
-        for _prog in $(grep -E 'IMPORT==?"[^ "]+' "$1" | sed -r 's/.*IMPORT==?"([^ "]+).*/\1/'); do
+    if grep -qE 'IMPORT\{program\}==?"[^ "]+' "$1"; then
+        for _prog in $(grep -E 'IMPORT\{program\}==?"[^ "]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/'); do
+            _bin=""
             if [ -x ${udevdir}/$_prog ]; then
                 _bin=${udevdir}/$_prog
-            else
+            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
                 _bin=$(find_binary "$_prog") || {
-                    dinfo "Skipping program $_prog using in udev rule $(basename $1) as it cannot be found"
+                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                     continue;
                 }
             fi
 
-            #dinfo "Installing $_bin due to it's use in the udev rule $(basename $1)"
-            dracut_install "$_bin"
+            [[ $_bin ]] && dracut_install "$_bin"
         done
     fi
 }
 
+# attempt to install any programs specified in a udev rule
+inst_rule_group_owner() {
+    local i
+
+    if grep -qE 'OWNER=?"[^ "]+' "$1"; then
+        for i in $(grep -E 'OWNER=?"[^ "]+' "$1" | sed -r 's/.*OWNER=?"([^ "]+).*/\1/'); do
+            if ! egrep -q "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
+                egrep "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+            fi
+        done
+    fi
+    if grep -qE 'GROUP=?"[^ "]+' "$1"; then
+        for i in $(grep -E 'GROUP=?"[^ "]+' "$1" | sed -r 's/.*GROUP=?"([^ "]+).*/\1/'); do
+            if ! egrep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then
+                egrep "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
+            fi
+        done
+    fi
+}
+
+inst_rule_initqueue() {
+    if grep -q -F initqueue "$1"; then
+        dracut_need_initqueue
+    fi
+}
+
 # udev rules always get installed in the same place, so
 # create a function to install them to make life simpler.
 inst_rules() {
@@ -759,19 +928,26 @@ inst_rules() {
     inst_dir "${udevdir}/rules.d"
     inst_dir "$_target"
     for _rule in "$@"; do
-        if [ "${rule#/}" = "$rule" ]; then
-            for r in ${udevdir}/rules.d /etc/udev/rules.d; do
-                if [[ -f $r/$_rule ]]; then
+        if [ "${_rule#/}" = "$_rule" ]; then
+            for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
+                if [[ -e $r/$_rule ]]; then
                     _found="$r/$_rule"
                     inst_rule_programs "$_found"
+                    inst_rule_group_owner "$_found"
+                    inst_rule_initqueue "$_found"
                     inst_simple "$_found"
                 fi
             done
         fi
-        for r in '' ./ $dracutbasedir/rules.d/; do
+        for r in '' $dracutbasedir/rules.d/; do
+            # skip rules without an absolute path
+            [[ "${r}$_rule" != /* ]] && continue
+
             if [[ -f ${r}$_rule ]]; then
                 _found="${r}$_rule"
                 inst_rule_programs "$_found"
+                inst_rule_group_owner "$_found"
+                inst_rule_initqueue "$_found"
                 inst_simple "$_found" "$_target/${_found##*/}"
             fi
         done
@@ -779,6 +955,33 @@ inst_rules() {
     done
 }
 
+prepare_udev_rules() {
+    [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
+
+    for f in "$@"; do
+        f="${initdir}/etc/udev/rules.d/$f"
+        [ -e "$f" ] || continue
+        while read line; do
+            if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
+                if [ $UDEVVERSION -ge 174 ]; then
+                    printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
+                else
+                    printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
+                fi
+            elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
+                if [ $UDEVVERSION -ge 176 ]; then
+                    printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
+                else
+                    printf '%sIMPORT{program}="/sbin/blkid -o udev -p $tempnode"\n' "${line%%IMPORT BLKID}"
+                fi
+            else
+                echo "$line"
+            fi
+        done < "${f}" > "${f}.new"
+        mv "${f}.new" "$f"
+    done
+}
+
 # install function specialized for hooks
 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
@@ -787,11 +990,11 @@ inst_hook() {
         dfatal "Cannot install a hook ($3) that does not exist."
         dfatal "Aborting initrd creation."
         exit 1
-    elif ! strstr "$hookdirs" "$1"; then
+    elif ! [[ "$hookdirs" == *$1* ]]; then
         dfatal "No such hook type $1. Aborting initrd creation."
         exit 1
     fi
-    inst_simple "$3" "/lib/dracut/hooks/${1}/${2}${3##*/}"
+    inst_simple "$3" "/lib/dracut/hooks/${1}/${2}-${3##*/}"
 }
 
 # install any of listed files
@@ -848,7 +1051,7 @@ inst_libdir_file() {
             done
         done
     fi
-    [[ $_files ]] && dracut_install $_files
+    [[ $_files ]] && inst_multiple $_files
 }
 
 
@@ -863,7 +1066,7 @@ inst_decompress() {
     for _src in $@
     do
         case ${_src} in
-            *.gz) _cmd='gzip -d' ;;
+            *.gz) _cmd='gzip -f -d' ;;
             *.bz2) _cmd='bzip2 -d' ;;
             *) return 1 ;;
         esac
@@ -904,13 +1107,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
+        moddir=$_moddir check $hostonly
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
     fi
     hostonly=$_hostonly
     return $_ret
@@ -931,12 +1135,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
-        is_func check || return 1
-        check 0
+        moddir=$_moddir check 0
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
     fi
     unset mount_needs
     return $_ret
@@ -955,12 +1159,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
-        is_func depends || return 0
-        depends
+        moddir=$_moddir 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
+        moddir=$_moddir cmdline
+        _ret=$?
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -976,12 +1201,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
-        is_func install || return 0
-        install
+        moddir=$_moddir install
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -997,12 +1222,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
-        is_func installkernel || return 0
-        installkernel
+        moddir=$_moddir installkernel
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -1015,35 +1240,57 @@ check_mount() {
     local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
     local _ret
     local _moddep
+
+    [ "${#host_fs_types[*]}" -le 0 ] && return 1
+
     # If we are already scheduled to be loaded, no need to check again.
-    strstr " $mods_to_load " " $_mod " && return 0
-    strstr " $mods_checked_as_dep " " $_mod " && return 1
+    [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
+    [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
 
     # This should never happen, but...
     [[ -d $_moddir ]] || return 1
 
     [[ $2 ]] || mods_checked_as_dep+=" $_mod "
 
-    strstr " $omit_dracutmodules " " $_mod " && return 1
+    if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
+        return 1
+    fi
+
+    if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
+        module_check_mount $_mod; ret=$?
 
-    if [ "${#host_fs_types[*]}" -gt 0 ]; then
-        module_check_mount $_mod || return 1
+        # explicit module, so also accept ret=255
+        [[ $ret = 0 || $ret = 255 ]] || return 1
     else
-        # skip this module
-        return 1
+        # module not in our list
+        if [[ $dracutmodules = all ]]; then
+            # check, if we can and should install this module
+            module_check_mount $_mod || return 1
+        else
+            # skip this module
+            return 1
+        fi
     fi
 
     for _moddep in $(module_depends $_mod); do
         # handle deps as if they were manually added
-        strstr " $add_dracutmodules " " $_moddep " || \
-            add_dracutmodules+=" $_moddep "
-        strstr " $force_add_dracutmodules " " $_moddep " || \
-            force_add_dracutmodules+=" $_moddep "
+        [[ " $dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
+            && dracutmodules+=" $_moddep "
+        [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
+            && add_dracutmodules+=" $_moddep "
+        [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
+            && force_add_dracutmodules+=" $_moddep "
         # if a module we depend on fail, fail also
-        check_module $_moddep || return 1
+        if ! check_module $_moddep; then
+            derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
+            return 1
+        fi
     done
 
-    strstr " $mods_to_load " " $_mod " || \
+    [[ " $mods_to_load " == *\ $_mod\ * ]] || \
         mods_to_load+=" $_mod "
 
     return 0
@@ -1059,18 +1306,21 @@ check_module() {
     local _ret
     local _moddep
     # If we are already scheduled to be loaded, no need to check again.
-    strstr " $mods_to_load " " $_mod " && return 0
-    strstr " $mods_checked_as_dep " " $_mod " && return 1
+    [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
+    [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
 
     # This should never happen, but...
     [[ -d $_moddir ]] || return 1
 
     [[ $2 ]] || mods_checked_as_dep+=" $_mod "
 
-    strstr " $omit_dracutmodules " " $_mod " && return 1
+    if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
+        dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
+        return 1
+    fi
 
-    if strstr " $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
-        if strstr " $force_add_dracutmodules" " $_mod"; then
+    if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
+        if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
             module_check $_mod 1; ret=$?
         else
             module_check $_mod 0; ret=$?
@@ -1081,7 +1331,11 @@ check_module() {
         # module not in our list
         if [[ $dracutmodules = all ]]; then
             # check, if we can and should install this module
-            module_check $_mod || return 1
+            module_check $_mod; ret=$?
+            if [[ $ret != 0 ]]; then
+                [[ $2 ]] && return 1
+                [[ $ret != 255 ]] && return 1
+            fi
         else
             # skip this module
             return 1
@@ -1090,15 +1344,23 @@ check_module() {
 
     for _moddep in $(module_depends $_mod); do
         # handle deps as if they were manually added
-        strstr " $add_dracutmodules " " $_moddep " || \
-            add_dracutmodules+=" $_moddep "
-        strstr " $force_add_dracutmodules " " $_moddep " || \
-            force_add_dracutmodules+=" $_moddep "
+        [[ " $dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
+            && dracutmodules+=" $_moddep "
+        [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
+            && add_dracutmodules+=" $_moddep "
+        [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
+            && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
+            && force_add_dracutmodules+=" $_moddep "
         # if a module we depend on fail, fail also
-        check_module $_moddep || return 1
+        if ! check_module $_moddep; then
+            derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
+            return 1
+        fi
     done
 
-    strstr " $mods_to_load " " $_mod " || \
+    [[ " $mods_to_load " == *\ $_mod\ * ]] || \
         mods_to_load+=" $_mod "
 
     return 0
@@ -1113,17 +1375,28 @@ for_each_module_dir() {
     local _func
     _func=$1
     for _moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
+        [[ -d $_moddir ]] || continue;
+        [[ -e $_moddir/install || -e $_moddir/installkernel || \
+            -e $_moddir/module-setup.sh ]] || continue
         _mod=${_moddir##*/}; _mod=${_mod#[0-9][0-9]}
         $_func $_mod 1
     done
 
     # Report any missing dracut modules, the user has specified
     _modcheck="$add_dracutmodules $force_add_dracutmodules"
-    [[ $dracutmodules != all ]] && _modcheck="$m $dracutmodules"
+    [[ $dracutmodules != all ]] && _modcheck="$_modcheck $dracutmodules"
     for _mod in $_modcheck; do
-        strstr "$mods_to_load" "$_mod" && continue
-        strstr "$omit_dracutmodules" "$_mod" && continue
-        derror "Dracut module \"$_mod\" cannot be found or installed."
+        [[ " $mods_to_load " == *\ $_mod\ * ]] && continue
+
+        [[ " $force_add_dracutmodules " != *\ $_mod\ * ]] \
+            && [[ " $dracutmodules " != *\ $_mod\ * ]] \
+            && [[ " $omit_dracutmodules " == *\ $_mod\ * ]] \
+            && continue
+
+        derror "dracut module '$_mod' cannot be found or installed."
+        [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] && exit 1
+        [[ " $dracutmodules " == *\ $_mod\ * ]] && exit 1
+        [[ " $add_dracutmodules " == *\ $_mod\ * ]] && exit 1
     done
 }
 
@@ -1154,6 +1427,14 @@ install_kmod_with_fw() {
         fi
     fi
 
+    if [[ $silent_omit_drivers ]]; then
+        local _kmod=${1##*/}
+        _kmod=${_kmod%.ko}
+        _kmod=${_kmod/-/_}
+        [[ "$_kmod" =~ $silent_omit_drivers ]] && return 0
+        [[ "${1##*/lib/modules/$kernel/}" =~ $silent_omit_drivers ]] && return 0
+    fi
+
     inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
     ret=$?
     [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
@@ -1204,9 +1485,10 @@ for_each_kmod_dep() {
 
 dracut_kernel_post() {
     local _moddirname=${srcmods%%/lib/modules/*}
+    local _pid
 
     if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
-        xargs -r modprobe -a ${_moddirname+-d ${_moddirname}/} \
+        xargs -r modprobe -a ${_moddirname:+-d ${_moddirname}/} \
             --ignore-install --show-depends --set-version $kernel \
             < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev/null \
             | sort -u \
@@ -1217,7 +1499,7 @@ dracut_kernel_post() {
 
         (
             if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
-                xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
+                xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
             else
                 while read _modpath; do
                     local _destpath=$_modpath
@@ -1227,6 +1509,8 @@ dracut_kernel_post() {
                 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
             fi
         ) &
+        _pid=$(jobs -p | while read a ; do printf ":$a";done)
+        _pid=${_pid##*:}
 
         if [[ $DRACUT_INSTALL ]]; then
             xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
@@ -1234,7 +1518,7 @@ dracut_kernel_post() {
                 for _fwdir in $fw_dir; do
                     echo $_fwdir/$line;
                 done;
-            done | xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
+            done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
         else
             for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
                 for _fwdir in $fw_dir; do
@@ -1246,16 +1530,9 @@ dracut_kernel_post() {
             done
         fi
 
-        wait
+        wait $_pid
     fi
 
-    for _f in modules.builtin.bin modules.builtin; do
-        [[ $srcmods/$_f ]] && break
-    done || {
-        dfatal "No modules.builtin.bin and modules.builtin found!"
-        return 1
-    }
-
     for _f in modules.builtin.bin modules.builtin modules.order; do
         [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
     done
@@ -1267,29 +1544,68 @@ dracut_kernel_post() {
         exit 1
     fi
 
-    [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr "$DRACUT_KERNEL_LAZY_HASHDIR"
+    [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
 }
 
-find_kernel_modules_by_path () (
-    local _OLDIFS
-    if ! [[ $hostonly ]]; then
-        _OLDIFS=$IFS
-        IFS=:
-        while read a rest; do
-            [[ $a = kernel*/$1/* ]] || continue
-            echo $srcmods/$a
-        done < $srcmods/modules.dep
-        IFS=$_OLDIFS
-    else
-        ( cd /sys/module; echo *; ) \
-        | xargs -r modinfo -F filename -k $kernel 2>/dev/null \
-        | while read a; do
-            [[ $a = kernel*/$1/* ]] || continue
-            echo $srcmods/$a
+[[ "$kernel_current" ]] || export kernel_current=$(uname -r)
+
+module_is_host_only() {
+    local _mod=$1
+    local _modenc a i _k _s _v _aliases
+    _mod=${_mod##*/}
+    _mod=${_mod%.ko}
+    _modenc=${_mod//-/_}
+
+    [[ " $add_drivers " == *\ ${_mod}\ * ]] && return 0
+
+    # check if module is loaded
+    [[ ${host_modules["$_modenc"]} ]] && return 0
+
+    [[ "$kernel_current" ]] || export kernel_current=$(uname -r)
+
+    if [[ "$kernel_current" != "$kernel" ]]; then
+        # check if module is loadable on the current kernel
+        # this covers the case, where a new module is introduced
+        # or a module was renamed
+        # or a module changed from builtin to a module
+
+        if [[ -d /lib/modules/$kernel_current ]]; then
+            # if the modinfo can be parsed, but the module
+            # is not loaded, then we can safely return 1
+            modinfo -F filename "$_mod" &>/dev/null && return 1
+        fi
+
+        _aliases=$(modinfo -k $kernel -F alias $_mod 2>/dev/null)
+
+        # if the module has no aliases, install it
+        [[ $_aliases ]] || return 0
+
+        # finally check all modalias
+        for a in $_aliases; do
+            for i in "${!host_modalias[@]}"; do
+                [[ $i == $a ]]  && return 0
+            done
         done
+
     fi
+
+    return 1
+}
+
+find_kernel_modules_by_path () {
+    local _OLDIFS
+
+    [[ -f "$srcmods/modules.dep" ]] || return 0
+
+    _OLDIFS=$IFS
+    IFS=:
+    while read a rest; do
+        [[ $a = */$1/* ]] || [[ $a = updates/* ]] || [[ $a = extra/* ]] || [[ $a = weak-updates/* ]] ||continue
+        printf "%s\n" "$srcmods/$a"
+    done < "$srcmods/modules.dep"
+    IFS=$_OLDIFS
     return 0
-)
+}
 
 find_kernel_modules () {
     find_kernel_modules_by_path  drivers
@@ -1325,7 +1641,6 @@ instmods() {
                 ((_ret+=$?))
                 ;;
             --*) _mpargs+=" $_mod" ;;
-            i2o_scsi) return 0;; # Do not load this diagnostic-only module
             *)
                 _mod=${_mod##*/}
                 # if we are already installed, skip this module and go on
@@ -1336,20 +1651,21 @@ instmods() {
                     return $_ret
                 fi
 
-                if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
+                _mod=${_mod/-/_}
+                if [[ $omit_drivers ]] && [[ "$_mod" =~ $omit_drivers ]]; then
                     dinfo "Omitting driver ${_mod##$srcmods}"
                     return 0
                 fi
+
                 # If we are building a host-specific initramfs and this
                 # module is not already loaded, move on to the next one.
                 [[ $hostonly ]] \
-                    && ! [[ -d $(echo /sys/module/${_mod//-/_}|{ read a b; echo $a; }) ]] \
-                    && ! [[ "$add_drivers" =~ " ${_mod} " ]] \
+                    && ! module_is_host_only "$_mod" \
                     && return 0
 
                 if [[ "$_check" = "yes" ]] || ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
                     # We use '-d' option in modprobe only if modules prefix path
-                    # differs from default '/'.  This allows us to use Dracut with
+                    # differs from default '/'.  This allows us to use dracut with
                     # old version of modprobe which doesn't have '-d' option.
                     local _moddirname=${srcmods%%/lib/modules/*}
                     [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
@@ -1374,7 +1690,7 @@ instmods() {
             while read _mod; do
                 inst1mod "${_mod%.ko*}" || {
                     if [[ "$_check" == "yes" ]]; then
-                        [[ "$_silent" == "no" ]] && dfatal "Failed to install $_mod"
+                        [[ "$_silent" == "no" ]] && dfatal "Failed to install module $_mod"
                         return 1
                     fi
                 }
@@ -1383,7 +1699,7 @@ instmods() {
         while (($# > 0)); do  # filenames as arguments
             inst1mod ${1%.ko*} || {
                 if [[ "$_check" == "yes" ]]; then
-                    [[ "$_silent" == "no" ]] && dfatal "Failed to install $1"
+                    [[ "$_silent" == "no" ]] && dfatal "Failed to install module $1"
                     return 1
                 fi
             }
@@ -1396,7 +1712,52 @@ instmods() {
     # Capture all stderr from modprobe to _fderr. We could use {var}>...
     # redirections, but that would make dracut require bash4 at least.
     eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
-    | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
+        | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
     _ret=$?
     return $_ret
 }
+# get_cpu_vendor
+# Only two values are returned: AMD or Intel
+get_cpu_vendor ()
+{
+    if grep -qE AMD /proc/cpuinfo; then
+        printf "AMD"
+    fi
+    if grep -qE Intel /proc/cpuinfo; then
+        printf "Intel"
+    fi
+}
+
+# get_host_ucode
+# Get the hosts' ucode file based on the /proc/cpuinfo
+get_ucode_file ()
+{
+    local family=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
+    local model=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
+    local stepping=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
+
+    if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
+        # If family greater or equal than 0x15
+        if [[ $family -ge 21 ]]; then
+            printf "microcode_amd_fam15h.bin"
+        else
+            printf "microcode_amd.bin"
+        fi
+    fi
+    if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
+        # The /proc/cpuinfo are in decimal.
+        printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
+    fi
+}
+
+# Not every device in /dev/mapper should be examined.
+# If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
+lvm_internal_dev() {
+    local dev_dm_dir=/sys/dev/block/$1/dm
+    [[ ! -f $dev_dm_dir/uuid || $(<$dev_dm_dir/uuid) != LVM-* ]] && return 1 # Not an LVM device
+    local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
+    eval $(dmsetup splitname --nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev/null)
+    [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 0 # Better skip this!
+    [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]
+}
+