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 ||
:
270 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
271 # If hosotnly mode is set to "strict", hostonly restrictions will still
272 # be applied, else will ignore hostonly mode and try to install all
274 optional_hostonly
() {
275 if [[ $hostonly_mode = "strict" ]]; then
276 printf -- "$hostonly"
284 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
288 # find symlinks linked to given library file
290 # Function searches for symlinks by stripping version numbers appended to
291 # library filename, checks if it points to the same target and finally
292 # prints the list of symlinks to stdout.
295 # rev_lib_symlinks libfoo.so.8.1
296 # output: libfoo.so.8 libfoo.so
297 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
299 [[ ! $1 ]] && return 0
301 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
303 [[ ${fn} == *.so.
* ]] ||
return 1
305 until [[ ${fn##*.} == so
]]; do
307 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
313 # attempt to install any programs specified in a udev rule
314 inst_rule_programs() {
317 for _prog in $(sed -nr 's/.*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 ]] && inst_binary "$_bin"
330 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^
"]+).*/\1/p' "$1"); do
332 if [ -x ${udevdir}/$_prog ]; then
333 _bin=${udevdir}/$_prog
334 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
335 _bin=$(find_binary "$_prog") || {
336 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
341 [[ $_bin ]] && inst_binary "$_bin"
343 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/p' "$1"); do
345 if [ -x ${udevdir}/$_prog ]; then
346 _bin=${udevdir}/$_prog
347 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
348 _bin=$(find_binary "$_prog") || {
349 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
354 [[ $_bin ]] && dracut_install "$_bin"
358 # attempt to install any programs specified in a udev rule
359 inst_rule_group_owner() {
362 for i in $(sed -nr 's/.*OWNER=?"([^
"]+).*/\1/p' "$1"); do
363 if ! grep -Eq "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
364 grep -E "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
367 for i in $(sed -nr 's/.*GROUP=?"([^
"]+).*/\1/p' "$1"); do
368 if ! grep -Eq "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
369 grep -E "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
374 inst_rule_initqueue() {
375 if grep -q -F initqueue "$1"; then
376 dracut_need_initqueue
380 # udev rules always get installed in the same place, so
381 # create a function to install them to make life simpler.
383 local _target=/etc/udev/rules.d _rule _found
385 inst_dir "${udevdir}/rules.d
"
387 for _rule in "$@
"; do
388 if [ "${_rule#/}" = "$_rule" ]; then
389 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
390 [[ -e $r/$_rule ]] || continue
392 inst_rule_programs "$_found"
393 inst_rule_group_owner "$_found"
394 inst_rule_initqueue "$_found"
395 inst_simple "$_found"
398 for r in '' $dracutbasedir/rules.d/; do
399 # skip rules without an absolute path
400 [[ "${r}$_rule" != /* ]] && continue
401 [[ -f ${r}$_rule ]] || continue
403 inst_rule_programs "$_found"
404 inst_rule_group_owner "$_found"
405 inst_rule_initqueue "$_found"
406 inst_simple "$_found" "$_target/${_found##*/}"
408 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
412 inst_rules_wildcard() {
413 local _target=/etc/udev/rules.d _rule _found
415 inst_dir "${udevdir}/rules.d
"
417 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
418 [[ -e $_rule ]] || continue
419 inst_rule_programs "$_rule"
420 inst_rule_group_owner "$_rule"
421 inst_rule_initqueue "$_rule"
425 if [[ -n ${hostonly} ]] ; then
426 for _rule in ${_target}/$1 ; do
427 [[ -f $_rule ]] || continue
428 inst_rule_programs "$_rule"
429 inst_rule_group_owner "$_rule"
430 inst_rule_initqueue "$_rule"
435 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
438 prepare_udev_rules() {
439 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
442 f="${initdir}/etc
/udev
/rules.d
/$f"
443 [ -e "$f" ] || continue
444 while read line || [ -n "$line" ]; do
445 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
446 if [ $UDEVVERSION -ge 174 ]; then
447 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
449 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
451 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
452 if [ $UDEVVERSION -ge 176 ]; then
453 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
455 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
460 done < "${f}" > "${f}.new
"
465 # install function specialized for hooks
466 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
467 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
469 if ! [[ -f $3 ]]; then
470 dfatal "Cannot
install a hook
($3) that does not exist.
"
471 dfatal "Aborting initrd creation.
"
473 elif ! [[ "$hookdirs" == *$1* ]]; then
474 dfatal "No such hook
type $1. Aborting initrd creation.
"
477 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
480 # install any of listed files
482 # If first argument is '-d' and second some destination path, first accessible
483 # source is installed into this path, otherwise it will installed in the same
484 # path as source. If none of listed files was installed, function return 1.
485 # On first successful installation it returns with 0 status.
489 # inst_any -d /bin/foo /bin/bar /bin/baz
491 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
496 [[ $1 = '-d' ]] && to="$2" && shift 2
499 [[ -e $f ]] || continue
500 [[ $to ]] && inst "$f" "$to" && return 0
501 inst "$f" && return 0
508 # inst_libdir_file [-n <pattern>] <file> [<file>...]
509 # Install a <file> located on a lib directory to the initramfs image
510 # -n <pattern> install matching files
513 if [[ "$1" == "-n" ]]; then
516 for _dir in $libdirs; do
518 for _f in "$_dir"/$_i; do
519 [[ "$_f" =~ $_pattern ]] || continue
520 [[ -e "$_f" ]] && _files+="$_f "
525 for _dir in $libdirs; do
527 for _f in "$_dir"/$_i; do
528 [[ -e "$_f" ]] && _files+="$_f "
533 [[ $_files ]] && inst_multiple $_files
537 # install function decompressing the target and handling symlinks
538 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
540 # Function install targets in the same paths inside overlay but decompressed
541 # and without extensions (.gz, .bz2).
548 *.gz) _cmd='gzip -f -d' ;;
549 *.bz2) _cmd='bzip2 -d' ;;
553 # Decompress with chosen tool. We assume that tool changes name e.g.
554 # from 'name.gz' to 'name'.
555 ${_cmd} "${initdir}${_src}"
559 # It's similar to above, but if file is not compressed, performs standard
562 inst_opt_decompress
() {
566 inst_decompress
"${_src}" || inst
"${_src}"
570 # module_check <dracut module>
571 # execute the check() function of module-setup.sh of <dracut module>
572 # or the "check" script, if module-setup.sh is not found
573 # "check $hostonly" is called
575 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
578 local _hostonly
=$hostonly
579 [ $# -eq 2 ] && _forced
=$2
580 [[ -d $_moddir ]] ||
return 1
581 if [[ ! -f $_moddir/module-setup.sh
]]; then
582 # if we do not have a check script, we are unconditionally included
583 [[ -x $_moddir/check
]] ||
return 0
584 [ $_forced -ne 0 ] && unset hostonly
585 $_moddir/check
$hostonly
588 unset check depends cmdline
install installkernel
590 .
$_moddir/module-setup.sh
591 is_func check ||
return 0
592 [ $_forced -ne 0 ] && unset hostonly
593 moddir
=$_moddir check
$hostonly
595 unset check depends cmdline
install installkernel
601 # module_check_mount <dracut module>
602 # execute the check() function of module-setup.sh of <dracut module>
603 # or the "check" script, if module-setup.sh is not found
604 # "mount_needs=1 check 0" is called
605 module_check_mount
() {
606 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
609 [[ -d $_moddir ]] ||
return 1
610 if [[ ! -f $_moddir/module-setup.sh
]]; then
611 # if we do not have a check script, we are unconditionally included
612 [[ -x $_moddir/check
]] ||
return 0
613 mount_needs
=1 $_moddir/check
0
616 unset check depends cmdline
install installkernel
618 .
$_moddir/module-setup.sh
619 moddir
=$_moddir check
0
621 unset check depends cmdline
install installkernel
627 # module_depends <dracut module>
628 # execute the depends() function of module-setup.sh of <dracut module>
629 # or the "depends" script, if module-setup.sh is not found
631 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
633 [[ -d $_moddir ]] ||
return 1
634 if [[ ! -f $_moddir/module-setup.sh
]]; then
635 # if we do not have a check script, we have no deps
636 [[ -x $_moddir/check
]] ||
return 0
640 unset check depends cmdline
install installkernel
642 .
$_moddir/module-setup.sh
643 moddir
=$_moddir depends
645 unset check depends cmdline
install installkernel
650 # module_cmdline <dracut module>
651 # execute the cmdline() function of module-setup.sh of <dracut module>
652 # or the "cmdline" script, if module-setup.sh is not found
654 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
656 [[ -d $_moddir ]] ||
return 1
657 if [[ ! -f $_moddir/module-setup.sh
]]; then
658 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
661 unset check depends cmdline
install installkernel
663 .
$_moddir/module-setup.sh
664 moddir
=$_moddir cmdline
666 unset check depends cmdline
install installkernel
671 # module_install <dracut module>
672 # execute the install() function of module-setup.sh of <dracut module>
673 # or the "install" script, if module-setup.sh is not found
675 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
677 [[ -d $_moddir ]] ||
return 1
678 if [[ ! -f $_moddir/module-setup.sh
]]; then
679 [[ -x $_moddir/install ]] && .
"$_moddir/install"
682 unset check depends cmdline
install installkernel
684 .
$_moddir/module-setup.sh
685 moddir
=$_moddir install
687 unset check depends cmdline
install installkernel
692 # module_installkernel <dracut module>
693 # execute the installkernel() function of module-setup.sh of <dracut module>
694 # or the "installkernel" script, if module-setup.sh is not found
695 module_installkernel
() {
696 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
698 [[ -d $_moddir ]] ||
return 1
699 if [[ ! -f $_moddir/module-setup.sh
]]; then
700 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
703 unset check depends cmdline
install installkernel
704 installkernel
() { true
; }
705 .
$_moddir/module-setup.sh
706 moddir
=$_moddir installkernel
708 unset check depends cmdline
install installkernel
713 # check_mount <dracut module>
714 # check_mount checks, if a dracut module is needed for the given
715 # device and filesystem types in "${host_fs_types[@]}"
718 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
722 [ "${#host_fs_types[@]}" -le 0 ] && return 1
724 # If we are already scheduled to be loaded, no need to check again.
725 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
726 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
728 # This should never happen, but...
729 [[ -d $_moddir ]] ||
return 1
731 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
733 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
737 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
738 module_check_mount
$_mod; ret
=$?
740 # explicit module, so also accept ret=255
741 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
743 # module not in our list
744 if [[ $dracutmodules = all
]]; then
745 # check, if we can and should install this module
746 module_check_mount
$_mod ||
return 1
753 for _moddep
in $
(module_depends
$_mod); do
754 # handle deps as if they were manually added
755 [[ " $dracutmodules " == *\
$_mod\
* ]] \
756 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
757 && dracutmodules
+=" $_moddep "
758 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
759 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
760 && add_dracutmodules
+=" $_moddep "
761 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
762 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
763 && force_add_dracutmodules
+=" $_moddep "
764 # if a module we depend on fail, fail also
765 if ! check_module
$_moddep; then
766 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
771 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
772 mods_to_load
+=" $_mod "
777 # check_module <dracut module> [<use_as_dep>]
778 # check if a dracut module is to be used in the initramfs process
779 # if <use_as_dep> is set, then the process also keeps track
780 # that the modules were checked for the dependency tracking process
783 local _moddir
=$
(echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; })
786 # If we are already scheduled to be loaded, no need to check again.
787 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
788 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
790 # This should never happen, but...
791 [[ -d $_moddir ]] ||
return 1
793 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
795 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
796 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
800 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
801 if [[ " $dracutmodules $force_add_dracutmodules " == *\
$_mod\
* ]]; then
802 module_check
$_mod 1; ret
=$?
804 module_check
$_mod 0; ret
=$?
806 # explicit module, so also accept ret=255
807 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
809 # module not in our list
810 if [[ $dracutmodules = all
]]; then
811 # check, if we can and should install this module
812 module_check
$_mod; ret
=$?
813 if [[ $ret != 0 ]]; then
815 [[ $ret != 255 ]] && return 1
823 for _moddep
in $
(module_depends
$_mod); do
824 # handle deps as if they were manually added
825 [[ " $dracutmodules " == *\
$_mod\
* ]] \
826 && [[ " $dracutmodules " != *\
$_moddep\
* ]] \
827 && dracutmodules
+=" $_moddep "
828 [[ " $add_dracutmodules " == *\
$_mod\
* ]] \
829 && [[ " $add_dracutmodules " != *\
$_moddep\
* ]] \
830 && add_dracutmodules
+=" $_moddep "
831 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] \
832 && [[ " $force_add_dracutmodules " != *\
$_moddep\
* ]] \
833 && force_add_dracutmodules
+=" $_moddep "
834 # if a module we depend on fail, fail also
835 if ! check_module
$_moddep; then
836 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
841 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
842 mods_to_load
+=" $_mod "
847 # for_each_module_dir <func>
848 # execute "<func> <dracut module> 1"
849 for_each_module_dir
() {
855 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
856 [[ -d $_moddir ]] ||
continue;
857 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
858 -e $_moddir/module-setup.sh
]] ||
continue
859 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
863 # Report any missing dracut modules, the user has specified
864 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
865 [[ $dracutmodules != all
]] && _modcheck
="$_modcheck $dracutmodules"
866 for _mod
in $_modcheck; do
867 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
869 [[ " $force_add_dracutmodules " != *\
$_mod\
* ]] \
870 && [[ " $dracutmodules " != *\
$_mod\
* ]] \
871 && [[ " $omit_dracutmodules " == *\
$_mod\
* ]] \
874 derror
"dracut module '$_mod' cannot be found or installed."
875 [[ " $force_add_dracutmodules " == *\
$_mod\
* ]] && exit 1
876 [[ " $dracutmodules " == *\
$_mod\
* ]] && exit 1
877 [[ " $add_dracutmodules " == *\
$_mod\
* ]] && exit 1
881 # Install a single kernel module along with any firmware it may require.
882 # $1 = full path to kernel module to install
883 install_kmod_with_fw
() {
884 # no need to go further if the module is already installed
886 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
889 if [[ $omit_drivers ]]; then
893 if [[ "$_kmod" =~
$omit_drivers ]]; then
894 dinfo
"Omitting driver $_kmod"
897 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
898 dinfo
"Omitting driver $_kmod"
903 if [[ $silent_omit_drivers ]]; then
907 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
908 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
911 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
913 (($ret != 0)) && return $ret
915 local _modname
=${1##*/} _fwdir _found _fw
916 _modname
=${_modname%.ko*}
917 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
919 for _fwdir
in $fw_dir; do
920 [[ -d $_fwdir && -f $_fwdir/$_fw ]] ||
continue
921 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
924 if [[ $_found != yes ]]; then
925 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
926 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
929 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
937 # Do something with all the dependencies of a kernel module.
938 # Note that kernel modules depend on themselves using the technique we use
939 # $1 = function to call for each dependency we find
940 # It will be passed the full path to the found kernel module
941 # $2 = module to get dependencies for
942 # rest of args = arguments to modprobe
943 # _fderr specifies FD passed from surrounding scope
944 for_each_kmod_dep
() {
945 local _func
=$1 _kmod
=$2 _cmd _modpath _options
947 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
948 while read _cmd _modpath _options ||
[ -n "$_cmd" ]; do
949 [[ $_cmd = insmod
]] ||
continue
950 $_func ${_modpath} ||
exit $?
955 dracut_kernel_post
() {
956 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
957 [[ -e $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
960 # generate module dependencies for the initrd
961 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
962 ! depmod
-a -b "$initdir" $kernel; then
963 dfatal
"\"depmod -a $kernel\" failed."
970 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
971 # instmods [-c [-s]] <kernel subsystem>
972 # install kernel modules along with all their dependencies.
973 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
980 [[ $no_kernel = yes ]] && return
982 if [[ $1 = '-c' ]]; then
986 if [[ $1 = '-s' ]]; then
992 read -r -d '' -a args
997 ${initdir:+-D "$initdir"} \
998 ${loginstall:+-L "$loginstall"} \
1000 ${omit_drivers:+-N "$omit_drivers"} \
1001 ${srcmods:+--kerneldir "$srcmods"} \
1003 ${_silent:+--silent} \
1007 if (($_ret != 0)) && [[ -z "$_silent" ]]; then
1010 ${initdir:+-D "$initdir"} \
1011 ${loginstall:+-L "$loginstall"} \
1013 ${omit_drivers:+-N "$omit_drivers"} \
1014 ${srcmods:+--kerneldir "$srcmods"} \
1016 ${_silent:+--silent} \
1020 [[ "$optional" ]] && return 0
1024 if [[ "$(ln --help)" == *--relative* ]]; then
1026 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1032 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1033 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"