]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - dracut-init.sh
test: increase test VM memory from 512M to 1024M to avoid OOM killer
[thirdparty/dracut.git] / dracut-init.sh
old mode 100644 (file)
new mode 100755 (executable)
index 641d093..ff1d4e3
@@ -19,7 +19,7 @@
 #
 export LC_MESSAGES=C
 
-if [[ "$EUID" = "0" ]] && ! [[ $DRACUT_NO_XATTR ]]; then
+if [[ $EUID == "0" ]] && ! [[ $DRACUT_NO_XATTR ]]; then
     export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr,links -dfr"
 else
     export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr"
@@ -28,12 +28,12 @@ fi
 # is_func <command>
 # Check whether $1 is a function.
 is_func() {
-    [[ "$(type -t "$1")" = "function" ]]
+    [[ "$(type -t "$1")" == "function" ]]
 }
 
 if ! [[ $dracutbasedir ]]; then
     dracutbasedir=${BASH_SOURCE[0]%/*}
-    [[ $dracutbasedir = dracut-functions* ]] && dracutbasedir="."
+    [[ $dracutbasedir == dracut-functions* ]] && dracutbasedir="."
     [[ $dracutbasedir ]] || dracutbasedir="."
     dracutbasedir="$(readlink -f $dracutbasedir)"
 fi
@@ -72,8 +72,6 @@ srcmods="$dracutsysrootdir/lib/modules/$kernel/"
 }
 export srcmods
 
-[[ $DRACUT_FIRMWARE_PATH ]] || export DRACUT_FIRMWARE_PATH="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
-
 # export standard hookdirs
 [[ $hookdirs ]] || {
     hookdirs="cmdline pre-udev pre-trigger netroot "
@@ -114,14 +112,14 @@ require_binaries() {
     local _module_name="${moddir##*/}"
     local _ret=0
 
-    if [[ "$1" = "-m" ]]; then
+    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!"
+            dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
             ((_ret++))
         fi
     done
