]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - dracut-functions.sh
guard ${arrays[@]} with ""
[thirdparty/dracut.git] / dracut-functions.sh
index c5bb1c4be8764da8e20eba02401a7c961639446b..3a0a5a25aa46037e047e6dec4cc52b5050654da4 100755 (executable)
@@ -1,6 +1,4 @@
 #!/bin/bash
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
-# ex: ts=8 sw=4 sts=4 et filetype=sh
 #
 # functions used by dracut and other tools.
 #
 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* ]]; }
+strstr() { [[ $1 = *"$2"* ]]; }
+# Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
+strglobin() { [[ $1 = *$2* ]]; }
+# Generic glob matching function. If glob pattern $2 matches all of $1, OK
+strglob() { [[ $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.
@@ -55,13 +101,10 @@ 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
@@ -73,6 +116,9 @@ if ! [[ $libdirs ]] ; then
         libdirs+=" /lib"
         [[ -d /usr/lib ]] && libdirs+=" /usr/lib"
     fi
+
+    libdirs+=" $(ldconfig_paths)"
+
     export libdirs
 fi
 
@@ -81,9 +127,37 @@ if ! [[ $kernel ]]; then
     export kernel
 fi
 
+# Version comparision function.  Assumes Linux style version scheme.
+# $1 = version a
+# $2 = comparision op (gt, ge, eq, le, lt, ne)
+# $3 = version b
+vercmp() {
+    local _n1=(${1//./ }) _op=$2 _n2=(${3//./ }) _i _res
+
+    for ((_i=0; ; _i++))
+    do
+        if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res=0
+        elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res=1
+        elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res=2
+        else continue
+        fi
+        break
+    done
+
+    case $_op in
+        gt) ((_res == 1));;
+        ge) ((_res != 2));;
+        eq) ((_res == 0));;
+        le) ((_res != 1));;
+        lt) ((_res == 2));;
+        ne) ((_res != 0));;
+    esac
+}
+
 srcmods="/lib/modules/$kernel/"
+
 [[ $drivers_dir ]] && {
-    if vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
+    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
@@ -91,7 +165,13 @@ srcmods="/lib/modules/$kernel/"
 }
 export srcmods
 
-if ! type dinfo >/dev/null 2>&1; then
+# is_func <command>
+# Check whether $1 is a function.
+is_func() {
+    [[ "$(type -t "$1")" = "function" ]]
+}
+
+if ! is_func dinfo >/dev/null 2>&1; then
     . "$dracutbasedir/dracut-logger.sh"
     dlog_init
 fi
@@ -115,7 +195,7 @@ dracut_need_initqueue() {
 }
 
 dracut_module_included() {
-    [[ "$mods_to_load $modules_loaded" == *$@* ]]
+    [[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
 }
 
 # Create all subdirectories for given path without creating the last element.
@@ -124,39 +204,6 @@ 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)
-# $3 = version b
-vercmp() {
-    local _n1=${1//./ } _op=$2 _n2=${3//./ } _i _res
-
-    for ((_i=0; ; _i++))
-    do
-        if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res=0
-        elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res=1
-        elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res=2
-        else continue
-        fi
-        break
-    done
-
-    case $_op in
-        gt) ((_res == 1));;
-        ge) ((_res != 2));;
-        eq) ((_res == 0));;
-        le) ((_res != 1));;
-        lt) ((_res == 2));;
-        ne) ((_res != 0));;
-    esac
-}
-
-# is_func <command>
-# Check whether $1 is a function.
-is_func() {
-    [[ "$(type -t "$1")" = "function" ]]
-}
-
 # Function prints global variables in format name=value line by line.
 # $@ = list of global variables' name
 print_vars() {
@@ -164,7 +211,7 @@ print_vars() {
 
     for _var in "$@"
     do
-        eval printf -v _value "%s" "\$$_var"
+        eval printf -v _value "%s" \""\$$_var"\"
         [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
     done
 }
@@ -179,7 +226,7 @@ normalize_path() {
     shopt -q -s extglob
     set -- "${1//+(\/)//}"
     shopt -q -u extglob
-    echo "${1%/}"
+    printf "%s\n" "${1%/}"
 }
 
 # convert_abs_rel <from> <to>
@@ -195,10 +242,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)
@@ -233,7 +280,7 @@ convert_abs_rel() {
         __newpath=$__newpath${__absolute[__i]}
     done
 
-    echo "$__newpath"
+    printf "%s\n" "$__newpath"
 }
 
 if [[ "$(ln --help)" == *--relative* ]]; then
@@ -249,26 +296,10 @@ else
     }
 fi
 
