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} "$@" ||
:
222 [[ $no_kernel = yes ]] && return
224 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
225 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" ||
:
229 local _hostonly_install
230 if [[ "$1" == "-H" ]]; then
231 _hostonly_install
="-H"
234 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
235 [[ -e $1 ]] ||
return 1 # no source
236 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
237 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
241 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
242 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
246 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
247 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
252 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
256 # find symlinks linked to given library file
258 # Function searches for symlinks by stripping version numbers appended to
259 # library filename, checks if it points to the same target and finally
260 # prints the list of symlinks to stdout.
263 # rev_lib_symlinks libfoo.so.8.1
264 # output: libfoo.so.8 libfoo.so
265 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
267 [[ ! $1 ]] && return 0
269 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
271 [[ ${fn} == *.so.
* ]] ||
return 1
273 until [[ ${fn##*.} == so
]]; do
275 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
281 # attempt to install any programs specified in a udev rule
282 inst_rule_programs() {
285 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
287 if [ -x ${udevdir}/$_prog ]; then
288 _bin=${udevdir}/$_prog
289 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
290 _bin=$(find_binary "$_prog") || {
291 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
296 [[ $_bin ]] && inst_binary "$_bin"
298 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
300 if [ -x ${udevdir}/$_prog ]; then
301 _bin=${udevdir}/$_prog
302 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
303 _bin=$(find_binary "$_prog") || {
304 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
309 [[ $_bin ]] && inst_binary "$_bin"
311 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
313 if [ -x ${udevdir}/$_prog ]; then
314 _bin=${udevdir}/$_prog
315 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
316 _bin=$(find_binary "$_prog") || {
317 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
322 [[ $_bin ]] && dracut_install "$_bin"
326 # attempt to install any programs specified in a udev rule
327 inst_rule_group_owner() {
330 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
331 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
332 grep -E "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
335 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
336 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
337 grep -E "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
342 inst_rule_initqueue() {
343 if grep -q -F initqueue "$1"; then
344 dracut_need_initqueue
348 # udev rules always get installed in the same place, so
349 # create a function to install them to make life simpler.
351 local _target=/etc/udev/rules.d _rule _found
353 inst_dir "${udevdir}/rules.d
"
355 for _rule in "$@
"; do
356 if [ "${_rule#/}" = "$_rule" ]; then
357 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
358 [[ -e $r/$_rule ]] || continue
360 inst_rule_programs "$_found"
361 inst_rule_group_owner "$_found"
362 inst_rule_initqueue "$_found"
363 inst_simple "$_found"
366 for r in '' $dracutbasedir/rules.d/; do
367 # skip rules without an absolute path
368 [[ "${r}$_rule" != /* ]] && continue
369 [[ -f ${r}$_rule ]] || continue
371 inst_rule_programs "$_found"
372 inst_rule_group_owner "$_found"
373 inst_rule_initqueue "$_found"
374 inst_simple "$_found" "$_target/${_found##*/}"
376 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
380 inst_rules_wildcard() {
381 local _target=/etc/udev/rules.d _rule _found
383 inst_dir "${udevdir}/rules.d
"
385 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
386 [[ -e $_rule ]] || continue
387 inst_rule_programs "$_rule"
388 inst_rule_group_owner "$_rule"
389 inst_rule_initqueue "$_rule"
393 if [[ -n ${hostonly} ]] ; then
394 for _rule in ${_target}/$1 ; do
395 [[ -f $_rule ]] || continue
396 inst_rule_programs "$_rule"
397 inst_rule_group_owner "$_rule"
398 inst_rule_initqueue "$_rule"
403 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
406 prepare_udev_rules() {
407 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
410 f="${initdir}/etc
/udev
/rules.d
/$f"
411 [ -e "$f" ] || continue
412 while read line || [ -n "$line" ]; do
413 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
414 if [ $UDEVVERSION -ge 174 ]; then
415 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
417 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
419 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
420 if [ $UDEVVERSION -ge 176 ]; then
421 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
423 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
428 done < "${f}" > "${f}.new
"
433 # install function specialized for hooks
434 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
435 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
437 if ! [[ -f $3 ]]; then
438 dfatal "Cannot
install a hook
($3) that does not exist.
"
439 dfatal "Aborting initrd creation.
"
441 elif ! [[ "$hookdirs" == *$1* ]]; then
442 dfatal "No such hook
type $1. Aborting initrd creation.
"
445 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
448 # install any of listed files
450 # If first argument is '-d' and second some destination path, first accessible
451 # source is installed into this path, otherwise it will installed in the same
452 # path as source. If none of listed files was installed, function return 1.
453 # On first successful installation it returns with 0 status.
457 # inst_any -d /bin/foo /bin/bar /bin/baz
459 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
464 [[ $1 = '-d' ]] && to="$2" && shift 2
467 [[ -e $f ]] || continue
468 [[ $to ]] && inst "$f" "$to" && return 0
469 inst "$f" && return 0
476 # inst_libdir_file [-n <pattern>] <file> [<file>...]
477 # Install a <file> located on a lib directory to the initramfs image
478 # -n <pattern> install matching files
481 if [[ "$1" == "-n" ]]; then
484 for _dir in $libdirs; do
486 for _f in "$_dir"/$_i; do
487 [[ "$_f" =~ $_pattern ]] || continue
488 [[ -e "$_f" ]] && _files+="$_f "
493 for _dir in $libdirs; do
495 for _f in "$_dir"/$_i; do
496 [[ -e "$_f" ]] && _files+="$_f "
501 [[ $_files ]] && inst_multiple $_files
505 # install function decompressing the target and handling symlinks
506 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
508 # Function install targets in the same paths inside overlay but decompressed
509 # and without extensions (.gz, .bz2).
516 *.gz) _cmd='gzip -f -d' ;;
517 *.bz2) _cmd='bzip2 -d' ;;
521 # Decompress with chosen tool. We assume that tool changes name e.g.
522 # from 'name.gz' to 'name'.
523 ${_cmd} "${initdir}${_src}"
527 # It's similar to above, but if file is not compressed, performs standard
530 inst_opt_decompress
() {
534 inst_decompress
"${_src}" || inst
"${_src}"
538 # module_check <dracut module>
539 # execute the check() function of module-setup.sh of <dracut module>
540 # or the "check" script, if module-setup.sh is not found
541 # "check $hostonly" is called
543 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
546 local _hostonly
=$hostonly
547 [ $# -eq 2 ] && _forced
=$2
548 [[ -d $_moddir ]] ||
return 1
549 if [[ ! -f $_moddir/module-setup.sh
]]; then
550 # if we do not have a check script, we are unconditionally included
551 [[ -x $_moddir/check
]] ||
return 0
552 [ $_forced -ne 0 ] && unset hostonly
553 $_moddir/check
$hostonly
556 unset check depends cmdline
install installkernel
558 .
$_moddir/module-setup.sh
559 is_func check ||
return 0
560 [ $_forced -ne 0 ] && unset hostonly
561 moddir
=$_moddir check
$hostonly
563 unset check depends cmdline
install installkernel
569 # module_check_mount <dracut module>
570 # execute the check() function of module-setup.sh of <dracut module>
571 # or the "check" script, if module-setup.sh is not found
572 # "mount_needs=1 check 0" is called
573 module_check_mount
() {
574 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
577 [[ -d $_moddir ]] ||
return 1
578 if [[ ! -f $_moddir/module-setup.sh
]]; then
579 # if we do not have a check script, we are unconditionally included
580 [[ -x $_moddir/check
]] ||
return 0
581 mount_needs
=1 $_moddir/check
0
584 unset check depends cmdline
install installkernel
586 .
$_moddir/module-setup.sh
587 moddir
=$_moddir check
0
589 unset check depends cmdline
install installkernel
595 # module_depends <dracut module>
596 # execute the depends() function of module-setup.sh of <dracut module>
597 # or the "depends" script, if module-setup.sh is not found
599 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
601 [[ -d $_moddir ]] ||
return 1
602 if [[ ! -f $_moddir/module-setup.sh
]]; then
603 # if we do not have a check script, we have no deps
604 [[ -x $_moddir/check
]] ||
return 0
608 unset check depends cmdline
install installkernel
610 .
$_moddir/module-setup.sh
611 moddir
=$_moddir depends
613 unset check depends cmdline
install installkernel
618 # module_cmdline <dracut module>
619 # execute the cmdline() function of module-setup.sh of <dracut module>
620 # or the "cmdline" script, if module-setup.sh is not found
622 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
624 [[ -d $_moddir ]] ||
return 1
625 if [[ ! -f $_moddir/module-setup.sh
]]; then
626 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
629 unset check depends cmdline
install installkernel
631 .
$_moddir/module-setup.sh
632 moddir
=$_moddir cmdline
634 unset check depends cmdline
install installkernel
639 # module_install <dracut module>
640 # execute the install() function of module-setup.sh of <dracut module>
641 # or the "install" script, if module-setup.sh is not found
643 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
645 [[ -d $_moddir ]] ||
return 1
646 if [[ ! -f $_moddir/module-setup.sh
]]; then
647 [[ -x $_moddir/install ]] && .
"$_moddir/install"
650 unset check depends cmdline
install installkernel
652 .
$_moddir/module-setup.sh
653 moddir
=$_moddir install
655 unset check depends cmdline
install installkernel
660 # module_installkernel <dracut module>
661 # execute the installkernel() function of module-setup.sh of <dracut module>
662 # or the "installkernel" script, if module-setup.sh is not found
663 module_installkernel
() {
664 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
666 [[ -d $_moddir ]] ||
return 1
667 if [[ ! -f $_moddir/module-setup.sh
]]; then
668 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
671 unset check depends cmdline
install installkernel
672 installkernel
() { true
; }
673 .
$_moddir/module-setup.sh
674 moddir
=$_moddir installkernel
676 unset check depends cmdline
install installkernel
681 # check_mount <dracut module>
682 # check_mount checks, if a dracut module is needed for the given
683 # device and filesystem types in "${host_fs_types[@]}"
686 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
690 [ "${#host_fs_types[@]}" -le 0 ] && return 1
692 # If we are already scheduled to be loaded, no need to check again.
693 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
694 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
696 # This should never happen, but...
697 [[ -d $_moddir ]] ||
return 1
699 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
701 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
705 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
706 module_check_mount
$_mod; ret
=$?
708 # explicit module, so also accept ret=255
709 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
711 # module not in our list
712 if [[ $dracutmodules = all
]]; then
713 # check, if we can and should install this module
714 module_check_mount
$_mod ||
return 1
721 for _moddep
in $
(module_depends
$_mod); do
722 # handle deps as if they were manually added
723 [[ " $dracutmodules " == *\
$_mod\
* ]] \
724 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
725 && dracutmodules
+=" $_moddep "
726 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
727 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
728 && add_dracutmodules
+=" $_moddep "
729 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
730 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
731 && force_add_dracutmodules
+=" $_moddep "
732 # if a module we depend on fail, fail also
733 if ! check_module
$_moddep; then
734 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
739 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
740 mods_to_load
+=" $_mod "
745 # check_module <dracut module> [<use_as_dep>]
746 # check if a dracut module is to be used in the initramfs process
747 # if <use_as_dep> is set, then the process also keeps track
748 # that the modules were checked for the dependency tracking process
751 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
754 # If we are already scheduled to be loaded, no need to check again.
755 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
756 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
758 # This should never happen, but...
759 [[ -d $_moddir ]] ||
return 1
761 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
763 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
764 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
768 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
769 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
770 module_check
$_mod 1; ret
=$?
772 module_check
$_mod 0; ret
=$?
774 # explicit module, so also accept ret=255
775 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
777 # module not in our list
778 if [[ $dracutmodules = all
]]; then
779 # check, if we can and should install this module
780 module_check
$_mod; ret
=$?
781 if [[ $ret != 0 ]]; then
783 [[ $ret != 255 ]] && return 1
791 for _moddep
in $
(module_depends
$_mod); do
792 # handle deps as if they were manually added
793 [[ " $dracutmodules " == *\
$_mod\
* ]] \
794 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
795 && dracutmodules
+=" $_moddep "
796 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
797 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
798 && add_dracutmodules
+=" $_moddep "
799 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
800 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
801 && force_add_dracutmodules
+=" $_moddep "
802 # if a module we depend on fail, fail also
803 if ! check_module
$_moddep; then
804 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
809 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
810 mods_to_load
+=" $_mod "
815 # for_each_module_dir <func>
816 # execute "<func> <dracut module> 1"
817 for_each_module_dir
() {
823 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
824 [[ -d $_moddir ]] ||
continue;
825 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
826 -e $_moddir/module-setup.sh
]] ||
continue
827 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
831 # Report any missing dracut modules, the user has specified
832 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
833 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
834 for _mod
in $_modcheck; do
835 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
837 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
838 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
839 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
842 derror
"dracut module '$_mod' cannot be found or installed."
843 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
844 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
845 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
849 # Install a single kernel module along with any firmware it may require.
850 # $1 = full path to kernel module to install
851 install_kmod_with_fw
() {
852 # no need to go further if the module is already installed
854 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
857 if [[ $omit_drivers ]]; then
861 if [[ "$_kmod" =~
$omit_drivers ]]; then
862 dinfo
"Omitting driver $_kmod"
865 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
866 dinfo
"Omitting driver $_kmod"
871 if [[ $silent_omit_drivers ]]; then
875 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
876 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
879 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
881 (($ret != 0)) && return $ret
883 local _modname
=${1##*/} _fwdir _found _fw
884 _modname
=${_modname%.ko*}
885 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
887 for _fwdir
in $fw_dir; do
888 [[ -d $_fwdir && -f $_fwdir/$_fw ]] ||
continue
889 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
892 if [[ $_found != yes ]]; then
893 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
894 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
897 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
905 # Do something with all the dependencies of a kernel module.
906 # Note that kernel modules depend on themselves using the technique we use
907 # $1 = function to call for each dependency we find
908 # It will be passed the full path to the found kernel module
909 # $2 = module to get dependencies for
910 # rest of args = arguments to modprobe
911 # _fderr specifies FD passed from surrounding scope
912 for_each_kmod_dep
() {
913 local _func
=$1 _kmod
=$2 _cmd _modpath _options
915 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
916 while read _cmd _modpath _options ||
[ -n "$_cmd" ]; do
917 [[ $_cmd = insmod
]] ||
continue
918 $_func ${_modpath} ||
exit $?
923 dracut_kernel_post
() {
924 local _moddirname
=${srcmods%%/lib/modules/*}
927 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
928 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
931 # generate module dependencies for the initrd
932 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
933 ! depmod
-a -b "$initdir" $kernel; then
934 dfatal
"\"depmod -a $kernel\" failed."
940 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
942 module_is_host_only
() {
944 local _modenc a i _k _s _v _aliases
949 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
951 # check if module is loaded
952 [[ ${host_modules["$_modenc"]} ]] && return 0
954 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
956 if [[ "$kernel_current" != "$kernel" ]]; then
957 # check if module is loadable on the current kernel
958 # this covers the case, where a new module is introduced
959 # or a module was renamed
960 # or a module changed from builtin to a module
962 if [[ -d /lib
/modules
/$kernel_current ]]; then
963 # if the modinfo can be parsed, but the module
964 # is not loaded, then we can safely return 1
965 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
968 # just install the module, better safe than sorry
975 find_kernel_modules_by_path
() {
978 [[ -f "$srcmods/modules.dep" ]] ||
return 0
982 while read a rest ||
[ -n "$a" ]; do
983 [[ $a = */$1/* ]] ||
[[ $a = updates
/* ]] ||
continue
984 printf "%s\n" "$srcmods/$a"
985 done < "$srcmods/modules.dep"
990 find_kernel_modules
() {
991 find_kernel_modules_by_path drivers
995 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
996 # instmods [-c [-s]] <kernel subsystem>
997 # install kernel modules along with all their dependencies.
998 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1001 local _optional
="-o"
1005 [[ $no_kernel = yes ]] && return
1007 if [[ $1 = '-c' ]]; then
1011 if [[ $1 = '-s' ]]; then
1016 if (($# == 0)); then
1017 read -r -d '' -a args
1022 ${initdir:+-D "$initdir"} \
1023 ${loginstall:+-L "$loginstall"} \
1025 ${omit_drivers:+-N "$omit_drivers"} \
1026 ${srcmods:+--kerneldir "$srcmods"} \
1028 ${_silent:+--silent} \
1032 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
1035 ${initdir:+-D "$initdir"} \
1036 ${loginstall:+-L "$loginstall"} \
1038 ${omit_drivers:+-N "$omit_drivers"} \
1039 ${srcmods:+--kerneldir "$srcmods"} \
1041 ${_silent:+--silent} \
1045 [[ "$optional" ]] && return 0