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 [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
56 if ! [[ -d "$initdir/.kernelmodseen" ]]; then
57 mkdir
-p "$initdir/.kernelmodseen"
59 DRACUT_KERNEL_LAZY_HASHDIR
="$initdir/.kernelmodseen"
62 if ! [[ $kernel ]]; then
67 srcmods
="/lib/modules/$kernel/"
69 [[ $drivers_dir ]] && {
70 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
71 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
74 srcmods
="$drivers_dir"
78 [[ $DRACUT_FIRMWARE_PATH ]] ||
export DRACUT_FIRMWARE_PATH
="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
80 # export standard hookdirs
82 hookdirs
="cmdline pre-udev pre-trigger netroot "
83 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
84 hookdirs
+="pre-mount pre-pivot cleanup mount "
85 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
89 .
$dracutbasedir/dracut-functions.sh
92 if ! [[ $libdirs ]] ; then
93 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
94 && [[ -d /lib64
]]; then
96 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
99 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
102 libdirs
+=" $(ldconfig_paths)"
107 # helper function for check() in module-setup.sh
108 # to check for required installed binaries
109 # issues a standardized warning message
111 local _module_name
="${moddir##*/}"
114 if [[ "$1" = "-m" ]]; then
120 if ! find_binary
"$cmd" &>/dev
/null
; then
121 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
128 require_any_binary
() {
129 local _module_name
="${moddir##*/}"
132 if [[ "$1" = "-m" ]]; then
138 if find_binary
"$cmd" &>/dev
/null
; then
144 if (( $_ret != 0 )); then
145 dinfo
"$_module_name: Could not find any command of '$@'!"
152 dracut_need_initqueue
() {
153 >"$initdir/lib/dracut/need-initqueue"
156 dracut_module_included
() {
157 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
160 if ! [[ $DRACUT_INSTALL ]]; then
161 DRACUT_INSTALL
=$
(find_binary dracut-install
)
164 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
165 DRACUT_INSTALL
=$dracutbasedir/dracut-install
166 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install
/dracut-install
]]; then
167 DRACUT_INSTALL
=$dracutbasedir/install
/dracut-install
170 if ! [[ -x $DRACUT_INSTALL ]]; then
171 dfatal
"dracut-install not found!"
175 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
177 [[ -e ${initdir}/"$1" ]] && return 0 # already there
178 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
179 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
183 local _hostonly_install
184 if [[ "$1" == "-H" ]]; then
185 _hostonly_install
="-H"
188 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
189 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
190 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
194 local _hostonly_install
195 if [[ "$1" == "-H" ]]; then
196 _hostonly_install
="-H"
199 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
200 [[ -e $1 ]] ||
return 1 # no source
201 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
202 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" ||
:
206 local _hostonly_install
207 if [[ "$1" == "-H" ]]; then
208 _hostonly_install
="-H"
211 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
212 [[ -L $1 ]] ||
return 1
213 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
214 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
219 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
221 (($_ret != 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
232 [[ $no_kernel = yes ]] && return
234 [[ $i == "--silent" ]] && _silent
=1
238 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
239 (($?
!= 0)) && (($_silent == 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" ||
:
243 local _hostonly_install
244 if [[ "$1" == "-H" ]]; then
245 _hostonly_install
="-H"
248 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
249 [[ -e $1 ]] ||
return 1 # no source
250 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
251 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
255 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
256 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
260 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
261 (($?
!= 0)) && derror FAILED
: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
266 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
270 # find symlinks linked to given library file
272 # Function searches for symlinks by stripping version numbers appended to
273 # library filename, checks if it points to the same target and finally
274 # prints the list of symlinks to stdout.
277 # rev_lib_symlinks libfoo.so.8.1
278 # output: libfoo.so.8 libfoo.so
279 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
281 [[ ! $1 ]] && return 0
283 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
285 [[ ${fn} == *.so.
* ]] ||
return 1
287 until [[ ${fn##*.} == so
]]; do
289 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
295 # attempt to install any programs specified in a udev rule
296 inst_rule_programs() {
299 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
301 if [ -x ${udevdir}/$_prog ]; then
302 _bin=${udevdir}/$_prog
303 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
304 _bin=$(find_binary "$_prog") || {
305 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
310 [[ $_bin ]] && inst_binary "$_bin"
312 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
314 if [ -x ${udevdir}/$_prog ]; then
315 _bin=${udevdir}/$_prog
316 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
317 _bin=$(find_binary "$_prog") || {
318 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
323 [[ $_bin ]] && inst_binary "$_bin"
325 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
327 if [ -x ${udevdir}/$_prog ]; then
328 _bin=${udevdir}/$_prog
329 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
330 _bin=$(find_binary "$_prog") || {
331 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
336 [[ $_bin ]] && dracut_install "$_bin"
340 # attempt to install any programs specified in a udev rule
341 inst_rule_group_owner() {
344 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
345 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
346 grep -E "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
349 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
350 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
351 grep -E "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
356 inst_rule_initqueue() {
357 if grep -q -F initqueue "$1"; then
358 dracut_need_initqueue
362 # udev rules always get installed in the same place, so
363 # create a function to install them to make life simpler.
365 local _target=/etc/udev/rules.d _rule _found
367 inst_dir "${udevdir}/rules.d
"
369 for _rule in "$@
"; do
370 if [ "${_rule#/}" = "$_rule" ]; then
371 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
372 [[ -e $r/$_rule ]] || continue
374 inst_rule_programs "$_found"
375 inst_rule_group_owner "$_found"
376 inst_rule_initqueue "$_found"
377 inst_simple "$_found"
380 for r in '' $dracutbasedir/rules.d/; do
381 # skip rules without an absolute path
382 [[ "${r}$_rule" != /* ]] && continue
383 [[ -f ${r}$_rule ]] || continue
385 inst_rule_programs "$_found"
386 inst_rule_group_owner "$_found"
387 inst_rule_initqueue "$_found"
388 inst_simple "$_found" "$_target/${_found##*/}"
390 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
394 inst_rules_wildcard() {
395 local _target=/etc/udev/rules.d _rule _found
397 inst_dir "${udevdir}/rules.d
"
399 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
400 [[ -e $_rule ]] || continue
401 inst_rule_programs "$_rule"
402 inst_rule_group_owner "$_rule"
403 inst_rule_initqueue "$_rule"
407 if [[ -n ${hostonly} ]] ; then
408 for _rule in ${_target}/$1 ; do
409 [[ -f $_rule ]] || continue
410 inst_rule_programs "$_rule"
411 inst_rule_group_owner "$_rule"
412 inst_rule_initqueue "$_rule"
417 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
420 prepare_udev_rules() {
421 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
424 f="${initdir}/etc
/udev
/rules.d
/$f"
425 [ -e "$f" ] || continue
426 while read line || [ -n "$line" ]; do
427 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
428 if [ $UDEVVERSION -ge 174 ]; then
429 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
431 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
433 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
434 if [ $UDEVVERSION -ge 176 ]; then
435 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
437 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
442 done < "${f}" > "${f}.new
"
447 # install function specialized for hooks
448 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
449 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
451 if ! [[ -f $3 ]]; then
452 dfatal "Cannot
install a hook
($3) that does not exist.
"
453 dfatal "Aborting initrd creation.
"
455 elif ! [[ "$hookdirs" == *$1* ]]; then
456 dfatal "No such hook
type $1. Aborting initrd creation.
"
459 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
462 # install any of listed files
464 # If first argument is '-d' and second some destination path, first accessible
465 # source is installed into this path, otherwise it will installed in the same
466 # path as source. If none of listed files was installed, function return 1.
467 # On first successful installation it returns with 0 status.
471 # inst_any -d /bin/foo /bin/bar /bin/baz
473 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
478 [[ $1 = '-d' ]] && to="$2" && shift 2
481 [[ -e $f ]] || continue
482 [[ $to ]] && inst "$f" "$to" && return 0
483 inst "$f" && return 0
490 # inst_libdir_file [-n <pattern>] <file> [<file>...]
491 # Install a <file> located on a lib directory to the initramfs image
492 # -n <pattern> install matching files
495 if [[ "$1" == "-n" ]]; then
498 for _dir in $libdirs; do
500 for _f in "$_dir"/$_i; do
501 [[ "$_f" =~ $_pattern ]] || continue
502 [[ -e "$_f" ]] && _files+="$_f "
507 for _dir in $libdirs; do
509 for _f in "$_dir"/$_i; do
510 [[ -e "$_f" ]] && _files+="$_f "
515 [[ $_files ]] && inst_multiple $_files
519 # install function decompressing the target and handling symlinks
520 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
522 # Function install targets in the same paths inside overlay but decompressed
523 # and without extensions (.gz, .bz2).
530 *.gz) _cmd='gzip -f -d' ;;
531 *.bz2) _cmd='bzip2 -d' ;;
535 # Decompress with chosen tool. We assume that tool changes name e.g.
536 # from 'name.gz' to 'name'.
537 ${_cmd} "${initdir}${_src}"
541 # It's similar to above, but if file is not compressed, performs standard
544 inst_opt_decompress
() {
548 inst_decompress
"${_src}" || inst
"${_src}"
552 # module_check <dracut module>
553 # execute the check() function of module-setup.sh of <dracut module>
554 # or the "check" script, if module-setup.sh is not found
555 # "check $hostonly" is called
557 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
560 local _hostonly
=$hostonly
561 [ $# -eq 2 ] && _forced
=$2
562 [[ -d $_moddir ]] ||
return 1
563 if [[ ! -f $_moddir/module-setup.sh
]]; then
564 # if we do not have a check script, we are unconditionally included
565 [[ -x $_moddir/check
]] ||
return 0
566 [ $_forced -ne 0 ] && unset hostonly
567 $_moddir/check
$hostonly
570 unset check depends cmdline
install installkernel
572 .
$_moddir/module-setup.sh
573 is_func check ||
return 0
574 [ $_forced -ne 0 ] && unset hostonly
575 moddir
=$_moddir check
$hostonly
577 unset check depends cmdline
install installkernel
583 # module_check_mount <dracut module>
584 # execute the check() function of module-setup.sh of <dracut module>
585 # or the "check" script, if module-setup.sh is not found
586 # "mount_needs=1 check 0" is called
587 module_check_mount
() {
588 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
591 [[ -d $_moddir ]] ||
return 1
592 if [[ ! -f $_moddir/module-setup.sh
]]; then
593 # if we do not have a check script, we are unconditionally included
594 [[ -x $_moddir/check
]] ||
return 0
595 mount_needs
=1 $_moddir/check
0
598 unset check depends cmdline
install installkernel
600 .
$_moddir/module-setup.sh
601 moddir
=$_moddir check
0
603 unset check depends cmdline
install installkernel
609 # module_depends <dracut module>
610 # execute the depends() function of module-setup.sh of <dracut module>
611 # or the "depends" script, if module-setup.sh is not found
613 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
615 [[ -d $_moddir ]] ||
return 1
616 if [[ ! -f $_moddir/module-setup.sh
]]; then
617 # if we do not have a check script, we have no deps
618 [[ -x $_moddir/check
]] ||
return 0
622 unset check depends cmdline
install installkernel
624 .
$_moddir/module-setup.sh
625 moddir
=$_moddir depends
627 unset check depends cmdline
install installkernel
632 # module_cmdline <dracut module>
633 # execute the cmdline() function of module-setup.sh of <dracut module>
634 # or the "cmdline" script, if module-setup.sh is not found
636 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
638 [[ -d $_moddir ]] ||
return 1
639 if [[ ! -f $_moddir/module-setup.sh
]]; then
640 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
643 unset check depends cmdline
install installkernel
645 .
$_moddir/module-setup.sh
646 moddir
=$_moddir cmdline
648 unset check depends cmdline
install installkernel
653 # module_install <dracut module>
654 # execute the install() function of module-setup.sh of <dracut module>
655 # or the "install" script, if module-setup.sh is not found
657 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
659 [[ -d $_moddir ]] ||
return 1
660 if [[ ! -f $_moddir/module-setup.sh
]]; then
661 [[ -x $_moddir/install ]] && .
"$_moddir/install"
664 unset check depends cmdline
install installkernel
666 .
$_moddir/module-setup.sh
667 moddir
=$_moddir install
669 unset check depends cmdline
install installkernel
674 # module_installkernel <dracut module>
675 # execute the installkernel() function of module-setup.sh of <dracut module>
676 # or the "installkernel" script, if module-setup.sh is not found
677 module_installkernel
() {
678 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
680 [[ -d $_moddir ]] ||
return 1
681 if [[ ! -f $_moddir/module-setup.sh
]]; then
682 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
685 unset check depends cmdline
install installkernel
686 installkernel
() { true
; }
687 .
$_moddir/module-setup.sh
688 moddir
=$_moddir installkernel
690 unset check depends cmdline
install installkernel
695 # check_mount <dracut module>
696 # check_mount checks, if a dracut module is needed for the given
697 # device and filesystem types in "${host_fs_types[@]}"
700 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
704 [ "${#host_fs_types[@]}" -le 0 ] && return 1
706 # If we are already scheduled to be loaded, no need to check again.
707 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
708 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
710 # This should never happen, but...
711 [[ -d $_moddir ]] ||
return 1
713 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
715 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
719 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
720 module_check_mount
$_mod; ret
=$?
722 # explicit module, so also accept ret=255
723 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
725 # module not in our list
726 if [[ $dracutmodules = all
]]; then
727 # check, if we can and should install this module
728 module_check_mount
$_mod ||
return 1
735 for _moddep
in $
(module_depends
$_mod); do
736 # handle deps as if they were manually added
737 [[ " $dracutmodules " == *\
$_mod\
* ]] \
738 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
739 && dracutmodules
+=" $_moddep "
740 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
741 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
742 && add_dracutmodules
+=" $_moddep "
743 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
744 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
745 && force_add_dracutmodules
+=" $_moddep "
746 # if a module we depend on fail, fail also
747 if ! check_module
$_moddep; then
748 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
753 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
754 mods_to_load
+=" $_mod "
759 # check_module <dracut module> [<use_as_dep>]
760 # check if a dracut module is to be used in the initramfs process
761 # if <use_as_dep> is set, then the process also keeps track
762 # that the modules were checked for the dependency tracking process
765 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
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
778 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
782 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
783 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
784 module_check
$_mod 1; ret
=$?
786 module_check
$_mod 0; ret
=$?
788 # explicit module, so also accept ret=255
789 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
791 # module not in our list
792 if [[ $dracutmodules = all
]]; then
793 # check, if we can and should install this module
794 module_check
$_mod; ret
=$?
795 if [[ $ret != 0 ]]; then
797 [[ $ret != 255 ]] && return 1
805 for _moddep
in $
(module_depends
$_mod); do
806 # handle deps as if they were manually added
807 [[ " $dracutmodules " == *\
$_mod\
* ]] \
808 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
809 && dracutmodules
+=" $_moddep "
810 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
811 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
812 && add_dracutmodules
+=" $_moddep "
813 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
814 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
815 && force_add_dracutmodules
+=" $_moddep "
816 # if a module we depend on fail, fail also
817 if ! check_module
$_moddep; then
818 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
823 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
824 mods_to_load
+=" $_mod "
829 # for_each_module_dir <func>
830 # execute "<func> <dracut module> 1"
831 for_each_module_dir
() {
837 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
838 [[ -d $_moddir ]] ||
continue;
839 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
840 -e $_moddir/module-setup.sh
]] ||
continue
841 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
845 # Report any missing dracut modules, the user has specified
846 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
847 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
848 for _mod
in $_modcheck; do
849 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
851 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
852 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
853 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
856 derror
"dracut module '$_mod' cannot be found or installed."
857 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
858 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
859 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
863 # Install a single kernel module along with any firmware it may require.
864 # $1 = full path to kernel module to install
865 install_kmod_with_fw
() {
866 # no need to go further if the module is already installed
868 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
871 if [[ $omit_drivers ]]; then
875 if [[ "$_kmod" =~
$omit_drivers ]]; then
876 dinfo
"Omitting driver $_kmod"
879 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
880 dinfo
"Omitting driver $_kmod"
885 if [[ $silent_omit_drivers ]]; then
889 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
890 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
893 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
895 (($ret != 0)) && return $ret
897 local _modname
=${1##*/} _fwdir _found _fw
898 _modname
=${_modname%.ko*}
899 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
901 for _fwdir
in $fw_dir; do
902 [[ -d $_fwdir && -f $_fwdir/$_fw ]] ||
continue
903 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
906 if [[ $_found != yes ]]; then
907 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
908 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
911 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
919 # Do something with all the dependencies of a kernel module.
920 # Note that kernel modules depend on themselves using the technique we use
921 # $1 = function to call for each dependency we find
922 # It will be passed the full path to the found kernel module
923 # $2 = module to get dependencies for
924 # rest of args = arguments to modprobe
925 # _fderr specifies FD passed from surrounding scope
926 for_each_kmod_dep
() {
927 local _func
=$1 _kmod
=$2 _cmd _modpath _options
929 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
930 while read _cmd _modpath _options ||
[ -n "$_cmd" ]; do
931 [[ $_cmd = insmod
]] ||
continue
932 $_func ${_modpath} ||
exit $?
937 dracut_kernel_post
() {
938 local _moddirname
=${srcmods%%/lib/modules/*}
941 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
942 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
945 # generate module dependencies for the initrd
946 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
947 ! depmod
-a -b "$initdir" $kernel; then
948 dfatal
"\"depmod -a $kernel\" failed."
955 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
956 # instmods [-c [-s]] <kernel subsystem>
957 # install kernel modules along with all their dependencies.
958 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
965 [[ $no_kernel = yes ]] && return
967 if [[ $1 = '-c' ]]; then
971 if [[ $1 = '-s' ]]; then
977 read -r -d '' -a args
982 ${initdir:+-D "$initdir"} \
983 ${loginstall:+-L "$loginstall"} \
985 ${omit_drivers:+-N "$omit_drivers"} \
986 ${srcmods:+--kerneldir "$srcmods"} \
988 ${_silent:+--silent} \
992 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
995 ${initdir:+-D "$initdir"} \
996 ${loginstall:+-L "$loginstall"} \
998 ${omit_drivers:+-N "$omit_drivers"} \
999 ${srcmods:+--kerneldir "$srcmods"} \
1001 ${_silent:+--silent} \
1005 [[ "$optional" ]] && return 0
1009 if [[ "$(ln --help)" == *--relative* ]]; then
1011 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1017 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1018 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"