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" ]]; 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 .
"$dracutbasedir/dracut-logger.sh"
46 if ! [[ $initdir ]]; then
47 dfatal
"initdir not set"
51 if ! [[ -d $initdir ]]; then
55 if ! [[ $kernel ]]; then
60 srcmods
="$dracutsysrootdir/lib/modules/$kernel/"
62 [[ $drivers_dir ]] && {
63 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
64 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
67 srcmods
="$drivers_dir"
71 [[ $DRACUT_FIRMWARE_PATH ]] ||
export DRACUT_FIRMWARE_PATH
="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
73 # export standard hookdirs
75 hookdirs
="cmdline pre-udev pre-trigger netroot "
76 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
77 hookdirs
+="pre-mount pre-pivot cleanup mount "
78 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
82 DRACUT_LDD
=${DRACUT_LDD:-ldd}
83 DRACUT_TESTBIN
=${DRACUT_TESTBIN:-/bin/sh}
84 DRACUT_LDCONFIG
=${DRACUT_LDCONFIG:-ldconfig}
86 .
$dracutbasedir/dracut-functions.sh
89 if ! [[ $libdirs ]] ; then
90 if [[ "$($DRACUT_LDD $dracutsysrootdir$DRACUT_TESTBIN)" == */lib64
/* ]] &>/dev
/null \
91 && [[ -d $dracutsysrootdir/lib64
]]; then
93 [[ -d $dracutsysrootdir/usr
/lib64
]] && libdirs
+=" /usr/lib64"
96 [[ -d $dracutsysrootdir/usr
/lib
]] && libdirs
+=" /usr/lib"
99 libdirs
+=" $(ldconfig_paths)"
104 # helper function for check() in module-setup.sh
105 # to check for required installed binaries
106 # issues a standardized warning message
108 local _module_name
="${moddir##*/}"
111 if [[ "$1" = "-m" ]]; then
117 if ! find_binary
"$cmd" &>/dev
/null
; then
118 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
125 require_any_binary
() {
126 local _module_name
="${moddir##*/}"
129 if [[ "$1" = "-m" ]]; then
135 if find_binary
"$cmd" &>/dev
/null
; then
141 if (( $_ret != 0 )); then
142 dinfo
"$_module_name: Could not find any command of '$@'!"
149 dracut_need_initqueue
() {
150 >"$initdir/lib/dracut/need-initqueue"
153 dracut_module_included
() {
154 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
157 dracut_no_switch_root
() {
158 >"$initdir/lib/dracut/no-switch-root"
161 dracut_module_path
() {
162 echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; }
165 if ! [[ $DRACUT_INSTALL ]]; then
166 DRACUT_INSTALL
=$
(find_binary dracut-install
)
169 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
170 DRACUT_INSTALL
=$dracutbasedir/dracut-install
171 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install
/dracut-install
]]; then
172 DRACUT_INSTALL
=$dracutbasedir/install
/dracut-install
175 # Test if dracut-install is a standalone executable with no options.
176 # E.g. DRACUT_INSTALL may be set externally as:
177 # DRACUT_INSTALL="valgrind dracut-install"
179 # DRACUT_INSTALL="dracut-install --debug"
180 # in which case the string cannot be tested for being executable.
182 for i
in $DRACUT_INSTALL ; do
183 DRINSTALLPARTS
=$
(($DRINSTALLPARTS+1))
186 if [[ $DRINSTALLPARTS = 1 ]] && ! [[ -x $DRACUT_INSTALL ]]; then
187 dfatal
"dracut-install not found!"
191 if [[ $hostonly == "-h" ]]; then
192 if ! [[ $DRACUT_KERNEL_MODALIASES ]] ||
! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
193 export DRACUT_KERNEL_MODALIASES
="${DRACUT_TMPDIR}/modaliases"
194 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
198 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
200 [[ -e ${initdir}/"$1" ]] && return 0 # already there
201 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
202 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@" ||
:
206 local _hostonly_install
207 if [[ "$1" == "-H" ]]; then
208 _hostonly_install
="-H"
211 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
212 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
213 (($?
!= 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} "$@" ||
:
217 local _hostonly_install
218 if [[ "$1" == "-H" ]]; then
219 _hostonly_install
="-H"
222 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
223 [[ -e $1 ]] ||
return 1 # no source
224 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
225 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" ||
:
229 local _hostonly_install
230 if [[ "$1" == "-H" ]]; then
231 _hostonly_install
="-H"
234 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
235 [[ -L $1 ]] ||
return 1
236 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
237 (($?
!= 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} "$@" ||
:
242 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
244 (($_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} "$@" ||
:
255 [[ $no_kernel = yes ]] && return
257 [[ $i == "--silent" ]] && _silent
=1
261 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
262 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
263 (($?
!= 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 "$@" ||
:
267 local _hostonly_install
268 if [[ "$1" == "-H" ]]; then
269 _hostonly_install
="-H"
272 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
273 [[ -e $1 ]] ||
return 1 # no source
274 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
275 (($?
!= 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} "$@" ||
:
279 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
280 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
284 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
285 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
289 local _helper
="/run/dracut/fsck/fsck_help_$1.txt"
290 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
291 (($?
!= 0)) && derror
$DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper ||
:
294 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
295 # If hosotnly mode is set to "strict", hostonly restrictions will still
296 # be applied, else will ignore hostonly mode and try to install all
298 optional_hostonly
() {
299 if [[ $hostonly_mode = "strict" ]]; then
300 printf -- "$hostonly"
308 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
312 # find symlinks linked to given library file
314 # Function searches for symlinks by stripping version numbers appended to
315 # library filename, checks if it points to the same target and finally
316 # prints the list of symlinks to stdout.
319 # rev_lib_symlinks libfoo.so.8.1
320 # output: libfoo.so.8 libfoo.so
321 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
323 [[ ! $1 ]] && return 0
325 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
327 [[ ${fn} == *.so.
* ]] ||
return 1
329 until [[ ${fn##*.} == so
]]; do
331 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
337 # attempt to install any programs specified in a udev rule
338 inst_rule_programs() {
341 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
343 if [ -x ${udevdir}/$_prog ]; then
344 _bin=${udevdir}/$_prog
345 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
346 _bin=$(find_binary "$_prog") || {
347 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
352 [[ $_bin ]] && inst_binary "$_bin"
354 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
356 if [ -x ${udevdir}/$_prog ]; then
357 _bin=${udevdir}/$_prog
358 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
359 _bin=$(find_binary "$_prog") || {
360 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
365 [[ $_bin ]] && inst_binary "$_bin"
367 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
369 if [ -x ${udevdir}/$_prog ]; then
370 _bin=${udevdir}/$_prog
371 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
372 _bin=$(find_binary "$_prog") || {
373 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
378 [[ $_bin ]] && dracut_install "$_bin"
382 # attempt to install any programs specified in a udev rule
383 inst_rule_group_owner() {
386 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
387 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
388 grep -E "^
$i:" $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
391 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
392 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
393 grep -E "^
$i:" $dracutsysrootdir/etc/group 2>/dev/null >> "$initdir/etc
/group
"
398 inst_rule_initqueue() {
399 if grep -q -F initqueue "$1"; then
400 dracut_need_initqueue
404 # udev rules always get installed in the same place, so
405 # create a function to install them to make life simpler.
407 local _target=/etc/udev/rules.d _rule _found
409 inst_dir "${udevdir}/rules.d
"
411 for _rule in "$@
"; do
412 if [ "${_rule#/}" = "$_rule" ]; then
413 for r in $dracutsysrootdir${udevdir}/rules.d ${hostonly:+$dracutsysrootdir/etc/udev/rules.d}; do
414 [[ -e $r/$_rule ]] || continue
416 inst_rule_programs "$_found"
417 inst_rule_group_owner "$_found"
418 inst_rule_initqueue "$_found"
419 inst_simple "$_found"
422 for r in '' $dracutsysrootdir$dracutbasedir/rules.d/; do
423 # skip rules without an absolute path
424 [[ "${r}$_rule" != /* ]] && continue
425 [[ -f ${r}$_rule ]] || continue
427 inst_rule_programs "$_found"
428 inst_rule_group_owner "$_found"
429 inst_rule_initqueue "$_found"
430 inst_simple "$_found" "$_target/${_found##*/}"
432 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
436 inst_rules_wildcard() {
437 local _target=/etc/udev/rules.d _rule _found
439 inst_dir "${udevdir}/rules.d
"
441 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
442 [[ -e $_rule ]] || continue
443 inst_rule_programs "$_rule"
444 inst_rule_group_owner "$_rule"
445 inst_rule_initqueue "$_rule"
449 if [[ -n ${hostonly} ]] ; then
450 for _rule in ${_target}/$1 ; do
451 [[ -f $_rule ]] || continue
452 inst_rule_programs "$_rule"
453 inst_rule_group_owner "$_rule"
454 inst_rule_initqueue "$_rule"
459 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
462 prepare_udev_rules() {
463 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
464 if [ -z "$UDEVVERSION" ]; then
465 derror "Failed to detect udev version
!"
468 if [ -z "${UDEVVERSION##*[!0-9]*}" ]; then
469 derror "udevadm
--version did not report an integer
, udev version cannot be determined
!"
474 f="${initdir}/etc
/udev
/rules.d
/$f"
475 [ -e "$f" ] || continue
476 while read line || [ -n "$line" ]; do
477 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
478 if [ $UDEVVERSION -ge 174 ]; then
479 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
481 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
483 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
484 if [ $UDEVVERSION -ge 176 ]; then
485 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
487 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
492 done < "${f}" > "${f}.new
"
497 # install function specialized for hooks
498 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
499 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
501 if ! [[ -f $3 ]]; then
502 dfatal "Cannot
install a hook
($3) that does not exist.
"
503 dfatal "Aborting initrd creation.
"
505 elif ! [[ "$hookdirs" == *$1* ]]; then
506 dfatal "No such hook
type $1. Aborting initrd creation.
"
509 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
512 # install any of listed files
514 # If first argument is '-d' and second some destination path, first accessible
515 # source is installed into this path, otherwise it will installed in the same
516 # path as source. If none of listed files was installed, function return 1.
517 # On first successful installation it returns with 0 status.
521 # inst_any -d /bin/foo /bin/bar /bin/baz
523 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
528 [[ $1 = '-d' ]] && to="$2" && shift 2
531 [[ -e $f ]] || continue
532 [[ $to ]] && inst "$f" "$to" && return 0
533 inst "$f" && return 0
540 # inst_libdir_file [-n <pattern>] <file> [<file>...]
541 # Install a <file> located on a lib directory to the initramfs image
542 # -n <pattern> install matching files
545 if [[ "$1" == "-n" ]]; then
548 for _dir in $libdirs; do
550 for _f in "$_dir"/$_i; do
551 [[ "$_f" =~ $_pattern ]] || continue
552 [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
557 for _dir in $libdirs; do
559 for _f in "$_dir"/$_i; do
560 [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
565 [[ $_files ]] && inst_multiple $_files
568 # get a command to decompress the given file
569 get_decompress_cmd() {
571 *.gz) echo 'gzip -f -d' ;;
572 *.bz2) echo 'bzip2 -d' ;;
573 *.xz) echo 'xz -f -d' ;;
577 # install function decompressing the target and handling symlinks
578 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
580 # Function install targets in the same paths inside overlay but decompressed
581 # and without extensions (.gz, .bz2).
587 _cmd=$(get_decompress_cmd ${_src})
588 [[ -z "${_cmd}" ]] && return 1
590 # Decompress with chosen tool. We assume that tool changes name e.g.
591 # from 'name.gz' to 'name'.
592 ${_cmd} "${initdir}${_src}"
596 # It's similar to above, but if file is not compressed, performs standard
599 inst_opt_decompress
() {
603 inst_decompress
"${_src}" || inst
"${_src}"
607 # module_check <dracut module> [<forced>] [<module path>]
608 # execute the check() function of module-setup.sh of <dracut module>
609 # or the "check" script, if module-setup.sh is not found
610 # "check $hostonly" is called
615 local _hostonly
=$hostonly
616 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
617 [ $# -eq 2 ] && _forced
=$2
618 [[ -d $_moddir ]] ||
return 1
619 if [[ ! -f $_moddir/module-setup.sh
]]; then
620 # if we do not have a check script, we are unconditionally included
621 [[ -x $_moddir/check
]] ||
return 0
622 [ $_forced -ne 0 ] && unset hostonly
623 $_moddir/check
$hostonly
626 unset check depends cmdline
install installkernel
628 .
$_moddir/module-setup.sh
629 is_func check ||
return 0
630 [ $_forced -ne 0 ] && unset hostonly
631 moddir
=$_moddir check
$hostonly
633 unset check depends cmdline
install installkernel
639 # module_check_mount <dracut module> [<module path>]
640 # execute the check() function of module-setup.sh of <dracut module>
641 # or the "check" script, if module-setup.sh is not found
642 # "mount_needs=1 check 0" is called
643 module_check_mount
() {
647 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
648 [[ -d $_moddir ]] ||
return 1
649 if [[ ! -f $_moddir/module-setup.sh
]]; then
650 # if we do not have a check script, we are unconditionally included
651 [[ -x $_moddir/check
]] ||
return 0
652 mount_needs
=1 $_moddir/check
0
655 unset check depends cmdline
install installkernel
657 .
$_moddir/module-setup.sh
658 moddir
=$_moddir check
0
660 unset check depends cmdline
install installkernel
666 # module_depends <dracut module> [<module path>]
667 # execute the depends() function of module-setup.sh of <dracut module>
668 # or the "depends" script, if module-setup.sh is not found
672 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
673 [[ -d $_moddir ]] ||
return 1
674 if [[ ! -f $_moddir/module-setup.sh
]]; then
675 # if we do not have a check script, we have no deps
676 [[ -x $_moddir/check
]] ||
return 0
680 unset check depends cmdline
install installkernel
682 .
$_moddir/module-setup.sh
683 moddir
=$_moddir depends
685 unset check depends cmdline
install installkernel
690 # module_cmdline <dracut module> [<module path>]
691 # execute the cmdline() function of module-setup.sh of <dracut module>
692 # or the "cmdline" script, if module-setup.sh is not found
696 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
697 [[ -d $_moddir ]] ||
return 1
698 if [[ ! -f $_moddir/module-setup.sh
]]; then
699 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
702 unset check depends cmdline
install installkernel
704 .
$_moddir/module-setup.sh
705 moddir
=$_moddir cmdline
707 unset check depends cmdline
install installkernel
712 # module_install <dracut module> [<module path>]
713 # execute the install() function of module-setup.sh of <dracut module>
714 # or the "install" script, if module-setup.sh is not found
718 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
719 [[ -d $_moddir ]] ||
return 1
720 if [[ ! -f $_moddir/module-setup.sh
]]; then
721 [[ -x $_moddir/install ]] && .
"$_moddir/install"
724 unset check depends cmdline
install installkernel
726 .
$_moddir/module-setup.sh
727 moddir
=$_moddir install
729 unset check depends cmdline
install installkernel
734 # module_installkernel <dracut module> [<module path>]
735 # execute the installkernel() function of module-setup.sh of <dracut module>
736 # or the "installkernel" script, if module-setup.sh is not found
737 module_installkernel
() {
740 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
741 [[ -d $_moddir ]] ||
return 1
742 if [[ ! -f $_moddir/module-setup.sh
]]; then
743 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
746 unset check depends cmdline
install installkernel
747 installkernel
() { true
; }
748 .
$_moddir/module-setup.sh
749 moddir
=$_moddir installkernel
751 unset check depends cmdline
install installkernel
756 # check_mount <dracut module> [<use_as_dep>] [<module path>]
757 # check_mount checks, if a dracut module is needed for the given
758 # device and filesystem types in "${host_fs_types[@]}"
765 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
766 [ "${#host_fs_types[@]}" -le 0 ] && return 1
768 # If we are already scheduled to be loaded, no need to check again.
769 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
770 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
772 # This should never happen, but...
773 [[ -d $_moddir ]] ||
return 1
775 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
777 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
781 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
782 module_check_mount
$_mod $_moddir; ret
=$?
784 # explicit module, so also accept ret=255
785 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
787 # module not in our list
788 if [[ $dracutmodules = all
]]; then
789 # check, if we can and should install this module
790 module_check_mount
$_mod $_moddir ||
return 1
797 for _moddep
in $
(module_depends
$_mod $_moddir); do
798 # handle deps as if they were manually added
799 [[ " $dracutmodules " == *\
$_mod\
* ]] \
800 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
801 && dracutmodules
+=" $_moddep "
802 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
803 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
804 && add_dracutmodules
+=" $_moddep "
805 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
806 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
807 && force_add_dracutmodules
+=" $_moddep "
808 # if a module we depend on fail, fail also
809 if ! check_module
$_moddep; then
810 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
815 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
816 mods_to_load
+=" $_mod "
821 # check_module <dracut module> [<use_as_dep>] [<module path>]
822 # check if a dracut module is to be used in the initramfs process
823 # if <use_as_dep> is set, then the process also keeps track
824 # that the modules were checked for the dependency tracking process
831 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
832 # If we are already scheduled to be loaded, no need to check again.
833 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
834 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
836 # This should never happen, but...
837 [[ -d $_moddir ]] ||
return 1
839 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
841 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
842 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
846 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
847 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
848 module_check
$_mod 1 $_moddir; ret
=$?
850 module_check
$_mod 0 $_moddir; ret
=$?
852 # explicit module, so also accept ret=255
853 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
855 # module not in our list
856 if [[ $dracutmodules = all
]]; then
857 # check, if we can and should install this module
858 module_check
$_mod 0 $_moddir; ret
=$?
859 if [[ $ret != 0 ]]; then
861 [[ $ret != 255 ]] && return 1
869 for _moddep
in $
(module_depends
$_mod $_moddir); do
870 # handle deps as if they were manually added
871 [[ " $dracutmodules " == *\
$_mod\
* ]] \
872 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
873 && dracutmodules
+=" $_moddep "
874 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
875 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
876 && add_dracutmodules
+=" $_moddep "
877 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
878 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
879 && force_add_dracutmodules
+=" $_moddep "
880 # if a module we depend on fail, fail also
881 if ! check_module
$_moddep; then
882 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
887 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
888 mods_to_load
+=" $_mod "
893 # for_each_module_dir <func>
894 # execute "<func> <dracut module> 1 <module path>"
895 for_each_module_dir
() {
901 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
902 [[ -d $_moddir ]] ||
continue;
903 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
904 -e $_moddir/module-setup.sh
]] ||
continue
905 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
906 $_func $_mod 1 $_moddir
909 # Report any missing dracut modules, the user has specified
910 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
911 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
912 for _mod
in $_modcheck; do
913 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
915 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
916 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
917 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
920 derror
"dracut module '$_mod' cannot be found or installed."
921 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
922 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
923 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
927 dracut_kernel_post
() {
928 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
929 [[ -e $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
932 # generate module dependencies for the initrd
933 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
934 ! depmod
-a -b "$initdir" $kernel; then
935 dfatal
"\"depmod -a $kernel\" failed."
942 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
943 # instmods [-c [-s]] <kernel subsystem>
944 # install kernel modules along with all their dependencies.
945 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
952 [[ $no_kernel = yes ]] && return
954 if [[ $1 = '-c' ]]; then
958 if [[ $1 = '-s' ]]; then
964 read -r -d '' -a args
973 ${initdir:+-D "$initdir"} \
974 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
975 ${loginstall:+-L "$loginstall"} \
977 ${omit_drivers:+-N "$omit_drivers"} \
978 ${srcmods:+--kerneldir "$srcmods"} \
980 ${_silent:+--silent} \
984 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
987 ${initdir:+-D "$initdir"} \
988 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
989 ${loginstall:+-L "$loginstall"} \
991 ${omit_drivers:+-N "$omit_drivers"} \
992 ${srcmods:+--kerneldir "$srcmods"} \
994 ${_silent:+--silent} \
998 [[ "$optional" ]] && return 0
1002 if [[ "$(ln --help)" == *--relative* ]]; then
1004 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1010 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1011 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
1015 is_qemu_virtualized
() {
1016 # 0 if a virt environment was detected
1017 # 1 if a virt environment could not be detected
1018 # 255 if any error was encountered
1019 if type -P systemd-detect-virt
>/dev
/null
2>&1; then
1020 vm
=$
(systemd-detect-virt
--vm >/dev
/null
2>&1)
1021 (($?
!= 0)) && return 255
1022 [[ $vm = "qemu" ]] && return 0
1023 [[ $vm = "kvm" ]] && return 0
1024 [[ $vm = "bochs" ]] && return 0
1027 for i
in /sys
/class
/dmi
/id
/*_vendor
; do
1028 [[ -f $i ]] ||
continue
1030 [[ "$vendor" == "QEMU" ]] && return 0
1031 [[ "$vendor" == "Red Hat" ]] && return 0
1032 [[ "$vendor" == "Bochs" ]] && return 0