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.
582 if ! lvm_internal_dev
$2; then "$1" $2 && return; fi
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.
598 if ! lvm_internal_dev
$2 && "$1" $2; then
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 # skip rules without an absolute path
887 [[ "${r}$_rule" != /* ]] && continue
889 if [[ -f ${r}$_rule ]]; then
891 inst_rule_programs "$_found"
892 inst_rule_group_owner "$_found"
893 inst_rule_initqueue "$_found"
894 inst_simple "$_found" "$_target/${_found##*/}"
897 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
901 prepare_udev_rules() {
902 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
905 f="${initdir}/etc
/udev
/rules.d
/$f"
906 [ -e "$f" ] || continue
908 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
909 if [ $UDEVVERSION -ge 174 ]; then
910 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
912 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
914 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
915 if [ $UDEVVERSION -ge 176 ]; then
916 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
918 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
923 done < "${f}" > "${f}.new
"
928 # install function specialized for hooks
929 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
930 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
932 if ! [[ -f $3 ]]; then
933 dfatal "Cannot
install a hook
($3) that does not exist.
"
934 dfatal "Aborting initrd creation.
"
936 elif ! [[ "$hookdirs" == *$1* ]]; then
937 dfatal "No such hook
type $1. Aborting initrd creation.
"
940 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
943 # install any of listed files
945 # If first argument is '-d' and second some destination path, first accessible
946 # source is installed into this path, otherwise it will installed in the same
947 # path as source. If none of listed files was installed, function return 1.
948 # On first successful installation it returns with 0 status.
952 # inst_any -d /bin/foo /bin/bar /bin/baz
954 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
959 [[ $1 = '-d' ]] && to="$2" && shift 2
963 [[ $to ]] && inst "$f" "$to" && return 0
964 inst "$f" && return 0
972 # inst_libdir_file [-n <pattern>] <file> [<file>...]
973 # Install a <file> located on a lib directory to the initramfs image
974 # -n <pattern> install matching files
977 if [[ "$1" == "-n" ]]; then
980 for _dir in $libdirs; do
982 for _f in "$_dir"/$_i; do
983 [[ "$_f" =~ $_pattern ]] || continue
984 [[ -e "$_f" ]] && _files+="$_f "
989 for _dir in $libdirs; do
991 for _f in "$_dir"/$_i; do
992 [[ -e "$_f" ]] && _files+="$_f "
997 [[ $_files ]] && inst_multiple $_files
1001 # install function decompressing the target and handling symlinks
1002 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1004 # Function install targets in the same paths inside overlay but decompressed
1005 # and without extensions (.gz, .bz2).
1012 *.gz) _cmd='gzip -f -d' ;;
1013 *.bz2) _cmd='bzip2 -d' ;;
1017 # Decompress with chosen tool. We assume that tool changes name e.g.
1018 # from 'name.gz' to 'name'.
1019 ${_cmd} "${initdir}${_src}"
1023 # It's similar to above, but if file is not compressed, performs standard
1025 # $@ = list of files
1026 inst_opt_decompress
() {
1031 inst_decompress
"${_src}" || inst
"${_src}"
1035 # module_check <dracut module>
1036 # execute the check() function of module-setup.sh of <dracut module>
1037 # or the "check" script, if module-setup.sh is not found
1038 # "check $hostonly" is called
1040 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1043 local _hostonly
=$hostonly
1044 [ $# -eq 2 ] && _forced
=$2
1045 [[ -d $_moddir ]] ||
return 1
1046 if [[ ! -f $_moddir/module-setup.sh
]]; then
1047 # if we do not have a check script, we are unconditionally included
1048 [[ -x $_moddir/check
]] ||
return 0
1049 [ $_forced -ne 0 ] && unset hostonly
1050 $_moddir/check
$hostonly
1053 unset check depends cmdline
install installkernel
1055 .
$_moddir/module-setup.sh
1056 is_func check ||
return 0
1057 [ $_forced -ne 0 ] && unset hostonly
1060 unset check depends cmdline
install installkernel
1066 # module_check_mount <dracut module>
1067 # execute the check() function of module-setup.sh of <dracut module>
1068 # or the "check" script, if module-setup.sh is not found
1069 # "mount_needs=1 check 0" is called
1070 module_check_mount
() {
1071 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1074 [[ -d $_moddir ]] ||
return 1
1075 if [[ ! -f $_moddir/module-setup.sh
]]; then
1076 # if we do not have a check script, we are unconditionally included
1077 [[ -x $_moddir/check
]] ||
return 0
1078 mount_needs
=1 $_moddir/check
0
1081 unset check depends cmdline
install installkernel
1083 .
$_moddir/module-setup.sh
1086 unset check depends cmdline
install installkernel
1092 # module_depends <dracut module>
1093 # execute the depends() function of module-setup.sh of <dracut module>
1094 # or the "depends" script, if module-setup.sh is not found
1096 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1098 [[ -d $_moddir ]] ||
return 1
1099 if [[ ! -f $_moddir/module-setup.sh
]]; then
1100 # if we do not have a check script, we have no deps
1101 [[ -x $_moddir/check
]] ||
return 0
1105 unset check depends cmdline
install installkernel
1107 .
$_moddir/module-setup.sh
1110 unset check depends cmdline
install installkernel
1115 # module_cmdline <dracut module>
1116 # execute the cmdline() function of module-setup.sh of <dracut module>
1117 # or the "cmdline" script, if module-setup.sh is not found
1119 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1121 [[ -d $_moddir ]] ||
return 1
1122 if [[ ! -f $_moddir/module-setup.sh
]]; then
1123 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1126 unset check depends cmdline
install installkernel
1128 .
$_moddir/module-setup.sh
1131 unset check depends cmdline
install installkernel
1136 # module_install <dracut module>
1137 # execute the install() function of module-setup.sh of <dracut module>
1138 # or the "install" script, if module-setup.sh is not found
1140 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1142 [[ -d $_moddir ]] ||
return 1
1143 if [[ ! -f $_moddir/module-setup.sh
]]; then
1144 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1147 unset check depends cmdline
install installkernel
1149 .
$_moddir/module-setup.sh
1152 unset check depends cmdline
install installkernel
1157 # module_installkernel <dracut module>
1158 # execute the installkernel() function of module-setup.sh of <dracut module>
1159 # or the "installkernel" script, if module-setup.sh is not found
1160 module_installkernel
() {
1161 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1163 [[ -d $_moddir ]] ||
return 1
1164 if [[ ! -f $_moddir/module-setup.sh
]]; then
1165 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1168 unset check depends cmdline
install installkernel
1169 installkernel
() { true
; }
1170 .
$_moddir/module-setup.sh
1173 unset check depends cmdline
install installkernel
1178 # check_mount <dracut module>
1179 # check_mount checks, if a dracut module is needed for the given
1180 # device and filesystem types in "${host_fs_types[@]}"
1183 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1187 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1189 # If we are already scheduled to be loaded, no need to check again.
1190 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1191 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1193 # This should never happen, but...
1194 [[ -d $_moddir ]] ||
return 1
1196 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1198 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1202 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1203 module_check_mount
$_mod; ret
=$?
1205 # explicit module, so also accept ret=255
1206 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1208 # module not in our list
1209 if [[ $dracutmodules = all
]]; then
1210 # check, if we can and should install this module
1211 module_check_mount
$_mod ||
return 1
1219 for _moddep
in $
(module_depends
$_mod); do
1220 # handle deps as if they were manually added
1221 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1222 add_dracutmodules
+=" $_moddep "
1223 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1224 force_add_dracutmodules
+=" $_moddep "
1225 # if a module we depend on fail, fail also
1226 if ! check_module
$_moddep; then
1227 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1232 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1233 mods_to_load
+=" $_mod "
1238 # check_module <dracut module> [<use_as_dep>]
1239 # check if a dracut module is to be used in the initramfs process
1240 # if <use_as_dep> is set, then the process also keeps track
1241 # that the modules were checked for the dependency tracking process
1244 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1247 # If we are already scheduled to be loaded, no need to check again.
1248 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1249 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1251 # This should never happen, but...
1252 [[ -d $_moddir ]] ||
return 1
1254 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1256 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1257 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1261 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1262 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1263 module_check
$_mod 1; ret
=$?
1265 module_check
$_mod 0; ret
=$?
1267 # explicit module, so also accept ret=255
1268 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1270 # module not in our list
1271 if [[ $dracutmodules = all
]]; then
1272 # check, if we can and should install this module
1273 module_check
$_mod ||
return 1
1280 for _moddep
in $
(module_depends
$_mod); do
1281 # handle deps as if they were manually added
1282 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1283 add_dracutmodules
+=" $_moddep "
1284 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1285 force_add_dracutmodules
+=" $_moddep "
1286 # if a module we depend on fail, fail also
1287 if ! check_module
$_moddep; then
1288 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1293 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1294 mods_to_load
+=" $_mod "
1299 # for_each_module_dir <func>
1300 # execute "<func> <dracut module> 1"
1301 for_each_module_dir
() {
1307 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1308 [[ -d $_moddir ]] ||
continue;
1309 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1310 -e $_moddir/module-setup.sh
]] ||
continue
1311 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1315 # Report any missing dracut modules, the user has specified
1316 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1317 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1318 for _mod
in $_modcheck; do
1319 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1320 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1321 derror
"dracut module '$_mod' cannot be found or installed."
1325 # Install a single kernel module along with any firmware it may require.
1326 # $1 = full path to kernel module to install
1327 install_kmod_with_fw
() {
1328 # no need to go further if the module is already installed
1330 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1333 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1334 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1338 if [[ $omit_drivers ]]; then
1339 local _kmod
=${1##*/}
1342 if [[ "$_kmod" =~
$omit_drivers ]]; then
1343 dinfo
"Omitting driver $_kmod"
1346 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1347 dinfo
"Omitting driver $_kmod"
1352 if [[ $silent_omit_drivers ]]; then
1353 local _kmod
=${1##*/}
1356 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1357 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1360 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1362 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1363 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1364 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1365 (($ret != 0)) && return $ret
1367 local _modname
=${1##*/} _fwdir _found _fw
1368 _modname
=${_modname%.ko*}
1369 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1371 for _fwdir
in $fw_dir; do
1372 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1373 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1377 if [[ $_found != yes ]]; then
1378 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1379 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1380 "\"${_modname}.ko\""
1382 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1383 "\"${_modname}.ko\""
1390 # Do something with all the dependencies of a kernel module.
1391 # Note that kernel modules depend on themselves using the technique we use
1392 # $1 = function to call for each dependency we find
1393 # It will be passed the full path to the found kernel module
1394 # $2 = module to get dependencies for
1395 # rest of args = arguments to modprobe
1396 # _fderr specifies FD passed from surrounding scope
1397 for_each_kmod_dep
() {
1398 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1400 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1401 while read _cmd _modpath _options
; do
1402 [[ $_cmd = insmod
]] ||
continue
1403 $_func ${_modpath} ||
exit $?
1408 dracut_kernel_post
() {
1409 local _moddirname
=${srcmods%%/lib/modules/*}
1412 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1413 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1414 --ignore-install --show-depends --set-version $kernel \
1415 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1417 |
while read _cmd _modpath _options
; do
1418 [[ $_cmd = insmod
]] ||
continue
1420 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1423 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1424 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1426 while read _modpath
; do
1427 local _destpath
=$_modpath
1428 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1429 _destpath
=${_destpath##*/lib/modules/$kernel/}
1430 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1431 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1434 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1437 if [[ $DRACUT_INSTALL ]]; then
1438 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1439 |
while read line
; do
1440 for _fwdir
in $fw_dir; do
1443 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1445 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1446 for _fwdir
in $fw_dir; do
1447 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1448 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1458 for _f
in modules.
builtin.bin modules.
builtin; do
1459 [[ $srcmods/$_f ]] && break
1461 dfatal
"No modules.builtin.bin and modules.builtin found!"
1465 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1466 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1469 # generate module dependencies for the initrd
1470 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1471 ! depmod
-a -b "$initdir" $kernel; then
1472 dfatal
"\"depmod -a $kernel\" failed."
1476 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1479 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1481 module_is_host_only
() {
1486 _modenc
=${_mod//-/_}
1488 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1490 # check if module is loaded
1491 [[ ${host_modules["$_modenc"]} ]] && return 0
1493 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1495 if [[ "$kernel_current" != "$kernel" ]]; then
1496 # check if module is loadable on the current kernel
1497 # this covers the case, where a new module is introduced
1498 # or a module was renamed
1499 # or a module changed from builtin to a module
1500 if [[ -d /lib
/modules
/$kernel_current ]]; then
1501 # if the modinfo can be parsed, but the module
1502 # is not loaded, then we can safely return 1
1503 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1506 # Finally check all modalias, if we install for a kernel
1507 # different from the current one
1508 for a
in $
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
); do
1509 for i
in "${!host_modalias[@]}"; do
1510 [[ $i == $a ]] && return 0
1518 find_kernel_modules_by_path
() {
1521 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1525 while read a rest
; do
1526 [[ $a = */$1/* ]] ||
continue
1527 printf "%s\n" "$srcmods/$a"
1528 done < "$srcmods/modules.dep"
1533 find_kernel_modules
() {
1534 find_kernel_modules_by_path drivers
1537 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1538 # instmods [-c [-s]] <kernel subsystem>
1539 # install kernel modules along with all their dependencies.
1540 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1542 [[ $no_kernel = yes ]] && return
1543 # called [sub]functions inherit _fderr
1547 if [[ $1 = '-c' ]]; then
1552 if [[ $1 = '-s' ]]; then
1557 function inst1mod
() {
1558 local _ret
=0 _mod
="$1"
1561 ( [[ "$_mpargs" ]] && echo $_mpargs
1562 find_kernel_modules_by_path
"${_mod#=}" ) \
1566 --*) _mpargs
+=" $_mod" ;;
1569 # if we are already installed, skip this module and go on
1571 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1572 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1573 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1578 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1579 dinfo
"Omitting driver ${_mod##$srcmods}"
1583 # If we are building a host-specific initramfs and this
1584 # module is not already loaded, move on to the next one.
1586 && ! module_is_host_only
"$_mod" \
1589 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1590 # We use '-d' option in modprobe only if modules prefix path
1591 # differs from default '/'. This allows us to use dracut with
1592 # old version of modprobe which doesn't have '-d' option.
1593 local _moddirname
=${srcmods%%/lib/modules/*}
1594 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1596 # ok, load the module, all its dependencies, and any firmware
1598 for_each_kmod_dep install_kmod_with_fw
$_mod \
1599 --set-version $kernel ${_moddirname} $_mpargs
1602 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1603 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1610 function instmods_1
() {
1612 if (($# == 0)); then # filenames from stdin
1614 inst1mod
"${_mod%.ko*}" ||
{
1615 if [[ "$_check" == "yes" ]]; then
1616 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1622 while (($# > 0)); do # filenames as arguments
1623 inst1mod
${1%.ko*} ||
{
1624 if [[ "$_check" == "yes" ]]; then
1625 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1634 local _ret _filter_not_found
='FATAL: Module .* not found.'
1635 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1636 # redirections, but that would make dracut require bash4 at least.
1637 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1638 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1643 # Only two values are returned: AMD or Intel
1646 if grep -qE AMD
/proc
/cpuinfo
; then
1649 if grep -qE Intel
/proc
/cpuinfo
; then
1655 # Get the hosts' ucode file based on the /proc/cpuinfo
1658 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1659 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1660 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1662 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1663 # If family greater or equal than 0x15
1664 if [[ $family -ge 21 ]]; then
1665 printf "microcode_amd_fam15h.bin"
1667 printf "microcode_amd.bin"
1670 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1671 # The /proc/cpuinfo are in decimal.
1672 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1676 # Not every device in /dev/mapper should be examined.
1677 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1678 lvm_internal_dev
() {
1679 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1680 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1681 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1682 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1683 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1684 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]