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 ]] ||
{ [[ "$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)"
63 ldconfig
-pN 2>/dev
/null |
while read a b c d
; do
64 [[ "$c" != "=>" ]] && continue
65 printf "%s\n" ${d%/*};
70 printf "%s\n" ${!a[@]}
74 if ! [[ $libdirs ]] ; then
75 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
76 && [[ -d /lib64
]]; then
78 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
81 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
84 libdirs
+="$(ldconfig_paths)"
89 if ! [[ $kernel ]]; then
94 # Version comparision function. Assumes Linux style version scheme.
96 # $2 = comparision op (gt, ge, eq, le, lt, ne)
99 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
103 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
104 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
105 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
121 srcmods
="/lib/modules/$kernel/"
123 [[ $drivers_dir ]] && {
124 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
125 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
128 srcmods
="$drivers_dir"
132 if ! type dinfo
>/dev
/null
2>&1; then
133 .
"$dracutbasedir/dracut-logger.sh"
137 if ! [[ $initdir ]]; then
138 dfatal
"initdir not set"
142 # export standard hookdirs
144 hookdirs
="cmdline pre-udev pre-trigger netroot "
145 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
146 hookdirs
+="pre-mount pre-pivot cleanup mount "
147 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
151 dracut_need_initqueue
() {
152 >"$initdir/lib/dracut/need-initqueue"
155 dracut_module_included
() {
156 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
159 # Create all subdirectories for given path without creating the last element.
162 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
166 # Check whether $1 is a function.
168 [[ "$(type -t "$1")" = "function" ]]
171 # Function prints global variables in format name=value line by line.
172 # $@ = list of global variables' name
178 eval printf -v _value
"%s" "\$$_var"
179 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
183 # normalize_path <path>
184 # Prints the normalized path, where it removes any duplicated
185 # and trailing slashes.
187 # $ normalize_path ///test/test//
191 set -- "${1//+(\/)//}"
193 printf "%s\n" "${1%/}"
196 # convert_abs_rel <from> <to>
197 # Prints the relative path, when creating a symlink to <to> from <from>.
199 # $ convert_abs_rel /usr/bin/test /bin/test-2
201 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
203 local __current __absolute __abssize __cursize __newpath
206 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
208 # corner case #1 - self looping link
209 [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
211 # corner case #2 - own dir link
212 [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
214 IFS
="/" __current
=($1)
215 IFS
="/" __absolute
=($2)
217 __abssize
=${#__absolute[@]}
218 __cursize
=${#__current[@]}
220 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
223 if (( __level
> __abssize || __level
> __cursize
))
229 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
233 __newpath
=$__newpath"/"
235 __newpath
=$__newpath".."
238 for ((__i
= __level
; __i
< __abssize
; __i
++))
240 if [[ -n $__newpath ]]
242 __newpath
=$__newpath"/"
244 __newpath
=$__newpath${__absolute[__i]}
247 printf "%s\n" "$__newpath"
250 if [[ "$(ln --help)" == *--relative* ]]; then
252 ln -sfnr "${initdir}/$1" "${initdir}/$2"
258 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
259 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
263 # get_fs_env <device>
264 # Get and the ID_FS_TYPE variable from udev for a device.
266 # $ get_fs_env /dev/sda2
274 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
275 |
while read line
; do
276 if [[ "$line" == TYPE\
=* ]]; then
277 printf "%s" "${line#TYPE=}";
281 if [[ $ID_FS_TYPE ]]; then
282 printf "%s" "$ID_FS_TYPE"
288 # get_maj_min <device>
289 # Prints the major and minor of a device node.
291 # $ get_maj_min /dev/sda2
294 local _maj _min _majmin
295 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
296 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
300 # get_devpath_block <device>
301 # get the DEVPATH in /sys of a block device
302 get_devpath_block
() {
304 _majmin
=$
(get_maj_min
"$1")
306 for _i
in /sys
/block
/*/dev
/sys
/block
/*/*/dev
; do
307 [[ -e "$_i" ]] ||
continue
308 if [[ "$_majmin" == "$(<"$_i")" ]]; then
309 printf "%s" "${_i%/dev}"
316 # get a persistent path from a device
317 get_persistent_dev
() {
320 _dev
=$
(get_maj_min
"$1")
321 [ -z "$_dev" ] && return
325 /dev
/disk
/${persistent_policy:-by-uuid}/* \
326 /dev
/disk
/by-uuid
/* \
327 /dev
/disk
/by-label
/* \
328 /dev
/disk
/by-partuuid
/* \
329 /dev
/disk
/by-partlabel
/* \
331 /dev
/disk
/by-path
/* \
333 [[ -e "$i" ]] ||
continue
334 [[ $i == /dev
/mapper
/control
]] && continue
335 [[ $i == /dev
/mapper
/mpath
* ]] && continue
336 _tmp
=$
(get_maj_min
"$i")
337 if [ "$_tmp" = "$_dev" ]; then
344 expand_persistent_dev
() {
349 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
354 _dev
="/dev/disk/by-uuid/${_dev}"
357 _dev
="${_dev#PARTUUID=}"
359 _dev
="/dev/disk/by-partuuid/${_dev}"
362 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
368 shorten_persistent_dev
() {
372 printf "%s" "UUID=${_dev##*/}";;
373 /dev
/disk
/by-label
/*)
374 printf "%s" "LABEL=${_dev##*/}";;
375 /dev
/disk
/by-partuuid
/*)
376 printf "%s" "PARTUUID=${_dev##*/}";;
377 /dev
/disk
/by-partlabel
/*)
378 printf "%s" "PARTLABEL=${_dev##*/}";;
380 printf "%s" "$_dev";;
384 # find_block_device <mountpoint>
385 # Prints the major and minor number of the block device
386 # for a given mountpoint.
387 # Unless $use_fstab is set to "yes" the functions
388 # uses /proc/self/mountinfo as the primary source of the
389 # information and only falls back to /etc/fstab, if the mountpoint
390 # is not found there.
392 # $ find_block_device /usr
394 find_block_device
() {
395 local _majmin _dev _majmin _find_mpt
397 if [[ $use_fstab != yes ]]; then
398 [[ -d $_find_mpt/.
]]
399 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
400 while read _majmin _dev
; do
401 if [[ -b $_dev ]]; then
402 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
403 _majmin
=$
(get_maj_min
$_dev)
405 if [[ $_majmin ]]; then
406 printf "%s\n" "$_majmin"
408 printf "%s\n" "$_dev"
412 if [[ $_dev = *:* ]]; then
413 printf "%s\n" "$_dev"
416 done; return 1; } && return 0
418 # fall back to /etc/fstab
420 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
421 while read _majmin _dev
; do
422 if ! [[ $_dev ]]; then
426 if [[ -b $_dev ]]; then
427 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
428 if [[ $_majmin ]]; then
429 printf "%s\n" "$_majmin"
431 printf "%s\n" "$_dev"
435 if [[ $_dev = *:* ]]; then
436 printf "%s\n" "$_dev"
439 done; return 1; } && return 0
444 # find_mp_fstype <mountpoint>
445 # Echo the filesystem type for a given mountpoint.
446 # /proc/self/mountinfo is taken as the primary source of information
447 # and /etc/fstab is used as a fallback.
448 # No newline is appended!
450 # $ find_mp_fstype /;echo
455 if [[ $use_fstab != yes ]]; then
456 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
458 [[ $_fs ]] ||
continue
459 [[ $_fs = "autofs" ]] && continue
462 done; return 1; } && return 0
465 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
467 [[ $_fs ]] ||
continue
468 [[ $_fs = "autofs" ]] && continue
471 done; return 1; } && return 0
476 # find_dev_fstype <device>
477 # Echo the filesystem type for a given device.
478 # /proc/self/mountinfo is taken as the primary source of information
479 # and /etc/fstab is used as a fallback.
480 # No newline is appended!
482 # $ find_dev_fstype /dev/sda2;echo
487 if ! [[ "$_find_dev" = /dev
* ]]; then
488 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
491 if [[ $use_fstab != yes ]]; then
492 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
494 [[ $_fs ]] ||
continue
495 [[ $_fs = "autofs" ]] && continue
498 done; return 1; } && return 0
501 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
503 [[ $_fs ]] ||
continue
504 [[ $_fs = "autofs" ]] && continue
507 done; return 1; } && return 0
512 # find_mp_fsopts <mountpoint>
513 # Echo the filesystem options for a given mountpoint.
514 # /proc/self/mountinfo is taken as the primary source of information
515 # and /etc/fstab is used as a fallback.
516 # No newline is appended!
518 # $ find_mp_fsopts /;echo
519 # rw,relatime,discard,data=ordered
521 if [[ $use_fstab != yes ]]; then
522 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
525 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
528 # find_dev_fsopts <device>
529 # Echo the filesystem options for a given device.
530 # /proc/self/mountinfo is taken as the primary source of information
531 # and /etc/fstab is used as a fallback.
533 # $ find_dev_fsopts /dev/sda2
534 # rw,relatime,discard,data=ordered
536 local _find_dev _opts
538 if ! [[ "$_find_dev" = /dev
* ]]; then
539 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
542 if [[ $use_fstab != yes ]]; then
543 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
546 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
550 # finds the major:minor of the block device backing the root filesystem.
551 find_root_block_device
() { find_block_device
/; }
553 # for_each_host_dev_fs <func>
554 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
555 # in ${host_fs_types[@]}
556 for_each_host_dev_fs
()
562 [[ "${!host_fs_types[@]}" ]] ||
return 0
564 for _dev
in "${!host_fs_types[@]}"; do
565 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
572 printf "%s\n" "${host_fs_types[@]}"
575 # Walk all the slave relationships for a given block device.
576 # Stop when our helper function returns success
577 # $1 = function to call on every found block device
578 # $2 = block device in major:minor format
579 check_block_and_slaves
() {
581 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
583 check_vol_slaves
"$@" && return 0
584 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
585 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
587 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
588 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
589 [[ -f $_x ]] ||
continue
590 check_block_and_slaves
$1 $
(<"$_x") && return 0
595 check_block_and_slaves_all
() {
597 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
601 check_vol_slaves
"$@" && return 0
602 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
603 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
605 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
606 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
607 [[ -f $_x ]] ||
continue
608 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
612 # for_each_host_dev_and_slaves <func>
613 # Execute "<func> <dev>" for every "<dev>" found
614 # in ${host_devs[@]} and their slaves
615 for_each_host_dev_and_slaves_all
()
621 [[ "${host_devs[@]}" ]] ||
return 0
623 for _dev
in ${host_devs[@]}; do
624 [[ -b "$_dev" ]] ||
continue
625 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
632 for_each_host_dev_and_slaves
()
637 [[ "${host_devs[@]}" ]] ||
return 0
639 for _dev
in ${host_devs[@]}; do
640 [[ -b "$_dev" ]] ||
continue
641 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
646 # ugly workaround for the lvm design
647 # There is no volume group device,
648 # so, there are no slave devices for volume groups.
649 # Logical volumes only have the slave devices they really live on,
650 # but you cannot create the logical volume without the volume group.
651 # And the volume group might be bigger than the devices the LV needs.
654 for i
in /dev
/mapper
/*; do
655 [[ $i == /dev
/mapper
/control
]] && continue
656 _lv
=$
(get_maj_min
$i)
657 if [[ $_lv = $2 ]]; then
658 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
660 _vg
=$
(printf "%s\n" "$_vg")
662 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
664 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
672 # fs_get_option <filesystem options> <search for option>
673 # search for a specific option in a bunch of filesystem options
674 # and return the value
682 while [ $# -gt 0 ]; do
685 echo ${1#${_option}=}
693 if ! [[ $DRACUT_INSTALL ]]; then
694 DRACUT_INSTALL
=$
(find_binary dracut-install
)
697 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
698 DRACUT_INSTALL
=$dracutbasedir/dracut-install
701 if ! [[ -x $DRACUT_INSTALL ]]; then
702 dfatal
"dracut-install not found!"
706 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
708 [[ -e ${initdir}/"$1" ]] && return 0 # already there
709 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
710 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
714 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
715 #dinfo "$DRACUT_INSTALL -l $@"
716 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
717 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
721 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
722 [[ -e $1 ]] ||
return 1 # no source
723 $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
724 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" ||
:
728 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
729 [[ -L $1 ]] ||
return 1
730 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
731 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
736 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
737 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
739 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
748 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
749 [[ -e $1 ]] ||
return 1 # no source
750 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
751 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
755 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
756 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
760 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
761 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
764 # find symlinks linked to given library file
766 # Function searches for symlinks by stripping version numbers appended to
767 # library filename, checks if it points to the same target and finally
768 # prints the list of symlinks to stdout.
771 # rev_lib_symlinks libfoo.so.8.1
772 # output: libfoo.so.8 libfoo.so
773 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
775 [[ ! $1 ]] && return 0
777 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
779 [[ ${fn} == *.so.
* ]] ||
return 1
781 until [[ ${fn##*.} == so
]]; do
783 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
789 # attempt to install any programs specified in a udev rule
790 inst_rule_programs() {
793 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
794 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
796 if [ -x ${udevdir}/$_prog ]; then
797 _bin=${udevdir}/$_prog
798 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
799 _bin=$(find_binary "$_prog") || {
800 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
805 [[ $_bin ]] && inst_binary "$_bin"
808 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
809 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
811 if [ -x ${udevdir}/$_prog ]; then
812 _bin=${udevdir}/$_prog
813 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
814 _bin=$(find_binary "$_prog") || {
815 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
820 [[ $_bin ]] && inst_binary "$_bin"
823 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
824 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
826 if [ -x ${udevdir}/$_prog ]; then
827 _bin=${udevdir}/$_prog
828 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
829 _bin=$(find_binary "$_prog") || {
830 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
835 [[ $_bin ]] && dracut_install "$_bin"
840 # attempt to install any programs specified in a udev rule
841 inst_rule_group_owner() {
844 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
845 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
846 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
847 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
851 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
852 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
853 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
854 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
860 inst_rule_initqueue() {
861 if grep -q -F initqueue "$1"; then
862 dracut_need_initqueue
866 # udev rules always get installed in the same place, so
867 # create a function to install them to make life simpler.
869 local _target=/etc/udev/rules.d _rule _found
871 inst_dir "${udevdir}/rules.d
"
873 for _rule in "$@
"; do
874 if [ "${_rule#/}" = "$_rule" ]; then
875 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
876 if [[ -e $r/$_rule ]]; then
878 inst_rule_programs "$_found"
879 inst_rule_group_owner "$_found"
880 inst_rule_initqueue "$_found"
881 inst_simple "$_found"
885 for r in '' ./ $dracutbasedir/rules.d/; do
886 if [[ -f ${r}$_rule ]]; then
888 inst_rule_programs "$_found"
889 inst_rule_group_owner "$_found"
890 inst_rule_initqueue "$_found"
891 inst_simple "$_found" "$_target/${_found##*/}"
894 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
898 prepare_udev_rules() {
899 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
902 f="${initdir}/etc
/udev
/rules.d
/$f"
903 [ -e "$f" ] || continue
905 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
906 if [ $UDEVVERSION -ge 174 ]; then
907 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
909 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
911 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
912 if [ $UDEVVERSION -ge 176 ]; then
913 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
915 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
920 done < "${f}" > "${f}.new
"
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 ! [[ "$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 ]] && inst_multiple $_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 -f -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 cmdline
install installkernel
1052 .
$_moddir/module-setup.sh
1053 is_func check ||
return 0
1054 [ $_forced -ne 0 ] && unset hostonly
1057 unset check depends cmdline
install installkernel
1063 # module_check_mount <dracut module>
1064 # execute the check() function of module-setup.sh of <dracut module>
1065 # or the "check" script, if module-setup.sh is not found
1066 # "mount_needs=1 check 0" is called
1067 module_check_mount
() {
1068 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1071 [[ -d $_moddir ]] ||
return 1
1072 if [[ ! -f $_moddir/module-setup.sh
]]; then
1073 # if we do not have a check script, we are unconditionally included
1074 [[ -x $_moddir/check
]] ||
return 0
1075 mount_needs
=1 $_moddir/check
0
1078 unset check depends cmdline
install installkernel
1080 .
$_moddir/module-setup.sh
1083 unset check depends cmdline
install installkernel
1089 # module_depends <dracut module>
1090 # execute the depends() function of module-setup.sh of <dracut module>
1091 # or the "depends" script, if module-setup.sh is not found
1093 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1095 [[ -d $_moddir ]] ||
return 1
1096 if [[ ! -f $_moddir/module-setup.sh
]]; then
1097 # if we do not have a check script, we have no deps
1098 [[ -x $_moddir/check
]] ||
return 0
1102 unset check depends cmdline
install installkernel
1104 .
$_moddir/module-setup.sh
1107 unset check depends cmdline
install installkernel
1112 # module_cmdline <dracut module>
1113 # execute the cmdline() function of module-setup.sh of <dracut module>
1114 # or the "cmdline" script, if module-setup.sh is not found
1116 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1118 [[ -d $_moddir ]] ||
return 1
1119 if [[ ! -f $_moddir/module-setup.sh
]]; then
1120 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1123 unset check depends cmdline
install installkernel
1125 .
$_moddir/module-setup.sh
1128 unset check depends cmdline
install installkernel
1133 # module_install <dracut module>
1134 # execute the install() function of module-setup.sh of <dracut module>
1135 # or the "install" script, if module-setup.sh is not found
1137 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1139 [[ -d $_moddir ]] ||
return 1
1140 if [[ ! -f $_moddir/module-setup.sh
]]; then
1141 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1144 unset check depends cmdline
install installkernel
1146 .
$_moddir/module-setup.sh
1149 unset check depends cmdline
install installkernel
1154 # module_installkernel <dracut module>
1155 # execute the installkernel() function of module-setup.sh of <dracut module>
1156 # or the "installkernel" script, if module-setup.sh is not found
1157 module_installkernel
() {
1158 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1160 [[ -d $_moddir ]] ||
return 1
1161 if [[ ! -f $_moddir/module-setup.sh
]]; then
1162 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1165 unset check depends cmdline
install installkernel
1166 installkernel
() { true
; }
1167 .
$_moddir/module-setup.sh
1170 unset check depends cmdline
install installkernel
1175 # check_mount <dracut module>
1176 # check_mount checks, if a dracut module is needed for the given
1177 # device and filesystem types in "${host_fs_types[@]}"
1180 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1184 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1186 # If we are already scheduled to be loaded, no need to check again.
1187 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1188 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1190 # This should never happen, but...
1191 [[ -d $_moddir ]] ||
return 1
1193 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1195 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1199 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1200 module_check_mount
$_mod; ret
=$?
1202 # explicit module, so also accept ret=255
1203 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1205 # module not in our list
1206 if [[ $dracutmodules = all
]]; then
1207 # check, if we can and should install this module
1208 module_check_mount
$_mod ||
return 1
1216 for _moddep
in $
(module_depends
$_mod); do
1217 # handle deps as if they were manually added
1218 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1219 add_dracutmodules
+=" $_moddep "
1220 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1221 force_add_dracutmodules
+=" $_moddep "
1222 # if a module we depend on fail, fail also
1223 if ! check_module
$_moddep; then
1224 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1229 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1230 mods_to_load
+=" $_mod "
1235 # check_module <dracut module> [<use_as_dep>]
1236 # check if a dracut module is to be used in the initramfs process
1237 # if <use_as_dep> is set, then the process also keeps track
1238 # that the modules were checked for the dependency tracking process
1241 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1244 # If we are already scheduled to be loaded, no need to check again.
1245 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1246 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1248 # This should never happen, but...
1249 [[ -d $_moddir ]] ||
return 1
1251 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1253 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1254 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1258 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1259 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1260 module_check
$_mod 1; ret
=$?
1262 module_check
$_mod 0; ret
=$?
1264 # explicit module, so also accept ret=255
1265 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1267 # module not in our list
1268 if [[ $dracutmodules = all
]]; then
1269 # check, if we can and should install this module
1270 module_check
$_mod ||
return 1
1277 for _moddep
in $
(module_depends
$_mod); do
1278 # handle deps as if they were manually added
1279 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1280 add_dracutmodules
+=" $_moddep "
1281 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1282 force_add_dracutmodules
+=" $_moddep "
1283 # if a module we depend on fail, fail also
1284 if ! check_module
$_moddep; then
1285 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1290 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1291 mods_to_load
+=" $_mod "
1296 # for_each_module_dir <func>
1297 # execute "<func> <dracut module> 1"
1298 for_each_module_dir
() {
1304 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1305 [[ -d $_moddir ]] ||
continue;
1306 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1307 -e $_moddir/module-setup.sh
]] ||
continue
1308 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1312 # Report any missing dracut modules, the user has specified
1313 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1314 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1315 for _mod
in $_modcheck; do
1316 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1317 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1318 derror
"dracut module '$_mod' cannot be found or installed."
1322 # Install a single kernel module along with any firmware it may require.
1323 # $1 = full path to kernel module to install
1324 install_kmod_with_fw
() {
1325 # no need to go further if the module is already installed
1327 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1330 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1331 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1335 if [[ $omit_drivers ]]; then
1336 local _kmod
=${1##*/}
1339 if [[ "$_kmod" =~
$omit_drivers ]]; then
1340 dinfo
"Omitting driver $_kmod"
1343 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1344 dinfo
"Omitting driver $_kmod"
1349 if [[ $silent_omit_drivers ]]; then
1350 local _kmod
=${1##*/}
1353 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1354 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1357 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1359 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1360 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1361 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1362 (($ret != 0)) && return $ret
1364 local _modname
=${1##*/} _fwdir _found _fw
1365 _modname
=${_modname%.ko*}
1366 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1368 for _fwdir
in $fw_dir; do
1369 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1370 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1374 if [[ $_found != yes ]]; then
1375 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1376 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1377 "\"${_modname}.ko\""
1379 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1380 "\"${_modname}.ko\""
1387 # Do something with all the dependencies of a kernel module.
1388 # Note that kernel modules depend on themselves using the technique we use
1389 # $1 = function to call for each dependency we find
1390 # It will be passed the full path to the found kernel module
1391 # $2 = module to get dependencies for
1392 # rest of args = arguments to modprobe
1393 # _fderr specifies FD passed from surrounding scope
1394 for_each_kmod_dep
() {
1395 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1397 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1398 while read _cmd _modpath _options
; do
1399 [[ $_cmd = insmod
]] ||
continue
1400 $_func ${_modpath} ||
exit $?
1405 dracut_kernel_post
() {
1406 local _moddirname
=${srcmods%%/lib/modules/*}
1409 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1410 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1411 --ignore-install --show-depends --set-version $kernel \
1412 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1414 |
while read _cmd _modpath _options
; do
1415 [[ $_cmd = insmod
]] ||
continue
1417 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1420 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1421 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1423 while read _modpath
; do
1424 local _destpath
=$_modpath
1425 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1426 _destpath
=${_destpath##*/lib/modules/$kernel/}
1427 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1428 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1431 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1434 if [[ $DRACUT_INSTALL ]]; then
1435 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1436 |
while read line
; do
1437 for _fwdir
in $fw_dir; do
1440 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1442 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1443 for _fwdir
in $fw_dir; do
1444 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1445 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1455 for _f
in modules.
builtin.bin modules.
builtin; do
1456 [[ $srcmods/$_f ]] && break
1458 dfatal
"No modules.builtin.bin and modules.builtin found!"
1462 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1463 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1466 # generate module dependencies for the initrd
1467 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1468 ! depmod
-a -b "$initdir" $kernel; then
1469 dfatal
"\"depmod -a $kernel\" failed."
1473 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1476 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1478 module_is_host_only
() {
1483 _modenc
=${_mod//-/_}
1485 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1487 # check if module is loaded
1488 [[ ${host_modules["$_modenc"]} ]] && return 0
1490 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1492 if [[ "$kernel_current" != "$kernel" ]]; then
1493 # check if module is loadable on the current kernel
1494 # this covers the case, where a new module is introduced
1495 # or a module was renamed
1496 # or a module changed from builtin to a module
1497 if [[ -d /lib
/modules
/$kernel_current ]]; then
1498 # if the modinfo can be parsed, but the module
1499 # is not loaded, then we can safely return 1
1500 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1503 # Finally check all modalias, if we install for a kernel
1504 # different from the current one
1505 for a
in $
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
); do
1506 for i
in "${!host_modalias[@]}"; do
1507 [[ $i == $a ]] && return 0
1515 find_kernel_modules_by_path
() {
1518 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1522 while read a rest
; do
1523 [[ $a = */$1/* ]] ||
continue
1524 printf "%s\n" "$srcmods/$a"
1525 done < "$srcmods/modules.dep"
1530 find_kernel_modules
() {
1531 find_kernel_modules_by_path drivers
1534 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1535 # instmods [-c [-s]] <kernel subsystem>
1536 # install kernel modules along with all their dependencies.
1537 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1539 [[ $no_kernel = yes ]] && return
1540 # called [sub]functions inherit _fderr
1544 if [[ $1 = '-c' ]]; then
1549 if [[ $1 = '-s' ]]; then
1554 function inst1mod
() {
1555 local _ret
=0 _mod
="$1"
1558 ( [[ "$_mpargs" ]] && echo $_mpargs
1559 find_kernel_modules_by_path
"${_mod#=}" ) \
1563 --*) _mpargs
+=" $_mod" ;;
1566 # if we are already installed, skip this module and go on
1568 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1569 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1570 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1575 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1576 dinfo
"Omitting driver ${_mod##$srcmods}"
1580 # If we are building a host-specific initramfs and this
1581 # module is not already loaded, move on to the next one.
1583 && ! module_is_host_only
"$_mod" \
1586 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1587 # We use '-d' option in modprobe only if modules prefix path
1588 # differs from default '/'. This allows us to use dracut with
1589 # old version of modprobe which doesn't have '-d' option.
1590 local _moddirname
=${srcmods%%/lib/modules/*}
1591 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1593 # ok, load the module, all its dependencies, and any firmware
1595 for_each_kmod_dep install_kmod_with_fw
$_mod \
1596 --set-version $kernel ${_moddirname} $_mpargs
1599 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1600 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1607 function instmods_1
() {
1609 if (($# == 0)); then # filenames from stdin
1611 inst1mod
"${_mod%.ko*}" ||
{
1612 if [[ "$_check" == "yes" ]]; then
1613 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1619 while (($# > 0)); do # filenames as arguments
1620 inst1mod
${1%.ko*} ||
{
1621 if [[ "$_check" == "yes" ]]; then
1622 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1631 local _ret _filter_not_found
='FATAL: Module .* not found.'
1632 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1633 # redirections, but that would make dracut require bash4 at least.
1634 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1635 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1640 # Only two values are returned: AMD or Intel
1643 if grep -qE AMD
/proc
/cpuinfo
; then
1646 if grep -qE Intel
/proc
/cpuinfo
; then
1652 # Get the hosts' ucode file based on the /proc/cpuinfo
1655 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1656 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1657 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1659 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1660 # If family greater or equal than 0x15
1661 if [[ $family -ge 21 ]]; then
1662 printf "microcode_amd_fam15h.bin"
1664 printf "microcode_amd.bin"
1667 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1668 # The /proc/cpuinfo are in decimal.
1669 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}