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%/*};
68 [[ "$i" = "/lib" ||
"$i" = "/usr/lib" ||
"$i" = "/lib64" ||
"$i" = "/usr/lib64" ]] && continue
71 printf "%s\n" ${!a[@]}
75 if ! [[ $libdirs ]] ; then
76 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
77 && [[ -d /lib64
]]; then
79 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
82 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
85 libdirs
+=" $(ldconfig_paths)"
90 if ! [[ $kernel ]]; then
95 # Version comparision function. Assumes Linux style version scheme.
97 # $2 = comparision op (gt, ge, eq, le, lt, ne)
100 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
104 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
105 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
106 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
122 srcmods
="/lib/modules/$kernel/"
124 [[ $drivers_dir ]] && {
125 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
126 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
129 srcmods
="$drivers_dir"
133 if ! type dinfo
>/dev
/null
2>&1; then
134 .
"$dracutbasedir/dracut-logger.sh"
138 if ! [[ $initdir ]]; then
139 dfatal
"initdir not set"
143 # export standard hookdirs
145 hookdirs
="cmdline pre-udev pre-trigger netroot "
146 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
147 hookdirs
+="pre-mount pre-pivot cleanup mount "
148 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
152 dracut_need_initqueue
() {
153 >"$initdir/lib/dracut/need-initqueue"
156 dracut_module_included
() {
157 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
160 # Create all subdirectories for given path without creating the last element.
163 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
167 # Check whether $1 is a function.
169 [[ "$(type -t "$1")" = "function" ]]
172 # Function prints global variables in format name=value line by line.
173 # $@ = list of global variables' name
179 eval printf -v _value
"%s" "\$$_var"
180 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
184 # normalize_path <path>
185 # Prints the normalized path, where it removes any duplicated
186 # and trailing slashes.
188 # $ normalize_path ///test/test//
192 set -- "${1//+(\/)//}"
194 printf "%s\n" "${1%/}"
197 # convert_abs_rel <from> <to>
198 # Prints the relative path, when creating a symlink to <to> from <from>.
200 # $ convert_abs_rel /usr/bin/test /bin/test-2
202 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
204 local __current __absolute __abssize __cursize __newpath
207 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
209 # corner case #1 - self looping link
210 [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
212 # corner case #2 - own dir link
213 [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
215 IFS
="/" __current
=($1)
216 IFS
="/" __absolute
=($2)
218 __abssize
=${#__absolute[@]}
219 __cursize
=${#__current[@]}
221 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
224 if (( __level
> __abssize || __level
> __cursize
))
230 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
234 __newpath
=$__newpath"/"
236 __newpath
=$__newpath".."
239 for ((__i
= __level
; __i
< __abssize
; __i
++))
241 if [[ -n $__newpath ]]
243 __newpath
=$__newpath"/"
245 __newpath
=$__newpath${__absolute[__i]}
248 printf "%s\n" "$__newpath"
251 if [[ "$(ln --help)" == *--relative* ]]; then
253 ln -sfnr "${initdir}/$1" "${initdir}/$2"
259 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
260 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
264 # get_fs_env <device>
265 # Get and the ID_FS_TYPE variable from udev for a device.
267 # $ get_fs_env /dev/sda2
275 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
276 |
while read line
; do
277 if [[ "$line" == TYPE\
=* ]]; then
278 printf "%s" "${line#TYPE=}";
282 if [[ $ID_FS_TYPE ]]; then
283 printf "%s" "$ID_FS_TYPE"
289 # get_maj_min <device>
290 # Prints the major and minor of a device node.
292 # $ get_maj_min /dev/sda2
295 local _maj _min _majmin
296 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
297 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
301 # get_devpath_block <device>
302 # get the DEVPATH in /sys of a block device
303 get_devpath_block
() {
305 _majmin
=$
(get_maj_min
"$1")
307 for _i
in /sys
/block
/*/dev
/sys
/block
/*/*/dev
; do
308 [[ -e "$_i" ]] ||
continue
309 if [[ "$_majmin" == "$(<"$_i")" ]]; then
310 printf "%s" "${_i%/dev}"
317 # get a persistent path from a device
318 get_persistent_dev
() {
321 _dev
=$
(get_maj_min
"$1")
322 [ -z "$_dev" ] && return
326 /dev
/disk
/${persistent_policy:-by-uuid}/* \
327 /dev
/disk
/by-uuid
/* \
328 /dev
/disk
/by-label
/* \
329 /dev
/disk
/by-partuuid
/* \
330 /dev
/disk
/by-partlabel
/* \
332 /dev
/disk
/by-path
/* \
334 [[ -e "$i" ]] ||
continue
335 [[ $i == /dev
/mapper
/control
]] && continue
336 [[ $i == /dev
/mapper
/mpath
* ]] && continue
337 _tmp
=$
(get_maj_min
"$i")
338 if [ "$_tmp" = "$_dev" ]; then
345 expand_persistent_dev
() {
350 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
355 _dev
="/dev/disk/by-uuid/${_dev}"
358 _dev
="${_dev#PARTUUID=}"
360 _dev
="/dev/disk/by-partuuid/${_dev}"
363 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
369 shorten_persistent_dev
() {
373 printf "%s" "UUID=${_dev##*/}";;
374 /dev
/disk
/by-label
/*)
375 printf "%s" "LABEL=${_dev##*/}";;
376 /dev
/disk
/by-partuuid
/*)
377 printf "%s" "PARTUUID=${_dev##*/}";;
378 /dev
/disk
/by-partlabel
/*)
379 printf "%s" "PARTLABEL=${_dev##*/}";;
381 printf "%s" "$_dev";;
385 # find_block_device <mountpoint>
386 # Prints the major and minor number of the block device
387 # for a given mountpoint.
388 # Unless $use_fstab is set to "yes" the functions
389 # uses /proc/self/mountinfo as the primary source of the
390 # information and only falls back to /etc/fstab, if the mountpoint
391 # is not found there.
393 # $ find_block_device /usr
395 find_block_device
() {
396 local _majmin _dev _majmin _find_mpt
398 if [[ $use_fstab != yes ]]; then
399 [[ -d $_find_mpt/.
]]
400 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
401 while read _majmin _dev
; do
402 if [[ -b $_dev ]]; then
403 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
404 _majmin
=$
(get_maj_min
$_dev)
406 if [[ $_majmin ]]; then
407 printf "%s\n" "$_majmin"
409 printf "%s\n" "$_dev"
413 if [[ $_dev = *:* ]]; then
414 printf "%s\n" "$_dev"
417 done; return 1; } && return 0
419 # fall back to /etc/fstab
421 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
422 while read _majmin _dev
; do
423 if ! [[ $_dev ]]; then
427 if [[ -b $_dev ]]; then
428 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
429 if [[ $_majmin ]]; then
430 printf "%s\n" "$_majmin"
432 printf "%s\n" "$_dev"
436 if [[ $_dev = *:* ]]; then
437 printf "%s\n" "$_dev"
440 done; return 1; } && return 0
445 # find_mp_fstype <mountpoint>
446 # Echo the filesystem type for a given mountpoint.
447 # /proc/self/mountinfo is taken as the primary source of information
448 # and /etc/fstab is used as a fallback.
449 # No newline is appended!
451 # $ find_mp_fstype /;echo
456 if [[ $use_fstab != yes ]]; then
457 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
459 [[ $_fs ]] ||
continue
460 [[ $_fs = "autofs" ]] && continue
463 done; return 1; } && return 0
466 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
468 [[ $_fs ]] ||
continue
469 [[ $_fs = "autofs" ]] && continue
472 done; return 1; } && return 0
477 # find_dev_fstype <device>
478 # Echo the filesystem type for a given device.
479 # /proc/self/mountinfo is taken as the primary source of information
480 # and /etc/fstab is used as a fallback.
481 # No newline is appended!
483 # $ find_dev_fstype /dev/sda2;echo
488 if ! [[ "$_find_dev" = /dev
* ]]; then
489 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
492 if [[ $use_fstab != yes ]]; then
493 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
495 [[ $_fs ]] ||
continue
496 [[ $_fs = "autofs" ]] && continue
499 done; return 1; } && return 0
502 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
504 [[ $_fs ]] ||
continue
505 [[ $_fs = "autofs" ]] && continue
508 done; return 1; } && return 0
513 # find_mp_fsopts <mountpoint>
514 # Echo the filesystem options for a given mountpoint.
515 # /proc/self/mountinfo is taken as the primary source of information
516 # and /etc/fstab is used as a fallback.
517 # No newline is appended!
519 # $ find_mp_fsopts /;echo
520 # rw,relatime,discard,data=ordered
522 if [[ $use_fstab != yes ]]; then
523 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
526 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
529 # find_dev_fsopts <device>
530 # Echo the filesystem options for a given device.
531 # /proc/self/mountinfo is taken as the primary source of information
532 # and /etc/fstab is used as a fallback.
534 # $ find_dev_fsopts /dev/sda2
535 # rw,relatime,discard,data=ordered
537 local _find_dev _opts
539 if ! [[ "$_find_dev" = /dev
* ]]; then
540 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
543 if [[ $use_fstab != yes ]]; then
544 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
547 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
551 # finds the major:minor of the block device backing the root filesystem.
552 find_root_block_device
() { find_block_device
/; }
554 # for_each_host_dev_fs <func>
555 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
556 # in ${host_fs_types[@]}
557 for_each_host_dev_fs
()
563 [[ "${!host_fs_types[@]}" ]] ||
return 0
565 for _dev
in "${!host_fs_types[@]}"; do
566 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
573 printf "%s\n" "${host_fs_types[@]}"
576 # Walk all the slave relationships for a given block device.
577 # Stop when our helper function returns success
578 # $1 = function to call on every found block device
579 # $2 = block device in major:minor format
580 check_block_and_slaves
() {
582 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
583 if ! lvm_internal_dev
$2; then "$1" $2 && return; fi
584 check_vol_slaves
"$@" && return 0
585 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
586 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 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
$1 $
(<"$_x") && return 0
596 check_block_and_slaves_all
() {
598 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
599 if ! lvm_internal_dev
$2 && "$1" $2; then
602 check_vol_slaves
"$@" && return 0
603 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
604 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
606 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
607 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
608 [[ -f $_x ]] ||
continue
609 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
613 # for_each_host_dev_and_slaves <func>
614 # Execute "<func> <dev>" for every "<dev>" found
615 # in ${host_devs[@]} and their slaves
616 for_each_host_dev_and_slaves_all
()
622 [[ "${host_devs[@]}" ]] ||
return 0
624 for _dev
in ${host_devs[@]}; do
625 [[ -b "$_dev" ]] ||
continue
626 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
633 for_each_host_dev_and_slaves
()
638 [[ "${host_devs[@]}" ]] ||
return 0
640 for _dev
in ${host_devs[@]}; do
641 [[ -b "$_dev" ]] ||
continue
642 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
647 # ugly workaround for the lvm design
648 # There is no volume group device,
649 # so, there are no slave devices for volume groups.
650 # Logical volumes only have the slave devices they really live on,
651 # but you cannot create the logical volume without the volume group.
652 # And the volume group might be bigger than the devices the LV needs.
655 for i
in /dev
/mapper
/*; do
656 [[ $i == /dev
/mapper
/control
]] && continue
657 _lv
=$
(get_maj_min
$i)
658 if [[ $_lv = $2 ]]; then
659 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
661 _vg
=$
(printf "%s\n" "$_vg")
663 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
665 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
673 # fs_get_option <filesystem options> <search for option>
674 # search for a specific option in a bunch of filesystem options
675 # and return the value
683 while [ $# -gt 0 ]; do
686 echo ${1#${_option}=}
694 if ! [[ $DRACUT_INSTALL ]]; then
695 DRACUT_INSTALL
=$
(find_binary dracut-install
)
698 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
699 DRACUT_INSTALL
=$dracutbasedir/dracut-install
702 if ! [[ -x $DRACUT_INSTALL ]]; then
703 dfatal
"dracut-install not found!"
707 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
709 [[ -e ${initdir}/"$1" ]] && return 0 # already there
710 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
711 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
715 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
716 #dinfo "$DRACUT_INSTALL -l $@"
717 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
718 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
722 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
723 [[ -e $1 ]] ||
return 1 # no source
724 $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
725 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" ||
:
729 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
730 [[ -L $1 ]] ||
return 1
731 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
732 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
737 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
738 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
740 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
749 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
750 [[ -e $1 ]] ||
return 1 # no source
751 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
752 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
756 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
757 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
761 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
762 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
765 # find symlinks linked to given library file
767 # Function searches for symlinks by stripping version numbers appended to
768 # library filename, checks if it points to the same target and finally
769 # prints the list of symlinks to stdout.
772 # rev_lib_symlinks libfoo.so.8.1
773 # output: libfoo.so.8 libfoo.so
774 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
776 [[ ! $1 ]] && return 0
778 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
780 [[ ${fn} == *.so.
* ]] ||
return 1
782 until [[ ${fn##*.} == so
]]; do
784 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
790 # attempt to install any programs specified in a udev rule
791 inst_rule_programs() {
794 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
795 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
797 if [ -x ${udevdir}/$_prog ]; then
798 _bin=${udevdir}/$_prog
799 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
800 _bin=$(find_binary "$_prog") || {
801 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
806 [[ $_bin ]] && inst_binary "$_bin"
809 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
810 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
812 if [ -x ${udevdir}/$_prog ]; then
813 _bin=${udevdir}/$_prog
814 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
815 _bin=$(find_binary "$_prog") || {
816 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
821 [[ $_bin ]] && inst_binary "$_bin"
824 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
825 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
827 if [ -x ${udevdir}/$_prog ]; then
828 _bin=${udevdir}/$_prog
829 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
830 _bin=$(find_binary "$_prog") || {
831 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
836 [[ $_bin ]] && dracut_install "$_bin"
841 # attempt to install any programs specified in a udev rule
842 inst_rule_group_owner() {
845 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
846 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
847 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
848 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
852 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
853 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
854 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
855 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
861 inst_rule_initqueue() {
862 if grep -q -F initqueue "$1"; then
863 dracut_need_initqueue
867 # udev rules always get installed in the same place, so
868 # create a function to install them to make life simpler.
870 local _target=/etc/udev/rules.d _rule _found
872 inst_dir "${udevdir}/rules.d
"
874 for _rule in "$@
"; do
875 if [ "${_rule#/}" = "$_rule" ]; then
876 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
877 if [[ -e $r/$_rule ]]; then
879 inst_rule_programs "$_found"
880 inst_rule_group_owner "$_found"
881 inst_rule_initqueue "$_found"
882 inst_simple "$_found"
886 for r in '' $dracutbasedir/rules.d/; do
887 # skip rules without an absolute path
888 [[ "${r}$_rule" != /* ]] && continue
890 if [[ -f ${r}$_rule ]]; then
892 inst_rule_programs "$_found"
893 inst_rule_group_owner "$_found"
894 inst_rule_initqueue "$_found"
895 inst_simple "$_found" "$_target/${_found##*/}"
898 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
902 prepare_udev_rules() {
903 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
906 f="${initdir}/etc
/udev
/rules.d
/$f"
907 [ -e "$f" ] || continue
909 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
910 if [ $UDEVVERSION -ge 174 ]; then
911 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
913 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
915 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
916 if [ $UDEVVERSION -ge 176 ]; then
917 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
919 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
924 done < "${f}" > "${f}.new
"
929 # install function specialized for hooks
930 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
931 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
933 if ! [[ -f $3 ]]; then
934 dfatal "Cannot
install a hook
($3) that does not exist.
"
935 dfatal "Aborting initrd creation.
"
937 elif ! [[ "$hookdirs" == *$1* ]]; then
938 dfatal "No such hook
type $1. Aborting initrd creation.
"
941 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
944 # install any of listed files
946 # If first argument is '-d' and second some destination path, first accessible
947 # source is installed into this path, otherwise it will installed in the same
948 # path as source. If none of listed files was installed, function return 1.
949 # On first successful installation it returns with 0 status.
953 # inst_any -d /bin/foo /bin/bar /bin/baz
955 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
960 [[ $1 = '-d' ]] && to="$2" && shift 2
964 [[ $to ]] && inst "$f" "$to" && return 0
965 inst "$f" && return 0
973 # inst_libdir_file [-n <pattern>] <file> [<file>...]
974 # Install a <file> located on a lib directory to the initramfs image
975 # -n <pattern> install matching files
978 if [[ "$1" == "-n" ]]; then
981 for _dir in $libdirs; do
983 for _f in "$_dir"/$_i; do
984 [[ "$_f" =~ $_pattern ]] || continue
985 [[ -e "$_f" ]] && _files+="$_f "
990 for _dir in $libdirs; do
992 for _f in "$_dir"/$_i; do
993 [[ -e "$_f" ]] && _files+="$_f "
998 [[ $_files ]] && inst_multiple $_files
1002 # install function decompressing the target and handling symlinks
1003 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1005 # Function install targets in the same paths inside overlay but decompressed
1006 # and without extensions (.gz, .bz2).
1013 *.gz) _cmd='gzip -f -d' ;;
1014 *.bz2) _cmd='bzip2 -d' ;;
1018 # Decompress with chosen tool. We assume that tool changes name e.g.
1019 # from 'name.gz' to 'name'.
1020 ${_cmd} "${initdir}${_src}"
1024 # It's similar to above, but if file is not compressed, performs standard
1026 # $@ = list of files
1027 inst_opt_decompress
() {
1032 inst_decompress
"${_src}" || inst
"${_src}"
1036 # module_check <dracut module>
1037 # execute the check() function of module-setup.sh of <dracut module>
1038 # or the "check" script, if module-setup.sh is not found
1039 # "check $hostonly" is called
1041 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1044 local _hostonly
=$hostonly
1045 [ $# -eq 2 ] && _forced
=$2
1046 [[ -d $_moddir ]] ||
return 1
1047 if [[ ! -f $_moddir/module-setup.sh
]]; then
1048 # if we do not have a check script, we are unconditionally included
1049 [[ -x $_moddir/check
]] ||
return 0
1050 [ $_forced -ne 0 ] && unset hostonly
1051 $_moddir/check
$hostonly
1054 unset check depends cmdline
install installkernel
1056 .
$_moddir/module-setup.sh
1057 is_func check ||
return 0
1058 [ $_forced -ne 0 ] && unset hostonly
1061 unset check depends cmdline
install installkernel
1067 # module_check_mount <dracut module>
1068 # execute the check() function of module-setup.sh of <dracut module>
1069 # or the "check" script, if module-setup.sh is not found
1070 # "mount_needs=1 check 0" is called
1071 module_check_mount
() {
1072 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1075 [[ -d $_moddir ]] ||
return 1
1076 if [[ ! -f $_moddir/module-setup.sh
]]; then
1077 # if we do not have a check script, we are unconditionally included
1078 [[ -x $_moddir/check
]] ||
return 0
1079 mount_needs
=1 $_moddir/check
0
1082 unset check depends cmdline
install installkernel
1084 .
$_moddir/module-setup.sh
1087 unset check depends cmdline
install installkernel
1093 # module_depends <dracut module>
1094 # execute the depends() function of module-setup.sh of <dracut module>
1095 # or the "depends" script, if module-setup.sh is not found
1097 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1099 [[ -d $_moddir ]] ||
return 1
1100 if [[ ! -f $_moddir/module-setup.sh
]]; then
1101 # if we do not have a check script, we have no deps
1102 [[ -x $_moddir/check
]] ||
return 0
1106 unset check depends cmdline
install installkernel
1108 .
$_moddir/module-setup.sh
1111 unset check depends cmdline
install installkernel
1116 # module_cmdline <dracut module>
1117 # execute the cmdline() function of module-setup.sh of <dracut module>
1118 # or the "cmdline" 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/cmdline
]] && .
"$_moddir/cmdline"
1127 unset check depends cmdline
install installkernel
1129 .
$_moddir/module-setup.sh
1132 unset check depends cmdline
install installkernel
1137 # module_install <dracut module>
1138 # execute the install() function of module-setup.sh of <dracut module>
1139 # or the "install" script, if module-setup.sh is not found
1141 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1143 [[ -d $_moddir ]] ||
return 1
1144 if [[ ! -f $_moddir/module-setup.sh
]]; then
1145 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1148 unset check depends cmdline
install installkernel
1150 .
$_moddir/module-setup.sh
1153 unset check depends cmdline
install installkernel
1158 # module_installkernel <dracut module>
1159 # execute the installkernel() function of module-setup.sh of <dracut module>
1160 # or the "installkernel" script, if module-setup.sh is not found
1161 module_installkernel
() {
1162 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1164 [[ -d $_moddir ]] ||
return 1
1165 if [[ ! -f $_moddir/module-setup.sh
]]; then
1166 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1169 unset check depends cmdline
install installkernel
1170 installkernel
() { true
; }
1171 .
$_moddir/module-setup.sh
1174 unset check depends cmdline
install installkernel
1179 # check_mount <dracut module>
1180 # check_mount checks, if a dracut module is needed for the given
1181 # device and filesystem types in "${host_fs_types[@]}"
1184 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1188 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1190 # If we are already scheduled to be loaded, no need to check again.
1191 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1192 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1194 # This should never happen, but...
1195 [[ -d $_moddir ]] ||
return 1
1197 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1199 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1203 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1204 module_check_mount
$_mod; ret
=$?
1206 # explicit module, so also accept ret=255
1207 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1209 # module not in our list
1210 if [[ $dracutmodules = all
]]; then
1211 # check, if we can and should install this module
1212 module_check_mount
$_mod ||
return 1
1220 for _moddep
in $
(module_depends
$_mod); do
1221 # handle deps as if they were manually added
1222 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1223 add_dracutmodules
+=" $_moddep "
1224 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1225 force_add_dracutmodules
+=" $_moddep "
1226 # if a module we depend on fail, fail also
1227 if ! check_module
$_moddep; then
1228 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1233 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1234 mods_to_load
+=" $_mod "
1239 # check_module <dracut module> [<use_as_dep>]
1240 # check if a dracut module is to be used in the initramfs process
1241 # if <use_as_dep> is set, then the process also keeps track
1242 # that the modules were checked for the dependency tracking process
1245 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1248 # If we are already scheduled to be loaded, no need to check again.
1249 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1250 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1252 # This should never happen, but...
1253 [[ -d $_moddir ]] ||
return 1
1255 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1257 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1258 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1262 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1263 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1264 module_check
$_mod 1; ret
=$?
1266 module_check
$_mod 0; ret
=$?
1268 # explicit module, so also accept ret=255
1269 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1271 # module not in our list
1272 if [[ $dracutmodules = all
]]; then
1273 # check, if we can and should install this module
1274 module_check
$_mod ||
return 1
1281 for _moddep
in $
(module_depends
$_mod); do
1282 # handle deps as if they were manually added
1283 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1284 add_dracutmodules
+=" $_moddep "
1285 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1286 force_add_dracutmodules
+=" $_moddep "
1287 # if a module we depend on fail, fail also
1288 if ! check_module
$_moddep; then
1289 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1294 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1295 mods_to_load
+=" $_mod "
1300 # for_each_module_dir <func>
1301 # execute "<func> <dracut module> 1"
1302 for_each_module_dir
() {
1308 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1309 [[ -d $_moddir ]] ||
continue;
1310 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1311 -e $_moddir/module-setup.sh
]] ||
continue
1312 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1316 # Report any missing dracut modules, the user has specified
1317 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1318 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1319 for _mod
in $_modcheck; do
1320 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1321 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1322 derror
"dracut module '$_mod' cannot be found or installed."
1326 # Install a single kernel module along with any firmware it may require.
1327 # $1 = full path to kernel module to install
1328 install_kmod_with_fw
() {
1329 # no need to go further if the module is already installed
1331 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1334 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1335 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1339 if [[ $omit_drivers ]]; then
1340 local _kmod
=${1##*/}
1343 if [[ "$_kmod" =~
$omit_drivers ]]; then
1344 dinfo
"Omitting driver $_kmod"
1347 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1348 dinfo
"Omitting driver $_kmod"
1353 if [[ $silent_omit_drivers ]]; then
1354 local _kmod
=${1##*/}
1357 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1358 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1361 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1363 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1364 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1365 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1366 (($ret != 0)) && return $ret
1368 local _modname
=${1##*/} _fwdir _found _fw
1369 _modname
=${_modname%.ko*}
1370 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1372 for _fwdir
in $fw_dir; do
1373 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1374 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1378 if [[ $_found != yes ]]; then
1379 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1380 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1381 "\"${_modname}.ko\""
1383 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1384 "\"${_modname}.ko\""
1391 # Do something with all the dependencies of a kernel module.
1392 # Note that kernel modules depend on themselves using the technique we use
1393 # $1 = function to call for each dependency we find
1394 # It will be passed the full path to the found kernel module
1395 # $2 = module to get dependencies for
1396 # rest of args = arguments to modprobe
1397 # _fderr specifies FD passed from surrounding scope
1398 for_each_kmod_dep
() {
1399 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1401 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1402 while read _cmd _modpath _options
; do
1403 [[ $_cmd = insmod
]] ||
continue
1404 $_func ${_modpath} ||
exit $?
1409 dracut_kernel_post
() {
1410 local _moddirname
=${srcmods%%/lib/modules/*}
1413 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1414 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1415 --ignore-install --show-depends --set-version $kernel \
1416 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1418 |
while read _cmd _modpath _options
; do
1419 [[ $_cmd = insmod
]] ||
continue
1421 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1424 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1425 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1427 while read _modpath
; do
1428 local _destpath
=$_modpath
1429 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1430 _destpath
=${_destpath##*/lib/modules/$kernel/}
1431 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1432 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1435 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1438 if [[ $DRACUT_INSTALL ]]; then
1439 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1440 |
while read line
; do
1441 for _fwdir
in $fw_dir; do
1444 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1446 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1447 for _fwdir
in $fw_dir; do
1448 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1449 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1459 for _f
in modules.
builtin.bin modules.
builtin; do
1460 [[ $srcmods/$_f ]] && break
1462 dfatal
"No modules.builtin.bin and modules.builtin found!"
1466 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1467 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1470 # generate module dependencies for the initrd
1471 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1472 ! depmod
-a -b "$initdir" $kernel; then
1473 dfatal
"\"depmod -a $kernel\" failed."
1477 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1480 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1482 module_is_host_only
() {
1484 local _modenc a i _k _s _v _aliases
1487 _modenc
=${_mod//-/_}
1489 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1491 # check if module is loaded
1492 [[ ${host_modules["$_modenc"]} ]] && return 0
1494 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1496 if [[ "$kernel_current" != "$kernel" ]]; then
1497 # check if module is loadable on the current kernel
1498 # this covers the case, where a new module is introduced
1499 # or a module was renamed
1500 # or a module changed from builtin to a module
1502 if [[ -d /lib
/modules
/$kernel_current ]]; then
1503 # if the modinfo can be parsed, but the module
1504 # is not loaded, then we can safely return 1
1505 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1508 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1510 # if the module has no aliases, install it
1511 [[ $_aliases ]] ||
return 0
1513 # finally check all modalias
1514 for a
in $_aliases; do
1515 for i
in "${!host_modalias[@]}"; do
1516 [[ $i == $a ]] && return 0
1525 find_kernel_modules_by_path
() {
1528 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1532 while read a rest
; do
1533 [[ $a = */$1/* ]] ||
continue
1534 printf "%s\n" "$srcmods/$a"
1535 done < "$srcmods/modules.dep"
1540 find_kernel_modules
() {
1541 find_kernel_modules_by_path drivers
1544 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1545 # instmods [-c [-s]] <kernel subsystem>
1546 # install kernel modules along with all their dependencies.
1547 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1549 [[ $no_kernel = yes ]] && return
1550 # called [sub]functions inherit _fderr
1554 if [[ $1 = '-c' ]]; then
1559 if [[ $1 = '-s' ]]; then
1564 function inst1mod
() {
1565 local _ret
=0 _mod
="$1"
1568 ( [[ "$_mpargs" ]] && echo $_mpargs
1569 find_kernel_modules_by_path
"${_mod#=}" ) \
1573 --*) _mpargs
+=" $_mod" ;;
1576 # if we are already installed, skip this module and go on
1578 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1579 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1580 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1585 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1586 dinfo
"Omitting driver ${_mod##$srcmods}"
1590 # If we are building a host-specific initramfs and this
1591 # module is not already loaded, move on to the next one.
1593 && ! module_is_host_only
"$_mod" \
1596 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1597 # We use '-d' option in modprobe only if modules prefix path
1598 # differs from default '/'. This allows us to use dracut with
1599 # old version of modprobe which doesn't have '-d' option.
1600 local _moddirname
=${srcmods%%/lib/modules/*}
1601 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1603 # ok, load the module, all its dependencies, and any firmware
1605 for_each_kmod_dep install_kmod_with_fw
$_mod \
1606 --set-version $kernel ${_moddirname} $_mpargs
1609 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1610 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1617 function instmods_1
() {
1619 if (($# == 0)); then # filenames from stdin
1621 inst1mod
"${_mod%.ko*}" ||
{
1622 if [[ "$_check" == "yes" ]]; then
1623 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1629 while (($# > 0)); do # filenames as arguments
1630 inst1mod
${1%.ko*} ||
{
1631 if [[ "$_check" == "yes" ]]; then
1632 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1641 local _ret _filter_not_found
='FATAL: Module .* not found.'
1642 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1643 # redirections, but that would make dracut require bash4 at least.
1644 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1645 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1650 # Only two values are returned: AMD or Intel
1653 if grep -qE AMD
/proc
/cpuinfo
; then
1656 if grep -qE Intel
/proc
/cpuinfo
; then
1662 # Get the hosts' ucode file based on the /proc/cpuinfo
1665 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1666 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1667 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1669 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1670 # If family greater or equal than 0x15
1671 if [[ $family -ge 21 ]]; then
1672 printf "microcode_amd_fam15h.bin"
1674 printf "microcode_amd.bin"
1677 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1678 # The /proc/cpuinfo are in decimal.
1679 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1683 # Not every device in /dev/mapper should be examined.
1684 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1685 lvm_internal_dev
() {
1686 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1687 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1688 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1689 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1690 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1691 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]