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#*:}))"
299 # get a persistent path from a device
300 get_persistent_dev
() {
303 _dev
=$
(get_maj_min
"$1")
304 [ -z "$_dev" ] && return
308 /dev
/disk
/${persistent_policy:-by-uuid}/* \
309 /dev
/disk
/by-uuid
/* \
310 /dev
/disk
/by-label
/* \
311 /dev
/disk
/by-partuuid
/* \
312 /dev
/disk
/by-partlabel
/* \
314 /dev
/disk
/by-path
/* \
316 [[ -e "$i" ]] ||
continue
317 [[ $i == /dev
/mapper
/control
]] && continue
318 [[ $i == /dev
/mapper
/mpath
* ]] && continue
319 _tmp
=$
(get_maj_min
"$i")
320 if [ "$_tmp" = "$_dev" ]; then
327 expand_persistent_dev
() {
332 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
337 _dev
="/dev/disk/by-uuid/${_dev}"
340 _dev
="${_dev#PARTUUID=}"
342 _dev
="/dev/disk/by-partuuid/${_dev}"
345 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
351 shorten_persistent_dev
() {
355 printf "%s" "UUID=${_dev##*/}";;
356 /dev
/disk
/by-label
/*)
357 printf "%s" "LABEL=${_dev##*/}";;
358 /dev
/disk
/by-partuuid
/*)
359 printf "%s" "PARTUUID=${_dev##*/}";;
360 /dev
/disk
/by-partlabel
/*)
361 printf "%s" "PARTLABEL=${_dev##*/}";;
363 printf "%s" "$_dev";;
367 # find_block_device <mountpoint>
368 # Prints the major and minor number of the block device
369 # for a given mountpoint.
370 # Unless $use_fstab is set to "yes" the functions
371 # uses /proc/self/mountinfo as the primary source of the
372 # information and only falls back to /etc/fstab, if the mountpoint
373 # is not found there.
375 # $ find_block_device /usr
377 find_block_device
() {
378 local _majmin _dev _majmin _find_mpt
380 if [[ $use_fstab != yes ]]; then
381 [[ -d $_find_mpt/.
]]
382 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
383 while read _majmin _dev
; do
384 if [[ -b $_dev ]]; then
385 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
386 _majmin
=$
(get_maj_min
$_dev)
388 if [[ $_majmin ]]; then
389 printf "%s\n" "$_majmin"
391 printf "%s\n" "$_dev"
395 if [[ $_dev = *:* ]]; then
396 printf "%s\n" "$_dev"
399 done; return 1; } && return 0
401 # fall back to /etc/fstab
403 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
404 while read _majmin _dev
; do
405 if ! [[ $_dev ]]; then
409 if [[ -b $_dev ]]; then
410 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
411 if [[ $_majmin ]]; then
412 printf "%s\n" "$_majmin"
414 printf "%s\n" "$_dev"
418 if [[ $_dev = *:* ]]; then
419 printf "%s\n" "$_dev"
422 done; return 1; } && return 0
427 # find_mp_fstype <mountpoint>
428 # Echo the filesystem type for a given mountpoint.
429 # /proc/self/mountinfo is taken as the primary source of information
430 # and /etc/fstab is used as a fallback.
431 # No newline is appended!
433 # $ find_mp_fstype /;echo
438 if [[ $use_fstab != yes ]]; then
439 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
441 [[ $_fs ]] ||
continue
442 [[ $_fs = "autofs" ]] && continue
445 done; return 1; } && return 0
448 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
450 [[ $_fs ]] ||
continue
451 [[ $_fs = "autofs" ]] && continue
454 done; return 1; } && return 0
459 # find_dev_fstype <device>
460 # Echo the filesystem type for a given device.
461 # /proc/self/mountinfo is taken as the primary source of information
462 # and /etc/fstab is used as a fallback.
463 # No newline is appended!
465 # $ find_dev_fstype /dev/sda2;echo
470 if ! [[ "$_find_dev" = /dev
* ]]; then
471 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
474 if [[ $use_fstab != yes ]]; then
475 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
477 [[ $_fs ]] ||
continue
478 [[ $_fs = "autofs" ]] && continue
481 done; return 1; } && return 0
484 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
486 [[ $_fs ]] ||
continue
487 [[ $_fs = "autofs" ]] && continue
490 done; return 1; } && return 0
495 # find_mp_fsopts <mountpoint>
496 # Echo the filesystem options for a given mountpoint.
497 # /proc/self/mountinfo is taken as the primary source of information
498 # and /etc/fstab is used as a fallback.
499 # No newline is appended!
501 # $ find_mp_fsopts /;echo
502 # rw,relatime,discard,data=ordered
504 if [[ $use_fstab != yes ]]; then
505 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
508 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
511 # find_dev_fsopts <device>
512 # Echo the filesystem options for a given device.
513 # /proc/self/mountinfo is taken as the primary source of information
514 # and /etc/fstab is used as a fallback.
516 # $ find_dev_fsopts /dev/sda2
517 # rw,relatime,discard,data=ordered
519 local _find_dev _opts
521 if ! [[ "$_find_dev" = /dev
* ]]; then
522 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
525 if [[ $use_fstab != yes ]]; then
526 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
529 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
533 # finds the major:minor of the block device backing the root filesystem.
534 find_root_block_device
() { find_block_device
/; }
536 # for_each_host_dev_fs <func>
537 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
538 # in ${host_fs_types[@]}
539 for_each_host_dev_fs
()
545 [[ "${!host_fs_types[@]}" ]] ||
return 0
547 for _dev
in "${!host_fs_types[@]}"; do
548 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
555 printf "%s\n" "${host_fs_types[@]}"
558 # Walk all the slave relationships for a given block device.
559 # Stop when our helper function returns success
560 # $1 = function to call on every found block device
561 # $2 = block device in major:minor format
562 check_block_and_slaves
() {
564 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
566 check_vol_slaves
"$@" && return 0
567 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
568 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
570 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
571 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
572 [[ -f $_x ]] ||
continue
573 check_block_and_slaves
$1 $
(<"$_x") && return 0
578 check_block_and_slaves_all
() {
580 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
584 check_vol_slaves
"$@" && return 0
585 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
586 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
588 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
589 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
590 [[ -f $_x ]] ||
continue
591 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
595 # for_each_host_dev_and_slaves <func>
596 # Execute "<func> <dev>" for every "<dev>" found
597 # in ${host_devs[@]} and their slaves
598 for_each_host_dev_and_slaves_all
()
604 [[ "${host_devs[@]}" ]] ||
return 0
606 for _dev
in ${host_devs[@]}; do
607 [[ -b "$_dev" ]] ||
continue
608 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
615 for_each_host_dev_and_slaves
()
620 [[ "${host_devs[@]}" ]] ||
return 0
622 for _dev
in ${host_devs[@]}; do
623 [[ -b "$_dev" ]] ||
continue
624 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
629 # ugly workaround for the lvm design
630 # There is no volume group device,
631 # so, there are no slave devices for volume groups.
632 # Logical volumes only have the slave devices they really live on,
633 # but you cannot create the logical volume without the volume group.
634 # And the volume group might be bigger than the devices the LV needs.
637 for i
in /dev
/mapper
/*; do
638 [[ $i == /dev
/mapper
/control
]] && continue
639 _lv
=$
(get_maj_min
$i)
640 if [[ $_lv = $2 ]]; then
641 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
643 _vg
=$
(printf "%s\n" "$_vg")
645 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
647 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
655 # fs_get_option <filesystem options> <search for option>
656 # search for a specific option in a bunch of filesystem options
657 # and return the value
665 while [ $# -gt 0 ]; do
668 echo ${1#${_option}=}
676 if ! [[ $DRACUT_INSTALL ]]; then
677 DRACUT_INSTALL
=$
(find_binary dracut-install
)
680 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
681 DRACUT_INSTALL
=$dracutbasedir/dracut-install
684 if ! [[ -x $DRACUT_INSTALL ]]; then
685 dfatal
"dracut-install not found!"
689 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
691 [[ -e ${initdir}/"$1" ]] && return 0 # already there
692 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
693 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
697 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
698 #dinfo "$DRACUT_INSTALL -l $@"
699 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
700 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
704 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
705 [[ -e $1 ]] ||
return 1 # no source
706 $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
707 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" ||
:
711 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
712 [[ -L $1 ]] ||
return 1
713 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
714 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
719 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
720 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
722 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
731 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
732 [[ -e $1 ]] ||
return 1 # no source
733 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
734 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
738 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
739 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
743 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
744 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
747 # find symlinks linked to given library file
749 # Function searches for symlinks by stripping version numbers appended to
750 # library filename, checks if it points to the same target and finally
751 # prints the list of symlinks to stdout.
754 # rev_lib_symlinks libfoo.so.8.1
755 # output: libfoo.so.8 libfoo.so
756 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
758 [[ ! $1 ]] && return 0
760 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
762 [[ ${fn} == *.so.
* ]] ||
return 1
764 until [[ ${fn##*.} == so
]]; do
766 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
772 # attempt to install any programs specified in a udev rule
773 inst_rule_programs() {
776 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
777 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
779 if [ -x ${udevdir}/$_prog ]; then
780 _bin=${udevdir}/$_prog
781 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
782 _bin=$(find_binary "$_prog") || {
783 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
788 [[ $_bin ]] && inst_binary "$_bin"
791 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
792 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
794 if [ -x ${udevdir}/$_prog ]; then
795 _bin=${udevdir}/$_prog
796 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
797 _bin=$(find_binary "$_prog") || {
798 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
803 [[ $_bin ]] && inst_binary "$_bin"
806 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
807 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
809 if [ -x ${udevdir}/$_prog ]; then
810 _bin=${udevdir}/$_prog
811 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
812 _bin=$(find_binary "$_prog") || {
813 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
818 [[ $_bin ]] && dracut_install "$_bin"
823 # attempt to install any programs specified in a udev rule
824 inst_rule_group_owner() {
827 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
828 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
829 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
830 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
834 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
835 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
836 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
837 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
843 inst_rule_initqueue() {
844 if grep -q -F initqueue "$1"; then
845 dracut_need_initqueue
849 # udev rules always get installed in the same place, so
850 # create a function to install them to make life simpler.
852 local _target=/etc/udev/rules.d _rule _found
854 inst_dir "${udevdir}/rules.d
"
856 for _rule in "$@
"; do
857 if [ "${_rule#/}" = "$_rule" ]; then
858 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
859 if [[ -e $r/$_rule ]]; then
861 inst_rule_programs "$_found"
862 inst_rule_group_owner "$_found"
863 inst_rule_initqueue "$_found"
864 inst_simple "$_found"
868 for r in '' ./ $dracutbasedir/rules.d/; do
869 if [[ -f ${r}$_rule ]]; then
871 inst_rule_programs "$_found"
872 inst_rule_group_owner "$_found"
873 inst_rule_initqueue "$_found"
874 inst_simple "$_found" "$_target/${_found##*/}"
877 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
881 prepare_udev_rules() {
882 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
885 f="${initdir}/etc
/udev
/rules.d
/$f"
886 [ -e "$f" ] || continue
888 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
889 if [ $UDEVVERSION -ge 174 ]; then
890 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
892 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
894 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
895 if [ $UDEVVERSION -ge 176 ]; then
896 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
898 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
903 done < "${f}" > "${f}.new
"
908 # install function specialized for hooks
909 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
910 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
912 if ! [[ -f $3 ]]; then
913 dfatal "Cannot
install a hook
($3) that does not exist.
"
914 dfatal "Aborting initrd creation.
"
916 elif ! [[ "$hookdirs" == *$1* ]]; then
917 dfatal "No such hook
type $1. Aborting initrd creation.
"
920 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
923 # install any of listed files
925 # If first argument is '-d' and second some destination path, first accessible
926 # source is installed into this path, otherwise it will installed in the same
927 # path as source. If none of listed files was installed, function return 1.
928 # On first successful installation it returns with 0 status.
932 # inst_any -d /bin/foo /bin/bar /bin/baz
934 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
939 [[ $1 = '-d' ]] && to="$2" && shift 2
943 [[ $to ]] && inst "$f" "$to" && return 0
944 inst "$f" && return 0
952 # inst_libdir_file [-n <pattern>] <file> [<file>...]
953 # Install a <file> located on a lib directory to the initramfs image
954 # -n <pattern> install matching files
957 if [[ "$1" == "-n" ]]; then
960 for _dir in $libdirs; do
962 for _f in "$_dir"/$_i; do
963 [[ "$_f" =~ $_pattern ]] || continue
964 [[ -e "$_f" ]] && _files+="$_f "
969 for _dir in $libdirs; do
971 for _f in "$_dir"/$_i; do
972 [[ -e "$_f" ]] && _files+="$_f "
977 [[ $_files ]] && inst_multiple $_files
981 # install function decompressing the target and handling symlinks
982 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
984 # Function install targets in the same paths inside overlay but decompressed
985 # and without extensions (.gz, .bz2).
992 *.gz) _cmd='gzip -f -d' ;;
993 *.bz2) _cmd='bzip2 -d' ;;
997 # Decompress with chosen tool. We assume that tool changes name e.g.
998 # from 'name.gz' to 'name'.
999 ${_cmd} "${initdir}${_src}"
1003 # It's similar to above, but if file is not compressed, performs standard
1005 # $@ = list of files
1006 inst_opt_decompress
() {
1011 inst_decompress
"${_src}" || inst
"${_src}"
1015 # module_check <dracut module>
1016 # execute the check() function of module-setup.sh of <dracut module>
1017 # or the "check" script, if module-setup.sh is not found
1018 # "check $hostonly" is called
1020 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1023 local _hostonly
=$hostonly
1024 [ $# -eq 2 ] && _forced
=$2
1025 [[ -d $_moddir ]] ||
return 1
1026 if [[ ! -f $_moddir/module-setup.sh
]]; then
1027 # if we do not have a check script, we are unconditionally included
1028 [[ -x $_moddir/check
]] ||
return 0
1029 [ $_forced -ne 0 ] && unset hostonly
1030 $_moddir/check
$hostonly
1033 unset check depends cmdline
install installkernel
1035 .
$_moddir/module-setup.sh
1036 is_func check ||
return 0
1037 [ $_forced -ne 0 ] && unset hostonly
1040 unset check depends cmdline
install installkernel
1046 # module_check_mount <dracut module>
1047 # execute the check() function of module-setup.sh of <dracut module>
1048 # or the "check" script, if module-setup.sh is not found
1049 # "mount_needs=1 check 0" is called
1050 module_check_mount
() {
1051 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1054 [[ -d $_moddir ]] ||
return 1
1055 if [[ ! -f $_moddir/module-setup.sh
]]; then
1056 # if we do not have a check script, we are unconditionally included
1057 [[ -x $_moddir/check
]] ||
return 0
1058 mount_needs
=1 $_moddir/check
0
1061 unset check depends cmdline
install installkernel
1063 .
$_moddir/module-setup.sh
1066 unset check depends cmdline
install installkernel
1072 # module_depends <dracut module>
1073 # execute the depends() function of module-setup.sh of <dracut module>
1074 # or the "depends" script, if module-setup.sh is not found
1076 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1078 [[ -d $_moddir ]] ||
return 1
1079 if [[ ! -f $_moddir/module-setup.sh
]]; then
1080 # if we do not have a check script, we have no deps
1081 [[ -x $_moddir/check
]] ||
return 0
1085 unset check depends cmdline
install installkernel
1087 .
$_moddir/module-setup.sh
1090 unset check depends cmdline
install installkernel
1095 # module_cmdline <dracut module>
1096 # execute the cmdline() function of module-setup.sh of <dracut module>
1097 # or the "cmdline" script, if module-setup.sh is not found
1099 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1101 [[ -d $_moddir ]] ||
return 1
1102 if [[ ! -f $_moddir/module-setup.sh
]]; then
1103 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1106 unset check depends cmdline
install installkernel
1108 .
$_moddir/module-setup.sh
1111 unset check depends cmdline
install installkernel
1116 # module_install <dracut module>
1117 # execute the install() function of module-setup.sh of <dracut module>
1118 # or the "install" script, if module-setup.sh is not found
1120 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1122 [[ -d $_moddir ]] ||
return 1
1123 if [[ ! -f $_moddir/module-setup.sh
]]; then
1124 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1127 unset check depends cmdline
install installkernel
1129 .
$_moddir/module-setup.sh
1132 unset check depends cmdline
install installkernel
1137 # module_installkernel <dracut module>
1138 # execute the installkernel() function of module-setup.sh of <dracut module>
1139 # or the "installkernel" script, if module-setup.sh is not found
1140 module_installkernel
() {
1141 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1143 [[ -d $_moddir ]] ||
return 1
1144 if [[ ! -f $_moddir/module-setup.sh
]]; then
1145 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1148 unset check depends cmdline
install installkernel
1149 installkernel
() { true
; }
1150 .
$_moddir/module-setup.sh
1153 unset check depends cmdline
install installkernel
1158 # check_mount <dracut module>
1159 # check_mount checks, if a dracut module is needed for the given
1160 # device and filesystem types in "${host_fs_types[@]}"
1163 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1167 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1169 # If we are already scheduled to be loaded, no need to check again.
1170 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1171 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1173 # This should never happen, but...
1174 [[ -d $_moddir ]] ||
return 1
1176 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1178 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1182 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1183 module_check_mount
$_mod; ret
=$?
1185 # explicit module, so also accept ret=255
1186 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1188 # module not in our list
1189 if [[ $dracutmodules = all
]]; then
1190 # check, if we can and should install this module
1191 module_check_mount
$_mod ||
return 1
1199 for _moddep
in $
(module_depends
$_mod); do
1200 # handle deps as if they were manually added
1201 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1202 add_dracutmodules
+=" $_moddep "
1203 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1204 force_add_dracutmodules
+=" $_moddep "
1205 # if a module we depend on fail, fail also
1206 if ! check_module
$_moddep; then
1207 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1212 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1213 mods_to_load
+=" $_mod "
1218 # check_module <dracut module> [<use_as_dep>]
1219 # check if a dracut module is to be used in the initramfs process
1220 # if <use_as_dep> is set, then the process also keeps track
1221 # that the modules were checked for the dependency tracking process
1224 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1227 # If we are already scheduled to be loaded, no need to check again.
1228 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1229 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1231 # This should never happen, but...
1232 [[ -d $_moddir ]] ||
return 1
1234 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1236 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1237 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1241 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1242 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1243 module_check
$_mod 1; ret
=$?
1245 module_check
$_mod 0; ret
=$?
1247 # explicit module, so also accept ret=255
1248 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1250 # module not in our list
1251 if [[ $dracutmodules = all
]]; then
1252 # check, if we can and should install this module
1253 module_check
$_mod ||
return 1
1260 for _moddep
in $
(module_depends
$_mod); do
1261 # handle deps as if they were manually added
1262 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1263 add_dracutmodules
+=" $_moddep "
1264 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1265 force_add_dracutmodules
+=" $_moddep "
1266 # if a module we depend on fail, fail also
1267 if ! check_module
$_moddep; then
1268 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1273 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1274 mods_to_load
+=" $_mod "
1279 # for_each_module_dir <func>
1280 # execute "<func> <dracut module> 1"
1281 for_each_module_dir
() {
1287 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1288 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1292 # Report any missing dracut modules, the user has specified
1293 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1294 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1295 for _mod
in $_modcheck; do
1296 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1297 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1298 derror
"dracut module '$_mod' cannot be found or installed."
1302 # Install a single kernel module along with any firmware it may require.
1303 # $1 = full path to kernel module to install
1304 install_kmod_with_fw
() {
1305 # no need to go further if the module is already installed
1307 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1310 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1311 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1315 if [[ $omit_drivers ]]; then
1316 local _kmod
=${1##*/}
1319 if [[ "$_kmod" =~
$omit_drivers ]]; then
1320 dinfo
"Omitting driver $_kmod"
1323 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1324 dinfo
"Omitting driver $_kmod"
1329 if [[ $silent_omit_drivers ]]; then
1330 local _kmod
=${1##*/}
1333 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1334 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1337 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1339 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1340 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1341 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1342 (($ret != 0)) && return $ret
1344 local _modname
=${1##*/} _fwdir _found _fw
1345 _modname
=${_modname%.ko*}
1346 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1348 for _fwdir
in $fw_dir; do
1349 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1350 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1354 if [[ $_found != yes ]]; then
1355 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1356 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1357 "\"${_modname}.ko\""
1359 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1360 "\"${_modname}.ko\""
1367 # Do something with all the dependencies of a kernel module.
1368 # Note that kernel modules depend on themselves using the technique we use
1369 # $1 = function to call for each dependency we find
1370 # It will be passed the full path to the found kernel module
1371 # $2 = module to get dependencies for
1372 # rest of args = arguments to modprobe
1373 # _fderr specifies FD passed from surrounding scope
1374 for_each_kmod_dep
() {
1375 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1377 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1378 while read _cmd _modpath _options
; do
1379 [[ $_cmd = insmod
]] ||
continue
1380 $_func ${_modpath} ||
exit $?
1385 dracut_kernel_post
() {
1386 local _moddirname
=${srcmods%%/lib/modules/*}
1389 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1390 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1391 --ignore-install --show-depends --set-version $kernel \
1392 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1394 |
while read _cmd _modpath _options
; do
1395 [[ $_cmd = insmod
]] ||
continue
1397 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1400 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1401 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1403 while read _modpath
; do
1404 local _destpath
=$_modpath
1405 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1406 _destpath
=${_destpath##*/lib/modules/$kernel/}
1407 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1408 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1411 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1414 if [[ $DRACUT_INSTALL ]]; then
1415 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1416 |
while read line
; do
1417 for _fwdir
in $fw_dir; do
1420 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1422 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1423 for _fwdir
in $fw_dir; do
1424 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1425 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1435 for _f
in modules.
builtin.bin modules.
builtin; do
1436 [[ $srcmods/$_f ]] && break
1438 dfatal
"No modules.builtin.bin and modules.builtin found!"
1442 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1443 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1446 # generate module dependencies for the initrd
1447 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1448 ! depmod
-a -b "$initdir" $kernel; then
1449 dfatal
"\"depmod -a $kernel\" failed."
1453 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1456 module_is_host_only
() {
1461 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1463 # check if module is loaded
1464 for i
in /sys
/module
/${_mod//-/_}; do
1465 [[ -d $i ]] && return 0
1468 # check if module is loadable on the current kernel
1469 # this covers the case, where a new module is introduced
1470 # or a module was renamed
1471 # or a module changed from builtin to a module
1472 modinfo
-F filename
"$_mod" &>/dev
/null ||
return 0
1477 find_kernel_modules_by_path
() {
1480 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1484 while read a rest
; do
1485 [[ $a = */$1/* ]] ||
continue
1486 printf "%s\n" "$srcmods/$a"
1487 done < "$srcmods/modules.dep"
1492 find_kernel_modules
() {
1493 find_kernel_modules_by_path drivers
1496 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1497 # instmods [-c [-s]] <kernel subsystem>
1498 # install kernel modules along with all their dependencies.
1499 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1501 [[ $no_kernel = yes ]] && return
1502 # called [sub]functions inherit _fderr
1506 if [[ $1 = '-c' ]]; then
1511 if [[ $1 = '-s' ]]; then
1516 function inst1mod
() {
1517 local _ret
=0 _mod
="$1"
1520 ( [[ "$_mpargs" ]] && echo $_mpargs
1521 find_kernel_modules_by_path
"${_mod#=}" ) \
1525 --*) _mpargs
+=" $_mod" ;;
1528 # if we are already installed, skip this module and go on
1530 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1531 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1532 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1537 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1538 dinfo
"Omitting driver ${_mod##$srcmods}"
1542 # If we are building a host-specific initramfs and this
1543 # module is not already loaded, move on to the next one.
1545 && ! module_is_host_only
"$_mod" \
1548 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1549 # We use '-d' option in modprobe only if modules prefix path
1550 # differs from default '/'. This allows us to use dracut with
1551 # old version of modprobe which doesn't have '-d' option.
1552 local _moddirname
=${srcmods%%/lib/modules/*}
1553 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1555 # ok, load the module, all its dependencies, and any firmware
1557 for_each_kmod_dep install_kmod_with_fw
$_mod \
1558 --set-version $kernel ${_moddirname} $_mpargs
1561 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1562 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1569 function instmods_1
() {
1571 if (($# == 0)); then # filenames from stdin
1573 inst1mod
"${_mod%.ko*}" ||
{
1574 if [[ "$_check" == "yes" ]]; then
1575 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1581 while (($# > 0)); do # filenames as arguments
1582 inst1mod
${1%.ko*} ||
{
1583 if [[ "$_check" == "yes" ]]; then
1584 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1593 local _ret _filter_not_found
='FATAL: Module .* not found.'
1594 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1595 # redirections, but that would make dracut require bash4 at least.
1596 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1597 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1602 # Only two values are returned: AMD or Intel
1605 if grep -qE AMD
/proc
/cpuinfo
; then
1608 if grep -qE Intel
/proc
/cpuinfo
; then
1614 # Get the hosts' ucode file based on the /proc/cpuinfo
1617 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1618 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1619 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1621 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1622 # If family greater or equal than 0x15
1623 if [[ $family -ge 21 ]]; then
1624 printf "microcode_amd_fam15h.bin"
1626 printf "microcode_amd.bin"
1629 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1630 # The /proc/cpuinfo are in decimal.
1631 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}