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 pre-shutdown 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 _find_mpt
316 if [[ $use_fstab != yes ]]; then
321 [[ $8 = "-" ]] && shift
324 [[ $_mpt = $_find_mpt ]] ||
continue
325 [[ $_fs = nfs
]] && { echo $_dev; return 0;}
326 [[ $_fs = nfs3
]] && { echo $_dev; return 0;}
327 [[ $_fs = nfs4
]] && { echo $_dev; return 0;}
328 [[ $_fs = btrfs
]] && {
332 if [[ ${_majmin#0:} = $_majmin ]]; then
334 return 0 # we have a winner!
336 done < /proc
/self
/mountinfo
338 # fall back to /etc/fstab
339 while read _dev _mpt _fs _x
; do
340 [ "${_dev%%#*}" != "$_dev" ] && continue
342 if [[ $_mpt = $_find_mpt ]]; then
343 [[ $_fs = nfs
]] && { echo $_dev; return 0;}
344 [[ $_fs = nfs3
]] && { echo $_dev; return 0;}
345 [[ $_fs = nfs4
]] && { echo $_dev; return 0;}
346 [[ $_dev != ${_dev#UUID=} ]] && _dev
=/dev
/disk
/by-uuid
/${_dev#UUID=}
347 [[ $_dev != ${_dev#LABEL=} ]] && _dev
=/dev
/disk
/by-label
/${_dev#LABEL=}
348 [[ -b $_dev ]] ||
return 1 # oops, not a block device.
349 get_maj_min
"$_dev" && return 0
356 # find_dev_fstype <device>
357 # Echo the filesystem type for a given device.
358 # /proc/self/mountinfo is taken as the primary source of information
359 # and /etc/fstab is used as a fallback.
360 # No newline is appended!
362 # $ find_dev_fstype /dev/sda2;echo
365 local _x _mpt _majmin _dev _fs _maj _min _find_dev
367 strstr
"$_find_dev" "/dev" || _find_dev
="/dev/block/$_find_dev"
372 [[ $8 = "-" ]] && shift
375 strstr
"$_dev" "/dev" ||
continue
376 [[ $_dev -ef $_find_dev ]] ||
continue
377 [[ $_fs = "autofs" ]] && continue
380 done < /proc
/self
/mountinfo
382 # fall back to /etc/fstab
383 while read _dev _mpt _fs _x
; do
384 [ "${_dev%%#*}" != "$_dev" ] && continue
387 _dev
="$(echo $_dev | sed 's,/,\\x2f,g')"
388 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
391 _dev
="/dev/disk/by-uuid/${_dev#UUID=}"
394 _dev
="/dev/disk/by-partuuid/${_dev#PARTUUID=}"
398 [[ $_dev -ef $_find_dev ]] ||
continue
406 # find_mp_fstype <mountpoint>
407 # Echo the filesystem type for a given mountpoint.
408 # /proc/self/mountinfo is taken as the primary source of information
409 # and /etc/fstab is used as a fallback.
410 # No newline is appended!
412 # $ find_mp_fstype /;echo
415 local _x _mpt _majmin _dev _fs _maj _min _find_mpt
421 [[ $8 = "-" ]] && shift
424 [[ $_mpt = $_find_mpt ]] ||
continue
425 [[ $_fs = "autofs" ]] && continue
428 done < /proc
/self
/mountinfo
430 # fall back to /etc/fstab
431 while read _dev _mpt _fs _x
; do
432 [ "${_dev%%#*}" != "$_dev" ] && continue
433 [[ $_mpt = $_find_mpt ]] ||
continue
441 # finds the major:minor of the block device backing the root filesystem.
442 find_root_block_device
() { find_block_device
/; }
444 # for_each_host_dev_fs <func>
445 # Execute "<func> <dev> <filesystem>" for every "<dev>|<fs>" pair found
446 # in ${host_fs_types[@]}
447 for_each_host_dev_fs
()
453 for f
in ${host_fs_types[@]}; do
459 [[ -b "$_dev" ]] ||
continue
461 $_func $_dev $_fs && _ret
=0
466 # Walk all the slave relationships for a given block device.
467 # Stop when our helper function returns success
468 # $1 = function to call on every found block device
469 # $2 = block device in major:minor format
470 check_block_and_slaves
() {
472 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
474 check_vol_slaves
"$@" && return 0
475 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
476 check_block_and_slaves
$1 $
(cat "/sys/dev/block/$2/../dev") && return 0
478 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
479 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
480 [[ -f $_x ]] ||
continue
481 check_block_and_slaves
$1 $
(cat "$_x") && return 0
486 check_block_and_slaves_all
() {
488 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
492 check_vol_slaves
"$@" && return 0
493 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
494 check_block_and_slaves_all
$1 $
(cat "/sys/dev/block/$2/../dev") && _ret
=0
496 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
497 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
498 [[ -f $_x ]] ||
continue
499 check_block_and_slaves_all
$1 $
(cat "$_x") && _ret
=0
503 # for_each_host_dev_and_slaves <func>
504 # Execute "<func> <dev>" for every "<dev>" found
505 # in ${host_devs[@]} and their slaves
506 for_each_host_dev_and_slaves_all
()
511 for _dev
in ${host_devs[@]}; do
512 [[ -b "$_dev" ]] ||
continue
513 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
520 for_each_host_dev_and_slaves
()
524 for _dev
in ${host_devs[@]}; do
525 [[ -b "$_dev" ]] ||
continue
526 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
531 # ugly workaround for the lvm design
532 # There is no volume group device,
533 # so, there are no slave devices for volume groups.
534 # Logical volumes only have the slave devices they really live on,
535 # but you cannot create the logical volume without the volume group.
536 # And the volume group might be bigger than the devices the LV needs.
539 for i
in /dev
/mapper
/*; do
540 _lv
=$
(get_maj_min
$i)
541 if [[ $_lv = $2 ]]; then
542 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
546 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
548 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
556 # fs_get_option <filesystem options> <search for option>
557 # search for a specific option in a bunch of filesystem options
558 # and return the value
566 while [ $# -gt 0 ]; do
569 echo ${1#${_option}=}
576 if [[ $DRACUT_INSTALL ]]; then
577 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
579 [[ -e ${initdir}/"$1" ]] && return 0 # already there
580 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
581 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" ||
:
585 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
586 #dinfo "$DRACUT_INSTALL -l $@"
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} "$@" ||
:
592 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
593 [[ -e $1 ]] ||
return 1 # no source
594 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
595 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" ||
:
599 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
600 [[ -L $1 ]] ||
return 1
601 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
602 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
607 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
608 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
610 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
615 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
616 [[ -e $1 ]] ||
return 1 # no source
617 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
618 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
622 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
623 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
627 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
628 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
633 # Install a directory, keeping symlinks as on the original system.
634 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
635 # will create ${initdir}/lib64, ${initdir}/lib64/file,
636 # and a symlink ${initdir}/lib -> lib64.
638 [[ -e ${initdir}/"$1" ]] && return 0 # already there
640 local _dir
="$1" _part
="${1%/*}" _file
641 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
646 # iterate over parent directories
647 for _file
in $_dir; do
648 [[ -e "${initdir}/$_file" ]] && continue
649 if [[ -L $_file ]]; then
650 inst_symlink
"$_file"
653 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
654 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
655 chmod u
+w
"${initdir}/$_file"
660 # $1 = file to copy to ramdisk
661 # $2 (optional) Name for the file on the ramdisk
662 # Location of the image dir is assumed to be $initdir
663 # We never overwrite the target if it exists.
665 [[ -f "$1" ]] ||
return 1
666 strstr
"$1" "/" ||
return 1
667 local _src
=$1 _target
="${2:-$1}"
669 [[ -L $_src ]] && { inst_symlink
$_src $_target; return $?
; }
671 if ! [[ -d ${initdir}/$_target ]]; then
672 [[ -e ${initdir}/$_target ]] && return 0
673 [[ -L ${initdir}/$_target ]] && return 0
674 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
676 if [[ $DRACUT_FIPS_MODE ]]; then
677 # install checksum files also
678 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
679 inst
"${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
681 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
682 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
684 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
685 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
688 ddebug
"Installing $_src"
689 cp --reflink=auto
--sparse=auto
-pfL "$_src" "${initdir}/$_target"
692 # same as above, but specialized for symlinks
694 local _src
=$1 _target
=${2:-$1} _realsrc
695 strstr
"$1" "/" ||
return 1
696 [[ -L $1 ]] ||
return 1
697 [[ -L $initdir/$_target ]] && return 0
698 _realsrc
=$
(readlink
-f "$_src")
699 if ! [[ -e $initdir/$_realsrc ]]; then
700 if [[ -d $_realsrc ]]; then
706 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
708 ln_r
"${_realsrc}" "${_target}"
711 # Same as above, but specialized to handle dynamic libraries.
712 # It handles making symlinks according to how the original library
715 local _src
="$1" _dest
=${2:-$1} _lib _reallib _symlink
716 strstr
"$1" "/" ||
return 1
717 [[ -e $initdir/$_dest ]] && return 0
718 if [[ -L $_src ]]; then
719 if [[ $DRACUT_FIPS_MODE ]]; then
720 # install checksum files also
721 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
722 inst
"${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
724 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
725 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
727 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
728 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
731 _reallib
=$
(readlink
-f "$_src")
732 inst_simple
"$_reallib" "$_reallib"
733 inst_dir
"${_dest%/*}"
734 ln_r
"${_reallib}" "${_dest}"
736 inst_simple
"$_src" "$_dest"
739 # Create additional symlinks. See rev_symlinks description.
740 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
741 [[ ! -e $initdir/$_symlink ]] && {
742 ddebug
"Creating extra symlink: $_symlink"
743 inst_symlink
$_symlink
748 # Same as above, but specialized to install binary executables.
749 # Install binary executable, and all shared library dependencies, if any.
752 _bin
=$
(find_binary
"$1") ||
return 1
754 [[ -e $initdir/$_target ]] && return 0
756 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
758 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
759 [[ $_line = 'not a dynamic executable' ]] && break
761 if [[ $_line =~
$_so_regex ]]; then
762 _file
=${BASH_REMATCH[1]}
763 [[ -e ${initdir}/$_file ]] && continue
764 inst_library
"$_file"
768 if [[ $_line =~ not\ found
]]; then
769 dfatal
"Missing a shared library required by $_bin."
770 dfatal
"Run \"ldd $_bin\" to find out what it is."
772 dfatal
"dracut cannot create an initrd."
776 inst_simple
"$_bin" "$_target"
779 # same as above, except for shell scripts.
780 # If your shell script does not start with shebang, it is not a shell script.
783 _bin
=$
(find_binary
"$1") ||
return 1
785 local _line _shebang_regex
786 read -r -n 80 _line
<"$_bin"
787 # If debug is set, clean unprintable chars to prevent messing up the term
788 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
789 _shebang_regex
='(#! *)(/[^ ]+).*'
790 [[ $_line =~
$_shebang_regex ]] ||
return 1
791 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
794 # general purpose installation function
795 # Same args as above.
801 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
802 [[ $initdir = $2 ]] && set $1;;
803 3) [[ -z $initdir ]] && export initdir
=$2
805 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
808 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
814 # dracut_install [-o ] <file> [<file> ... ]
815 # Install <file> to the initramfs image
816 # -o optionally install the <file> and don't fail, if it is not there
819 if [[ $1 = '-o' ]]; then
824 if ! inst
"$1" ; then
825 if [[ $_optional = yes ]]; then
826 dinfo
"Skipping program $1 as it cannot be found and is" \
827 "flagged to be optional"
829 dfatal
"Failed to install $1"
839 # find symlinks linked to given library file
841 # Function searches for symlinks by stripping version numbers appended to
842 # library filename, checks if it points to the same target and finally
843 # prints the list of symlinks to stdout.
846 # rev_lib_symlinks libfoo.so.8.1
847 # output: libfoo.so.8 libfoo.so
848 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
850 [[ ! $1 ]] && return 0
852 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
854 [[ ${fn} =~ .
*\.so\..
* ]] ||
return 1
856 until [[ ${fn##*.} == so
]]; do
858 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
864 # attempt to install any programs specified in a udev rule
865 inst_rule_programs() {
868 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
869 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
871 if [ -x ${udevdir}/$_prog ]; then
872 _bin=${udevdir}/$_prog
873 elif [[ "${_prog/\$\{/}" != "$_prog" ]]; then
874 _bin=$(find_binary "$_prog") || {
875 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
880 [[ $_bin ]] && dracut_install "$_bin"
883 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
884 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
886 if [ -x ${udevdir}/$_prog ]; then
887 _bin=${udevdir}/$_prog
888 elif [[ "${_prog/\$\{/}" != "$_prog" ]]; then
889 _bin=$(find_binary "$_prog") || {
890 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
895 [[ $_bin ]] && dracut_install "$_bin"
898 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
899 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
901 if [ -x ${udevdir}/$_prog ]; then
902 _bin=${udevdir}/$_prog
903 elif [[ "${_prog/\$\{/}" != "$_prog" ]]; then
904 _bin=$(find_binary "$_prog") || {
905 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
910 [[ $_bin ]] && dracut_install "$_bin"
915 # attempt to install any programs specified in a udev rule
916 inst_rule_group_owner() {
919 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
920 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
921 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
922 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
926 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
927 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
928 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
929 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
935 # udev rules always get installed in the same place, so
936 # create a function to install them to make life simpler.
938 local _target=/etc/udev/rules.d _rule _found
940 inst_dir "${udevdir}/rules.d
"
942 for _rule in "$@
"; do
943 if [ "${_rule#/}" = "$_rule" ]; then
944 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
945 if [[ -f $r/$_rule ]]; then
947 inst_rule_programs "$_found"
948 inst_rule_group_owner "$_found"
949 inst_simple "$_found"
953 for r in '' ./ $dracutbasedir/rules.d/; do
954 if [[ -f ${r}$_rule ]]; then
956 inst_rule_programs "$_found"
957 inst_rule_group_owner "$_found"
958 inst_simple "$_found" "$_target/${_found##*/}"
961 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
965 # install function specialized for hooks
966 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
967 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
969 if ! [[ -f $3 ]]; then
970 dfatal "Cannot
install a hook
($3) that does not exist.
"
971 dfatal "Aborting initrd creation.
"
973 elif ! strstr "$hookdirs" "$1"; then
974 dfatal "No such hook
type $1. Aborting initrd creation.
"
977 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
980 # install any of listed files
982 # If first argument is '-d' and second some destination path, first accessible
983 # source is installed into this path, otherwise it will installed in the same
984 # path as source. If none of listed files was installed, function return 1.
985 # On first successful installation it returns with 0 status.
989 # inst_any -d /bin/foo /bin/bar /bin/baz
991 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
996 [[ $1 = '-d' ]] && to="$2" && shift 2
1000 [[ $to ]] && inst "$f" "$to" && return 0
1001 inst "$f" && return 0
1009 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1010 # Install a <file> located on a lib directory to the initramfs image
1011 # -n <pattern> install matching files
1012 inst_libdir_file() {
1014 if [[ "$1" == "-n" ]]; then
1017 for _dir in $libdirs; do
1019 for _f in "$_dir"/$_i; do
1020 [[ "$_f" =~ $_pattern ]] || continue
1021 [[ -e "$_f" ]] && _files+="$_f "
1026 for _dir in $libdirs; do
1028 for _f in "$_dir"/$_i; do
1029 [[ -e "$_f" ]] && _files+="$_f "
1034 [[ $_files ]] && dracut_install $_files
1038 # install function decompressing the target and handling symlinks
1039 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1041 # Function install targets in the same paths inside overlay but decompressed
1042 # and without extensions (.gz, .bz2).
1049 *.gz) _cmd='gzip -f -d' ;;
1050 *.bz2) _cmd='bzip2 -d' ;;
1054 # Decompress with chosen tool. We assume that tool changes name e.g.
1055 # from 'name.gz' to 'name'.
1056 ${_cmd} "${initdir}${_src}"
1060 # It's similar to above, but if file is not compressed, performs standard
1062 # $@ = list of files
1063 inst_opt_decompress
() {
1068 inst_decompress
"${_src}" || inst
"${_src}"
1072 # module_check <dracut module>
1073 # execute the check() function of module-setup.sh of <dracut module>
1074 # or the "check" script, if module-setup.sh is not found
1075 # "check $hostonly" is called
1077 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1080 local _hostonly
=$hostonly
1081 [ $# -eq 2 ] && _forced
=$2
1082 [[ -d $_moddir ]] ||
return 1
1083 if [[ ! -f $_moddir/module-setup.sh
]]; then
1084 # if we do not have a check script, we are unconditionally included
1085 [[ -x $_moddir/check
]] ||
return 0
1086 [ $_forced -ne 0 ] && unset hostonly
1087 $_moddir/check
$hostonly
1090 unset check depends
install installkernel
1091 .
$_moddir/module-setup.sh
1092 is_func check ||
return 0
1093 [ $_forced -ne 0 ] && unset hostonly
1096 unset check depends
install installkernel
1102 # module_check_mount <dracut module>
1103 # execute the check() function of module-setup.sh of <dracut module>
1104 # or the "check" script, if module-setup.sh is not found
1105 # "mount_needs=1 check 0" is called
1106 module_check_mount
() {
1107 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1110 [[ -d $_moddir ]] ||
return 1
1111 if [[ ! -f $_moddir/module-setup.sh
]]; then
1112 # if we do not have a check script, we are unconditionally included
1113 [[ -x $_moddir/check
]] ||
return 0
1114 mount_needs
=1 $_moddir/check
0
1117 unset check depends
install installkernel
1118 .
$_moddir/module-setup.sh
1119 is_func check ||
return 1
1122 unset check depends
install installkernel
1128 # module_depends <dracut module>
1129 # execute the depends() function of module-setup.sh of <dracut module>
1130 # or the "depends" script, if module-setup.sh is not found
1132 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1134 [[ -d $_moddir ]] ||
return 1
1135 if [[ ! -f $_moddir/module-setup.sh
]]; then
1136 # if we do not have a check script, we have no deps
1137 [[ -x $_moddir/check
]] ||
return 0
1141 unset check depends
install installkernel
1142 .
$_moddir/module-setup.sh
1143 is_func depends ||
return 0
1146 unset check depends
install installkernel
1151 # module_install <dracut module>
1152 # execute the install() function of module-setup.sh of <dracut module>
1153 # or the "install" script, if module-setup.sh is not found
1155 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1157 [[ -d $_moddir ]] ||
return 1
1158 if [[ ! -f $_moddir/module-setup.sh
]]; then
1159 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1162 unset check depends
install installkernel
1163 .
$_moddir/module-setup.sh
1164 is_func
install ||
return 0
1167 unset check depends
install installkernel
1172 # module_installkernel <dracut module>
1173 # execute the installkernel() function of module-setup.sh of <dracut module>
1174 # or the "installkernel" script, if module-setup.sh is not found
1175 module_installkernel
() {
1176 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1178 [[ -d $_moddir ]] ||
return 1
1179 if [[ ! -f $_moddir/module-setup.sh
]]; then
1180 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1183 unset check depends
install installkernel
1184 .
$_moddir/module-setup.sh
1185 is_func installkernel ||
return 0
1188 unset check depends
install installkernel
1193 # check_mount <dracut module>
1194 # check_mount checks, if a dracut module is needed for the given
1195 # device and filesystem types in "${host_fs_types[@]}"
1198 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1202 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1204 # If we are already scheduled to be loaded, no need to check again.
1205 strstr
" $mods_to_load " " $_mod " && return 0
1206 strstr
" $mods_checked_as_dep " " $_mod " && return 1
1208 # This should never happen, but...
1209 [[ -d $_moddir ]] ||
return 1
1211 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1213 if strstr
" $omit_dracutmodules " " $_mod "; then
1214 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1218 if strstr
" $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1219 module_check_mount
$_mod; ret
=$?
1221 # explicit module, so also accept ret=255
1222 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1224 # module not in our list
1225 if [[ $dracutmodules = all
]]; then
1226 # check, if we can and should install this module
1227 module_check_mount
$_mod ||
return 1
1235 for _moddep
in $
(module_depends
$_mod); do
1236 # handle deps as if they were manually added
1237 strstr
" $add_dracutmodules " " $_moddep " || \
1238 add_dracutmodules
+=" $_moddep "
1239 strstr
" $force_add_dracutmodules " " $_moddep " || \
1240 force_add_dracutmodules
+=" $_moddep "
1241 # if a module we depend on fail, fail also
1242 if ! check_module
$_moddep; then
1243 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1248 strstr
" $mods_to_load " " $_mod " || \
1249 mods_to_load
+=" $_mod "
1254 # check_module <dracut module> [<use_as_dep>]
1255 # check if a dracut module is to be used in the initramfs process
1256 # if <use_as_dep> is set, then the process also keeps track
1257 # that the modules were checked for the dependency tracking process
1260 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1263 # If we are already scheduled to be loaded, no need to check again.
1264 strstr
" $mods_to_load " " $_mod " && return 0
1265 strstr
" $mods_checked_as_dep " " $_mod " && return 1
1267 # This should never happen, but...
1268 [[ -d $_moddir ]] ||
return 1
1270 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1272 if strstr
" $omit_dracutmodules " " $_mod "; then
1273 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1277 if strstr
" $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1278 if strstr
" $force_add_dracutmodules" " $_mod"; then
1279 module_check
$_mod 1; ret
=$?
1281 module_check
$_mod 0; ret
=$?
1283 # explicit module, so also accept ret=255
1284 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1286 # module not in our list
1287 if [[ $dracutmodules = all
]]; then
1288 # check, if we can and should install this module
1289 module_check
$_mod ||
return 1
1296 for _moddep
in $
(module_depends
$_mod); do
1297 # handle deps as if they were manually added
1298 strstr
" $add_dracutmodules " " $_moddep " || \
1299 add_dracutmodules
+=" $_moddep "
1300 strstr
" $force_add_dracutmodules " " $_moddep " || \
1301 force_add_dracutmodules
+=" $_moddep "
1302 # if a module we depend on fail, fail also
1303 if ! check_module
$_moddep; then
1304 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1309 strstr
" $mods_to_load " " $_mod " || \
1310 mods_to_load
+=" $_mod "
1315 # for_each_module_dir <func>
1316 # execute "<func> <dracut module> 1"
1317 for_each_module_dir
() {
1323 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1324 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1328 # Report any missing dracut modules, the user has specified
1329 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1330 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1331 for _mod
in $_modcheck; do
1332 strstr
"$mods_to_load" "$_mod" && continue
1333 strstr
"$omit_dracutmodules" "$_mod" && continue
1334 derror
"dracut module '$_mod' cannot be found or installed."
1338 # Install a single kernel module along with any firmware it may require.
1339 # $1 = full path to kernel module to install
1340 install_kmod_with_fw
() {
1341 # no need to go further if the module is already installed
1343 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1346 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1347 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1351 if [[ $omit_drivers ]]; then
1352 local _kmod
=${1##*/}
1355 if [[ "$_kmod" =~
$omit_drivers ]]; then
1356 dinfo
"Omitting driver $_kmod"
1359 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1360 dinfo
"Omitting driver $_kmod"
1365 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1367 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1368 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1369 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1370 (($ret != 0)) && return $ret
1372 local _modname
=${1##*/} _fwdir _found _fw
1373 _modname
=${_modname%.ko*}
1374 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1376 for _fwdir
in $fw_dir; do
1377 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1378 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1382 if [[ $_found != yes ]]; then
1383 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1384 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1385 "\"${_modname}.ko\""
1387 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1388 "\"${_modname}.ko\""
1395 # Do something with all the dependencies of a kernel module.
1396 # Note that kernel modules depend on themselves using the technique we use
1397 # $1 = function to call for each dependency we find
1398 # It will be passed the full path to the found kernel module
1399 # $2 = module to get dependencies for
1400 # rest of args = arguments to modprobe
1401 # _fderr specifies FD passed from surrounding scope
1402 for_each_kmod_dep
() {
1403 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1405 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1406 while read _cmd _modpath _options
; do
1407 [[ $_cmd = insmod
]] ||
continue
1408 $_func ${_modpath} ||
exit $?
1413 dracut_kernel_post
() {
1414 local _moddirname
=${srcmods%%/lib/modules/*}
1416 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1417 xargs -r modprobe
-a ${_moddirname+-d ${_moddirname}/} \
1418 --ignore-install --show-depends --set-version $kernel \
1419 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1421 |
while read _cmd _modpath _options
; do
1422 [[ $_cmd = insmod
]] ||
continue
1424 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1427 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1428 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1430 while read _modpath
; do
1431 local _destpath
=$_modpath
1432 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1433 _destpath
=${_destpath##*/lib/modules/$kernel/}
1434 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1435 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1439 if [[ $DRACUT_INSTALL ]]; then
1440 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1441 |
while read line
; do
1442 for _fwdir
in $fw_dir; do
1445 done |
xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
1447 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1448 for _fwdir
in $fw_dir; do
1449 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1450 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1460 for _f
in modules.
builtin.bin modules.
builtin; do
1461 [[ $srcmods/$_f ]] && break
1463 dfatal
"No modules.builtin.bin and modules.builtin found!"
1467 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1468 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1471 # generate module dependencies for the initrd
1472 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1473 ! depmod
-a -b "$initdir" $kernel; then
1474 dfatal
"\"depmod -a $kernel\" failed."
1478 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr "$DRACUT_KERNEL_LAZY_HASHDIR"
1481 module_is_host_only
() (
1486 [[ "$add_drivers" =~
" ${_mod} " ]] && return 0
1488 # check if module is loaded
1489 [[ -d $
(echo /sys
/module
/${_mod//-/_}|
{ read a b
; echo $a; }) ]] && return 0
1491 # check if module is loadable on the current kernel
1492 # this covers the case, where a new module is introduced
1493 # or a module was renamed
1494 # or a module changed from builtin to a module
1495 modinfo
-F filename
"$_mod" &>/dev
/null ||
return 0
1500 find_kernel_modules_by_path
() (
1503 [[ -f $srcmods/modules.dep
]] ||
return 0
1507 while read a rest
; do
1508 [[ $a = */$1/* ]] ||
continue
1510 done < $srcmods/modules.dep
1515 find_kernel_modules
() {
1516 find_kernel_modules_by_path drivers
1519 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1520 # instmods [-c [-s]] <kernel subsystem>
1521 # install kernel modules along with all their dependencies.
1522 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1524 [[ $no_kernel = yes ]] && return
1525 # called [sub]functions inherit _fderr
1529 if [[ $1 = '-c' ]]; then
1534 if [[ $1 = '-s' ]]; then
1539 function inst1mod
() {
1540 local _ret
=0 _mod
="$1"
1543 ( [[ "$_mpargs" ]] && echo $_mpargs
1544 find_kernel_modules_by_path
"${_mod#=}" ) \
1548 --*) _mpargs
+=" $_mod" ;;
1551 # if we are already installed, skip this module and go on
1553 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1554 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1555 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1559 if [[ $omit_drivers ]] && [[ "$1" =~
$omit_drivers ]]; then
1560 dinfo
"Omitting driver ${_mod##$srcmods}"
1564 # If we are building a host-specific initramfs and this
1565 # module is not already loaded, move on to the next one.
1567 && ! module_is_host_only
"$_mod" \
1570 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1571 # We use '-d' option in modprobe only if modules prefix path
1572 # differs from default '/'. This allows us to use dracut with
1573 # old version of modprobe which doesn't have '-d' option.
1574 local _moddirname
=${srcmods%%/lib/modules/*}
1575 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1577 # ok, load the module, all its dependencies, and any firmware
1579 for_each_kmod_dep install_kmod_with_fw
$_mod \
1580 --set-version $kernel ${_moddirname} $_mpargs
1583 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1584 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1591 function instmods_1
() {
1593 if (($# == 0)); then # filenames from stdin
1595 inst1mod
"${_mod%.ko*}" ||
{
1596 if [[ "$_check" == "yes" ]]; then
1597 [[ "$_silent" == "no" ]] && dfatal
"Failed to install $_mod"
1603 while (($# > 0)); do # filenames as arguments
1604 inst1mod
${1%.ko*} ||
{
1605 if [[ "$_check" == "yes" ]]; then
1606 [[ "$_silent" == "no" ]] && dfatal
"Failed to install $1"
1615 local _ret _filter_not_found
='FATAL: Module .* not found.'
1616 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1617 # redirections, but that would make dracut require bash4 at least.
1618 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1619 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror