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/>.
23 # Check whether $1 is a function.
25 [[ "$(type -t "$1")" = "function" ]]
28 if ! [[ $dracutbasedir ]]; then
29 dracutbasedir
=${BASH_SOURCE[0]%/*}
30 [[ $dracutbasedir = dracut-functions
* ]] && dracutbasedir
="."
31 [[ $dracutbasedir ]] || dracutbasedir
="."
32 dracutbasedir
="$(readlink -f $dracutbasedir)"
35 if ! is_func dinfo
>/dev
/null
2>&1; then
36 .
"$dracutbasedir/dracut-logger.sh"
40 if ! [[ $initdir ]]; then
41 dfatal
"initdir not set"
45 if ! [[ -d $initdir ]]; then
49 if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
50 if ! [[ -d "$initdir/.kernelmodseen" ]]; then
51 mkdir
-p "$initdir/.kernelmodseen"
53 DRACUT_KERNEL_LAZY_HASHDIR
="$initdir/.kernelmodseen"
56 if ! [[ $kernel ]]; then
61 srcmods
="/lib/modules/$kernel/"
63 [[ $drivers_dir ]] && {
64 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
65 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
68 srcmods
="$drivers_dir"
72 # export standard hookdirs
74 hookdirs
="cmdline pre-udev pre-trigger netroot "
75 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
76 hookdirs
+="pre-mount pre-pivot cleanup mount "
77 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
81 .
$dracutbasedir/dracut-functions.sh
84 if ! [[ $libdirs ]] ; then
85 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
86 && [[ -d /lib64
]]; then
88 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
91 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
94 libdirs
+=" $(ldconfig_paths)"
99 # helper function for check() in module-setup.sh
100 # to check for required installed binaries
101 # issues a standardized warning message
103 local _module_name
="${moddir##*/}"
106 if [[ "$1" = "-m" ]]; then
112 if ! find_binary
"$cmd" &>/dev
/null
; then
113 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
120 require_any_binary
() {
121 local _module_name
="${moddir##*/}"
124 if [[ "$1" = "-m" ]]; then
130 if find_binary
"$cmd" &>/dev
/null
; then
136 if (( $_ret != 0 )); then
137 dinfo
"$_module_name: Could not find any command of '$@'!"
144 dracut_need_initqueue
() {
145 >"$initdir/lib/dracut/need-initqueue"
148 dracut_module_included
() {
149 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
152 if ! [[ $DRACUT_INSTALL ]]; then
153 DRACUT_INSTALL
=$
(find_binary dracut-install
)
156 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
157 DRACUT_INSTALL
=$dracutbasedir/dracut-install
158 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install
/dracut-install
]]; then
159 DRACUT_INSTALL
=$dracutbasedir/install
/dracut-install
162 if ! [[ -x $DRACUT_INSTALL ]]; then
163 dfatal
"dracut-install not found!"
167 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
169 [[ -e ${initdir}/"$1" ]] && return 0 # already there
170 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
171 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
175 local _hostonly_install
176 if [[ "$1" == "-H" ]]; then
177 _hostonly_install
="-H"
180 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
181 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
182 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
186 local _hostonly_install
187 if [[ "$1" == "-H" ]]; then
188 _hostonly_install
="-H"
191 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
192 [[ -e $1 ]] ||
return 1 # no source
193 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
194 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" ||
:
198 local _hostonly_install
199 if [[ "$1" == "-H" ]]; then
200 _hostonly_install
="-H"
203 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
204 [[ -L $1 ]] ||
return 1
205 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
206 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
211 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
213 (($_ret != 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
224 [[ $no_kernel = yes ]] && return
226 [[ $i == "--silent" ]] && silent
=1
230 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
231 (($?
!= 0)) && (($silent == 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" ||
:
235 local _hostonly_install
236 if [[ "$1" == "-H" ]]; then
237 _hostonly_install
="-H"
240 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
241 [[ -e $1 ]] ||
return 1 # no source
242 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
243 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
247 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
248 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
252 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
253 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
258 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
262 # find symlinks linked to given library file
264 # Function searches for symlinks by stripping version numbers appended to
265 # library filename, checks if it points to the same target and finally
266 # prints the list of symlinks to stdout.
269 # rev_lib_symlinks libfoo.so.8.1
270 # output: libfoo.so.8 libfoo.so
271 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
273 [[ ! $1 ]] && return 0
275 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
277 [[ ${fn} == *.so.
* ]] ||
return 1
279 until [[ ${fn##*.} == so
]]; do
281 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
287 # attempt to install any programs specified in a udev rule
288 inst_rule_programs() {
291 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
293 if [ -x ${udevdir}/$_prog ]; then
294 _bin=${udevdir}/$_prog
295 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
296 _bin=$(find_binary "$_prog") || {
297 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
302 [[ $_bin ]] && inst_binary "$_bin"
304 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
306 if [ -x ${udevdir}/$_prog ]; then
307 _bin=${udevdir}/$_prog
308 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
309 _bin=$(find_binary "$_prog") || {
310 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
315 [[ $_bin ]] && inst_binary "$_bin"
317 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
319 if [ -x ${udevdir}/$_prog ]; then
320 _bin=${udevdir}/$_prog
321 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
322 _bin=$(find_binary "$_prog") || {
323 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
328 [[ $_bin ]] && dracut_install "$_bin"
332 # attempt to install any programs specified in a udev rule
333 inst_rule_group_owner() {
336 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
337 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
338 grep -E "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
341 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
342 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
343 grep -E "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
348 inst_rule_initqueue() {
349 if grep -q -F initqueue "$1"; then
350 dracut_need_initqueue
354 # udev rules always get installed in the same place, so
355 # create a function to install them to make life simpler.
357 local _target=/etc/udev/rules.d _rule _found
359 inst_dir "${udevdir}/rules.d
"
361 for _rule in "$@
"; do
362 if [ "${_rule#/}" = "$_rule" ]; then
363 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
364 [[ -e $r/$_rule ]] || continue
366 inst_rule_programs "$_found"
367 inst_rule_group_owner "$_found"
368 inst_rule_initqueue "$_found"
369 inst_simple "$_found"
372 for r in '' $dracutbasedir/rules.d/; do
373 # skip rules without an absolute path
374 [[ "${r}$_rule" != /* ]] && continue
375 [[ -f ${r}$_rule ]] || continue
377 inst_rule_programs "$_found"
378 inst_rule_group_owner "$_found"
379 inst_rule_initqueue "$_found"
380 inst_simple "$_found" "$_target/${_found##*/}"
382 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
386 inst_rules_wildcard() {
387 local _target=/etc/udev/rules.d _rule _found
389 inst_dir "${udevdir}/rules.d
"
391 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
392 [[ -e $_rule ]] || continue
393 inst_rule_programs "$_rule"
394 inst_rule_group_owner "$_rule"
395 inst_rule_initqueue "$_rule"
399 if [[ -n ${hostonly} ]] ; then
400 for _rule in ${_target}/$1 ; do
401 [[ -f $_rule ]] || continue
402 inst_rule_programs "$_rule"
403 inst_rule_group_owner "$_rule"
404 inst_rule_initqueue "$_rule"
409 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
412 prepare_udev_rules() {
413 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
416 f="${initdir}/etc
/udev
/rules.d
/$f"
417 [ -e "$f" ] || continue
418 while read line || [ -n "$line" ]; do
419 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
420 if [ $UDEVVERSION -ge 174 ]; then
421 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
423 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
425 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
426 if [ $UDEVVERSION -ge 176 ]; then
427 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
429 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
434 done < "${f}" > "${f}.new
"
439 # install function specialized for hooks
440 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
441 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
443 if ! [[ -f $3 ]]; then
444 dfatal "Cannot
install a hook
($3) that does not exist.
"
445 dfatal "Aborting initrd creation.
"
447 elif ! [[ "$hookdirs" == *$1* ]]; then
448 dfatal "No such hook
type $1. Aborting initrd creation.
"
451 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
454 # install any of listed files
456 # If first argument is '-d' and second some destination path, first accessible
457 # source is installed into this path, otherwise it will installed in the same
458 # path as source. If none of listed files was installed, function return 1.
459 # On first successful installation it returns with 0 status.
463 # inst_any -d /bin/foo /bin/bar /bin/baz
465 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
470 [[ $1 = '-d' ]] && to="$2" && shift 2
473 [[ -e $f ]] || continue
474 [[ $to ]] && inst "$f" "$to" && return 0
475 inst "$f" && return 0
482 # inst_libdir_file [-n <pattern>] <file> [<file>...]
483 # Install a <file> located on a lib directory to the initramfs image
484 # -n <pattern> install matching files
487 if [[ "$1" == "-n" ]]; then
490 for _dir in $libdirs; do
492 for _f in "$_dir"/$_i; do
493 [[ "$_f" =~ $_pattern ]] || continue
494 [[ -e "$_f" ]] && _files+="$_f "
499 for _dir in $libdirs; do
501 for _f in "$_dir"/$_i; do
502 [[ -e "$_f" ]] && _files+="$_f "
507 [[ $_files ]] && inst_multiple $_files
511 # install function decompressing the target and handling symlinks
512 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
514 # Function install targets in the same paths inside overlay but decompressed
515 # and without extensions (.gz, .bz2).
522 *.gz) _cmd='gzip -f -d' ;;
523 *.bz2) _cmd='bzip2 -d' ;;
527 # Decompress with chosen tool. We assume that tool changes name e.g.
528 # from 'name.gz' to 'name'.
529 ${_cmd} "${initdir}${_src}"
533 # It's similar to above, but if file is not compressed, performs standard
536 inst_opt_decompress
() {
540 inst_decompress
"${_src}" || inst
"${_src}"
544 # module_check <dracut module>
545 # execute the check() function of module-setup.sh of <dracut module>
546 # or the "check" script, if module-setup.sh is not found
547 # "check $hostonly" is called
549 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
552 local _hostonly
=$hostonly
553 [ $# -eq 2 ] && _forced
=$2
554 [[ -d $_moddir ]] ||
return 1
555 if [[ ! -f $_moddir/module-setup.sh
]]; then
556 # if we do not have a check script, we are unconditionally included
557 [[ -x $_moddir/check
]] ||
return 0
558 [ $_forced -ne 0 ] && unset hostonly
559 $_moddir/check
$hostonly
562 unset check depends cmdline
install installkernel
564 .
$_moddir/module-setup.sh
565 is_func check ||
return 0
566 [ $_forced -ne 0 ] && unset hostonly
567 moddir
=$_moddir check
$hostonly
569 unset check depends cmdline
install installkernel
575 # module_check_mount <dracut module>
576 # execute the check() function of module-setup.sh of <dracut module>
577 # or the "check" script, if module-setup.sh is not found
578 # "mount_needs=1 check 0" is called
579 module_check_mount
() {
580 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
583 [[ -d $_moddir ]] ||
return 1
584 if [[ ! -f $_moddir/module-setup.sh
]]; then
585 # if we do not have a check script, we are unconditionally included
586 [[ -x $_moddir/check
]] ||
return 0
587 mount_needs
=1 $_moddir/check
0
590 unset check depends cmdline
install installkernel
592 .
$_moddir/module-setup.sh
593 moddir
=$_moddir check
0
595 unset check depends cmdline
install installkernel
601 # module_depends <dracut module>
602 # execute the depends() function of module-setup.sh of <dracut module>
603 # or the "depends" script, if module-setup.sh is not found
605 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
607 [[ -d $_moddir ]] ||
return 1
608 if [[ ! -f $_moddir/module-setup.sh
]]; then
609 # if we do not have a check script, we have no deps
610 [[ -x $_moddir/check
]] ||
return 0
614 unset check depends cmdline
install installkernel
616 .
$_moddir/module-setup.sh
617 moddir
=$_moddir depends
619 unset check depends cmdline
install installkernel
624 # module_cmdline <dracut module>
625 # execute the cmdline() function of module-setup.sh of <dracut module>
626 # or the "cmdline" script, if module-setup.sh is not found
628 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
630 [[ -d $_moddir ]] ||
return 1
631 if [[ ! -f $_moddir/module-setup.sh
]]; then
632 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
635 unset check depends cmdline
install installkernel
637 .
$_moddir/module-setup.sh
638 moddir
=$_moddir cmdline
640 unset check depends cmdline
install installkernel
645 # module_install <dracut module>
646 # execute the install() function of module-setup.sh of <dracut module>
647 # or the "install" script, if module-setup.sh is not found
649 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
651 [[ -d $_moddir ]] ||
return 1
652 if [[ ! -f $_moddir/module-setup.sh
]]; then
653 [[ -x $_moddir/install ]] && .
"$_moddir/install"
656 unset check depends cmdline
install installkernel
658 .
$_moddir/module-setup.sh
659 moddir
=$_moddir install
661 unset check depends cmdline
install installkernel
666 # module_installkernel <dracut module>
667 # execute the installkernel() function of module-setup.sh of <dracut module>
668 # or the "installkernel" script, if module-setup.sh is not found
669 module_installkernel
() {
670 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
672 [[ -d $_moddir ]] ||
return 1
673 if [[ ! -f $_moddir/module-setup.sh
]]; then
674 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
677 unset check depends cmdline
install installkernel
678 installkernel
() { true
; }
679 .
$_moddir/module-setup.sh
680 moddir
=$_moddir installkernel
682 unset check depends cmdline
install installkernel
687 # check_mount <dracut module>
688 # check_mount checks, if a dracut module is needed for the given
689 # device and filesystem types in "${host_fs_types[@]}"
692 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
696 [ "${#host_fs_types[@]}" -le 0 ] && return 1
698 # If we are already scheduled to be loaded, no need to check again.
699 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
700 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
702 # This should never happen, but...
703 [[ -d $_moddir ]] ||
return 1
705 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
707 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
711 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
712 module_check_mount
$_mod; ret
=$?
714 # explicit module, so also accept ret=255
715 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
717 # module not in our list
718 if [[ $dracutmodules = all
]]; then
719 # check, if we can and should install this module
720 module_check_mount
$_mod ||
return 1
727 for _moddep
in $
(module_depends
$_mod); do
728 # handle deps as if they were manually added
729 [[ " $dracutmodules " == *\
$_mod\
* ]] \
730 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
731 && dracutmodules
+=" $_moddep "
732 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
733 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
734 && add_dracutmodules
+=" $_moddep "
735 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
736 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
737 && force_add_dracutmodules
+=" $_moddep "
738 # if a module we depend on fail, fail also
739 if ! check_module
$_moddep; then
740 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
745 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
746 mods_to_load
+=" $_mod "
751 # check_module <dracut module> [<use_as_dep>]
752 # check if a dracut module is to be used in the initramfs process
753 # if <use_as_dep> is set, then the process also keeps track
754 # that the modules were checked for the dependency tracking process
757 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
760 # If we are already scheduled to be loaded, no need to check again.
761 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
762 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
764 # This should never happen, but...
765 [[ -d $_moddir ]] ||
return 1
767 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
769 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
770 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
774 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
775 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
776 module_check
$_mod 1; ret
=$?
778 module_check
$_mod 0; 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
$_mod; ret
=$?
787 if [[ $ret != 0 ]]; then
789 [[ $ret != 255 ]] && return 1
797 for _moddep
in $
(module_depends
$_mod); 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 # for_each_module_dir <func>
822 # execute "<func> <dracut module> 1"
823 for_each_module_dir
() {
829 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
830 [[ -d $_moddir ]] ||
continue;
831 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
832 -e $_moddir/module-setup.sh
]] ||
continue
833 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
837 # Report any missing dracut modules, the user has specified
838 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
839 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
840 for _mod
in $_modcheck; do
841 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
843 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
844 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
845 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
848 derror
"dracut module '$_mod' cannot be found or installed."
849 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
850 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
851 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
855 # Install a single kernel module along with any firmware it may require.
856 # $1 = full path to kernel module to install
857 install_kmod_with_fw
() {
858 # no need to go further if the module is already installed
860 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
863 if [[ $omit_drivers ]]; then
867 if [[ "$_kmod" =~
$omit_drivers ]]; then
868 dinfo
"Omitting driver $_kmod"
871 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
872 dinfo
"Omitting driver $_kmod"
877 if [[ $silent_omit_drivers ]]; then
881 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
882 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
885 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
887 (($ret != 0)) && return $ret
889 local _modname
=${1##*/} _fwdir _found _fw
890 _modname
=${_modname%.ko*}
891 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
893 for _fwdir
in $fw_dir; do
894 [[ -d $_fwdir && -f $_fwdir/$_fw ]] ||
continue
895 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
898 if [[ $_found != yes ]]; then
899 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
900 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
903 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
911 # Do something with all the dependencies of a kernel module.
912 # Note that kernel modules depend on themselves using the technique we use
913 # $1 = function to call for each dependency we find
914 # It will be passed the full path to the found kernel module
915 # $2 = module to get dependencies for
916 # rest of args = arguments to modprobe
917 # _fderr specifies FD passed from surrounding scope
918 for_each_kmod_dep
() {
919 local _func
=$1 _kmod
=$2 _cmd _modpath _options
921 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
922 while read _cmd _modpath _options ||
[ -n "$_cmd" ]; do
923 [[ $_cmd = insmod
]] ||
continue
924 $_func ${_modpath} ||
exit $?
929 dracut_kernel_post
() {
930 local _moddirname
=${srcmods%%/lib/modules/*}
933 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
934 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
937 # generate module dependencies for the initrd
938 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
939 ! depmod
-a -b "$initdir" $kernel; then
940 dfatal
"\"depmod -a $kernel\" failed."
947 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
948 # instmods [-c [-s]] <kernel subsystem>
949 # install kernel modules along with all their dependencies.
950 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
957 [[ $no_kernel = yes ]] && return
959 if [[ $1 = '-c' ]]; then
963 if [[ $1 = '-s' ]]; then
969 read -r -d '' -a args
974 ${initdir:+-D "$initdir"} \
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 ${loginstall:+-L "$loginstall"} \
990 ${omit_drivers:+-N "$omit_drivers"} \
991 ${srcmods:+--kerneldir "$srcmods"} \
993 ${_silent:+--silent} \
997 [[ "$optional" ]] && return 0
1001 if [[ "$(ln --help)" == *--relative* ]]; then
1003 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1009 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1010 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"