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
="/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 .
$dracutbasedir/dracut-functions.sh
85 if ! [[ $libdirs ]] ; then
86 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
87 && [[ -d /lib64
]]; then
89 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
92 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
95 libdirs
+=" $(ldconfig_paths)"
100 # helper function for check() in module-setup.sh
101 # to check for required installed binaries
102 # issues a standardized warning message
104 local _module_name
="${moddir##*/}"
107 if [[ "$1" = "-m" ]]; then
113 if ! find_binary
"$cmd" &>/dev
/null
; then
114 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
121 require_any_binary
() {
122 local _module_name
="${moddir##*/}"
125 if [[ "$1" = "-m" ]]; then
131 if find_binary
"$cmd" &>/dev
/null
; then
137 if (( $_ret != 0 )); then
138 dinfo
"$_module_name: Could not find any command of '$@'!"
145 dracut_need_initqueue
() {
146 >"$initdir/lib/dracut/need-initqueue"
149 dracut_module_included
() {
150 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
153 if ! [[ $DRACUT_INSTALL ]]; then
154 DRACUT_INSTALL
=$
(find_binary dracut-install
)
157 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
158 DRACUT_INSTALL
=$dracutbasedir/dracut-install
159 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install
/dracut-install
]]; then
160 DRACUT_INSTALL
=$dracutbasedir/install
/dracut-install
163 if ! [[ -x $DRACUT_INSTALL ]]; then
164 dfatal
"dracut-install not found!"
168 if [[ $hostonly == "-h" ]]; then
169 if ! [[ $DRACUT_KERNEL_MODALIASES ]] ||
! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
170 export DRACUT_KERNEL_MODALIASES
="${DRACUT_TMPDIR}/modaliases"
171 $DRACUT_INSTALL ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
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} "$@" ||
:
265 local _helper
="/run/dracut/fsck/fsck_help_$1.txt"
266 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
267 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper ||
:
272 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
276 # find symlinks linked to given library file
278 # Function searches for symlinks by stripping version numbers appended to
279 # library filename, checks if it points to the same target and finally
280 # prints the list of symlinks to stdout.
283 # rev_lib_symlinks libfoo.so.8.1
284 # output: libfoo.so.8 libfoo.so
285 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
287 [[ ! $1 ]] && return 0
289 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
291 [[ ${fn} == *.so.
* ]] ||
return 1
293 until [[ ${fn##*.} == so
]]; do
295 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
301 # attempt to install any programs specified in a udev rule
302 inst_rule_programs() {
305 for _prog in $(sed -nr 's/.*PROGRAM==?"([^
"]+).*/\1/p' "$1"); do
307 if [ -x ${udevdir}/$_prog ]; then
308 _bin=${udevdir}/$_prog
309 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
310 _bin=$(find_binary "$_prog") || {
311 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
316 [[ $_bin ]] && inst_binary "$_bin"
318 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
320 if [ -x ${udevdir}/$_prog ]; then
321 _bin=${udevdir}/$_prog
322 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
323 _bin=$(find_binary "$_prog") || {
324 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
329 [[ $_bin ]] && inst_binary "$_bin"
331 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
333 if [ -x ${udevdir}/$_prog ]; then
334 _bin=${udevdir}/$_prog
335 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
336 _bin=$(find_binary "$_prog") || {
337 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
342 [[ $_bin ]] && dracut_install "$_bin"
346 # attempt to install any programs specified in a udev rule
347 inst_rule_group_owner() {
350 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
351 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
352 grep -E "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
355 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
356 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
357 grep -E "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
362 inst_rule_initqueue() {
363 if grep -q -F initqueue "$1"; then
364 dracut_need_initqueue
368 # udev rules always get installed in the same place, so
369 # create a function to install them to make life simpler.
371 local _target=/etc/udev/rules.d _rule _found
373 inst_dir "${udevdir}/rules.d
"
375 for _rule in "$@
"; do
376 if [ "${_rule#/}" = "$_rule" ]; then
377 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
378 [[ -e $r/$_rule ]] || continue
380 inst_rule_programs "$_found"
381 inst_rule_group_owner "$_found"
382 inst_rule_initqueue "$_found"
383 inst_simple "$_found"
386 for r in '' $dracutbasedir/rules.d/; do
387 # skip rules without an absolute path
388 [[ "${r}$_rule" != /* ]] && continue
389 [[ -f ${r}$_rule ]] || continue
391 inst_rule_programs "$_found"
392 inst_rule_group_owner "$_found"
393 inst_rule_initqueue "$_found"
394 inst_simple "$_found" "$_target/${_found##*/}"
396 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
400 inst_rules_wildcard() {
401 local _target=/etc/udev/rules.d _rule _found
403 inst_dir "${udevdir}/rules.d
"
405 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
406 [[ -e $_rule ]] || continue
407 inst_rule_programs "$_rule"
408 inst_rule_group_owner "$_rule"
409 inst_rule_initqueue "$_rule"
413 if [[ -n ${hostonly} ]] ; then
414 for _rule in ${_target}/$1 ; do
415 [[ -f $_rule ]] || continue
416 inst_rule_programs "$_rule"
417 inst_rule_group_owner "$_rule"
418 inst_rule_initqueue "$_rule"
423 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
426 prepare_udev_rules() {
427 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
430 f="${initdir}/etc
/udev
/rules.d
/$f"
431 [ -e "$f" ] || continue
432 while read line || [ -n "$line" ]; do
433 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
434 if [ $UDEVVERSION -ge 174 ]; then
435 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
437 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
439 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
440 if [ $UDEVVERSION -ge 176 ]; then
441 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
443 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
448 done < "${f}" > "${f}.new
"
453 # install function specialized for hooks
454 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
455 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
457 if ! [[ -f $3 ]]; then
458 dfatal "Cannot
install a hook
($3) that does not exist.
"
459 dfatal "Aborting initrd creation.
"
461 elif ! [[ "$hookdirs" == *$1* ]]; then
462 dfatal "No such hook
type $1. Aborting initrd creation.
"
465 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
468 # install any of listed files
470 # If first argument is '-d' and second some destination path, first accessible
471 # source is installed into this path, otherwise it will installed in the same
472 # path as source. If none of listed files was installed, function return 1.
473 # On first successful installation it returns with 0 status.
477 # inst_any -d /bin/foo /bin/bar /bin/baz
479 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
484 [[ $1 = '-d' ]] && to="$2" && shift 2
487 [[ -e $f ]] || continue
488 [[ $to ]] && inst "$f" "$to" && return 0
489 inst "$f" && return 0
496 # inst_libdir_file [-n <pattern>] <file> [<file>...]
497 # Install a <file> located on a lib directory to the initramfs image
498 # -n <pattern> install matching files
501 if [[ "$1" == "-n" ]]; then
504 for _dir in $libdirs; do
506 for _f in "$_dir"/$_i; do
507 [[ "$_f" =~ $_pattern ]] || continue
508 [[ -e "$_f" ]] && _files+="$_f "
513 for _dir in $libdirs; do
515 for _f in "$_dir"/$_i; do
516 [[ -e "$_f" ]] && _files+="$_f "
521 [[ $_files ]] && inst_multiple $_files
525 # install function decompressing the target and handling symlinks
526 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
528 # Function install targets in the same paths inside overlay but decompressed
529 # and without extensions (.gz, .bz2).
536 *.gz) _cmd='gzip -f -d' ;;
537 *.bz2) _cmd='bzip2 -d' ;;
541 # Decompress with chosen tool. We assume that tool changes name e.g.
542 # from 'name.gz' to 'name'.
543 ${_cmd} "${initdir}${_src}"
547 # It's similar to above, but if file is not compressed, performs standard
550 inst_opt_decompress
() {
554 inst_decompress
"${_src}" || inst
"${_src}"
558 # module_check <dracut module>
559 # execute the check() function of module-setup.sh of <dracut module>
560 # or the "check" script, if module-setup.sh is not found
561 # "check $hostonly" is called
563 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
566 local _hostonly
=$hostonly
567 [ $# -eq 2 ] && _forced
=$2
568 [[ -d $_moddir ]] ||
return 1
569 if [[ ! -f $_moddir/module-setup.sh
]]; then
570 # if we do not have a check script, we are unconditionally included
571 [[ -x $_moddir/check
]] ||
return 0
572 [ $_forced -ne 0 ] && unset hostonly
573 $_moddir/check
$hostonly
576 unset check depends cmdline
install installkernel
578 .
$_moddir/module-setup.sh
579 is_func check ||
return 0
580 [ $_forced -ne 0 ] && unset hostonly
581 moddir
=$_moddir check
$hostonly
583 unset check depends cmdline
install installkernel
589 # module_check_mount <dracut module>
590 # execute the check() function of module-setup.sh of <dracut module>
591 # or the "check" script, if module-setup.sh is not found
592 # "mount_needs=1 check 0" is called
593 module_check_mount
() {
594 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
597 [[ -d $_moddir ]] ||
return 1
598 if [[ ! -f $_moddir/module-setup.sh
]]; then
599 # if we do not have a check script, we are unconditionally included
600 [[ -x $_moddir/check
]] ||
return 0
601 mount_needs
=1 $_moddir/check
0
604 unset check depends cmdline
install installkernel
606 .
$_moddir/module-setup.sh
607 moddir
=$_moddir check
0
609 unset check depends cmdline
install installkernel
615 # module_depends <dracut module>
616 # execute the depends() function of module-setup.sh of <dracut module>
617 # or the "depends" script, if module-setup.sh is not found
619 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
621 [[ -d $_moddir ]] ||
return 1
622 if [[ ! -f $_moddir/module-setup.sh
]]; then
623 # if we do not have a check script, we have no deps
624 [[ -x $_moddir/check
]] ||
return 0
628 unset check depends cmdline
install installkernel
630 .
$_moddir/module-setup.sh
631 moddir
=$_moddir depends
633 unset check depends cmdline
install installkernel
638 # module_cmdline <dracut module>
639 # execute the cmdline() function of module-setup.sh of <dracut module>
640 # or the "cmdline" script, if module-setup.sh is not found
642 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
644 [[ -d $_moddir ]] ||
return 1
645 if [[ ! -f $_moddir/module-setup.sh
]]; then
646 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
649 unset check depends cmdline
install installkernel
651 .
$_moddir/module-setup.sh
652 moddir
=$_moddir cmdline
654 unset check depends cmdline
install installkernel
659 # module_install <dracut module>
660 # execute the install() function of module-setup.sh of <dracut module>
661 # or the "install" script, if module-setup.sh is not found
663 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
665 [[ -d $_moddir ]] ||
return 1
666 if [[ ! -f $_moddir/module-setup.sh
]]; then
667 [[ -x $_moddir/install ]] && .
"$_moddir/install"
670 unset check depends cmdline
install installkernel
672 .
$_moddir/module-setup.sh
673 moddir
=$_moddir install
675 unset check depends cmdline
install installkernel
680 # module_installkernel <dracut module>
681 # execute the installkernel() function of module-setup.sh of <dracut module>
682 # or the "installkernel" script, if module-setup.sh is not found
683 module_installkernel
() {
684 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
686 [[ -d $_moddir ]] ||
return 1
687 if [[ ! -f $_moddir/module-setup.sh
]]; then
688 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
691 unset check depends cmdline
install installkernel
692 installkernel
() { true
; }
693 .
$_moddir/module-setup.sh
694 moddir
=$_moddir installkernel
696 unset check depends cmdline
install installkernel
701 # check_mount <dracut module>
702 # check_mount checks, if a dracut module is needed for the given
703 # device and filesystem types in "${host_fs_types[@]}"
706 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
710 [ "${#host_fs_types[@]}" -le 0 ] && return 1
712 # If we are already scheduled to be loaded, no need to check again.
713 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
714 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
716 # This should never happen, but...
717 [[ -d $_moddir ]] ||
return 1
719 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
721 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
725 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
726 module_check_mount
$_mod; ret
=$?
728 # explicit module, so also accept ret=255
729 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
731 # module not in our list
732 if [[ $dracutmodules = all
]]; then
733 # check, if we can and should install this module
734 module_check_mount
$_mod ||
return 1
741 for _moddep
in $
(module_depends
$_mod); do
742 # handle deps as if they were manually added
743 [[ " $dracutmodules " == *\
$_mod\
* ]] \
744 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
745 && dracutmodules
+=" $_moddep "
746 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
747 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
748 && add_dracutmodules
+=" $_moddep "
749 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
750 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
751 && force_add_dracutmodules
+=" $_moddep "
752 # if a module we depend on fail, fail also
753 if ! check_module
$_moddep; then
754 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
759 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
760 mods_to_load
+=" $_mod "
765 # check_module <dracut module> [<use_as_dep>]
766 # check if a dracut module is to be used in the initramfs process
767 # if <use_as_dep> is set, then the process also keeps track
768 # that the modules were checked for the dependency tracking process
771 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
774 # If we are already scheduled to be loaded, no need to check again.
775 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
776 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
778 # This should never happen, but...
779 [[ -d $_moddir ]] ||
return 1
781 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
783 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
784 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
788 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
789 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
790 module_check
$_mod 1; ret
=$?
792 module_check
$_mod 0; ret
=$?
794 # explicit module, so also accept ret=255
795 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
797 # module not in our list
798 if [[ $dracutmodules = all
]]; then
799 # check, if we can and should install this module
800 module_check
$_mod; ret
=$?
801 if [[ $ret != 0 ]]; then
803 [[ $ret != 255 ]] && return 1
811 for _moddep
in $
(module_depends
$_mod); do
812 # handle deps as if they were manually added
813 [[ " $dracutmodules " == *\
$_mod\
* ]] \
814 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
815 && dracutmodules
+=" $_moddep "
816 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
817 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
818 && add_dracutmodules
+=" $_moddep "
819 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
820 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
821 && force_add_dracutmodules
+=" $_moddep "
822 # if a module we depend on fail, fail also
823 if ! check_module
$_moddep; then
824 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
829 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
830 mods_to_load
+=" $_mod "
835 # for_each_module_dir <func>
836 # execute "<func> <dracut module> 1"
837 for_each_module_dir
() {
843 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
844 [[ -d $_moddir ]] ||
continue;
845 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
846 -e $_moddir/module-setup.sh
]] ||
continue
847 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
851 # Report any missing dracut modules, the user has specified
852 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
853 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
854 for _mod
in $_modcheck; do
855 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
857 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
858 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
859 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
862 derror
"dracut module '$_mod' cannot be found or installed."
863 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
864 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
865 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
869 # Install a single kernel module along with any firmware it may require.
870 # $1 = full path to kernel module to install
871 install_kmod_with_fw
() {
872 # no need to go further if the module is already installed
874 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
877 if [[ $omit_drivers ]]; then
881 if [[ "$_kmod" =~
$omit_drivers ]]; then
882 dinfo
"Omitting driver $_kmod"
885 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
886 dinfo
"Omitting driver $_kmod"
891 if [[ $silent_omit_drivers ]]; then
895 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
896 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
899 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
901 (($ret != 0)) && return $ret
903 local _modname
=${1##*/} _fwdir _found _fw
904 _modname
=${_modname%.ko*}
905 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
907 for _fwdir
in $fw_dir; do
908 [[ -d $_fwdir && -f $_fwdir/$_fw ]] ||
continue
909 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
912 if [[ $_found != yes ]]; then
913 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
914 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
917 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
925 # Do something with all the dependencies of a kernel module.
926 # Note that kernel modules depend on themselves using the technique we use
927 # $1 = function to call for each dependency we find
928 # It will be passed the full path to the found kernel module
929 # $2 = module to get dependencies for
930 # rest of args = arguments to modprobe
931 # _fderr specifies FD passed from surrounding scope
932 for_each_kmod_dep
() {
933 local _func
=$1 _kmod
=$2 _cmd _modpath _options
935 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
936 while read _cmd _modpath _options ||
[ -n "$_cmd" ]; do
937 [[ $_cmd = insmod
]] ||
continue
938 $_func ${_modpath} ||
exit $?
943 dracut_kernel_post
() {
944 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
945 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
948 # generate module dependencies for the initrd
949 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
950 ! depmod
-a -b "$initdir" $kernel; then
951 dfatal
"\"depmod -a $kernel\" failed."
958 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
959 # instmods [-c [-s]] <kernel subsystem>
960 # install kernel modules along with all their dependencies.
961 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
968 [[ $no_kernel = yes ]] && return
970 if [[ $1 = '-c' ]]; then
974 if [[ $1 = '-s' ]]; then
980 read -r -d '' -a args
985 ${initdir:+-D "$initdir"} \
986 ${loginstall:+-L "$loginstall"} \
988 ${omit_drivers:+-N "$omit_drivers"} \
989 ${srcmods:+--kerneldir "$srcmods"} \
991 ${_silent:+--silent} \
995 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
998 ${initdir:+-D "$initdir"} \
999 ${loginstall:+-L "$loginstall"} \
1001 ${omit_drivers:+-N "$omit_drivers"} \
1002 ${srcmods:+--kerneldir "$srcmods"} \
1004 ${_silent:+--silent} \
1008 [[ "$optional" ]] && return 0
1012 if [[ "$(ln --help)" == *--relative* ]]; then
1014 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1020 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1021 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"