]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - dracut-init.sh
Fix a missing space in example configs
[thirdparty/dracut.git] / dracut-init.sh
index a67aca2676c84dddb6f5df177b78c3cc809937d8..50d23e2d110dd1f220eb134e7a5cb5adf3211277 100644 (file)
 #
 export LC_MESSAGES=C
 
+if [[ "$EUID" = "0" ]]; 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"
+fi
+
 # is_func <command>
 # Check whether $1 is a function.
 is_func() {
@@ -46,13 +52,6 @@ if ! [[ -d $initdir ]]; then
     mkdir -p "$initdir"
 fi
 
-if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
-    if ! [[ -d "$initdir/.kernelmodseen" ]]; then
-        mkdir -p "$initdir/.kernelmodseen"
-    fi
-    DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
-fi
-
 if ! [[ $kernel ]]; then
     kernel=$(uname -r)
     export kernel
@@ -69,6 +68,8 @@ srcmods="/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 "
@@ -164,11 +165,18 @@ if ! [[ -x $DRACUT_INSTALL ]]; then
     exit 10
 fi
 
+if [[ $hostonly == "-h" ]]; then
+    if ! [[ $DRACUT_KERNEL_MODALIASES ]] || ! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
+        export DRACUT_KERNEL_MODALIASES="${DRACUT_TMPDIR}/modaliases"
+        $DRACUT_INSTALL ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
+    fi
+fi
+
 [[ $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 "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" || :
 }
 
 inst() {
@@ -179,7 +187,7 @@ inst() {
     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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_simple() {
@@ -191,7 +199,7 @@ inst_simple() {
     [[ -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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_symlink() {
@@ -203,14 +211,14 @@ inst_symlink() {
     [[ -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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 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} "$@" || :
+    (($_ret != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
     return $_ret
 }
 
@@ -218,6 +226,19 @@ dracut_install() {
     inst_multiple "$@"
 }
 
+dracut_instmods() {
+    local _silent=0;
+    local i;
+    [[ $no_kernel = yes ]] && return
+    for i in "$@"; do
+        [[ $i == "--silent" ]] && _silent=1
+    done
+
+    $DRACUT_INSTALL \
+        ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
+    (($? != 0)) && (($_silent == 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" || :
+}
+
 inst_library() {
     local _hostonly_install
     if [[ "$1" == "-H" ]]; then
@@ -227,17 +248,35 @@ inst_library() {
     [[ -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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
 }
 
 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} "$@" || :
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+}
+
+inst_fsck_help() {
+    local _helper="/run/dracut/fsck/fsck_help_$1.txt"
+    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
+    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$2" $_helper || :
+}
+
+# Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
+# If hosotnly 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() {
+    if [[ $hostonly_mode = "strict" ]]; then
+        printf -- "$hostonly"
+    else
+        printf ""
+    fi
 }
 
 mark_hostonly() {
@@ -275,71 +314,61 @@ rev_lib_symlinks() {
 inst_rule_programs() {
     local _prog _bin
 
-    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
-            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
-                _bin=$(find_binary "$_prog") || {
-                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
-                    continue;
-                }
-            fi
+    for _prog in $(sed -nr 's/.*PROGRAM==?"([^ "]+).*/\1/p' "$1"); do
+        _bin=""
+        if [ -x ${udevdir}/$_prog ]; then
+            _bin=${udevdir}/$_prog
+        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
+            _bin=$(find_binary "$_prog") || {
+                dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
+                continue;
+            }
+        fi
 
-            [[ $_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
-            _bin=""
-            if [ -x ${udevdir}/$_prog ]; then
-                _bin=${udevdir}/$_prog
-            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;
-                }
-            fi
+        [[ $_bin ]] && inst_binary "$_bin"
+    done
+    for _prog in $(sed -nr 's/.*RUN[+=]=?"([^ "]+).*/\1/p' "$1"); do
+        _bin=""
+        if [ -x ${udevdir}/$_prog ]; then
+            _bin=${udevdir}/$_prog
+        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;
+            }
+        fi
 
-            [[ $_bin ]] && inst_binary "$_bin"
-        done
-    fi
-    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
-            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
-                _bin=$(find_binary "$_prog") || {
-                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
-                    continue;
-                }
-            fi
+        [[ $_bin ]] && inst_binary "$_bin"
+    done
+    for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/p' "$1"); do
+        _bin=""
+        if [ -x ${udevdir}/$_prog ]; then
+            _bin=${udevdir}/$_prog
+        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
+            _bin=$(find_binary "$_prog") || {
+                dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
+                continue;
+            }
+        fi
 
-            [[ $_bin ]] && dracut_install "$_bin"
-        done
-    fi
+        [[ $_bin ]] && dracut_install "$_bin"
+    done
 }
 
 # 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 ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
-                grep -E "^$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 ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then
-                grep -E "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
-            fi
-        done
-    fi
+    for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p' "$1"); do
+        if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
+            grep -E "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+        fi
+    done
+    for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do
+        if ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then
+            grep -E "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
+        fi
+    done
 }
 
 inst_rule_initqueue() {
@@ -857,11 +886,6 @@ install_kmod_with_fw() {
     [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
         && return 0
 
-    if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
-        read ret < "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
-        return $ret
-    fi
-
     if [[ $omit_drivers ]]; then
         local _kmod=${1##*/}
         _kmod=${_kmod%.ko*}
@@ -886,9 +910,6 @@ install_kmod_with_fw() {
 
     inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
     ret=$?
-    [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
-        [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
-        echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
     (($ret != 0)) && return $ret
 
     local _modname=${1##*/} _fwdir _found _fw
@@ -932,56 +953,8 @@ 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}/} \
-            --ignore-install --show-depends --set-version $kernel \
-            < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev/null \
-            | sort -u \
-            | 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"} ${loginstall:+-L "$loginstall"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
-            else
-                while read _modpath || [ -n "$_modpath" ]; do
-                    local _destpath=$_modpath
-                    [[ $_moddirname ]] && _destpath=${_destpath##$_moddirname/}
-                    _destpath=${_destpath##*/lib/modules/$kernel/}
-                    inst_simple "$_modpath" "/lib/modules/$kernel/${_destpath}" || exit $?
-                done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
-            fi
-        ) &
-        _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 || [ -n "$line" ]; do
-                for _fwdir in $fw_dir; do
-                    echo $_fwdir/$line;
-                done;
-            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
-                    [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
-                    inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
-                    break
-                done
-            done
-        fi
-
-        wait $_pid
-    fi
-
     for _f in modules.builtin.bin modules.builtin modules.order; do
-        [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
+        [[ -e $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
     done
 
     # generate module dependencies for the initrd
@@ -991,170 +964,76 @@ dracut_kernel_post() {
         exit 1
     fi
 
-    [[ $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*}
-    _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
-
-        # just install the module, better safe than sorry
-        return 0
-    fi
-
-    return 1
-}
-
-find_kernel_modules_by_path () {
-    local _OLDIFS
-
-    [[ -f "$srcmods/modules.dep" ]] || return 0
-
-    _OLDIFS=$IFS
-    IFS=:
-    while read a rest || [ -n "$a" ]; do
-        [[ $a = */$1/* ]] || [[ $a = updates/* ]] || continue
-        printf "%s\n" "$srcmods/$a"
-    done < "$srcmods/modules.dep"
-    IFS=$_OLDIFS
-    return 0
-}
-
-find_kernel_modules () {
-    find_kernel_modules_by_path  drivers
-}
-
-# instmods [-c [-s]] <kernel module> [<kernel module> ... ]
-# instmods [-c [-s]] <kernel subsystem>
-# install kernel modules along with all their dependencies.
-# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
 instmods() {
+    # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
+    # instmods [-c [-s]] <kernel subsystem>
+    # install kernel modules along with all their dependencies.
+    # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
+    # -c check
+    # -s silent
+    local _optional="-o"
+    local _silent
+    local _ret
+
     [[ $no_kernel = yes ]] && return
-    # called [sub]functions inherit _fderr
-    local _fderr=9
-    local _check=no
-    local _silent=no
+
     if [[ $1 = '-c' ]]; then
-        _check=yes
+        unset _optional
         shift
     fi
-
     if [[ $1 = '-s' ]]; then
-        _silent=yes
+        _silent=1
         shift
     fi
 
-    function inst1mod() {
-        local _ret=0 _mod="$1"
-        case $_mod in
-            =*)
-                ( [[ "$_mpargs" ]] && echo $_mpargs
-                    find_kernel_modules_by_path "${_mod#=}" ) \
-                        | instmods
-                ((_ret+=$?))
-                ;;
-            --*) _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*}" ]]; then
-                    read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko*}"
-                    return $_ret
-                fi
-
-                _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 ]] \
-                    && ! 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
-                    # old version of modprobe which doesn't have '-d' option.
-                    local _moddirname=${srcmods%%/lib/modules/*}
-                    [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
-
-                    # ok, load the module, all its dependencies, and any firmware
-                    # it may require
-                    for_each_kmod_dep install_kmod_with_fw $_mod \
-                        --set-version $kernel ${_moddirname} $_mpargs
-                    ((_ret+=$?))
-                else
-                    [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
-                        echo ${_mod%.ko*} >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
-                fi
-                ;;
-        esac
-        return $_ret
-    }
+    if (($# == 0)); then
+        read -r -d '' -a args
+        set -- "${args[@]}"
+    fi
 
-    function instmods_1() {
-        local _mod _mpargs
-        if (($# == 0)); then  # filenames from stdin
-            while read _mod || [ -n "$_mod" ]; do
-                inst1mod "${_mod%.ko*}" || {
-                    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" ]] && [[ "$_silent" == "no" ]]; then
-                    dfatal "Failed to install module $1"
-                fi
-            }
-            shift
-        done
+    if (($# == 0)); then
         return 0
-    }
+    fi
 
-    local _ret _filter_not_found='FATAL: Module .* not found.'
-    # 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 || [ -n "$line" ]; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
+    $DRACUT_INSTALL \
+        ${initdir:+-D "$initdir"} \
+        ${loginstall:+-L "$loginstall"} \
+        ${hostonly:+-H} \
+        ${omit_drivers:+-N "$omit_drivers"} \
+        ${srcmods:+--kerneldir "$srcmods"} \
+        ${_optional:+-o} \
+        ${_silent:+--silent} \
+        -m "$@"
     _ret=$?
+
+    if (($_ret != 0)) && [[ -z "$_silent" ]]; then
+        derror "FAILED: " \
+            $DRACUT_INSTALL \
+                ${initdir:+-D "$initdir"} \
+                ${loginstall:+-L "$loginstall"} \
+                ${hostonly:+-H} \
+                ${omit_drivers:+-N "$omit_drivers"} \
+                ${srcmods:+--kerneldir "$srcmods"} \
+                ${_optional:+-o} \
+                ${_silent:+--silent} \
+                -m "$@"
+    fi
+
+    [[ "$optional" ]] && return 0
     return $_ret
 }
+
+if [[ "$(ln --help)" == *--relative* ]]; then
+    ln_r() {
+        ln -sfnr "${initdir}/$1" "${initdir}/$2"
+    }
+else
+    ln_r() {
+        local _source=$1
+        local _dest=$2
+        [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
+        ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
+    }
+fi