2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # functions used by dracut and other tools.
7 # Copyright 2005-2009 Red Hat, Inc. All rights reserved.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
25 if ! [[ -d "$initdir/.kernelmodseen" ]]; then
26 mkdir
-p "$initdir/.kernelmodseen"
28 DRACUT_KERNEL_LAZY_HASHDIR
="$initdir/.kernelmodseen"
31 if [[ $initdir ]] && ! [[ -d $initdir ]]; then
35 # Generic substring function. If $2 is in $1, return 0.
36 strstr
() { [[ $1 = *$2* ]]; }
38 # find a binary. If we were not passed the full path directly,
39 # search in the usual places to find the binary.
41 if [[ -z ${1##/*} ]]; then
42 if [[ -x $1 ]] ||
{ strstr
"$1" ".so" && ldd
$1 &>/dev
/null
; }; then
51 if ! [[ $dracutbasedir ]]; then
52 dracutbasedir
=${BASH_SOURCE[0]%/*}
53 [[ $dracutbasedir = "dracut-functions" ]] && dracutbasedir
="."
54 [[ $dracutbasedir ]] || dracutbasedir
="."
55 dracutbasedir
="$(readlink -f $dracutbasedir)"
58 if ! [[ $DRACUT_INSTALL ]]; then
59 DRACUT_INSTALL
=$
(find_binary dracut-install
)
62 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
63 DRACUT_INSTALL
=$dracutbasedir/dracut-install
67 if ! [[ $libdirs ]] ; then
68 if strstr
"$(ldd /bin/sh)" "/lib64/" &>/dev
/null \
69 && [[ -d /lib64
]]; then
71 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
74 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
79 if ! [[ $kernel ]]; then
84 srcmods
="/lib/modules/$kernel/"
85 [[ $drivers_dir ]] && {
86 if vercmp $
(modprobe
--version | cut
-d' ' -f3) lt
3.7; then
87 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
90 srcmods
="$drivers_dir"
94 if ! type dinfo
>/dev
/null
2>&1; then
95 .
"$dracutbasedir/dracut-logger.sh"
99 if ! [[ $initdir ]]; then
100 dfatal
"initdir not set"
104 # export standard hookdirs
106 hookdirs
="cmdline pre-udev pre-trigger netroot "
107 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
108 hookdirs
+="pre-mount pre-pivot cleanup mount "
109 hookdirs
+="emergency shutdown-emergency shutdown "
113 # Create all subdirectories for given path without creating the last element.
115 mksubdirs
() { [[ -e ${1%/*} ]] || mkdir -m 0755 -p ${1%/*}; }
117 # Version comparision function. Assumes Linux style version scheme.
119 # $2 = comparision op (gt, ge, eq, le, lt, ne)
122 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
126 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
127 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
128 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
145 # Check whether $1 is a function.
147 [[ $
(type -t $1) = "function" ]]
150 # Function prints global variables in format name=value line by line.
151 # $@ = list of global variables' name
157 _value
=$
(eval echo \$
$_var)
158 [[ ${_value} ]] && echo "${_var}=\"${_value}\""
162 # normalize_path <path>
163 # Prints the normalized path, where it removes any duplicated
164 # and trailing slashes.
166 # $ normalize_path ///test/test//
170 set -- "${1//+(\/)//}"
175 # convert_abs_rel <from> <to>
176 # Prints the relative path, when creating a symlink to <to> from <from>.
178 # $ convert_abs_rel /usr/bin/test /bin/test-2
180 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
182 local __current __absolute __abssize __cursize __newpath
185 set -- "$
(normalize_path
"$1")" "$
(normalize_path
"$2")"
187 # corner case #1 - self looping link
188 [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
190 # corner case #2 - own dir link
191 [[ "${1%/*}" == "$2" ]] && { echo ".
"; return; }
193 IFS="/" __current=($1)
194 IFS="/" __absolute=($2)
196 __abssize=${#__absolute[@]}
197 __cursize=${#__current[@]}
199 while [[ ${__absolute[__level]} == ${__current[__level]} ]]
202 if (( __level > __abssize || __level > __cursize ))
208 for ((__i = __level; __i < __cursize-1; __i++))
212 __newpath=$__newpath"/"
214 __newpath=$__newpath"..
"
217 for ((__i = __level; __i < __abssize; __i++))
219 if [[ -n $__newpath ]]
221 __newpath=$__newpath"/"
223 __newpath=$__newpath${__absolute[__i]}
229 if strstr "$
(ln --help)" "--relative"; then
231 ln -sfnr "${initdir}/$1" "${initdir}/$2"
237 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
238 ln -sfn $
(convert_abs_rel
"${_dest}" "${_source}") "${initdir}/${_dest}"
242 get_persistent_dev
() {
245 _dev
=$
(udevadm info
--query=name
--name="$1" 2>/dev
/null
)
246 [ -z "$_dev" ] && return
248 for i
in /dev
/mapper
/* /dev
/disk
/by-uuid
/* /dev
/disk
/by-id
/*; do
249 _tmp
=$
(udevadm info
--query=name
--name="$i" 2>/dev
/null
)
250 if [ "$_tmp" = "$_dev" ]; then
257 # get_fs_env <device>
258 # Get and set the ID_FS_TYPE and ID_FS_UUID variable from udev for a device.
260 # $ get_fs_env /dev/sda2; echo $ID_FS_TYPE; echo $ID_FS_UUID
262 # 551a39aa-4ae9-4e70-a262-ef665cadb574
270 if evalstr
=$
(udevadm info
--query=env
--name=$1 \
271 |
{ while read line
; do
272 strstr
"$line" "DEVPATH" && found
=1;
273 strstr
"$line" "ID_FS_TYPE=" && { echo $line; exit 0;}
274 done; [[ $found ]] && exit 0; exit 1; }) ; then
276 [[ $ID_FS_TYPE ]] && return 0
280 # Fallback, if we don't have udev information
281 if find_binary blkid
>/dev
/null
; then
282 eval $
(blkid
-o udev
$1 \
283 |
while read line
; do
284 strstr
"$line" "ID_FS_TYPE=" && echo $line;
286 [[ $ID_FS_TYPE ]] && return 0
291 # get_maj_min <device>
292 # Prints the major and minor of a device node.
294 # $ get_maj_min /dev/sda2
298 _dev
=$
(stat
-L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev
/null
)
299 _dev
=$
(eval "echo $_dev")
303 # find_block_device <mountpoint>
304 # Prints the major and minor number of the block device
305 # for a given mountpoint.
306 # Unless $use_fstab is set to "yes" the functions
307 # uses /proc/self/mountinfo as the primary source of the
308 # information and only falls back to /etc/fstab, if the mountpoint
309 # is not found there.
311 # $ find_block_device /usr
313 find_block_device
() {
314 local _x _mpt _majmin _dev _fs _maj _min
315 if [[ $use_fstab != yes ]]; then
316 while read _x _x _majmin _x _mpt _x _x _fs _dev _x
; do
317 [[ $_mpt = $1 ]] ||
continue
318 [[ $_fs = nfs
]] && { echo $_dev; return 0;}
319 [[ $_fs = nfs3
]] && { echo $_dev; return 0;}
320 [[ $_fs = nfs4
]] && { echo $_dev; return 0;}
321 [[ $_fs = btrfs
]] && {
325 if [[ ${_majmin#0:} = $_majmin ]]; then
327 return 0 # we have a winner!
329 done < /proc
/self
/mountinfo
331 # fall back to /etc/fstab
332 while read _dev _mpt _fs _x
; do
333 [ "${_dev%%#*}" != "$_dev" ] && continue
335 if [[ $_mpt = $1 ]]; then
336 [[ $_fs = nfs
]] && { echo $_dev; return 0;}
337 [[ $_fs = nfs3
]] && { echo $_dev; return 0;}
338 [[ $_fs = nfs4
]] && { echo $_dev; return 0;}
339 [[ $_dev != ${_dev#UUID=} ]] && _dev
=/dev
/disk
/by-uuid
/${_dev#UUID=}
340 [[ $_dev != ${_dev#LABEL=} ]] && _dev
=/dev
/disk
/by-label
/${_dev#LABEL=}
341 [[ -b $_dev ]] ||
return 1 # oops, not a block device.
342 get_maj_min
"$_dev" && return 0
349 # find_dev_fstype <device>
350 # Echo the filesystem type for a given device.
351 # /proc/self/mountinfo is taken as the primary source of information
352 # and /etc/fstab is used as a fallback.
353 # No newline is appended!
355 # $ find_dev_fstype /dev/sda2;echo
358 local _x _mpt _majmin _dev _fs _maj _min
359 while read _x _x _majmin _x _mpt _x _x _fs _dev _x
; do
360 [[ $_dev = $1 ]] ||
continue
363 done < /proc
/self
/mountinfo
365 # fall back to /etc/fstab
366 while read _dev _mpt _fs _x
; do
367 [[ $_dev = $1 ]] ||
continue
375 # find_mp_fstype <mountpoint>
376 # Echo the filesystem type for a given mountpoint.
377 # /proc/self/mountinfo is taken as the primary source of information
378 # and /etc/fstab is used as a fallback.
379 # No newline is appended!
381 # $ find_mp_fstype /;echo
384 local _x _mpt _majmin _dev _fs _maj _min
385 while read _x _x _majmin _x _mpt _x _x _fs _dev _x
; do
386 [[ $_mpt = $1 ]] ||
continue
389 done < /proc
/self
/mountinfo
391 # fall back to /etc/fstab
392 while read _dev _mpt _fs _x
; do
393 [[ $_mpt = $1 ]] ||
continue
401 # finds the major:minor of the block device backing the root filesystem.
402 find_root_block_device
() { find_block_device
/; }
404 # for_each_host_dev_fs <func>
405 # Execute "<func> <dev> <filesystem>" for every "<dev>|<fs>" pair found
406 # in ${host_fs_types[@]}
407 for_each_host_dev_fs
()
413 for f
in ${host_fs_types[@]}; do
419 [[ -b "$_dev" ]] ||
continue
421 $_func $_dev $_fs && _ret
=0
426 # Walk all the slave relationships for a given block device.
427 # Stop when our helper function returns success
428 # $1 = function to call on every found block device
429 # $2 = block device in major:minor format
430 check_block_and_slaves
() {
432 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
434 check_vol_slaves
"$@" && return 0
435 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
436 check_block_and_slaves
$1 $
(cat "/sys/dev/block/$2/../dev") && return 0
438 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
439 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
440 [[ -f $_x ]] ||
continue
441 check_block_and_slaves
$1 $
(cat "$_x") && return 0
446 check_block_and_slaves_all
() {
448 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
452 check_vol_slaves
"$@" && return 0
453 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
454 check_block_and_slaves_all
$1 $
(cat "/sys/dev/block/$2/../dev") && _ret
=0
456 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
457 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
458 [[ -f $_x ]] ||
continue
459 check_block_and_slaves_all
$1 $
(cat "$_x") && _ret
=0
463 # for_each_host_dev_and_slaves <func>
464 # Execute "<func> <dev>" for every "<dev>" found
465 # in ${host_devs[@]} and their slaves
466 for_each_host_dev_and_slaves_all
()
471 for _dev
in ${host_devs[@]}; do
472 [[ -b "$_dev" ]] ||
continue
473 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
480 for_each_host_dev_and_slaves
()
484 for _dev
in ${host_devs[@]}; do
485 [[ -b "$_dev" ]] ||
continue
486 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
491 # ugly workaround for the lvm design
492 # There is no volume group device,
493 # so, there are no slave devices for volume groups.
494 # Logical volumes only have the slave devices they really live on,
495 # but you cannot create the logical volume without the volume group.
496 # And the volume group might be bigger than the devices the LV needs.
499 for i
in /dev
/mapper
/*; do
500 _lv
=$
(get_maj_min
$i)
501 if [[ $_lv = $2 ]]; then
502 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
506 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
508 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
516 # fs_get_option <filesystem options> <search for option>
517 # search for a specific option in a bunch of filesystem options
518 # and return the value
526 while [ $# -gt 0 ]; do
529 echo ${1#${_option}=}
536 if [[ $DRACUT_INSTALL ]]; then
537 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
539 [[ -e ${initdir}/"$1" ]] && return 0 # already there
540 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
541 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" ||
:
545 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
546 #dinfo "$DRACUT_INSTALL -l $@"
547 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
548 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
552 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
553 [[ -e $1 ]] ||
return 1 # no source
554 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
555 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" ||
:
559 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
560 [[ -L $1 ]] ||
return 1
561 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
562 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
567 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
568 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
570 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
575 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
576 [[ -e $1 ]] ||
return 1 # no source
577 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
578 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
582 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
583 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
587 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
588 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
593 # Install a directory, keeping symlinks as on the original system.
594 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
595 # will create ${initdir}/lib64, ${initdir}/lib64/file,
596 # and a symlink ${initdir}/lib -> lib64.
598 [[ -e ${initdir}/"$1" ]] && return 0 # already there
600 local _dir
="$1" _part
="${1%/*}" _file
601 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
606 # iterate over parent directories
607 for _file
in $_dir; do
608 [[ -e "${initdir}/$_file" ]] && continue
609 if [[ -L $_file ]]; then
610 inst_symlink
"$_file"
613 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
614 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
615 chmod u
+w
"${initdir}/$_file"
620 # $1 = file to copy to ramdisk
621 # $2 (optional) Name for the file on the ramdisk
622 # Location of the image dir is assumed to be $initdir
623 # We never overwrite the target if it exists.
625 [[ -f "$1" ]] ||
return 1
626 strstr
"$1" "/" ||
return 1
627 local _src
=$1 _target
="${2:-$1}"
629 [[ -L $_src ]] && { inst_symlink
$_src $_target; return $?
; }
631 if ! [[ -d ${initdir}/$_target ]]; then
632 [[ -e ${initdir}/$_target ]] && return 0
633 [[ -L ${initdir}/$_target ]] && return 0
634 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
636 if [[ $DRACUT_FIPS_MODE ]]; then
637 # install checksum files also
638 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
639 inst
"${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
641 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
642 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
644 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
645 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
648 ddebug
"Installing $_src"
649 cp --reflink=auto
--sparse=auto
-pfL "$_src" "${initdir}/$_target"
652 # same as above, but specialized for symlinks
654 local _src
=$1 _target
=${2:-$1} _realsrc
655 strstr
"$1" "/" ||
return 1
656 [[ -L $1 ]] ||
return 1
657 [[ -L $initdir/$_target ]] && return 0
658 _realsrc
=$
(readlink
-f "$_src")
659 if ! [[ -e $initdir/$_realsrc ]]; then
660 if [[ -d $_realsrc ]]; then
666 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
668 ln_r
"${_realsrc}" "${_target}"
671 # Same as above, but specialized to handle dynamic libraries.
672 # It handles making symlinks according to how the original library
675 local _src
="$1" _dest
=${2:-$1} _lib _reallib _symlink
676 strstr
"$1" "/" ||
return 1
677 [[ -e $initdir/$_dest ]] && return 0
678 if [[ -L $_src ]]; then
679 if [[ $DRACUT_FIPS_MODE ]]; then
680 # install checksum files also
681 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
682 inst
"${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
684 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
685 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
687 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
688 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
691 _reallib
=$
(readlink
-f "$_src")
692 inst_simple
"$_reallib" "$_reallib"
693 inst_dir
"${_dest%/*}"
694 ln_r
"${_reallib}" "${_dest}"
696 inst_simple
"$_src" "$_dest"
699 # Create additional symlinks. See rev_symlinks description.
700 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
701 [[ ! -e $initdir/$_symlink ]] && {
702 ddebug
"Creating extra symlink: $_symlink"
703 inst_symlink
$_symlink
708 # Same as above, but specialized to install binary executables.
709 # Install binary executable, and all shared library dependencies, if any.
712 _bin
=$
(find_binary
"$1") ||
return 1
714 [[ -e $initdir/$_target ]] && return 0
716 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
718 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
719 [[ $_line = 'not a dynamic executable' ]] && break
721 if [[ $_line =~
$_so_regex ]]; then
722 _file
=${BASH_REMATCH[1]}
723 [[ -e ${initdir}/$_file ]] && continue
724 inst_library
"$_file"
728 if [[ $_line =~ not\ found
]]; then
729 dfatal
"Missing a shared library required by $_bin."
730 dfatal
"Run \"ldd $_bin\" to find out what it is."
732 dfatal
"dracut cannot create an initrd."
736 inst_simple
"$_bin" "$_target"
739 # same as above, except for shell scripts.
740 # If your shell script does not start with shebang, it is not a shell script.
743 _bin
=$
(find_binary
"$1") ||
return 1
745 local _line _shebang_regex
746 read -r -n 80 _line
<"$_bin"
747 # If debug is set, clean unprintable chars to prevent messing up the term
748 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
749 _shebang_regex
='(#! *)(/[^ ]+).*'
750 [[ $_line =~
$_shebang_regex ]] ||
return 1
751 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
754 # general purpose installation function
755 # Same args as above.
761 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
762 [[ $initdir = $2 ]] && set $1;;
763 3) [[ -z $initdir ]] && export initdir
=$2
765 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
768 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
774 # dracut_install [-o ] <file> [<file> ... ]
775 # Install <file> to the initramfs image
776 # -o optionally install the <file> and don't fail, if it is not there
779 if [[ $1 = '-o' ]]; then
784 if ! inst
"$1" ; then
785 if [[ $_optional = yes ]]; then
786 dinfo
"Skipping program $1 as it cannot be found and is" \
787 "flagged to be optional"
789 dfatal
"Failed to install $1"
799 # find symlinks linked to given library file
801 # Function searches for symlinks by stripping version numbers appended to
802 # library filename, checks if it points to the same target and finally
803 # prints the list of symlinks to stdout.
806 # rev_lib_symlinks libfoo.so.8.1
807 # output: libfoo.so.8 libfoo.so
808 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
810 [[ ! $1 ]] && return 0
812 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
814 [[ ${fn} =~ .
*\.so\..
* ]] ||
return 1
816 until [[ ${fn##*.} == so
]]; do
818 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
824 # attempt to install any programs specified in a udev rule
825 inst_rule_programs() {
828 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
829 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
830 if [ -x ${udevdir}/$_prog ]; then
831 _bin=${udevdir}/$_prog
833 _bin=$(find_binary "$_prog") || {
834 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
839 #dinfo "Installing
$_bin due to it
's use in the udev rule $(${1##*/})"
840 dracut_install "$_bin"
843 if grep -qE 'RUN
[+=]=?
"[^ "]+' "$1"; then
844 for _prog in $(grep -E 'RUN
[+=]=?
"[^ "]+' "$1" | sed -r 's
/.
*RUN
[+=]=?
"([^ "]+).
*/\
1/'); do
845 if [ -x ${udevdir}/$_prog ]; then
846 _bin=${udevdir}/$_prog
848 _bin=$(find_binary "$_prog") || {
849 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
854 #dinfo "Installing $_bin due to it's use
in the udev rule $
(${1##*/})"
855 dracut_install "$_bin"
858 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
859 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
860 if [ -x ${udevdir}/$_prog ]; then
861 _bin=${udevdir}/$_prog
863 _bin=$(find_binary "$_prog") || {
864 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
869 #dinfo "Installing
$_bin due to it
's use in the udev rule $(${1##*/})"
870 dracut_install "$_bin"
875 # attempt to install any programs specified in a udev rule
876 inst_rule_group_owner() {
879 if grep -qE 'OWNER
=?
"[^ "]+' "$1"; then
880 for i in $(grep -E 'OWNER
=?
"[^ "]+' "$1" | sed -r 's
/.
*OWNER
=?
"([^ "]+).
*/\
1/'); do
881 if ! egrep -q "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
882 egrep "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
886 if grep -qE 'GROUP
=?
"[^ "]+' "$1"; then
887 for i in $(grep -E 'GROUP
=?
"[^ "]+' "$1" | sed -r 's
/.
*GROUP
=?
"([^ "]+).
*/\
1/'); do
888 if ! egrep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then
889 egrep "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
895 # udev rules always get installed in the same place, so
896 # create a function to install them to make life simpler.
898 local _target=/etc/udev/rules.d _rule _found
900 inst_dir "${udevdir}/rules.d"
902 for _rule in "$@"; do
903 if [ "${rule#/}" = "$rule" ]; then
904 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
905 if [[ -f $r/$_rule ]]; then
907 inst_rule_programs "$_found"
908 inst_rule_group_owner "$_found"
909 inst_simple "$_found"
913 for r in '' ./ $dracutbasedir/rules.d/; do
914 if [[ -f ${r}$_rule ]]; then
916 inst_rule_programs "$_found"
917 inst_rule_group_owner "$_found"
918 inst_simple "$_found" "$_target/${_found##*/}"
921 [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
925 # install function specialized for hooks
926 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
927 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
929 if ! [[ -f $3 ]]; then
930 dfatal "Cannot install a hook ($3) that does not exist."
931 dfatal "Aborting initrd creation."
933 elif ! strstr "$hookdirs" "$1"; then
934 dfatal "No such hook type $1. Aborting initrd creation."
937 inst_simple "$3" "/lib/dracut/hooks/${1}/${2}-${3##*/}"
940 # install any of listed files
942 # If first argument is '-d' and second some destination path, first accessible
943 # source is installed into this path, otherwise it will installed in the same
944 # path as source. If none of listed files was installed, function return 1.
945 # On first successful installation it returns with 0 status.
949 # inst_any -d /bin/foo /bin/bar /bin/baz
951 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
956 [[ $1 = '-d' ]] && to="$2" && shift 2
960 [[ $to ]] && inst "$f" "$to" && return 0
961 inst "$f" && return 0
969 # inst_libdir_file [-n <pattern>] <file> [<file>...]
970 # Install a <file> located on a lib directory to the initramfs image
971 # -n <pattern> install matching files
974 if [[ "$1" == "-n" ]]; then
977 for _dir in $libdirs; do
979 for _f in "$_dir"/$_i; do
980 [[ "$_f" =~ $_pattern ]] || continue
981 [[ -e "$_f" ]] && _files+="$_f "
986 for _dir in $libdirs; do
988 for _f in "$_dir"/$_i; do
989 [[ -e "$_f" ]] && _files+="$_f "
994 [[ $_files ]] && dracut_install $_files
998 # install function decompressing the target and handling symlinks
999 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1001 # Function install targets in the same paths inside overlay but decompressed
1002 # and without extensions (.gz, .bz2).
1009 *.gz) _cmd='gzip -d' ;;
1010 *.bz2) _cmd='bzip2 -d' ;;
1014 # Decompress with chosen tool. We assume that tool changes name e.g.
1015 # from 'name.gz
' to 'name
'.
1016 ${_cmd} "${initdir}${_src}"
1020 # It's similar to above
, but
if file is not compressed
, performs standard
1022 # $@ = list of files
1023 inst_opt_decompress
() {
1028 inst_decompress
"${_src}" || inst
"${_src}"
1032 # module_check <dracut module>
1033 # execute the check() function of module-setup.sh of <dracut module>
1034 # or the "check" script, if module-setup.sh is not found
1035 # "check $hostonly" is called
1037 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1040 local _hostonly
=$hostonly
1041 [ $# -eq 2 ] && _forced
=$2
1042 [[ -d $_moddir ]] ||
return 1
1043 if [[ ! -f $_moddir/module-setup.sh
]]; then
1044 # if we do not have a check script, we are unconditionally included
1045 [[ -x $_moddir/check
]] ||
return 0
1046 [ $_forced -ne 0 ] && unset hostonly
1047 $_moddir/check
$hostonly
1050 unset check depends
install installkernel
1051 .
$_moddir/module-setup.sh
1052 is_func check ||
return 0
1053 [ $_forced -ne 0 ] && unset hostonly
1056 unset check depends
install installkernel
1062 # module_check_mount <dracut module>
1063 # execute the check() function of module-setup.sh of <dracut module>
1064 # or the "check" script, if module-setup.sh is not found
1065 # "mount_needs=1 check 0" is called
1066 module_check_mount
() {
1067 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1070 [[ -d $_moddir ]] ||
return 1
1071 if [[ ! -f $_moddir/module-setup.sh
]]; then
1072 # if we do not have a check script, we are unconditionally included
1073 [[ -x $_moddir/check
]] ||
return 0
1074 mount_needs
=1 $_moddir/check
0
1077 unset check depends
install installkernel
1078 .
$_moddir/module-setup.sh
1079 is_func check ||
return 1
1082 unset check depends
install installkernel
1088 # module_depends <dracut module>
1089 # execute the depends() function of module-setup.sh of <dracut module>
1090 # or the "depends" script, if module-setup.sh is not found
1092 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1094 [[ -d $_moddir ]] ||
return 1
1095 if [[ ! -f $_moddir/module-setup.sh
]]; then
1096 # if we do not have a check script, we have no deps
1097 [[ -x $_moddir/check
]] ||
return 0
1101 unset check depends
install installkernel
1102 .
$_moddir/module-setup.sh
1103 is_func depends ||
return 0
1106 unset check depends
install installkernel
1111 # module_install <dracut module>
1112 # execute the install() function of module-setup.sh of <dracut module>
1113 # or the "install" script, if module-setup.sh is not found
1115 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1117 [[ -d $_moddir ]] ||
return 1
1118 if [[ ! -f $_moddir/module-setup.sh
]]; then
1119 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1122 unset check depends
install installkernel
1123 .
$_moddir/module-setup.sh
1124 is_func
install ||
return 0
1127 unset check depends
install installkernel
1132 # module_installkernel <dracut module>
1133 # execute the installkernel() function of module-setup.sh of <dracut module>
1134 # or the "installkernel" script, if module-setup.sh is not found
1135 module_installkernel
() {
1136 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1138 [[ -d $_moddir ]] ||
return 1
1139 if [[ ! -f $_moddir/module-setup.sh
]]; then
1140 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1143 unset check depends
install installkernel
1144 .
$_moddir/module-setup.sh
1145 is_func installkernel ||
return 0
1148 unset check depends
install installkernel
1153 # check_mount <dracut module>
1154 # check_mount checks, if a dracut module is needed for the given
1155 # device and filesystem types in "${host_fs_types[@]}"
1158 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1162 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1164 # If we are already scheduled to be loaded, no need to check again.
1165 strstr
" $mods_to_load " " $_mod " && return 0
1166 strstr
" $mods_checked_as_dep " " $_mod " && return 1
1168 # This should never happen, but...
1169 [[ -d $_moddir ]] ||
return 1
1171 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1173 if strstr
" $omit_dracutmodules " " $_mod "; then
1174 dinfo
"Dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1178 if strstr
" $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1179 module_check_mount
$_mod; ret
=$?
1181 # explicit module, so also accept ret=255
1182 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1184 # module not in our list
1185 if [[ $dracutmodules = all
]]; then
1186 # check, if we can and should install this module
1187 module_check_mount
$_mod ||
return 1
1195 for _moddep
in $
(module_depends
$_mod); do
1196 # handle deps as if they were manually added
1197 strstr
" $add_dracutmodules " " $_moddep " || \
1198 add_dracutmodules
+=" $_moddep "
1199 strstr
" $force_add_dracutmodules " " $_moddep " || \
1200 force_add_dracutmodules
+=" $_moddep "
1201 # if a module we depend on fail, fail also
1202 if ! check_module
$_moddep; then
1203 derror
"Dracut module '$_mod' depends on '$_moddep', which can't be installed"
1208 strstr
" $mods_to_load " " $_mod " || \
1209 mods_to_load
+=" $_mod "
1214 # check_module <dracut module> [<use_as_dep>]
1215 # check if a dracut module is to be used in the initramfs process
1216 # if <use_as_dep> is set, then the process also keeps track
1217 # that the modules were checked for the dependency tracking process
1220 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1223 # If we are already scheduled to be loaded, no need to check again.
1224 strstr
" $mods_to_load " " $_mod " && return 0
1225 strstr
" $mods_checked_as_dep " " $_mod " && return 1
1227 # This should never happen, but...
1228 [[ -d $_moddir ]] ||
return 1
1230 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1232 if strstr
" $omit_dracutmodules " " $_mod "; then
1233 dinfo
"Dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1237 if strstr
" $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1238 if strstr
" $force_add_dracutmodules" " $_mod"; then
1239 module_check
$_mod 1; ret
=$?
1241 module_check
$_mod 0; ret
=$?
1243 # explicit module, so also accept ret=255
1244 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1246 # module not in our list
1247 if [[ $dracutmodules = all
]]; then
1248 # check, if we can and should install this module
1249 module_check
$_mod ||
return 1
1256 for _moddep
in $
(module_depends
$_mod); do
1257 # handle deps as if they were manually added
1258 strstr
" $add_dracutmodules " " $_moddep " || \
1259 add_dracutmodules
+=" $_moddep "
1260 strstr
" $force_add_dracutmodules " " $_moddep " || \
1261 force_add_dracutmodules
+=" $_moddep "
1262 # if a module we depend on fail, fail also
1263 if ! check_module
$_moddep; then
1264 derror
"Dracut module '$_mod' depends on '$_moddep', which can't be installed"
1269 strstr
" $mods_to_load " " $_mod " || \
1270 mods_to_load
+=" $_mod "
1275 # for_each_module_dir <func>
1276 # execute "<func> <dracut module> 1"
1277 for_each_module_dir
() {
1283 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1284 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1288 # Report any missing dracut modules, the user has specified
1289 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1290 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1291 for _mod
in $_modcheck; do
1292 strstr
"$mods_to_load" "$_mod" && continue
1293 strstr
"$omit_dracutmodules" "$_mod" && continue
1294 derror
"Dracut module '$_mod' cannot be found or installed."
1298 # Install a single kernel module along with any firmware it may require.
1299 # $1 = full path to kernel module to install
1300 install_kmod_with_fw
() {
1301 # no need to go further if the module is already installed
1303 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1306 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1307 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1311 if [[ $omit_drivers ]]; then
1312 local _kmod
=${1##*/}
1315 if [[ "$_kmod" =~
$omit_drivers ]]; then
1316 dinfo
"Omitting driver $_kmod"
1319 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1320 dinfo
"Omitting driver $_kmod"
1325 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1327 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1328 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1329 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1330 (($ret != 0)) && return $ret
1332 local _modname
=${1##*/} _fwdir _found _fw
1333 _modname
=${_modname%.ko*}
1334 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1336 for _fwdir
in $fw_dir; do
1337 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1338 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1342 if [[ $_found != yes ]]; then
1343 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1344 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1345 "\"${_modname}.ko\""
1347 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1348 "\"${_modname}.ko\""
1355 # Do something with all the dependencies of a kernel module.
1356 # Note that kernel modules depend on themselves using the technique we use
1357 # $1 = function to call for each dependency we find
1358 # It will be passed the full path to the found kernel module
1359 # $2 = module to get dependencies for
1360 # rest of args = arguments to modprobe
1361 # _fderr specifies FD passed from surrounding scope
1362 for_each_kmod_dep
() {
1363 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1365 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1366 while read _cmd _modpath _options
; do
1367 [[ $_cmd = insmod
]] ||
continue
1368 $_func ${_modpath} ||
exit $?
1373 dracut_kernel_post
() {
1374 local _moddirname
=${srcmods%%/lib/modules/*}
1376 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1377 xargs -r modprobe
-a ${_moddirname+-d ${_moddirname}/} \
1378 --ignore-install --show-depends --set-version $kernel \
1379 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1381 |
while read _cmd _modpath _options
; do
1382 [[ $_cmd = insmod
]] ||
continue
1384 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1387 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1388 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1390 while read _modpath
; do
1391 local _destpath
=$_modpath
1392 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1393 _destpath
=${_destpath##*/lib/modules/$kernel/}
1394 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1395 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1399 if [[ $DRACUT_INSTALL ]]; then
1400 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1401 |
while read line
; do
1402 for _fwdir
in $fw_dir; do
1405 done |
xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
1407 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1408 for _fwdir
in $fw_dir; do
1409 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1410 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1420 for _f
in modules.
builtin.bin modules.
builtin; do
1421 [[ $srcmods/$_f ]] && break
1423 dfatal
"No modules.builtin.bin and modules.builtin found!"
1427 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1428 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1431 # generate module dependencies for the initrd
1432 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1433 ! depmod
-a -b "$initdir" $kernel; then
1434 dfatal
"\"depmod -a $kernel\" failed."
1438 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr "$DRACUT_KERNEL_LAZY_HASHDIR"
1441 module_is_host_only
() (
1446 [[ "$add_drivers" =~
" ${_mod} " ]] && return 0
1448 # check if module is loaded
1449 [[ -d $
(echo /sys
/module
/${_mod//-/_}|
{ read a b
; echo $a; }) ]] && return 0
1451 # check if module is loadable on the current kernel
1452 # this covers the case, where a new module is introduced
1453 # or a module was renamed
1454 # or a module changed from builtin to a module
1455 modinfo
-F filename
"$_mod" &>/dev
/null ||
return 0
1460 find_kernel_modules_by_path
() (
1464 while read a rest
; do
1465 [[ $a = kernel
*/$1/* ]] ||
continue
1467 done < $srcmods/modules.dep
1472 find_kernel_modules
() {
1473 find_kernel_modules_by_path drivers
1476 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1477 # instmods [-c [-s]] <kernel subsystem>
1478 # install kernel modules along with all their dependencies.
1479 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1481 [[ $no_kernel = yes ]] && return
1482 # called [sub]functions inherit _fderr
1486 if [[ $1 = '-c' ]]; then
1491 if [[ $1 = '-s' ]]; then
1496 function inst1mod
() {
1497 local _ret
=0 _mod
="$1"
1500 ( [[ "$_mpargs" ]] && echo $_mpargs
1501 find_kernel_modules_by_path
"${_mod#=}" ) \
1505 --*) _mpargs
+=" $_mod" ;;
1508 # if we are already installed, skip this module and go on
1510 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1511 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1512 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1516 if [[ $omit_drivers ]] && [[ "$1" =~
$omit_drivers ]]; then
1517 dinfo
"Omitting driver ${_mod##$srcmods}"
1521 # If we are building a host-specific initramfs and this
1522 # module is not already loaded, move on to the next one.
1524 && ! module_is_host_only
"$_mod" \
1527 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1528 # We use '-d' option in modprobe only if modules prefix path
1529 # differs from default '/'. This allows us to use Dracut with
1530 # old version of modprobe which doesn't have '-d' option.
1531 local _moddirname
=${srcmods%%/lib/modules/*}
1532 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1534 # ok, load the module, all its dependencies, and any firmware
1536 for_each_kmod_dep install_kmod_with_fw
$_mod \
1537 --set-version $kernel ${_moddirname} $_mpargs
1540 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1541 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1548 function instmods_1
() {
1550 if (($# == 0)); then # filenames from stdin
1552 inst1mod
"${_mod%.ko*}" ||
{
1553 if [[ "$_check" == "yes" ]]; then
1554 [[ "$_silent" == "no" ]] && dfatal
"Failed to install $_mod"
1560 while (($# > 0)); do # filenames as arguments
1561 inst1mod
${1%.ko*} ||
{
1562 if [[ "$_check" == "yes" ]]; then
1563 [[ "$_silent" == "no" ]] && dfatal
"Failed to install $1"
1572 local _ret _filter_not_found
='FATAL: Module .* not found.'
1573 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1574 # redirections, but that would make dracut require bash4 at least.
1575 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1576 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror