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
fi
-srcmods="/lib/modules/$kernel/"
+srcmods="$dracutsysrootdir/lib/modules/$kernel/"
[[ $drivers_dir ]] && {
if ! command -v kmod &>/dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
export hookdirs
}
+DRACUT_LDD=${DRACUT_LDD:-ldd}
+DRACUT_TESTBIN=${DRACUT_TESTBIN:-/bin/sh}
+DRACUT_LDCONFIG=${DRACUT_LDCONFIG:-ldconfig}
+
. $dracutbasedir/dracut-functions.sh
# Detect lib paths
if ! [[ $libdirs ]] ; then
- if [[ "$(ldd /bin/sh)" == */lib64/* ]] &>/dev/null \
- && [[ -d /lib64 ]]; then
+ if [[ "$($DRACUT_LDD $dracutsysrootdir$DRACUT_TESTBIN)" == */lib64/* ]] &>/dev/null \
+ && [[ -d $dracutsysrootdir/lib64 ]]; then
libdirs+=" /lib64"
- [[ -d /usr/lib64 ]] && libdirs+=" /usr/lib64"
+ [[ -d $dracutsysrootdir/usr/lib64 ]] && libdirs+=" /usr/lib64"
else
libdirs+=" /lib"
- [[ -d /usr/lib ]] && libdirs+=" /usr/lib"
+ [[ -d $dracutsysrootdir/usr/lib ]] && libdirs+=" /usr/lib"
fi
libdirs+=" $(ldconfig_paths)"
[[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
}
+dracut_no_switch_root() {
+ >"$initdir/lib/dracut/no-switch-root"
+}
+
+dracut_module_path() {
+ echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; }
+}
+
if ! [[ $DRACUT_INSTALL ]]; then
DRACUT_INSTALL=$(find_binary dracut-install)
fi
DRACUT_INSTALL=$dracutbasedir/install/dracut-install
fi
-if ! [[ -x $DRACUT_INSTALL ]]; then
+# Test if dracut-install is a standalone executable with no options.
+# E.g. DRACUT_INSTALL may be set externally as:
+# DRACUT_INSTALL="valgrind dracut-install"
+# or
+# DRACUT_INSTALL="dracut-install --debug"
+# in which case the string cannot be tested for being executable.
+DRINSTALLPARTS=0
+for i in $DRACUT_INSTALL ; do
+ DRINSTALLPARTS=$(($DRINSTALLPARTS+1))
+done
+
+if [[ $DRINSTALLPARTS = 1 ]] && ! [[ -x $DRACUT_INSTALL ]]; then
dfatal "dracut-install not found!"
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 ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@" || :
}
inst() {
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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
}
inst_simple() {
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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
}
inst_symlink() {
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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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} "$@"
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
_ret=$?
- (($_ret != 0)) && derror FAILED: $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 ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
return $_ret
}
local i;
[[ $no_kernel = yes ]] && return
for i in "$@"; do
- [[ $i == "--silent" ]] && silent=1
+ [[ $i == "--silent" ]] && _silent=1
done
$DRACUT_INSTALL \
+ ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
${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 "$@" || :
+ (($? != 0)) && (($_silent == 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" || :
}
inst_library() {
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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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 FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
+ $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+ (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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 ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
+ (($? != 0)) && derror $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${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() {
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"
+ grep -E "^$i:" $dracutsysrootdir/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"
+ grep -E "^$i:" $dracutsysrootdir/etc/group 2>/dev/null >> "$initdir/etc/group"
fi
done
}
inst_dir "$_target"
for _rule in "$@"; do
if [ "${_rule#/}" = "$_rule" ]; then
- for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
+ for r in $dracutsysrootdir${udevdir}/rules.d ${hostonly:+$dracutsysrootdir/etc/udev/rules.d}; do
[[ -e $r/$_rule ]] || continue
_found="$r/$_rule"
inst_rule_programs "$_found"
inst_simple "$_found"
done
fi
- for r in '' $dracutbasedir/rules.d/; do
+ for r in '' $dracutsysrootdir$dracutbasedir/rules.d/; do
# skip rules without an absolute path
[[ "${r}$_rule" != /* ]] && continue
[[ -f ${r}$_rule ]] || continue
prepare_udev_rules() {
[ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
+ if [ -z "$UDEVVERSION" ]; then
+ derror "Failed to detect udev version!"
+ return 1
+ fi
+ if [ -z "${UDEVVERSION##*[!0-9]*}" ]; then
+ derror "udevadm --version did not report an integer, udev version cannot be determined!"
+ return 1
+ fi
for f in "$@"; do
f="${initdir}/etc/udev/rules.d/$f"
for _i in "$@"; do
for _f in "$_dir"/$_i; do
[[ "$_f" =~ $_pattern ]] || continue
- [[ -e "$_f" ]] && _files+="$_f "
+ [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
done
done
done
for _dir in $libdirs; do
for _i in "$@"; do
for _f in "$_dir"/$_i; do
- [[ -e "$_f" ]] && _files+="$_f "
+ [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
done
done
done
[[ $_files ]] && inst_multiple $_files
}
+# get a command to decompress the given file
+get_decompress_cmd() {
+ case "$1" in
+ *.gz) echo 'gzip -f -d' ;;
+ *.bz2) echo 'bzip2 -d' ;;
+ *.xz) echo 'xz -f -d' ;;
+ esac
+}
# install function decompressing the target and handling symlinks
# $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
for _src in $@
do
- case ${_src} in
- *.gz) _cmd='gzip -f -d' ;;
- *.bz2) _cmd='bzip2 -d' ;;
- *) return 1 ;;
- esac
+ _cmd=$(get_decompress_cmd ${_src})
+ [[ -z "${_cmd}" ]] && return 1
inst_simple ${_src}
# Decompress with chosen tool. We assume that tool changes name e.g.
# from 'name.gz' to 'name'.
done
}
-# module_check <dracut module>
+# module_check <dracut module> [<forced>] [<module path>]
# execute the check() function of module-setup.sh of <dracut module>
# or the "check" script, if module-setup.sh is not found
# "check $hostonly" is called
module_check() {
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
+ local _moddir=$3
local _ret
local _forced=0
local _hostonly=$hostonly
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[ $# -eq 2 ] && _forced=$2
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
return $_ret
}
-# module_check_mount <dracut module>
+# module_check_mount <dracut module> [<module path>]
# execute the check() function of module-setup.sh of <dracut module>
# 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} | { read a b; echo "$a"; })
+ local _moddir=$2
local _ret
mount_needs=1
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
# if we do not have a check script, we are unconditionally included
return $_ret
}
-# module_depends <dracut module>
+# module_depends <dracut module> [<module path>]
# 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} | { read a b; echo "$a"; })
+ local _moddir=$2
local _ret
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
# if we do not have a check script, we have no deps
fi
}
-# module_cmdline <dracut module>
+# module_cmdline <dracut module> [<module path>]
# 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 _moddir=$2
local _ret
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
[[ -x $_moddir/cmdline ]] && . "$_moddir/cmdline"
fi
}
-# module_install <dracut module>
+# module_install <dracut module> [<module path>]
# 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} | { read a b; echo "$a"; })
+ local _moddir=$2
local _ret
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
[[ -x $_moddir/install ]] && . "$_moddir/install"
fi
}
-# module_installkernel <dracut module>
+# module_installkernel <dracut module> [<module path>]
# 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} | { read a b; echo "$a"; })
+ local _moddir=$2
local _ret
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[[ -d $_moddir ]] || return 1
if [[ ! -f $_moddir/module-setup.sh ]]; then
[[ -x $_moddir/installkernel ]] && . "$_moddir/installkernel"
fi
}
-# check_mount <dracut module>
+# check_mount <dracut module> [<use_as_dep>] [<module path>]
# check_mount checks, if a dracut module is needed for the given
# device and filesystem types in "${host_fs_types[@]}"
check_mount() {
local _mod=$1
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
+ local _moddir=$3
local _ret
local _moddep
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
[ "${#host_fs_types[@]}" -le 0 ] && return 1
# If we are already scheduled to be loaded, no need to check again.
fi
if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
- module_check_mount $_mod; ret=$?
+ module_check_mount $_mod $_moddir; ret=$?
# explicit module, so also accept ret=255
[[ $ret = 0 || $ret = 255 ]] || return 1
# module not in our list
if [[ $dracutmodules = all ]]; then
# check, if we can and should install this module
- module_check_mount $_mod || return 1
+ module_check_mount $_mod $_moddir || return 1
else
# skip this module
return 1
fi
fi
- for _moddep in $(module_depends $_mod); do
+ for _moddep in $(module_depends $_mod $_moddir); do
# handle deps as if they were manually added
[[ " $dracutmodules " == *\ $_mod\ * ]] \
&& [[ " $dracutmodules " != *\ $_moddep\ * ]] \
return 0
}
-# check_module <dracut module> [<use_as_dep>]
+# check_module <dracut module> [<use_as_dep>] [<module path>]
# check if a dracut module is to be used in the initramfs process
# if <use_as_dep> is set, then the process also keeps track
# that the modules were checked for the dependency tracking process
check_module() {
local _mod=$1
- local _moddir=$(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
+ local _moddir=$3
local _ret
local _moddep
+
+ [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
# If we are already scheduled to be loaded, no need to check again.
[[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
[[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
- module_check $_mod 1; ret=$?
+ module_check $_mod 1 $_moddir; ret=$?
else
- module_check $_mod 0; ret=$?
+ module_check $_mod 0 $_moddir; ret=$?
fi
# explicit module, so also accept ret=255
[[ $ret = 0 || $ret = 255 ]] || return 1
# module not in our list
if [[ $dracutmodules = all ]]; then
# check, if we can and should install this module
- module_check $_mod; ret=$?
+ module_check $_mod 0 $_moddir; ret=$?
if [[ $ret != 0 ]]; then
[[ $2 ]] && return 1
[[ $ret != 255 ]] && return 1
fi
fi
- for _moddep in $(module_depends $_mod); do
+ for _moddep in $(module_depends $_mod $_moddir); do
# handle deps as if they were manually added
[[ " $dracutmodules " == *\ $_mod\ * ]] \
&& [[ " $dracutmodules " != *\ $_moddep\ * ]] \
}
# for_each_module_dir <func>
-# execute "<func> <dracut module> 1"
+# execute "<func> <dracut module> 1 <module path>"
for_each_module_dir() {
local _modcheck
local _mod
[[ -e $_moddir/install || -e $_moddir/installkernel || \
-e $_moddir/module-setup.sh ]] || continue
_mod=${_moddir##*/}; _mod=${_mod#[0-9][0-9]}
- $_func $_mod 1
+ $_func $_mod 1 $_moddir
done
# Report any missing dracut modules, the user has specified
done
}
-# Install a single kernel module along with any firmware it may require.
-# $1 = full path to kernel module to install
-install_kmod_with_fw() {
- # no need to go further if the module is already installed
-
- [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
- && return 0
-
- if [[ $omit_drivers ]]; then
- local _kmod=${1##*/}
- _kmod=${_kmod%.ko*}
- _kmod=${_kmod/-/_}
- if [[ "$_kmod" =~ $omit_drivers ]]; then
- dinfo "Omitting driver $_kmod"
- return 0
- fi
- if [[ "${1##*/lib/modules/$kernel/}" =~ $omit_drivers ]]; then
- dinfo "Omitting driver $_kmod"
- return 0
- 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=$?
- (($ret != 0)) && return $ret
-
- local _modname=${1##*/} _fwdir _found _fw
- _modname=${_modname%.ko*}
- for _fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
- _found=''
- for _fwdir in $fw_dir; do
- [[ -d $_fwdir && -f $_fwdir/$_fw ]] || continue
- inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
- _found=yes
- done
- if [[ $_found != yes ]]; then
- if ! [[ -d $(echo /sys/module/${_modname//-/_}|{ read a b; echo $a; }) ]]; then
- dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
- "\"${_modname}.ko\""
- else
- dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
- "\"${_modname}.ko\""
- fi
- fi
- done
- return 0
-}
-
-# Do something with all the dependencies of a kernel module.
-# Note that kernel modules depend on themselves using the technique we use
-# $1 = function to call for each dependency we find
-# It will be passed the full path to the found kernel module
-# $2 = module to get dependencies for
-# rest of args = arguments to modprobe
-# _fderr specifies FD passed from surrounding scope
-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 || [ -n "$_cmd" ]; do
- [[ $_cmd = insmod ]] || continue
- $_func ${_modpath} || exit $?
- done
- )
-}
-
dracut_kernel_post() {
- local _moddirname=${srcmods%%/lib/modules/*}
- local _pid
-
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
set -- "${args[@]}"
fi
+ if (($# == 0)); then
+ return 0
+ fi
+
$DRACUT_INSTALL \
${initdir:+-D "$initdir"} \
+ ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
${loginstall:+-L "$loginstall"} \
${hostonly:+-H} \
${omit_drivers:+-N "$omit_drivers"} \
derror "FAILED: " \
$DRACUT_INSTALL \
${initdir:+-D "$initdir"} \
+ ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
${loginstall:+-L "$loginstall"} \
${hostonly:+-H} \
${omit_drivers:+-N "$omit_drivers"} \
ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
}
fi
+
+is_qemu_virtualized() {
+ # 0 if a virt environment was detected
+ # 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
+ vm=$(systemd-detect-virt --vm >/dev/null 2>&1)
+ (($? != 0)) && return 255
+ [[ $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 vendor < $i
+ [[ "$vendor" == "QEMU" ]] && return 0
+ [[ "$vendor" == "Red Hat" ]] && return 0
+ [[ "$vendor" == "Bochs" ]] && return 0
+ done
+ return 1
+}