3 # functions used only by dracut and dracut modules
5 # Copyright 2005-2009 Red Hat, Inc. All rights reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 if [[ "$EUID" = "0" ]] && ! [[ $DRACUT_NO_XATTR ]]; then
23 export DRACUT_CP
="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr,links -dfr"
25 export DRACUT_CP
="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr"
29 # Check whether $1 is a function.
31 [[ "$(type -t "$1")" = "function" ]]
34 if ! [[ $dracutbasedir ]]; then
35 dracutbasedir
=${BASH_SOURCE[0]%/*}
36 [[ $dracutbasedir = dracut-functions
* ]] && dracutbasedir
="."
37 [[ $dracutbasedir ]] || dracutbasedir
="."
38 dracutbasedir
="$(readlink -f $dracutbasedir)"
41 if ! is_func dinfo
>/dev
/null
2>&1; then
42 # shellcheck source=./dracut-logger.sh
43 .
"$dracutbasedir/dracut-logger.sh"
47 # shellcheck disable=SC2154
48 if ! [[ $initdir ]]; then
49 dfatal
"initdir not set"
53 if ! [[ -d $initdir ]]; then
57 if ! [[ $kernel ]]; then
62 # shellcheck disable=SC2154
63 srcmods
="$dracutsysrootdir/lib/modules/$kernel/"
65 # shellcheck disable=SC2154
66 [[ $drivers_dir ]] && {
67 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
68 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
71 srcmods
="$drivers_dir"
75 [[ $DRACUT_FIRMWARE_PATH ]] ||
export DRACUT_FIRMWARE_PATH
="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
77 # export standard hookdirs
79 hookdirs
="cmdline pre-udev pre-trigger netroot "
80 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
81 hookdirs
+="pre-mount pre-pivot cleanup mount "
82 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
86 DRACUT_LDD
=${DRACUT_LDD:-ldd}
87 DRACUT_TESTBIN
=${DRACUT_TESTBIN:-/bin/sh}
88 DRACUT_LDCONFIG
=${DRACUT_LDCONFIG:-ldconfig}
90 # shellcheck source=./dracut-functions.sh
91 .
"$dracutbasedir"/dracut-functions.sh
94 if ! [[ $libdirs ]] ; then
95 if [[ $
("$DRACUT_LDD" "$dracutsysrootdir$DRACUT_TESTBIN") == */lib64
/* ]] &>/dev
/null \
96 && [[ -d $dracutsysrootdir/lib64
]]; then
98 [[ -d $dracutsysrootdir/usr
/lib64
]] && libdirs
+=" /usr/lib64"
101 [[ -d $dracutsysrootdir/usr
/lib
]] && libdirs
+=" /usr/lib"
104 libdirs
+=" $(ldconfig_paths)"
109 # helper function for check() in module-setup.sh
110 # to check for required installed binaries
111 # issues a standardized warning message
113 # shellcheck disable=SC2154
114 local _module_name
="${moddir##*/}"
117 if [[ "$1" = "-m" ]]; then
123 if ! find_binary
"$cmd" &>/dev
/null
; then
124 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
131 require_any_binary
() {
132 local _module_name
="${moddir##*/}"
135 if [[ "$1" = "-m" ]]; then
141 if find_binary
"$cmd" &>/dev
/null
; then
147 if (( _ret
!= 0 )); then
148 dinfo
"$_module_name: Could not find any command of '$*'!"
155 dracut_need_initqueue
() {
156 : >"$initdir/lib/dracut/need-initqueue"
159 dracut_module_included
() {
160 # shellcheck disable=SC2154
161 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
164 dracut_no_switch_root
() {
165 : >"$initdir/lib/dracut/no-switch-root"
168 dracut_module_path
() {
171 # shellcheck disable=SC2231
172 for _dir
in "${dracutbasedir}"/modules.d
/??
${1}; do
179 if ! [[ $DRACUT_INSTALL ]]; then
180 DRACUT_INSTALL
=$
(find_binary dracut-install
)
183 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
184 DRACUT_INSTALL
=$dracutbasedir/dracut-install
185 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install
/dracut-install
]]; then
186 DRACUT_INSTALL
=$dracutbasedir/install
/dracut-install
189 # Test if dracut-install is a standalone executable with no options.
190 # E.g. DRACUT_INSTALL may be set externally as:
191 # DRACUT_INSTALL="valgrind dracut-install"
193 # DRACUT_INSTALL="dracut-install --debug"
194 # in which case the string cannot be tested for being executable.
196 for i
in $DRACUT_INSTALL ; do
197 DRINSTALLPARTS
=$
((DRINSTALLPARTS
+1))
200 if [[ $DRINSTALLPARTS = 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev
/null
2>&1 ; then
201 dfatal
"dracut-install not found!"
205 if [[ $hostonly == "-h" ]]; then
206 if ! [[ $DRACUT_KERNEL_MODALIASES ]] ||
! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
207 export DRACUT_KERNEL_MODALIASES
="${DRACUT_TMPDIR}/modaliases"
208 "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
212 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
214 [[ -e ${initdir}/"$1" ]] && return 0 # already there
215 if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then
216 derror FAILED
: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
221 local _hostonly_install
222 if [[ "$1" == "-H" ]]; then
223 _hostonly_install
="-H"
226 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
227 # shellcheck disable=SC2154
228 if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
229 derror FAILED
: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
234 local _hostonly_install
235 if [[ "$1" == "-H" ]]; then
236 _hostonly_install
="-H"
239 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
240 [[ -e $1 ]] ||
return 1 # no source
241 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
242 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" ||
:
246 local _hostonly_install
247 if [[ "$1" == "-H" ]]; then
248 _hostonly_install
="-H"
251 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
252 [[ -L $1 ]] ||
return 1
253 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
254 (($?
!= 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} "$@" ||
:
259 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
261 (($_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} "$@" ||
:
272 [[ $no_kernel = yes ]] && return
274 [[ $i == "--silent" ]] && _silent
=1
278 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
279 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
280 (($?
!= 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 "$@" ||
:
284 local _hostonly_install
285 if [[ "$1" == "-H" ]]; then
286 _hostonly_install
="-H"
289 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
290 [[ -e $1 ]] ||
return 1 # no source
291 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
292 (($?
!= 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} "$@" ||
:
296 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
297 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
301 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
302 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
306 local _helper
="/run/dracut/fsck/fsck_help_$1.txt"
307 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
308 (($?
!= 0)) && derror
$DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper ||
:
311 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
312 # If hosotnly mode is set to "strict", hostonly restrictions will still
313 # be applied, else will ignore hostonly mode and try to install all
315 optional_hostonly
() {
316 if [[ $hostonly_mode = "strict" ]]; then
317 printf -- "$hostonly"
325 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
329 # find symlinks linked to given library file
331 # Function searches for symlinks by stripping version numbers appended to
332 # library filename, checks if it points to the same target and finally
333 # prints the list of symlinks to stdout.
336 # rev_lib_symlinks libfoo.so.8.1
337 # output: libfoo.so.8 libfoo.so
338 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
340 [[ ! $1 ]] && return 0
342 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
344 [[ ${fn} == *.so.
* ]] ||
return 1
346 until [[ ${fn##*.} == so
]]; do
348 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
354 # attempt to install any programs specified in a udev rule
355 inst_rule_programs() {
358 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
360 if [ -x ${udevdir}/$_prog ]; then
361 _bin=${udevdir}/$_prog
362 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
363 _bin=$(find_binary "$_prog") || {
364 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
369 [[ $_bin ]] && inst_binary "$_bin"
371 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
373 if [ -x ${udevdir}/$_prog ]; then
374 _bin=${udevdir}/$_prog
375 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
376 _bin=$(find_binary "$_prog") || {
377 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
382 [[ $_bin ]] && inst_binary "$_bin"
384 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
386 if [ -x ${udevdir}/$_prog ]; then
387 _bin=${udevdir}/$_prog
388 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
389 _bin=$(find_binary "$_prog") || {
390 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
395 [[ $_bin ]] && dracut_install "$_bin"
399 # attempt to install any programs specified in a udev rule
400 inst_rule_group_owner() {
403 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
404 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
405 grep -E "^
$i:" $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
408 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
409 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
410 grep -E "^
$i:" $dracutsysrootdir/etc/group 2>/dev/null >> "$initdir/etc
/group
"
415 inst_rule_initqueue() {
416 if grep -q -F initqueue "$1"; then
417 dracut_need_initqueue
421 # udev rules always get installed in the same place, so
422 # create a function to install them to make life simpler.
424 local _target=/etc/udev/rules.d _rule _found
426 inst_dir "${udevdir}/rules.d
"
428 for _rule in "$@
"; do
429 if [ "${_rule#/}" = "$_rule" ]; then
430 for r in $dracutsysrootdir${udevdir}/rules.d ${hostonly:+$dracutsysrootdir/etc/udev/rules.d}; do
431 [[ -e $r/$_rule ]] || continue
433 inst_rule_programs "$_found"
434 inst_rule_group_owner "$_found"
435 inst_rule_initqueue "$_found"
436 inst_simple "$_found"
439 for r in '' $dracutsysrootdir$dracutbasedir/rules.d/; do
440 # skip rules without an absolute path
441 [[ "${r}$_rule" != /* ]] && continue
442 [[ -f ${r}$_rule ]] || continue
444 inst_rule_programs "$_found"
445 inst_rule_group_owner "$_found"
446 inst_rule_initqueue "$_found"
447 inst_simple "$_found" "$_target/${_found##*/}"
449 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
453 inst_rules_wildcard() {
454 local _target=/etc/udev/rules.d _rule _found
456 inst_dir "${udevdir}/rules.d
"
458 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
459 [[ -e $_rule ]] || continue
460 inst_rule_programs "$_rule"
461 inst_rule_group_owner "$_rule"
462 inst_rule_initqueue "$_rule"
466 if [[ -n ${hostonly} ]] ; then
467 for _rule in ${_target}/$1 ; do
468 [[ -f $_rule ]] || continue
469 inst_rule_programs "$_rule"
470 inst_rule_group_owner "$_rule"
471 inst_rule_initqueue "$_rule"
476 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
479 prepare_udev_rules() {
480 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
481 if [ -z "$UDEVVERSION" ]; then
482 derror "Failed to detect udev version
!"
485 if [ -z "${UDEVVERSION##*[!0-9]*}" ]; then
486 derror "udevadm
--version did not report an integer
, udev version cannot be determined
!"
491 f="${initdir}/etc
/udev
/rules.d
/$f"
492 [ -e "$f" ] || continue
493 while read line || [ -n "$line" ]; do
494 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
495 if [ $UDEVVERSION -ge 174 ]; then
496 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
498 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
500 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
501 if [ $UDEVVERSION -ge 176 ]; then
502 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
504 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
509 done < "${f}" > "${f}.new
"
514 # install function specialized for hooks
515 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
516 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
518 if ! [[ -f $3 ]]; then
519 dfatal "Cannot
install a hook
($3) that does not exist.
"
520 dfatal "Aborting initrd creation.
"
522 elif ! [[ "$hookdirs" == *$1* ]]; then
523 dfatal "No such hook
type $1. Aborting initrd creation.
"
526 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
529 # install any of listed files
531 # If first argument is '-d' and second some destination path, first accessible
532 # source is installed into this path, otherwise it will installed in the same
533 # path as source. If none of listed files was installed, function return 1.
534 # On first successful installation it returns with 0 status.
538 # inst_any -d /bin/foo /bin/bar /bin/baz
540 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
545 [[ $1 = '-d' ]] && to="$2" && shift 2
548 [[ -e $f ]] || continue
549 [[ $to ]] && inst "$f" "$to" && return 0
550 inst "$f" && return 0
557 # inst_libdir_file [-n <pattern>] <file> [<file>...]
558 # Install a <file> located on a lib directory to the initramfs image
559 # -n <pattern> install matching files
562 if [[ "$1" == "-n" ]]; then
565 for _dir in $libdirs; do
567 for _f in "$dracutsysrootdir$_dir"/$_i; do
568 [[ "${_f#$dracutsysrootdir}" =~ $_pattern ]] || continue
569 [[ -e "$_f" ]] && _files+="${_f#$dracutsysrootdir} "
574 for _dir in $libdirs; do
576 for _f in "$dracutsysrootdir$_dir"/$_i; do
577 [[ -e "$_f" ]] && _files+="${_f#$dracutsysrootdir} "
582 [[ $_files ]] && inst_multiple $_files
585 # get a command to decompress the given file
586 get_decompress_cmd() {
588 *.gz) echo 'gzip -f -d' ;;
589 *.bz2) echo 'bzip2 -d' ;;
590 *.xz) echo 'xz -f -d' ;;
594 # install function decompressing the target and handling symlinks
595 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
597 # Function install targets in the same paths inside overlay but decompressed
598 # and without extensions (.gz, .bz2).
604 _cmd=$(get_decompress_cmd ${_src})
605 [[ -z "${_cmd}" ]] && return 1
607 # Decompress with chosen tool. We assume that tool changes name e.g.
608 # from 'name.gz' to 'name'.
609 ${_cmd} "${initdir}${_src}"
613 # It's similar to above, but if file is not compressed, performs standard
616 inst_opt_decompress
() {
620 inst_decompress
"${_src}" || inst
"${_src}"
624 # module_check <dracut module> [<forced>] [<module path>]
625 # execute the check() function of module-setup.sh of <dracut module>
626 # or the "check" script, if module-setup.sh is not found
627 # "check $hostonly" is called
632 local _hostonly
=$hostonly
633 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
634 [ $# -eq 2 ] && _forced
=$2
635 [[ -d $_moddir ]] ||
return 1
636 if [[ ! -f $_moddir/module-setup.sh
]]; then
637 # if we do not have a check script, we are unconditionally included
638 [[ -x $_moddir/check
]] ||
return 0
639 [ $_forced -ne 0 ] && unset hostonly
640 $_moddir/check
$hostonly
643 unset check depends cmdline
install installkernel
645 .
$_moddir/module-setup.sh
646 is_func check ||
return 0
647 [ $_forced -ne 0 ] && unset hostonly
648 moddir
=$_moddir check
$hostonly
650 unset check depends cmdline
install installkernel
656 # module_check_mount <dracut module> [<module path>]
657 # execute the check() function of module-setup.sh of <dracut module>
658 # or the "check" script, if module-setup.sh is not found
659 # "mount_needs=1 check 0" is called
660 module_check_mount
() {
664 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
665 [[ -d $_moddir ]] ||
return 1
666 if [[ ! -f $_moddir/module-setup.sh
]]; then
667 # if we do not have a check script, we are unconditionally included
668 [[ -x $_moddir/check
]] ||
return 0
669 mount_needs
=1 $_moddir/check
0
672 unset check depends cmdline
install installkernel
674 .
$_moddir/module-setup.sh
675 moddir
=$_moddir check
0
677 unset check depends cmdline
install installkernel
683 # module_depends <dracut module> [<module path>]
684 # execute the depends() function of module-setup.sh of <dracut module>
685 # or the "depends" script, if module-setup.sh is not found
689 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
690 [[ -d $_moddir ]] ||
return 1
691 if [[ ! -f $_moddir/module-setup.sh
]]; then
692 # if we do not have a check script, we have no deps
693 [[ -x $_moddir/check
]] ||
return 0
697 unset check depends cmdline
install installkernel
699 .
$_moddir/module-setup.sh
700 moddir
=$_moddir depends
702 unset check depends cmdline
install installkernel
707 # module_cmdline <dracut module> [<module path>]
708 # execute the cmdline() function of module-setup.sh of <dracut module>
709 # or the "cmdline" script, if module-setup.sh is not found
713 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
714 [[ -d $_moddir ]] ||
return 1
715 if [[ ! -f $_moddir/module-setup.sh
]]; then
716 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
719 unset check depends cmdline
install installkernel
721 .
$_moddir/module-setup.sh
722 moddir
=$_moddir cmdline
724 unset check depends cmdline
install installkernel
729 # module_install <dracut module> [<module path>]
730 # execute the install() function of module-setup.sh of <dracut module>
731 # or the "install" script, if module-setup.sh is not found
735 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
736 [[ -d $_moddir ]] ||
return 1
737 if [[ ! -f $_moddir/module-setup.sh
]]; then
738 [[ -x $_moddir/install ]] && .
"$_moddir/install"
741 unset check depends cmdline
install installkernel
743 .
$_moddir/module-setup.sh
744 moddir
=$_moddir install
746 unset check depends cmdline
install installkernel
751 # module_installkernel <dracut module> [<module path>]
752 # execute the installkernel() function of module-setup.sh of <dracut module>
753 # or the "installkernel" script, if module-setup.sh is not found
754 module_installkernel
() {
757 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
758 [[ -d $_moddir ]] ||
return 1
759 if [[ ! -f $_moddir/module-setup.sh
]]; then
760 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
763 unset check depends cmdline
install installkernel
764 installkernel
() { true
; }
765 .
$_moddir/module-setup.sh
766 moddir
=$_moddir installkernel
768 unset check depends cmdline
install installkernel
773 # check_mount <dracut module> [<use_as_dep>] [<module path>]
774 # check_mount checks, if a dracut module is needed for the given
775 # device and filesystem types in "${host_fs_types[@]}"
782 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
783 [ "${#host_fs_types[@]}" -le 0 ] && return 1
785 # If we are already scheduled to be loaded, no need to check again.
786 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
787 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
789 # This should never happen, but...
790 [[ -d $_moddir ]] ||
return 1
792 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
794 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
798 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
799 module_check_mount
$_mod $_moddir; ret
=$?
801 # explicit module, so also accept ret=255
802 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
804 # module not in our list
805 if [[ $dracutmodules = all
]]; then
806 # check, if we can and should install this module
807 module_check_mount
$_mod $_moddir ||
return 1
814 for _moddep
in $
(module_depends
$_mod $_moddir); do
815 # handle deps as if they were manually added
816 [[ " $dracutmodules " == *\
$_mod\
* ]] \
817 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
818 && dracutmodules
+=" $_moddep "
819 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
820 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
821 && add_dracutmodules
+=" $_moddep "
822 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
823 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
824 && force_add_dracutmodules
+=" $_moddep "
825 # if a module we depend on fail, fail also
826 if ! check_module
$_moddep; then
827 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
832 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
833 mods_to_load
+=" $_mod "
838 # check_module <dracut module> [<use_as_dep>] [<module path>]
839 # check if a dracut module is to be used in the initramfs process
840 # if <use_as_dep> is set, then the process also keeps track
841 # that the modules were checked for the dependency tracking process
848 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
849 # If we are already scheduled to be loaded, no need to check again.
850 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
851 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
853 # This should never happen, but...
854 [[ -d $_moddir ]] ||
return 1
856 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
858 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
859 ddebug
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
863 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
864 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
865 module_check
$_mod 1 $_moddir; ret
=$?
867 module_check
$_mod 0 $_moddir; ret
=$?
869 # explicit module, so also accept ret=255
870 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
872 # module not in our list
873 if [[ $dracutmodules = all
]]; then
874 # check, if we can and should install this module
875 module_check
$_mod 0 $_moddir; ret
=$?
876 if [[ $ret != 0 ]]; then
878 [[ $ret != 255 ]] && return 1
886 for _moddep
in $
(module_depends
$_mod $_moddir); do
887 # handle deps as if they were manually added
888 [[ " $dracutmodules " == *\
$_mod\
* ]] \
889 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
890 && dracutmodules
+=" $_moddep "
891 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
892 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
893 && add_dracutmodules
+=" $_moddep "
894 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
895 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
896 && force_add_dracutmodules
+=" $_moddep "
897 # if a module we depend on fail, fail also
898 if ! check_module
$_moddep; then
899 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
904 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
905 mods_to_load
+=" $_mod "
910 # for_each_module_dir <func>
911 # execute "<func> <dracut module> 1 <module path>"
912 for_each_module_dir
() {
918 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
919 [[ -d $_moddir ]] ||
continue;
920 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
921 -e $_moddir/module-setup.sh
]] ||
continue
922 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
923 $_func $_mod 1 $_moddir
926 # Report any missing dracut modules, the user has specified
927 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
928 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
929 for _mod
in $_modcheck; do
930 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
932 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
933 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
934 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
937 derror
"dracut module '$_mod' cannot be found or installed."
938 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
939 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
940 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
944 dracut_kernel_post
() {
945 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
946 [[ -e $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
949 # generate module dependencies for the initrd
950 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
951 ! depmod
-a -b "$initdir" $kernel; then
952 dfatal
"\"depmod -a $kernel\" failed."
959 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
960 # instmods [-c [-s]] <kernel subsystem>
961 # install kernel modules along with all their dependencies.
962 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
969 [[ $no_kernel = yes ]] && return
971 if [[ $1 = '-c' ]]; then
975 if [[ $1 = '-s' ]]; then
981 read -r -d '' -a args
990 ${initdir:+-D "$initdir"} \
991 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
992 ${loginstall:+-L "$loginstall"} \
994 ${omit_drivers:+-N "$omit_drivers"} \
995 ${srcmods:+--kerneldir "$srcmods"} \
997 ${_silent:+--silent} \
1001 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
1004 ${initdir:+-D "$initdir"} \
1005 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
1006 ${loginstall:+-L "$loginstall"} \
1008 ${omit_drivers:+-N "$omit_drivers"} \
1009 ${srcmods:+--kerneldir "$srcmods"} \
1011 ${_silent:+--silent} \
1015 [[ "$optional" ]] && return 0
1019 if [[ "$(ln --help)" == *--relative* ]]; then
1021 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1027 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1028 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
1032 is_qemu_virtualized
() {
1033 # 0 if a virt environment was detected
1034 # 1 if a virt environment could not be detected
1035 # 255 if any error was encountered
1036 if type -P systemd-detect-virt
>/dev
/null
2>&1; then
1037 vm
=$
(systemd-detect-virt
--vm >/dev
/null
2>&1)
1038 (($?
!= 0)) && return 255
1039 [[ $vm = "qemu" ]] && return 0
1040 [[ $vm = "kvm" ]] && return 0
1041 [[ $vm = "bochs" ]] && return 0
1044 for i
in /sys
/class
/dmi
/id
/*_vendor
; do
1045 [[ -f $i ]] ||
continue
1047 [[ "$vendor" == "QEMU" ]] && return 0
1048 [[ "$vendor" == "Red Hat" ]] && return 0
1049 [[ "$vendor" == "Bochs" ]] && return 0