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
!"
470 f="${initdir}/etc
/udev
/rules.d
/$f"
471 [ -e "$f" ] || continue
472 while read line || [ -n "$line" ]; do
473 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
474 if [ $UDEVVERSION -ge 174 ]; then
475 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
477 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
479 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
480 if [ $UDEVVERSION -ge 176 ]; then
481 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
483 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
488 done < "${f}" > "${f}.new
"
493 # install function specialized for hooks
494 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
495 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
497 if ! [[ -f $3 ]]; then
498 dfatal "Cannot
install a hook
($3) that does not exist.
"
499 dfatal "Aborting initrd creation.
"
501 elif ! [[ "$hookdirs" == *$1* ]]; then
502 dfatal "No such hook
type $1. Aborting initrd creation.
"
505 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
508 # install any of listed files
510 # If first argument is '-d' and second some destination path, first accessible
511 # source is installed into this path, otherwise it will installed in the same
512 # path as source. If none of listed files was installed, function return 1.
513 # On first successful installation it returns with 0 status.
517 # inst_any -d /bin/foo /bin/bar /bin/baz
519 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
524 [[ $1 = '-d' ]] && to="$2" && shift 2
527 [[ -e $f ]] || continue
528 [[ $to ]] && inst "$f" "$to" && return 0
529 inst "$f" && return 0
536 # inst_libdir_file [-n <pattern>] <file> [<file>...]
537 # Install a <file> located on a lib directory to the initramfs image
538 # -n <pattern> install matching files
541 if [[ "$1" == "-n" ]]; then
544 for _dir in $libdirs; do
546 for _f in "$_dir"/$_i; do
547 [[ "$_f" =~ $_pattern ]] || continue
548 [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
553 for _dir in $libdirs; do
555 for _f in "$_dir"/$_i; do
556 [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
561 [[ $_files ]] && inst_multiple $_files
564 # get a command to decompress the given file
565 get_decompress_cmd() {
567 *.gz) echo 'gzip -f -d' ;;
568 *.bz2) echo 'bzip2 -d' ;;
569 *.xz) echo 'xz -f -d' ;;
573 # install function decompressing the target and handling symlinks
574 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
576 # Function install targets in the same paths inside overlay but decompressed
577 # and without extensions (.gz, .bz2).
583 _cmd=$(get_decompress_cmd ${_src})
584 [[ -z "${_cmd}" ]] && return 1
586 # Decompress with chosen tool. We assume that tool changes name e.g.
587 # from 'name.gz' to 'name'.
588 ${_cmd} "${initdir}${_src}"
592 # It's similar to above, but if file is not compressed, performs standard
595 inst_opt_decompress
() {
599 inst_decompress
"${_src}" || inst
"${_src}"
603 # module_check <dracut module> [<forced>] [<module path>]
604 # execute the check() function of module-setup.sh of <dracut module>
605 # or the "check" script, if module-setup.sh is not found
606 # "check $hostonly" is called
611 local _hostonly
=$hostonly
612 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
613 [ $# -eq 2 ] && _forced
=$2
614 [[ -d $_moddir ]] ||
return 1
615 if [[ ! -f $_moddir/module-setup.sh
]]; then
616 # if we do not have a check script, we are unconditionally included
617 [[ -x $_moddir/check
]] ||
return 0
618 [ $_forced -ne 0 ] && unset hostonly
619 $_moddir/check
$hostonly
622 unset check depends cmdline
install installkernel
624 .
$_moddir/module-setup.sh
625 is_func check ||
return 0
626 [ $_forced -ne 0 ] && unset hostonly
627 moddir
=$_moddir check
$hostonly
629 unset check depends cmdline
install installkernel
635 # module_check_mount <dracut module> [<module path>]
636 # execute the check() function of module-setup.sh of <dracut module>
637 # or the "check" script, if module-setup.sh is not found
638 # "mount_needs=1 check 0" is called
639 module_check_mount
() {
643 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
644 [[ -d $_moddir ]] ||
return 1
645 if [[ ! -f $_moddir/module-setup.sh
]]; then
646 # if we do not have a check script, we are unconditionally included
647 [[ -x $_moddir/check
]] ||
return 0
648 mount_needs
=1 $_moddir/check
0
651 unset check depends cmdline
install installkernel
653 .
$_moddir/module-setup.sh
654 moddir
=$_moddir check
0
656 unset check depends cmdline
install installkernel
662 # module_depends <dracut module> [<module path>]
663 # execute the depends() function of module-setup.sh of <dracut module>
664 # or the "depends" script, if module-setup.sh is not found
668 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
669 [[ -d $_moddir ]] ||
return 1
670 if [[ ! -f $_moddir/module-setup.sh
]]; then
671 # if we do not have a check script, we have no deps
672 [[ -x $_moddir/check
]] ||
return 0
676 unset check depends cmdline
install installkernel
678 .
$_moddir/module-setup.sh
679 moddir
=$_moddir depends
681 unset check depends cmdline
install installkernel
686 # module_cmdline <dracut module> [<module path>]
687 # execute the cmdline() function of module-setup.sh of <dracut module>
688 # or the "cmdline" script, if module-setup.sh is not found
692 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
693 [[ -d $_moddir ]] ||
return 1
694 if [[ ! -f $_moddir/module-setup.sh
]]; then
695 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
698 unset check depends cmdline
install installkernel
700 .
$_moddir/module-setup.sh
701 moddir
=$_moddir cmdline
703 unset check depends cmdline
install installkernel
708 # module_install <dracut module> [<module path>]
709 # execute the install() function of module-setup.sh of <dracut module>
710 # or the "install" script, if module-setup.sh is not found
714 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
715 [[ -d $_moddir ]] ||
return 1
716 if [[ ! -f $_moddir/module-setup.sh
]]; then
717 [[ -x $_moddir/install ]] && .
"$_moddir/install"
720 unset check depends cmdline
install installkernel
722 .
$_moddir/module-setup.sh
723 moddir
=$_moddir install
725 unset check depends cmdline
install installkernel
730 # module_installkernel <dracut module> [<module path>]
731 # execute the installkernel() function of module-setup.sh of <dracut module>
732 # or the "installkernel" script, if module-setup.sh is not found
733 module_installkernel
() {
736 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
737 [[ -d $_moddir ]] ||
return 1
738 if [[ ! -f $_moddir/module-setup.sh
]]; then
739 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
742 unset check depends cmdline
install installkernel
743 installkernel
() { true
; }
744 .
$_moddir/module-setup.sh
745 moddir
=$_moddir installkernel
747 unset check depends cmdline
install installkernel
752 # check_mount <dracut module> [<use_as_dep>] [<module path>]
753 # check_mount checks, if a dracut module is needed for the given
754 # device and filesystem types in "${host_fs_types[@]}"
761 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
762 [ "${#host_fs_types[@]}" -le 0 ] && return 1
764 # If we are already scheduled to be loaded, no need to check again.
765 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
766 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
768 # This should never happen, but...
769 [[ -d $_moddir ]] ||
return 1
771 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
773 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
777 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
778 module_check_mount
$_mod $_moddir; ret
=$?
780 # explicit module, so also accept ret=255
781 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
783 # module not in our list
784 if [[ $dracutmodules = all
]]; then
785 # check, if we can and should install this module
786 module_check_mount
$_mod $_moddir ||
return 1
793 for _moddep
in $
(module_depends
$_mod $_moddir); do
794 # handle deps as if they were manually added
795 [[ " $dracutmodules " == *\
$_mod\
* ]] \
796 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
797 && dracutmodules
+=" $_moddep "
798 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
799 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
800 && add_dracutmodules
+=" $_moddep "
801 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
802 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
803 && force_add_dracutmodules
+=" $_moddep "
804 # if a module we depend on fail, fail also
805 if ! check_module
$_moddep; then
806 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
811 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
812 mods_to_load
+=" $_mod "
817 # check_module <dracut module> [<use_as_dep>] [<module path>]
818 # check if a dracut module is to be used in the initramfs process
819 # if <use_as_dep> is set, then the process also keeps track
820 # that the modules were checked for the dependency tracking process
827 [[ -z $_moddir ]] && _moddir
=$
(dracut_module_path
"$1")
828 # If we are already scheduled to be loaded, no need to check again.
829 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
830 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
832 # This should never happen, but...
833 [[ -d $_moddir ]] ||
return 1
835 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
837 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
838 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
842 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
843 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
844 module_check
$_mod 1 $_moddir; ret
=$?
846 module_check
$_mod 0 $_moddir; ret
=$?
848 # explicit module, so also accept ret=255
849 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
851 # module not in our list
852 if [[ $dracutmodules = all
]]; then
853 # check, if we can and should install this module
854 module_check
$_mod 0 $_moddir; ret
=$?
855 if [[ $ret != 0 ]]; then
857 [[ $ret != 255 ]] && return 1
865 for _moddep
in $
(module_depends
$_mod $_moddir); do
866 # handle deps as if they were manually added
867 [[ " $dracutmodules " == *\
$_mod\
* ]] \
868 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
869 && dracutmodules
+=" $_moddep "
870 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
871 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
872 && add_dracutmodules
+=" $_moddep "
873 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
874 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
875 && force_add_dracutmodules
+=" $_moddep "
876 # if a module we depend on fail, fail also
877 if ! check_module
$_moddep; then
878 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
883 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
884 mods_to_load
+=" $_mod "
889 # for_each_module_dir <func>
890 # execute "<func> <dracut module> 1 <module path>"
891 for_each_module_dir
() {
897 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
898 [[ -d $_moddir ]] ||
continue;
899 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
900 -e $_moddir/module-setup.sh
]] ||
continue
901 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
902 $_func $_mod 1 $_moddir
905 # Report any missing dracut modules, the user has specified
906 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
907 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
908 for _mod
in $_modcheck; do
909 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
911 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
912 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
913 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
916 derror
"dracut module '$_mod' cannot be found or installed."
917 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
918 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
919 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
923 dracut_kernel_post
() {
924 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
925 [[ -e $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
928 # generate module dependencies for the initrd
929 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
930 ! depmod
-a -b "$initdir" $kernel; then
931 dfatal
"\"depmod -a $kernel\" failed."
938 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
939 # instmods [-c [-s]] <kernel subsystem>
940 # install kernel modules along with all their dependencies.
941 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
948 [[ $no_kernel = yes ]] && return
950 if [[ $1 = '-c' ]]; then
954 if [[ $1 = '-s' ]]; then
960 read -r -d '' -a args
969 ${initdir:+-D "$initdir"} \
970 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
971 ${loginstall:+-L "$loginstall"} \
973 ${omit_drivers:+-N "$omit_drivers"} \
974 ${srcmods:+--kerneldir "$srcmods"} \
976 ${_silent:+--silent} \
980 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
983 ${initdir:+-D "$initdir"} \
984 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
985 ${loginstall:+-L "$loginstall"} \
987 ${omit_drivers:+-N "$omit_drivers"} \
988 ${srcmods:+--kerneldir "$srcmods"} \
990 ${_silent:+--silent} \
994 [[ "$optional" ]] && return 0
998 if [[ "$(ln --help)" == *--relative* ]]; then
1000 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1006 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1007 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
1011 is_qemu_virtualized
() {
1012 # 0 if a virt environment was detected
1013 # 1 if a virt environment could not be detected
1014 # 255 if any error was encountered
1015 if type -P systemd-detect-virt
>/dev
/null
2>&1; then
1016 vm
=$
(systemd-detect-virt
--vm >/dev
/null
2>&1)
1017 (($?
!= 0)) && return 255
1018 [[ $vm = "qemu" ]] && return 0
1019 [[ $vm = "kvm" ]] && return 0
1020 [[ $vm = "bochs" ]] && return 0
1023 for i
in /sys
/class
/dmi
/id
/*_vendor
; do
1024 [[ -f $i ]] ||
continue
1026 [[ "$vendor" == "QEMU" ]] && return 0
1027 [[ "$vendor" == "Red Hat" ]] && return 0
1028 [[ "$vendor" == "Bochs" ]] && return 0