@@ -132,7 +130,7 @@ require_any_binary() {
     local _module_name="${moddir##*/}"
     local _ret=1
 
-    if [[ "$1" = "-m" ]]; then
+    if [[ $1 == "-m" ]]; then
         _module_name="$2"
         shift 2
     fi
@@ -152,6 +150,31 @@ require_any_binary() {
     return 0
 }
 
+# helper function for check() in module-setup.sh
+# to check for required kernel modules
+# issues a standardized warning message
+require_kernel_modules() {
+    # shellcheck disable=SC2154
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    # Ignore kernel module requirement for no-kernel build
+    [[ $no_kernel == yes ]] && return 0
+
+    if [[ $1 == "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for mod in "$@"; do
+        if ! check_kernel_module "$mod" &> /dev/null; then
+            dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because kernel module '$mod' is not available!"
+            ((_ret++))
+        fi
+    done
+    return "$_ret"
+}
+
 dracut_need_initqueue() {
     : > "$initdir/lib/dracut/need-initqueue"
 }
@@ -182,8 +205,8 @@ fi
 
 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
+elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/src/install/dracut-install ]]; then
+    DRACUT_INSTALL=$dracutbasedir/src/install/dracut-install
 fi
 
 # Test if dracut-install is a standalone executable with no options.
@@ -197,72 +220,92 @@ for i in $DRACUT_INSTALL; do
     DRINSTALLPARTS=$((DRINSTALLPARTS + 1))
 done
 
-if [[ $DRINSTALLPARTS = 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev/null 2>&1; then
+if [[ $DRINSTALLPARTS == 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev/null 2>&1; then
     dfatal "dracut-install not found!"
     exit 10
 fi
 
 if [[ $hostonly == "-h" ]]; then
-    if ! [[ $DRACUT_KERNEL_MODALIASES ]] || ! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
+    if ! [[ $DRACUT_KERNEL_MODALIASES ]] || ! [[ -f $DRACUT_KERNEL_MODALIASES ]]; then
         export DRACUT_KERNEL_MODALIASES="${DRACUT_TMPDIR}/modaliases"
-        "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
+        $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
     fi
 fi
 
 [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
 inst_dir() {
+    local _ret
     [[ -e ${initdir}/"$1" ]] && return 0 # already there
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then
+        return 0
+    else
+        _ret=$?
         derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
+        return $_ret
     fi
 }
 
 inst() {
-    local _hostonly_install
-    if [[ "$1" == "-H" ]]; then
+    local _ret _hostonly_install
+    if [[ $1 == "-H" ]]; then
         _hostonly_install="-H"
         shift
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
-    # shellcheck disable=SC2154
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
+        return 0
+    else
+        _ret=$?
         derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+        return $_ret
     fi
 }
 
 inst_simple() {
-    local _hostonly_install
-    if [[ "$1" == "-H" ]]; then
+    local _ret _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
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
+        return 0
+    else
+        _ret=$?
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+        return $_ret
     fi
 }
 
 inst_symlink() {
-    local _hostonly_install
-    if [[ "$1" == "-H" ]]; then
+    local _ret _hostonly_install
+    if [[ $1 == "-H" ]]; then
         _hostonly_install="-H"
         shift
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
     [[ -L $1 ]] || return 1
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
+        return 0
+    else
+        _ret=$?
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+        return $_ret
     fi
 }
 
 inst_multiple() {
-    local _ret
-    if "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
+    local _ret _hostonly_install
+    if [[ $1 == "-H" ]]; then
+        _hostonly_install="-H"
+        shift
+    fi
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
         return 0
     else
         _ret=$?
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
         return $_ret
     fi
 }
@@ -272,63 +315,84 @@ dracut_install() {
 }
 
 dracut_instmods() {
-    local _silent=0
+    local _ret _silent=0
     local i
     # shellcheck disable=SC2154
-    [[ $no_kernel = yes ]] && return
+    [[ $no_kernel == yes ]] && return
     for i in "$@"; do
         [[ $i == "--silent" ]] && _silent=1
     done
 
-    # shellcheck disable=SC2154
-    if ! "$DRACUT_INSTALL" \
+    if $DRACUT_INSTALL \
         ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
         ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"; then
+        return 0
+    else
+        _ret=$?
         if ((_silent == 0)); then
-            derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" || :
+            derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
         fi
+        return $_ret
     fi
 }
 
 inst_library() {
-    local _hostonly_install
-    if [[ "$1" == "-H" ]]; then
+    local _ret _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
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
+        return 0
+    else
+        _ret=$?
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+        return $_ret
     fi
 }
 
 inst_binary() {
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    local _ret
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
+        return 0
+    else
+        _ret=$?
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+        return $_ret
     fi
 }
 
 inst_script() {
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
-        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    local _ret
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
+        return 0
+    else
+        _ret=$?
+        derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+        return $_ret
     fi
 }
 
 inst_fsck_help() {
-    local _helper="/run/dracut/fsck/fsck_help_$1.txt"
-    if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"; then
-        derror "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper" || :
+    local _ret _helper="/run/dracut/fsck/fsck_help_$1.txt"
+    if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"; then
+        return 0
+    else
+        _ret=$?
+        derror "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"
+        return $_ret
     fi
 }
 
 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
-# If hosotnly mode is set to "strict", hostonly restrictions will still
+# If hostonly mode is set to "strict", hostonly restrictions will still
 # be applied, else will ignore hostonly mode and try to install all
 # given modules.
 optional_hostonly() {
     # shellcheck disable=SC2154
-    if [[ $hostonly_mode = "strict" ]]; then
+    if [[ $hostonly_mode == "strict" ]]; then
         printf -- "%s" "$hostonly"
     else
         printf ""
@@ -382,7 +446,7 @@ inst_rule_programs() {
         # shellcheck disable=SC2154
         if [[ -x ${udevdir}/$_prog ]]; then
             _bin="${udevdir}"/$_prog
-        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
+        elif [[ ${_prog/\$env\{/} == "$_prog" ]]; then
             _bin=$(find_binary "$_prog") || {
                 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                 continue
@@ -397,7 +461,7 @@ inst_rule_programs() {
         _bin=""
         if [[ -x ${udevdir}/$_prog ]]; then
             _bin=${udevdir}/$_prog
-        elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
+        elif [[ ${_prog/\$env\{/} == "$_prog" ]] && [[ ${_prog} != "/sbin/initqueue" ]]; then
             _bin=$(find_binary "$_prog") || {
                 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                 continue
@@ -412,7 +476,7 @@ inst_rule_programs() {
         _bin=""
         if [[ -x ${udevdir}/$_prog ]]; then
             _bin=${udevdir}/$_prog
-        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
+        elif [[ ${_prog/\$env\{/} == "$_prog" ]]; then
             _bin=$(find_binary "$_prog") || {
                 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
                 continue
@@ -423,7 +487,7 @@ inst_rule_programs() {
     done
 }
 
-# attempt to install any programs specified in a udev rule
+# attempt to create any groups and users specified in a udev rule
 inst_rule_group_owner() {
     local i
 
@@ -476,7 +540,7 @@ inst_rules() {
             inst_rule_initqueue "$_found"
             inst_simple "$_found" "$_target/${_found##*/}"
         done
-        [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
+        [[ $_found ]] || ddebug "Skipping udev rule: $_rule"
     done
 }
 
@@ -503,10 +567,26 @@ inst_rules_wildcard() {
             _found=$_rule
         done
     fi
-    [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
+    [[ $_found ]] || ddebug "Skipping udev rule: $_rule"
+}
+
+# make sure that library links are correct and up to date
+build_ld_cache() {
+    for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
+        [[ -f $f ]] && inst_simple "${f#"$dracutsysrootdir"}"
+    done
+    if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
+        if [[ $EUID == 0 ]]; then
+            derror "ldconfig exited ungracefully"
+        else
+            derror "ldconfig might need uid=0 (root) for chroot()"
+        fi
+    fi
 }
 
 prepare_udev_rules() {
+    dwarn "prepare_udev_rules: deprecated and will be removed"
+
     if [ -z "$UDEVVERSION" ]; then
         UDEVVERSION=$(udevadm --version)
         export UDEVVERSION
@@ -550,15 +630,18 @@ prepare_udev_rules() {
 # $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.
 inst_hook() {
+    local hook
     if ! [[ -f $3 ]]; then
         dfatal "Cannot install a hook ($3) that does not exist."
         dfatal "Aborting initrd creation."
         exit 1
-    elif ! [[ "$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##*/}"
+    hook="/lib/dracut/hooks/${1}/${2}-${3##*/}"
+    inst_simple "$3" "$hook"
+    chmod u+x "$initdir/$hook"
 }
 
 # install any of listed files
@@ -577,7 +660,7 @@ inst_hook() {
 inst_any() {
     local to f
 
-    [[ $1 = '-d' ]] && to="$2" && shift 2
+    [[ $1 == '-d' ]] && to="$2" && shift 2
 
     for f in "$@"; do
         [[ -e $f ]] || continue
@@ -588,19 +671,35 @@ inst_any() {
     return 1
 }
 
+# inst_libdir_dir <dir> [<dir>...]
+# Install a <dir> located on a lib directory to the initramfs image
+inst_libdir_dir() {
+    local -a _dirs
+    for _dir in $libdirs; do
+        for _i in "$@"; do
+            for _d in "$dracutsysrootdir$_dir"/$_i; do
+                [[ -d $_d ]] && _dirs+=("${_d#"$dracutsysrootdir"}")
+            done
+        done
+    done
+    for _dir in "${_dirs[@]}"; do
+        inst_dir "$_dir"
+    done
+}
+
 # inst_libdir_file [-n <pattern>] <file> [<file>...]
 # Install a <file> located on a lib directory to the initramfs image
 # -n <pattern> install matching files
 inst_libdir_file() {
     local -a _files
-    if [[ "$1" == "-n" ]]; then
+    if [[ $1 == "-n" ]]; then
         local _pattern=$2
         shift 2
         for _dir in $libdirs; do
             for _i in "$@"; do
                 for _f in "$dracutsysrootdir$_dir"/$_i; do
-                    [[ "${_f#$dracutsysrootdir}" =~ $_pattern ]] || continue
-                    [[ -e "$_f" ]] && _files+=("${_f#$dracutsysrootdir}")
+                    [[ ${_f#"$dracutsysrootdir"} =~ $_pattern ]] || continue
+                    [[ -e $_f ]] && _files+=("${_f#"$dracutsysrootdir"}")
                 done
             done
         done
@@ -608,7 +707,7 @@ inst_libdir_file() {
         for _dir in $libdirs; do
             for _i in "$@"; do
                 for _f in "$dracutsysrootdir$_dir"/$_i; do
-                    [[ -e "$_f" ]] && _files+=("${_f#$dracutsysrootdir}")
+                    [[ -e $_f ]] && _files+=("${_f#"$dracutsysrootdir"}")
                 done
             done
         done
@@ -622,6 +721,7 @@ get_decompress_cmd() {
         *.gz) echo 'gzip -f -d' ;;
         *.bz2) echo 'bzip2 -d' ;;
         *.xz) echo 'xz -f -d' ;;
+        *.zst) echo 'zstd -f -d ' ;;
     esac
 }
 
@@ -635,7 +735,7 @@ inst_decompress() {
 
     for _src in "$@"; do
         _cmd=$(get_decompress_cmd "${_src}")
-        [[ -z "${_cmd}" ]] && return 1
+        [[ -z ${_cmd} ]] && return 1
         inst_simple "${_src}"
         # Decompress with chosen tool.  We assume that tool changes name e.g.
         # from 'name.gz' to 'name'.
@@ -664,7 +764,7 @@ module_check() {
     local _forced=0
     local _hostonly=$hostonly
     [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
-    [ $# -eq 2 ] && _forced=$2
+    [ $# -ge 2 ] && _forced=$2
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
         # if we do not have a check script, we are unconditionally included
@@ -677,6 +777,7 @@ module_check() {
     else
         unset check depends cmdline install installkernel
         check() { true; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         is_func check || return 0
         [[ $_forced != 0 ]] && unset hostonly
@@ -708,6 +809,7 @@ module_check_mount() {
     else
         unset check depends cmdline install installkernel
         check() { false; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         moddir=$_moddir check 0
         _ret=$?
@@ -733,6 +835,7 @@ module_depends() {
     else
         unset check depends cmdline install installkernel
         depends() { true; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         moddir=$_moddir depends
         _ret=$?
@@ -750,11 +853,13 @@ module_cmdline() {
     [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
+        # shellcheck disable=SC1090
         [[ -x $_moddir/cmdline ]] && . "$_moddir/cmdline"
         return $?
     else
         unset check depends cmdline install installkernel
         cmdline() { true; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         moddir="$_moddir" cmdline
         _ret=$?
@@ -772,11 +877,13 @@ module_install() {
     [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
+        # shellcheck disable=SC1090
         [[ -x $_moddir/install ]] && . "$_moddir/install"
         return $?
     else
         unset check depends cmdline install installkernel
         install() { true; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         moddir="$_moddir" install
         _ret=$?
@@ -794,11 +901,13 @@ module_installkernel() {
     [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
     [[ -d $_moddir ]] || return 1
     if [[ ! -f $_moddir/module-setup.sh ]]; then
+        # shellcheck disable=SC1090
         [[ -x $_moddir/installkernel ]] && . "$_moddir/installkernel"
         return $?
     else
         unset check depends cmdline install installkernel
         installkernel() { true; }
+        # shellcheck disable=SC1090
         . "$_moddir"/module-setup.sh
         moddir="$_moddir" installkernel
         _ret=$?
@@ -836,13 +945,13 @@ check_mount() {
 
     if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
         module_check_mount "$_mod" "$_moddir"
-        ret=$?
+        _ret=$?
 
-        # explicit module, so also accept ret=255
-        [[ $ret = 0 || $ret = 255 ]] || return 1
+        # explicit module, so also accept _ret=255
+        [[ $_ret == 0 || $_ret == 255 ]] || return 1
     else
         # module not in our list
-        if [[ $dracutmodules = all ]]; then
+        if [[ $dracutmodules == all ]]; then
             # check, if we can and should install this module
             module_check_mount "$_mod" "$_moddir" || return 1
         else
@@ -864,7 +973,7 @@ check_mount() {
             && 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"
+            derror "Module '$_mod' depends on '$_moddep', which can't be installed"
             return 1
         fi
     done
@@ -896,29 +1005,29 @@ check_module() {
     [[ $2 ]] || mods_checked_as_dep+=" $_mod "
 
     if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
-        ddebug "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
+        ddebug "Module '$_mod' will not be installed, because it's in the list to be omitted!"
         return 1
     fi
 
     if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
         if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
             module_check "$_mod" 1 "$_moddir"
-            ret=$?
+            _ret=$?
         else
             module_check "$_mod" 0 "$_moddir"
-            ret=$?
+            _ret=$?
         fi
-        # explicit module, so also accept ret=255
-        [[ $ret = 0 || $ret = 255 ]] || return 1
+        # explicit module, so also accept _ret=255
+        [[ $_ret == 0 || $_ret == 255 ]] || return 1
     else
         # module not in our list
-        if [[ $dracutmodules = all ]]; then
+        if [[ $dracutmodules == all ]]; then
             # check, if we can and should install this module
             module_check "$_mod" 0 "$_moddir"
-            ret=$?
-            if [[ $ret != 0 ]]; then
+            _ret=$?
+            if [[ $_ret != 0 ]]; then
                 [[ $2 ]] && return 1
-                [[ $ret != 255 ]] && return 1
+                [[ $_ret != 255 ]] && return 1
             fi
         else
             # skip this module
@@ -939,7 +1048,7 @@ check_module() {
             && 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"
+            derror "Module '$_mod' depends on '$_moddep', which can't be installed"
             return 1
         fi
     done
@@ -957,11 +1066,11 @@ for_each_module_dir() {
     local _mod
     local _moddir
     local _func
+    local _reason
     _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
+        [[ -e $_moddir/install || -e $_moddir/installkernel || -e $_moddir/module-setup.sh ]] || continue
         _mod=${_moddir##*/}
         _mod=${_mod#[0-9][0-9]}
         $_func "$_mod" 1 "$_moddir"
@@ -978,7 +1087,10 @@ for_each_module_dir() {
             && [[ " $omit_dracutmodules " == *\ $_mod\ * ]] \
             && continue
 
-        derror "dracut module '$_mod' cannot be found or installed."
+        [[ -d $(echo "$dracutbasedir/modules.d"/[0-9][0-9]"$_mod") ]] \
+            && _reason="installed" \
+            || _reason="found"
+        derror "Module '$_mod' cannot be $_reason."
         [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] && exit 1
         [[ " $dracutmodules " == *\ $_mod\ * ]] && exit 1
         [[ " $add_dracutmodules " == *\ $_mod\ * ]] && exit 1
@@ -986,7 +1098,7 @@ for_each_module_dir() {
 }
 
 dracut_kernel_post() {
-    for _f in modules.builtin.bin modules.builtin modules.order; do
+    for _f in modules.builtin modules.builtin.alias modules.builtin.modinfo modules.order; do
         [[ -e $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
     done
 
@@ -1010,13 +1122,13 @@ instmods() {
     local _silent
     local _ret
 
-    [[ $no_kernel = yes ]] && return
+    [[ $no_kernel == yes ]] && return
 
-    if [[ $1 = '-c' ]]; then
+    if [[ $1 == '-c' ]]; then
         unset _optional
         shift
     fi
-    if [[ $1 = '-s' ]]; then
+    if [[ $1 == '-s' ]]; then
         _silent=1
         shift
     fi
@@ -1030,7 +1142,7 @@ instmods() {
         return 0
     fi
 
-    "$DRACUT_INSTALL" \
+    $DRACUT_INSTALL \
         ${initdir:+-D "$initdir"} \
         ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
         ${loginstall:+-L "$loginstall"} \
@@ -1042,7 +1154,7 @@ instmods() {
         -m "$@"
     _ret=$?
 
-    if ((_ret != 0)) && [[ -z "$_silent" ]]; then
+    if ((_ret != 0)) && [[ -z $_silent ]]; then
         derror "FAILED: " \
             "$DRACUT_INSTALL" \
             ${initdir:+-D "$initdir"} \
@@ -1056,7 +1168,7 @@ instmods() {
             -m "$@"
     fi
 
-    [[ "$optional" ]] && return 0
+    [[ "$_optional" ]] && return 0
     return $_ret
 }
 
@@ -1068,7 +1180,7 @@ else
     ln_r() {
         local _source=$1
         local _dest=$2
-        [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
+        [[ -d ${_dest%/*} ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
         ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
     }
 fi
@@ -1078,20 +1190,20 @@ is_qemu_virtualized() {
     # 1 if a virt environment could not be detected
     # 255 if any error was encountered
     if type -P systemd-detect-virt > /dev/null 2>&1; then
-        if ! vm=$(systemd-detect-virt --vm > /dev/null 2>&1); then
+        if ! vm=$(systemd-detect-virt --vm 2> /dev/null); then
             return 255
         fi
-        [[ $vm = "qemu" ]] && return 0
-        [[ $vm = "kvm" ]] && return 0
-        [[ $vm = "bochs" ]] && return 0
+        [[ $vm == "qemu" ]] && return 0
+        [[ $vm == "kvm" ]] && return 0
+        [[ $vm == "bochs" ]] && return 0
     fi
 
     for i in /sys/class/dmi/id/*_vendor; do
         [[ -f $i ]] || continue
         read -r vendor < "$i"
-        [[ "$vendor" == "QEMU" ]] && return 0
-        [[ "$vendor" == "Red Hat" ]] && return 0
-        [[ "$vendor" == "Bochs" ]] && return 0
+        [[ $vendor == "QEMU" ]] && return 0
+        [[ $vendor == "Red Hat" ]] && return 0
+        [[ $vendor == "Bochs" ]] && return 0
     done
     return 1
 }