export LC_MESSAGES=C
if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
- if ! [[ -d "$initdir/.kernelmodseen" ]]; then
- mkdir -p "$initdir/.kernelmodseen"
+ if [[ -d "$initdir/.kernelmodseen" ]]; then
+ DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
fi
- DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
-fi
-
-if [[ $initdir ]] && ! [[ -d $initdir ]]; then
- mkdir -p "$initdir"
fi
# Generic substring function. If $2 is in $1, return 0.
strstr() { [[ $1 = *$2* ]]; }
+# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
+str_starts() { [ "${1#"$2"*}" != "$1" ]; }
+# returns OK if $1 contains literal string $2 at the end, and isn't empty
+str_ends() { [ "${1%*"$2"}" != "$1" ]; }
+
+# helper function for check() in module-setup.sh
+# to check for required installed binaries
+# issues a standardized warning message
+require_binaries() {
+ local _module_name="${moddir##*/}"
+ local _ret=0
+
+ if [[ "$1" = "-m" ]]; then
+ _module_name="$2"
+ shift 2
+ fi
+
+ for cmd in "$@"; do
+ if ! find_binary "$cmd" &>/dev/null; then
+ dinfo "dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
+ ((_ret++))
+ fi
+ done
+ return $_ret
+}
+
+require_any_binary() {
+ local _module_name="${moddir##*/}"
+ local _ret=1
+
+ if [[ "$1" = "-m" ]]; then
+ _module_name="$2"
+ shift 2
+ fi
+
+ for cmd in "$@"; do
+ if find_binary "$cmd" &>/dev/null; then
+ _ret=0
+ break
+ fi
+ done
+
+ if (( $_ret != 0 )); then
+ dinfo "$_module_name: Could not find any command of '$@'!"
+ return 1
+ fi
+
+ return 0
+}
# find a binary. If we were not passed the full path directly,
# search in the usual places to find the binary.
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
libdirs+=" /lib"
[[ -d /usr/lib ]] && libdirs+=" /usr/lib"
fi
+
+ libdirs+=" $(ldconfig_paths)"
+
export libdirs
fi
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
}
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
}
dracut_module_included() {
- [[ "$mods_to_load $modules_loaded" == *$@* ]]
+ [[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
}
# Create all subdirectories for given path without creating the last element.
[[ -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() {
for _var in "$@"
do
- eval printf -v _value "%s" "\$$_var"
+ eval printf -v _value "%s" \""\$$_var"\"
[[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
done
}
shopt -q -s extglob
set -- "${1//+(\/)//}"
shopt -q -u extglob
- echo "${1%/}"
+ printf "%s\n" "${1%/}"
}
# convert_abs_rel <from> <to>
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)
__newpath=$__newpath${__absolute[__i]}
done
- echo "$__newpath"
+ printf "%s\n" "$__newpath"
}
if [[ "$(ln --help)" == *--relative* ]]; then
}
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
[[ $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
- return 1
- 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; 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
}
# $ get_maj_min /dev/sda2
# 8:2
get_maj_min() {
- local _maj _min
- read _maj _min < <(stat -L -c '%t %T' "$1" 2>/dev/null)
- printf "%s" "$((0x$_maj)):$((0x$_min))"
+ local _maj _min _majmin
+ _majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
+ printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
+}
+
+
+# get_devpath_block <device>
+# get the DEVPATH in /sys of a block device
+get_devpath_block() {
+ local _majmin _i
+ _majmin=$(get_maj_min "$1")
+
+ for _i in /sys/block/*/dev /sys/block/*/*/dev; do
+ [[ -e "$_i" ]] || continue
+ if [[ "$_majmin" == "$(<"$_i")" ]]; then
+ printf "%s" "${_i%/dev}"
+ return 0
+ fi
+ done
+ return 1
+}
+
+# get a persistent path from a device
+get_persistent_dev() {
+ local i _tmp _dev
+
+ _dev=$(get_maj_min "$1")
+ [ -z "$_dev" ] && return
+
+ for i in \
+ /dev/mapper/* \
+ /dev/disk/${persistent_policy:-by-uuid}/* \
+ /dev/disk/by-uuid/* \
+ /dev/disk/by-label/* \
+ /dev/disk/by-partuuid/* \
+ /dev/disk/by-partlabel/* \
+ /dev/disk/by-id/* \
+ /dev/disk/by-path/* \
+ ; do
+ [[ -e "$i" ]] || continue
+ [[ $i == /dev/mapper/control ]] && continue
+ [[ $i == /dev/mapper/mpath* ]] && continue
+ _tmp=$(get_maj_min "$i")
+ if [ "$_tmp" = "$_dev" ]; then
+ printf -- "%s" "$i"
+ return
+ fi
+ done
+}
+
+expand_persistent_dev() {
+ local _dev=$1
+
+ case "$_dev" in
+ LABEL=*)
+ _dev="/dev/disk/by-label/${_dev#LABEL=}"
+ ;;
+ UUID=*)
+ _dev="${_dev#UUID=}"
+ _dev="${_dev,,}"
+ _dev="/dev/disk/by-uuid/${_dev}"
+ ;;
+ PARTUUID=*)
+ _dev="${_dev#PARTUUID=}"
+ _dev="${_dev,,}"
+ _dev="/dev/disk/by-partuuid/${_dev}"
+ ;;
+ PARTLABEL=*)
+ _dev="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
+ ;;
+ esac
+ printf "%s" "$_dev"
+}
+
+shorten_persistent_dev() {
+ local _dev="$1"
+ case "$_dev" in
+ /dev/disk/by-uuid/*)
+ printf "%s" "UUID=${_dev##*/}";;
+ /dev/disk/by-label/*)
+ printf "%s" "LABEL=${_dev##*/}";;
+ /dev/disk/by-partuuid/*)
+ printf "%s" "PARTUUID=${_dev##*/}";;
+ /dev/disk/by-partlabel/*)
+ printf "%s" "PARTLABEL=${_dev##*/}";;
+ *)
+ printf "%s" "$_dev";;
+ esac
}
# find_block_device <mountpoint>
_find_mpt="$1"
if [[ $use_fstab != yes ]]; then
[[ -d $_find_mpt/. ]]
+ findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
+ while read _majmin _dev; do
+ if [[ -b $_dev ]]; then
+ if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
+ _majmin=$(get_maj_min $_dev)
+ fi
+ if [[ $_majmin ]]; then
+ printf "%s\n" "$_majmin"
+ else
+ printf "%s\n" "$_dev"
+ fi
+ return 0
+ fi
+ if [[ $_dev = *:* ]]; then
+ printf "%s\n" "$_dev"
+ return 0
+ fi
+ done; return 1; } && return 0
+ fi
+ # fall back to /etc/fstab
+
+ findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
while read _majmin _dev; do
+ if ! [[ $_dev ]]; then
+ _dev="$_majmin"
+ unset _majmin
+ fi
if [[ -b $_dev ]]; then
- if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
- read _majmin < <(get_maj_min $_dev)
- fi
+ [[ $_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 < <(findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
- fi
- # fall back to /etc/fstab
-
- while read _majmin _dev; do
- if ! [[ $_dev ]]; then
- _dev="$_majmin"
- unset _majmin
- fi
- if [[ -b $_dev ]]; then
- [[ $_majmin ]] || read _majmin < <(get_maj_min $_dev)
- if [[ $_majmin ]]; then
- echo $_majmin
- else
- echo $_dev
- fi
- return 0
- fi
- if [[ $_dev = *:* ]]; then
- echo $_dev
- return 0
- fi
- done < <(findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
+ done; return 1; } && return 0
return 1
}
local _fs
if [[ $use_fstab != yes ]]; then
+ findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \
+ while read _fs; do
+ [[ $_fs ]] || continue
+ [[ $_fs = "autofs" ]] && continue
+ printf "%s" "$_fs"
+ return 0
+ done; return 1; } && return 0
+ fi
+
+ findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \
while read _fs; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
- echo -n $_fs
+ printf "%s" "$_fs"
return 0
- done < <(findmnt -e -v -n -o 'FSTYPE' --target "$1")
- fi
-
- while read _fs; do
- [[ $_fs ]] || continue
- [[ $_fs = "autofs" ]] && continue
- echo -n $_fs
- return 0
- done < <(findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1")
+ done; return 1; } && return 0
return 1
}
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
+ [[ $_fs ]] || continue
+ [[ $_fs = "autofs" ]] && continue
+ printf "%s" "$_fs"
+ return 0
+ done; return 1; } && return 0
+ fi
+
+ findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
while read _fs; do
[[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue
- echo -n $_fs
+ printf "%s" "$_fs"
return 0
- done < <(findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev")
+ 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
- while read _fs; do
- [[ $_fs ]] || continue
- [[ $_fs = "autofs" ]] && continue
- echo -n $_fs
- return 0
- done < <(findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev")
+ findmnt --fstab -e -v -n -o 'OPTIONS' --target "$1"
+}
- return 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 /; }
host_fs_all()
{
- echo "${host_fs_types[@]}"
+ printf "%s\n" "${host_fs_types[@]}"
}
# Walk all the slave relationships for a given block device.
check_block_and_slaves() {
local _x
[[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
- "$1" $2 && return
+ if ! lvm_internal_dev $2; then "$1" $2 && return; fi
check_vol_slaves "$@" && return 0
if [[ -f /sys/dev/block/$2/../dev ]]; then
- check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
+ check_block_and_slaves $1 $(<"/sys/dev/block/$2/../dev") && return 0
fi
[[ -d /sys/dev/block/$2/slaves ]] || return 1
for _x in /sys/dev/block/$2/slaves/*/dev; do
[[ -f $_x ]] || continue
- check_block_and_slaves $1 $(cat "$_x") && return 0
+ check_block_and_slaves $1 $(<"$_x") && return 0
done
return 1
}
check_block_and_slaves_all() {
local _x _ret=1
[[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
- if "$1" $2; then
- _ret=0
+ if ! lvm_internal_dev $2 && "$1" $2; then
+ _ret=0
fi
- check_vol_slaves "$@" && return 0
+ check_vol_slaves_all "$@" && return 0
if [[ -f /sys/dev/block/$2/../dev ]]; then
- check_block_and_slaves_all $1 $(cat "/sys/dev/block/$2/../dev") && _ret=0
+ check_block_and_slaves_all $1 $(<"/sys/dev/block/$2/../dev") && _ret=0
fi
[[ -d /sys/dev/block/$2/slaves ]] || return 1
for _x in /sys/dev/block/$2/slaves/*/dev; do
[[ -f $_x ]] || continue
- check_block_and_slaves_all $1 $(cat "$_x") && _ret=0
+ check_block_and_slaves_all $1 $(<"$_x") && _ret=0
done
return $_ret
}
for _dev in ${host_devs[@]}; do
[[ -b "$_dev" ]] || continue
if check_block_and_slaves_all $_func $(get_maj_min $_dev); then
- _ret=0
+ _ret=0
fi
done
return $_ret
check_vol_slaves() {
local _lv _vg _pv
for i in /dev/mapper/*; do
+ [[ $i == /dev/mapper/control ]] && continue
_lv=$(get_maj_min $i)
if [[ $_lv = $2 ]]; then
_vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
# strip space
- _vg=$(echo $_vg)
+ _vg="${_vg//[[:space:]]/}"
if [[ $_vg ]]; then
for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
do
return 1
}
+check_vol_slaves_all() {
+ local _lv _vg _pv
+ for i in /dev/mapper/*; do
+ [[ $i == /dev/mapper/control ]] && continue
+ _lv=$(get_maj_min $i)
+ if [[ $_lv = $2 ]]; then
+ _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
+ # strip space
+ _vg="${_vg//[[:space:]]/}"
+ if [[ $_vg ]]; then
+ for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
+ do
+ check_block_and_slaves_all $1 $(get_maj_min $_pv)
+ done
+ return 0
+ fi
+ fi
+ done
+ return 1
+}
+
+
+
# fs_get_option <filesystem options> <search for option>
# search for a specific option in a bunch of filesystem options
# and return the value
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
- # iterate over parent directories
- for _file in $_dir; do
- [[ -e "${initdir}/$_file" ]] && continue
- if [[ -L $_file ]]; then
- inst_symlink "$_file"
- else
- # create directory
- mkdir -m 0755 -p "${initdir}/$_file" || return 1
- [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
- chmod u+w "${initdir}/$_file"
- fi
- done
- }
+if ! [[ $DRACUT_INSTALL ]]; then
+ DRACUT_INSTALL=$(find_binary dracut-install)
+fi
- # $1 = file to copy to ramdisk
- # $2 (optional) Name for the file on the ramdisk
- # Location of the image dir is assumed to be $initdir
- # We never overwrite the target if it exists.
- inst_simple() {
- [[ -f "$1" ]] || return 1
- [[ "$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 ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
+ DRACUT_INSTALL=$dracutbasedir/dracut-install
+fi
- # same as above, but specialized for symlinks
- inst_symlink() {
- local _src=$1 _target=${2:-$1} _realsrc
- [[ "$1" == */* ]] || return 1
- [[ -L $1 ]] || return 1
- [[ -L $initdir/$_target ]] && return 0
- _realsrc=$(readlink -f "$_src")
- if ! [[ -e $initdir/$_realsrc ]]; then
- if [[ -d $_realsrc ]]; then
- inst_dir "$_realsrc"
- else
- inst "$_realsrc"
- fi
- fi
- [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
+if ! [[ -x $DRACUT_INSTALL ]]; then
+ dfatal "dracut-install not found!"
+ exit 10
+fi
- ln_r "${_realsrc}" "${_target}"
- }
+[[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
+inst_dir() {
+ [[ -e ${initdir}/"$1" ]] && return 0 # already there
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" || :
+}
- # Same as above, but specialized to handle dynamic libraries.
- # It handles making symlinks according to how the original library
- # is referenced.
- inst_library() {
- local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
- [[ "$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() {
+ [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
+ #dinfo "$DRACUT_INSTALL -l $@"
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
- # Create additional symlinks. See rev_symlinks description.
- for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
- [[ ! -e $initdir/$_symlink ]] && {
- ddebug "Creating extra symlink: $_symlink"
- inst_symlink $_symlink
- }
- done
- }
+inst_simple() {
+ [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
+ [[ -e $1 ]] || return 1 # no source
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" || :
+}
- # Same as above, but specialized to install binary executables.
- # Install binary executable, and all shared library dependencies, if any.
- inst_binary() {
- local _bin _target
- _bin=$(find_binary "$1") || return 1
- _target=${2:-$_bin}
- [[ -e $initdir/$_target ]] && return 0
- local _file _line
- local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
- # I love bash!
- LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
- [[ $_line = 'not a dynamic executable' ]] && break
-
- if [[ $_line =~ $_so_regex ]]; then
- _file=${BASH_REMATCH[1]}
- [[ -e ${initdir}/$_file ]] && continue
- inst_library "$_file"
- continue
- fi
+inst_symlink() {
+ [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
+ [[ -L $1 ]] || return 1
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
- if [[ $_line == *not\ found* ]]; then
- dfatal "Missing a shared library required by $_bin."
- dfatal "Run \"ldd $_bin\" to find out what it is."
- dfatal "$_line"
- dfatal "dracut cannot create an initrd."
- exit 1
- fi
- done
- inst_simple "$_bin" "$_target"
- }
+inst_multiple() {
+ local ret
+ #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ ret=$?
+ (($ret != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+ return $ret
+}
- # same as above, except for shell scripts.
- # If your shell script does not start with shebang, it is not a shell script.
- inst_script() {
- local _bin
- _bin=$(find_binary "$1") || return 1
- shift
- local _line _shebang_regex
- read -r -n 80 _line <"$_bin"
- # If debug is set, clean unprintable chars to prevent messing up the term
- [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
- _shebang_regex='(#! *)(/[^ ]+).*'
- [[ $_line =~ $_shebang_regex ]] || return 1
- inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
- }
+dracut_install() {
+ inst_multiple "$@"
+}
- # general purpose installation function
- # Same args as above.
- inst() {
- local _x
-
- case $# in
- 1) ;;
- 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
- [[ $initdir = $2 ]] && set $1;;
- 3) [[ -z $initdir ]] && export initdir=$2
- set $1 $3;;
- *) dfatal "inst only takes 1 or 2 or 3 arguments"
- exit 1;;
- esac
- for _x in inst_symlink inst_script inst_binary inst_simple; do
- $_x "$@" && return 0
- done
- return 1
- }
+inst_library() {
+ [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
+ [[ -e $1 ]] || return 1 # no source
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
- # dracut_install [-o ] <file> [<file> ... ]
- # Install <file> to the initramfs image
- # -o optionally install the <file> and don't fail, if it is not there
- dracut_install() {
- local _optional=no
- if [[ $1 = '-o' ]]; then
- _optional=yes
- shift
- fi
- while (($# > 0)); do
- if ! inst "$1" ; then
- if [[ $_optional = yes ]]; then
- dinfo "Skipping program $1 as it cannot be found and is" \
- "flagged to be optional"
- else
- dfatal "Failed to install $1"
- exit 1
- fi
- fi
- shift
- done
- }
+inst_binary() {
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
-fi
+inst_script() {
+ $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
+ (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" || :
+}
# find symlinks linked to given library file
# $1 = library file
}
fi
- [[ $_bin ]] && dracut_install "$_bin"
+ [[ $_bin ]] && inst_binary "$_bin"
done
fi
if grep -qE 'RUN[+=]=?"[^ "]+' "$1"; then
}
fi
- [[ $_bin ]] && dracut_install "$_bin"
+ [[ $_bin ]] && inst_binary "$_bin"
done
fi
if grep -qE 'IMPORT\{program\}==?"[^ "]+' "$1"; then
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"
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"
done
done
fi
- [[ $_files ]] && dracut_install $_files
+ [[ $_files ]] && inst_multiple $_files
}
$_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
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
$_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 cmdline install installkernel
+ return $_ret
+ fi
+}
+
+# module_cmdline <dracut module>
+# execute the cmdline() function of module-setup.sh of <dracut module>
+# or the "cmdline" script, if module-setup.sh is not found
+module_cmdline() {
+ local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
+ local _ret
+ [[ -d $_moddir ]] || return 1
+ if [[ ! -f $_moddir/module-setup.sh ]]; then
+ [[ -x $_moddir/cmdline ]] && . "$_moddir/cmdline"
+ return $?
+ else
+ unset check depends cmdline install installkernel
+ cmdline() { true; }
+ . $_moddir/module-setup.sh
+ moddir=$_moddir cmdline
_ret=$?
- unset check depends install installkernel
+ unset check depends cmdline install installkernel
return $_ret
fi
}
[[ -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
}
[[ -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/module-setup.sh
+ moddir=$_moddir installkernel
_ret=$?
- unset check depends install installkernel
+ unset check depends cmdline install installkernel
return $_ret
fi
}
[[ $2 ]] || mods_checked_as_dep+=" $_mod "
if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
- dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
return 1
fi
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"
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=$?
# 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
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"
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
}
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 ]] && \
dracut_kernel_post() {
local _moddirname=${srcmods%%/lib/modules/*}
+ local _pid
if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
- xargs -r modprobe -a ${_moddirname+-d ${_moddirname}/} \
+ xargs -r modprobe -a ${_moddirname:+-d ${_moddirname}/} \
--ignore-install --show-depends --set-version $kernel \
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev/null \
| sort -u \
(
if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
- xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
+ xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
else
while read _modpath; do
local _destpath=$_modpath
done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
fi
) &
+ _pid=$(jobs -p | while read a ; do printf ":$a";done)
+ _pid=${_pid##*:}
if [[ $DRACUT_INSTALL ]]; then
xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
for _fwdir in $fw_dir; do
echo $_fwdir/$line;
done;
- done | xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
+ done | xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
else
for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
for _fwdir in $fw_dir; do
done
fi
- wait
+ wait $_pid
fi
- for _f in modules.builtin.bin modules.builtin; do
- [[ $srcmods/$_f ]] && break
- done || {
- dfatal "No modules.builtin.bin and modules.builtin found!"
- return 1
- }
-
for _f in modules.builtin.bin modules.builtin modules.order; do
[[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
done
[[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
}
-module_is_host_only() { (
+[[ "$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
- 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
- # 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
+ _aliases=$(modinfo -k $kernel -F alias $_mod 2>/dev/null)
+
+ # if the module has no aliases, install it
+ [[ $_aliases ]] || return 0
+
+ # finally check all modalias
+ for a in $_aliases; do
+ for i in "${!host_modalias[@]}"; do
+ [[ $i == $a ]] && return 0
+ done
+ done
+
+ fi
return 1
- )
}
find_kernel_modules_by_path () {
_OLDIFS=$IFS
IFS=:
while read a rest; do
- [[ $a = */$1/* ]] || continue
+ [[ $a = */$1/* ]] || [[ $a = updates/* ]] || [[ $a = extra/* ]] || [[ $a = weak-updates/* ]] ||continue
printf "%s\n" "$srcmods/$a"
done < "$srcmods/modules.dep"
IFS=$_OLDIFS
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
# Capture all stderr from modprobe to _fderr. We could use {var}>...
# redirections, but that would make dracut require bash4 at least.
eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
- | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
+ | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
_ret=$?
return $_ret
}
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} ]]
+}
+