-get_persistent_dev() {
-    local i _tmp _dev
-
-    _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
-    [ -z "$_dev" ] && return
-
-    for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
-        [[ $i == /dev/mapper/mpath* ]] && continue
-        _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
-        if [ "$_tmp" = "$_dev" ]; then
-            printf -- "%s" "$i"
-            return
-        fi
-    done
-}
-
 # get_fs_env <device>
-# Get and set the ID_FS_TYPE 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
+# $ get_fs_env /dev/sda2
 # ext4
 get_fs_env() {
     local evalstr
@@ -276,33 +307,16 @@ get_fs_env() {
 
     [[ $1 ]] || return
     unset ID_FS_TYPE
-    if ID_FS_TYPE=$(udevadm info --query=env --name="$1" \
-        | { while read line; do
-                    [[ "$line" == DEVPATH\=* ]] && found=1;
-                    if [[ "$line" == ID_FS_TYPE\=* ]]; then
-                        printf "%s" "${line#ID_FS_TYPE=}";
-                        exit 0;
-                    fi
-                done; [[ $found ]] && exit 0; exit 1; }) ; then
-        if [[ $ID_FS_TYPE ]]; then
-            printf "%s" "$ID_FS_TYPE"
-            return 0
-        fi
-    fi
-
-    # Fallback, if we don't have udev information
-    if find_binary blkid >/dev/null; then
-        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
+    ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
+        | while read line || [ -n "$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
 }
@@ -318,6 +332,92 @@ get_maj_min() {
     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
+    printf -- "%s" "$1"
+}
+
+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>
 # Prints the major and minor number of the block device
 # for a given mountpoint.
@@ -334,20 +434,20 @@ find_block_device() {
     if [[ $use_fstab != yes ]]; then
         [[ -d $_find_mpt/. ]]
         findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
-            while read _majmin _dev; do
+            while read _majmin _dev || [ -n "$_dev" ]; do
                 if [[ -b $_dev ]]; then
                     if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
                         _majmin=$(get_maj_min $_dev)
                     fi
                     if [[ $_majmin ]]; then
-                        echo $_majmin
+                        printf "%s\n" "$_majmin"
                     else
-                        echo $_dev
+                        printf "%s\n" "$_dev"
                     fi
                     return 0
                 fi
                 if [[ $_dev = *:* ]]; then
-                    echo $_dev
+                    printf "%s\n" "$_dev"
                     return 0
                 fi
             done; return 1; } && return 0
@@ -355,7 +455,7 @@ find_block_device() {
     # fall back to /etc/fstab
 
     findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
-        while read _majmin _dev; do
+        while read _majmin _dev || [ -n "$_dev" ]; do
             if ! [[ $_dev ]]; then
                 _dev="$_majmin"
                 unset _majmin
@@ -363,14 +463,14 @@ find_block_device() {
             if [[ -b $_dev ]]; then
                 [[ $_majmin ]] || _majmin=$(get_maj_min $_dev)
                 if [[ $_majmin ]]; then
-                    echo $_majmin
+                    printf "%s\n" "$_majmin"
                 else
-                    echo $_dev
+                    printf "%s\n" "$_dev"
                 fi
                 return 0
             fi
             if [[ $_dev = *:* ]]; then
-                echo $_dev
+                printf "%s\n" "$_dev"
                 return 0
             fi
         done; return 1; } && return 0
@@ -391,19 +491,19 @@ find_mp_fstype() {
 
     if [[ $use_fstab != yes ]]; then
         findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \
-            while read _fs; do
+            while read _fs || [ -n "$_fs" ]; do
                 [[ $_fs ]] || continue
                 [[ $_fs = "autofs" ]] && continue
-                echo -n $_fs
+                printf "%s" "$_fs"
                 return 0
             done; return 1; } && return 0
     fi
 
     findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \
-        while read _fs; do
+        while read _fs || [ -n "$_fs" ]; do
             [[ $_fs ]] || continue
             [[ $_fs = "autofs" ]] && continue
-            echo -n $_fs
+            printf "%s" "$_fs"
             return 0
         done; return 1; } && return 0
 
@@ -421,30 +521,69 @@ find_mp_fstype() {
 find_dev_fstype() {
     local _find_dev _fs
     _find_dev="$1"
-    [[ "$_find_dev" = /dev* ]] || _find_dev="/dev/block/$_find_dev"
+    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 'FSTYPE' --source "$_find_dev" | { \
-            while read _fs; do
+            while read _fs || [ -n "$_fs" ]; do
                 [[ $_fs ]] || continue
                 [[ $_fs = "autofs" ]] && continue
-                echo -n $_fs
+                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
+        while read _fs || [ -n "$_fs" ]; do
             [[ $_fs ]] || continue
             [[ $_fs = "autofs" ]] && continue
-            echo -n $_fs
+            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 /; }
 
@@ -457,7 +596,7 @@ for_each_host_dev_fs()
     local _dev
     local _ret=1
 
-    [[ "${!host_fs_types[@]}" ]] || return 0
+    [[ "${#host_fs_types[@]}" ]] || return 0
 
     for _dev in "${!host_fs_types[@]}"; do
         $_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
@@ -467,7 +606,7 @@ for_each_host_dev_fs()
 
 host_fs_all()
 {
-    echo "${host_fs_types[@]}"
+    printf "%s\n" "${host_fs_types[@]}"
 }
 
 # Walk all the slave relationships for a given block device.
@@ -477,7 +616,7 @@ host_fs_all()
 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 $(<"/sys/dev/block/$2/../dev") && return 0
@@ -493,7 +632,7 @@ check_block_and_slaves() {
 check_block_and_slaves_all() {
     local _x _ret=1
     [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
-    if "$1" $2; then
+    if ! lvm_internal_dev $2 && "$1" $2; then
         _ret=0
     fi
     check_vol_slaves "$@" && return 0
@@ -518,7 +657,7 @@ for_each_host_dev_and_slaves_all()
 
     [[ "${host_devs[@]}" ]] || return 0
 
-    for _dev in ${host_devs[@]}; do
+    for _dev in "${host_devs[@]}"; do
         [[ -b "$_dev" ]] || continue
         if check_block_and_slaves_all $_func $(get_maj_min $_dev); then
             _ret=0
@@ -534,7 +673,7 @@ for_each_host_dev_and_slaves()
 
     [[ "${host_devs[@]}" ]] || return 0
 
-    for _dev in ${host_devs[@]}; do
+    for _dev in "${host_devs[@]}"; do
         [[ -b "$_dev" ]] || continue
         check_block_and_slaves $_func $(get_maj_min $_dev) && return 0
     done
@@ -548,13 +687,16 @@ for_each_host_dev_and_slaves()
 # but you cannot create the logical volume without the volume group.
 # And the volume group might be bigger than the devices the LV needs.
 check_vol_slaves() {
-    local _lv _vg _pv
+    local _lv _vg _pv _dm
     for i in /dev/mapper/*; do
+        [[ $i == /dev/mapper/control ]] && continue
         _lv=$(get_maj_min $i)
+        _dm=/sys/dev/block/$_lv/dm
+        [[ -f $_dm/uuid  && $(<$_dm/uuid) =~ LVM-* ]] || continue
         if [[ $_lv = $2 ]]; then
             _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
             # strip space
-            _vg=$(echo $_vg)
+            _vg=$(printf "%s\n" "$_vg")
             if [[ $_vg ]]; then
                 for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
                 do
@@ -586,268 +728,102 @@ fs_get_option() {
     done
 }
 
-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() {
-        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
-    }
-
-    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} "$@" || :
-    }
-
-    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
-
-    # 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
+if ! [[ $DRACUT_INSTALL ]]; then
+    DRACUT_INSTALL=$(find_binary dracut-install)
+fi
 
-        # 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 ]] && [[ -x $dracutbasedir/dracut-install ]]; then
+    DRACUT_INSTALL=$dracutbasedir/dracut-install
+elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]]; then
+    DRACUT_INSTALL=$dracutbasedir/install/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
-        [[ "$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
-            if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
-                inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
-            fi
-            if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
-                inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
-            fi
-        fi
-        ddebug "Installing $_src"
-        cp --reflink=auto --sparse=auto -pfL "$_src" "${initdir}/$_target"
-    }
+if ! [[ -x $DRACUT_INSTALL ]]; then
+    dfatal "dracut-install not found!"
+    exit 10
+fi
 
-    # same as above, but specialized for symlinks
-    inst_symlink() {
-        local _src=$1 _target=${2:-$1} _realsrc
-        [[ "$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%/*}"
+[[ $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 "$@" || :
+}
 
-        ln_r "${_realsrc}" "${_target}"
-    }
+inst() {
+    local _hostonly_install
+    if [[ "$1" == "-H" ]]; then
+        _hostonly_install="-H"
+        shift
+    fi
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+}
 
-    # 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
-        [[ "$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
-                if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
-                    inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
-                fi
-                if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
-                    inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_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_simple() {
+    local _hostonly_install
+    if [[ "$1" == "-H" ]]; then
+        _hostonly_install="-H"
+        shift
+    fi
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-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_symlink() {
+    local _hostonly_install
+    if [[ "$1" == "-H" ]]; then
+        _hostonly_install="-H"
+        shift
+    fi
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -L $1 ]] || return 1
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+}
 
-    # 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_multiple() {
+    local _ret
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    _ret=$?
+    (($_ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    return $_ret
+}
 
-            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"
-    }
+dracut_install() {
+    inst_multiple "$@"
+}
 
-    # 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
+inst_library() {
+    local _hostonly_install
+    if [[ "$1" == "-H" ]]; then
+        _hostonly_install="-H"
         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" "$@"
-    }
+    fi
+    [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
+    [[ -e $1 ]] || return 1  # no source
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+}
 
-    # 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_binary() {
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+}
 
-    # 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_script() {
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+}
 
-fi
+mark_hostonly() {
+    for i in "$@"; do
+        echo "$i" >> "$initdir/lib/dracut/hostonly-files"
+    done
+}
 
 # find symlinks linked to given library file
 # $1 = library file
@@ -890,7 +866,7 @@ inst_rule_programs() {
                 }
             fi
 
-            [[ $_bin ]] && dracut_install "$_bin"
+            [[ $_bin ]] && inst_binary "$_bin"
         done
     fi
     if grep -qE 'RUN[+=]=?"[^ "]+' "$1"; then
@@ -905,7 +881,7 @@ inst_rule_programs() {
                 }
             fi
 
-            [[ $_bin ]] && dracut_install "$_bin"
+            [[ $_bin ]] && inst_binary "$_bin"
         done
     fi
     if grep -qE 'IMPORT\{program\}==?"[^ "]+' "$1"; then
@@ -960,8 +936,8 @@ inst_rules() {
     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
+            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"
@@ -970,7 +946,10 @@ inst_rules() {
                 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"
@@ -983,13 +962,41 @@ inst_rules() {
     done
 }
 
+inst_rules_wildcard() {
+    local _target=/etc/udev/rules.d _rule _found
+
+    inst_dir "${udevdir}/rules.d"
+    inst_dir "$_target"
+    for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
+        if [[ -e $_rule ]]; then
+            inst_rule_programs "$_rule"
+            inst_rule_group_owner "$_rule"
+            inst_rule_initqueue "$_rule"
+            inst_simple "$_rule"
+            _found=$_rule
+        fi
+    done
+    if [[ -n ${hostonly} ]] ; then
+        for _rule in ${_target}/$1 ; do
+            if [[ -f $_rule ]]; then
+                inst_rule_programs "$_rule"
+                inst_rule_group_owner "$_rule"
+                inst_rule_initqueue "$_rule"
+                inst_simple "$_rule"
+                _found=$_rule
+            fi
+        done
+    fi
+    [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
+}
+
 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
+        while read line || [ -n "$line" ]; do
             if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
                 if [ $UDEVVERSION -ge 174 ]; then
                     printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
@@ -1079,7 +1086,7 @@ inst_libdir_file() {
             done
         done
     fi
-    [[ $_files ]] && dracut_install $_files
+    [[ $_files ]] && inst_multiple $_files
 }
 
 
@@ -1122,7 +1129,7 @@ inst_opt_decompress() {
 # or the "check" script, if module-setup.sh is not found
 # "check $hostonly" is called
 module_check() {
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     local _forced=0
     local _hostonly=$hostonly
@@ -1135,14 +1142,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
@@ -1153,7 +1160,7 @@ module_check() {
 # or the "check" script, if module-setup.sh is not found
 # "mount_needs=1 check 0" is called
 module_check_mount() {
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     mount_needs=1
     [[ -d $_moddir ]] || return 1
@@ -1163,12 +1170,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
+        moddir=$_moddir check 0
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
     fi
     unset mount_needs
     return $_ret
@@ -1178,7 +1185,7 @@ module_check_mount() {
 # execute the depends() function of module-setup.sh of <dracut module>
 # or the "depends" script, if module-setup.sh is not found
 module_depends() {
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
@@ -1187,12 +1194,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
+        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} | { read a b; echo "$a"; })
+    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
 }
@@ -1201,19 +1229,19 @@ module_depends() {
 # execute the install() function of module-setup.sh of <dracut module>
 # or the "install" script, if module-setup.sh is not found
 module_install() {
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
         [[ -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
+        moddir=$_moddir install
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -1222,19 +1250,19 @@ module_install() {
 # execute the installkernel() function of module-setup.sh of <dracut module>
 # or the "installkernel" script, if module-setup.sh is not found
 module_installkernel() {
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
         [[ -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
+        moddir=$_moddir installkernel
         _ret=$?
-        unset check depends install installkernel
+        unset check depends cmdline install installkernel
         return $_ret
     fi
 }
@@ -1244,11 +1272,11 @@ module_installkernel() {
 # device and filesystem types in "${host_fs_types[@]}"
 check_mount() {
     local _mod=$1
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     local _moddep
 
-    [ "${#host_fs_types[*]}" -le 0 ] && return 1
+    [ "${#host_fs_types[@]}" -le 0 ] && return 1
 
     # If we are already scheduled to be loaded, no need to check again.
     [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
@@ -1279,13 +1307,17 @@ check_mount() {
         fi
     fi
 
-
     for _moddep in $(module_depends $_mod); do
         # handle deps as if they were manually added
-        [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
-            add_dracutmodules+=" $_moddep "
-        [[ " $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
         if ! check_module $_moddep; then
             derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
@@ -1305,7 +1337,7 @@ check_mount() {
 # that the modules were checked for the dependency tracking process
 check_module() {
     local _mod=$1
-    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+    local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
     local _ret
     local _moddep
     # If we are already scheduled to be loaded, no need to check again.
@@ -1323,7 +1355,7 @@ check_module() {
     fi
 
     if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
-        if [[ " $force_add_dracutmodules " == *\ $_mod\ * ]]; then
+        if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
             module_check $_mod 1; ret=$?
         else
             module_check $_mod 0; ret=$?
@@ -1334,7 +1366,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
@@ -1343,10 +1379,15 @@ check_module() {
 
     for _moddep in $(module_depends $_mod); do
         # handle deps as if they were manually added
-        [[ " $add_dracutmodules " == *\ $_moddep\ * ]] || \
-            add_dracutmodules+=" $_moddep "
-        [[ " $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
         if ! check_module $_moddep; then
             derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
@@ -1369,17 +1410,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
         [[ " $mods_to_load " == *\ $_mod\ * ]] && continue
-        [[ " $omit_dracutmodules " == *\ $_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
 }
 
@@ -1398,7 +1450,7 @@ install_kmod_with_fw() {
 
     if [[ $omit_drivers ]]; then
         local _kmod=${1##*/}
-        _kmod=${_kmod%.ko}
+        _kmod=${_kmod%.ko*}
         _kmod=${_kmod/-/_}
         if [[ "$_kmod" =~ $omit_drivers ]]; then
             dinfo "Omitting driver $_kmod"
@@ -1410,6 +1462,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 ]] && \
@@ -1451,7 +1511,7 @@ for_each_kmod_dep() {
     local _func=$1 _kmod=$2 _cmd _modpath _options
     shift 2
     modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
-        while read _cmd _modpath _options; do
+        while read _cmd _modpath _options || [ -n "$_cmd" ]; do
             [[ $_cmd = insmod ]] || continue
             $_func ${_modpath} || exit $?
         done
@@ -1463,20 +1523,20 @@ dracut_kernel_post() {
     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 \
-            | while read _cmd _modpath _options; do
+            | while read _cmd _modpath _options || [ -n "$_cmd" ]; do
             [[ $_cmd = insmod ]] || continue
             echo "$_modpath"
         done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
 
         (
             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"} ${loginstall:+-L "$loginstall"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
             else
-                while read _modpath; do
+                while read _modpath || [ -n "$_modpath" ]; do
                     local _destpath=$_modpath
                     [[ $_moddirname ]] && _destpath=${_destpath##$_moddirname/}
                     _destpath=${_destpath##*/lib/modules/$kernel/}
@@ -1484,16 +1544,16 @@ dracut_kernel_post() {
                 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
             fi
         ) &
-        _pid=$(jobs -p | while read a ; do printf ":$a";done)
+        _pid=$(jobs -p | while read a  || [ -n "$a" ]; do printf ":$a";done)
         _pid=${_pid##*:}
 
         if [[ $DRACUT_INSTALL ]]; then
             xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
-                | while read line; do
+                | while read line || [ -n "$line" ]; do
                 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"} ${loginstall:+-L "$loginstall"} -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
@@ -1508,13 +1568,6 @@ dracut_kernel_post() {
         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
@@ -1529,23 +1582,47 @@ dracut_kernel_post() {
     [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
 }
 
+[[ "$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}
+    _mod=${_mod%.ko*}
+    _modenc=${_mod//-/_}
 
     [[ " $add_drivers " == *\ ${_mod}\ * ]] && return 0
 
     # check if module is loaded
-    for i in /sys/module/${_mod//-/_}; do
-        [[ -d $i ]] && return 0
-    done
+    [[ ${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)
 
-    # 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
-    modinfo -F filename "$_mod" &>/dev/null || return 0
+        # 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
 }
@@ -1557,8 +1634,8 @@ find_kernel_modules_by_path () {
 
     _OLDIFS=$IFS
     IFS=:
-    while read a rest; do
-        [[ $a = */$1/* ]] || continue
+    while read a rest || [ -n "$a" ]; do
+        [[ $a = */$1/* ]] || [[ $a = updates/* ]] || continue
         printf "%s\n" "$srcmods/$a"
     done < "$srcmods/modules.dep"
     IFS=$_OLDIFS
@@ -1601,15 +1678,23 @@ instmods() {
             --*) _mpargs+=" $_mod" ;;
             *)
                 _mod=${_mod##*/}
+                # Check for aliased modules
+                _modalias=$(modinfo -k $kernel -F filename $_mod 2> /dev/null)
+                _modalias=${_modalias%.ko*}
+                if [[ $_modalias ]] && [ "${_modalias##*/}" != "${_mod%.ko*}" ] ; then
+                    _mod=${_modalias##*/}
+                fi
+
                 # if we are already installed, skip this module and go on
                 # to the next one.
                 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
-                    [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
-                    read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
+                    [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko*}" ]]; then
+                    read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko*}"
                     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
@@ -1634,7 +1719,7 @@ instmods() {
                     ((_ret+=$?))
                 else
                     [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
-                        echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
+                        echo ${_mod%.ko*} >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
                 fi
                 ;;
         esac
@@ -1644,20 +1729,18 @@ instmods() {
     function instmods_1() {
         local _mod _mpargs
         if (($# == 0)); then  # filenames from stdin
-            while read _mod; do
+            while read _mod || [ -n "$_mod" ]; do
                 inst1mod "${_mod%.ko*}" || {
-                    if [[ "$_check" == "yes" ]]; then
-                        [[ "$_silent" == "no" ]] && dfatal "Failed to install module $_mod"
-                        return 1
+                    if [[ "$_check" == "yes" ]] && [[ "$_silent" == "no" ]]; then
+                        dfatal "Failed to install module $_mod"
                     fi
                 }
             done
         fi
         while (($# > 0)); do  # filenames as arguments
             inst1mod ${1%.ko*} || {
-                if [[ "$_check" == "yes" ]]; then
-                    [[ "$_silent" == "no" ]] && dfatal "Failed to install module $1"
-                    return 1
+                if [[ "$_check" == "yes" ]] && [[ "$_silent" == "no" ]]; then
+                    dfatal "Failed to install module $1"
                 fi
             }
             shift
@@ -1669,10 +1752,28 @@ 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 || [ -n "$line" ]; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
     _ret=$?
     return $_ret
 }
+
+check_kernel_config()
+{
+    local _config_opt="$1"
+    local _config_file
+    [[ -f /boot/config-$kernel ]] \
+        && _config_file="/boot/config-$kernel"
+    [[ -f /lib/modules/$kernel/config ]] \
+        && _config_file="/lib/modules/$kernel/config"
+
+    # no kernel config file, so return true
+    [[ $_config_file ]] || return 0
+
+    grep -q -F "${_config_opt}=" "$_config_file" && return 0
+    return 1
+}
+
+
 # get_cpu_vendor
 # Only two values are returned: AMD or Intel
 get_cpu_vendor ()
@@ -1706,3 +1807,24 @@ get_ucode_file ()
         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} ]]
+}
+
+btrfs_devs() {
+    local _mp="$1"
+    btrfs device usage "$_mp" \
+        | while read _dev _rest; do
+        str_starts "$_dev" "/" || continue
+        _dev=${_dev%,}
+        printf -- "%s\n" "$_dev"
+        done
+}