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 inst_rules_wildcard() {
903 local _target=/etc/udev/rules.d _rule _found
905 inst_dir "${udevdir}/rules.d
"
907 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
908 if [[ -e $_rule ]]; then
909 inst_rule_programs "$_rule"
910 inst_rule_group_owner "$_rule"
911 inst_rule_initqueue "$_rule"
916 if [ -n ${hostonly} ] ; then
917 for _rule in ${_target}/$1 ; do
918 if [[ -f $_rule ]]; then
919 inst_rule_programs "$_rule"
920 inst_rule_group_owner "$_rule"
921 inst_rule_initqueue "$_rule"
927 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
930 prepare_udev_rules() {
931 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
934 f="${initdir}/etc
/udev
/rules.d
/$f"
935 [ -e "$f" ] || continue
937 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
938 if [ $UDEVVERSION -ge 174 ]; then
939 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
941 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
943 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
944 if [ $UDEVVERSION -ge 176 ]; then
945 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
947 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
952 done < "${f}" > "${f}.new
"
957 # install function specialized for hooks
958 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
959 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
961 if ! [[ -f $3 ]]; then
962 dfatal "Cannot
install a hook
($3) that does not exist.
"
963 dfatal "Aborting initrd creation.
"
965 elif ! [[ "$hookdirs" == *$1* ]]; then
966 dfatal "No such hook
type $1. Aborting initrd creation.
"
969 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
972 # install any of listed files
974 # If first argument is '-d' and second some destination path, first accessible
975 # source is installed into this path, otherwise it will installed in the same
976 # path as source. If none of listed files was installed, function return 1.
977 # On first successful installation it returns with 0 status.
981 # inst_any -d /bin/foo /bin/bar /bin/baz
983 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
988 [[ $1 = '-d' ]] && to="$2" && shift 2
992 [[ $to ]] && inst "$f" "$to" && return 0
993 inst "$f" && return 0
1001 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1002 # Install a <file> located on a lib directory to the initramfs image
1003 # -n <pattern> install matching files
1004 inst_libdir_file() {
1006 if [[ "$1" == "-n" ]]; then
1009 for _dir in $libdirs; do
1011 for _f in "$_dir"/$_i; do
1012 [[ "$_f" =~ $_pattern ]] || continue
1013 [[ -e "$_f" ]] && _files+="$_f "
1018 for _dir in $libdirs; do
1020 for _f in "$_dir"/$_i; do
1021 [[ -e "$_f" ]] && _files+="$_f "
1026 [[ $_files ]] && inst_multiple $_files
1030 # install function decompressing the target and handling symlinks
1031 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1033 # Function install targets in the same paths inside overlay but decompressed
1034 # and without extensions (.gz, .bz2).
1041 *.gz) _cmd='gzip -f -d' ;;
1042 *.bz2) _cmd='bzip2 -d' ;;
1046 # Decompress with chosen tool. We assume that tool changes name e.g.
1047 # from 'name.gz' to 'name'.
1048 ${_cmd} "${initdir}${_src}"
1052 # It's similar to above, but if file is not compressed, performs standard
1054 # $@ = list of files
1055 inst_opt_decompress
() {
1060 inst_decompress
"${_src}" || inst
"${_src}"
1064 # module_check <dracut module>
1065 # execute the check() function of module-setup.sh of <dracut module>
1066 # or the "check" script, if module-setup.sh is not found
1067 # "check $hostonly" is called
1069 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1072 local _hostonly
=$hostonly
1073 [ $# -eq 2 ] && _forced
=$2
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 [ $_forced -ne 0 ] && unset hostonly
1079 $_moddir/check
$hostonly
1082 unset check depends cmdline
install installkernel
1084 .
$_moddir/module-setup.sh
1085 is_func check ||
return 0
1086 [ $_forced -ne 0 ] && unset hostonly
1089 unset check depends cmdline
install installkernel
1095 # module_check_mount <dracut module>
1096 # execute the check() function of module-setup.sh of <dracut module>
1097 # or the "check" script, if module-setup.sh is not found
1098 # "mount_needs=1 check 0" is called
1099 module_check_mount
() {
1100 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1103 [[ -d $_moddir ]] ||
return 1
1104 if [[ ! -f $_moddir/module-setup.sh
]]; then
1105 # if we do not have a check script, we are unconditionally included
1106 [[ -x $_moddir/check
]] ||
return 0
1107 mount_needs
=1 $_moddir/check
0
1110 unset check depends cmdline
install installkernel
1112 .
$_moddir/module-setup.sh
1115 unset check depends cmdline
install installkernel
1121 # module_depends <dracut module>
1122 # execute the depends() function of module-setup.sh of <dracut module>
1123 # or the "depends" script, if module-setup.sh is not found
1125 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1127 [[ -d $_moddir ]] ||
return 1
1128 if [[ ! -f $_moddir/module-setup.sh
]]; then
1129 # if we do not have a check script, we have no deps
1130 [[ -x $_moddir/check
]] ||
return 0
1134 unset check depends cmdline
install installkernel
1136 .
$_moddir/module-setup.sh
1139 unset check depends cmdline
install installkernel
1144 # module_cmdline <dracut module>
1145 # execute the cmdline() function of module-setup.sh of <dracut module>
1146 # or the "cmdline" script, if module-setup.sh is not found
1148 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1150 [[ -d $_moddir ]] ||
return 1
1151 if [[ ! -f $_moddir/module-setup.sh
]]; then
1152 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1155 unset check depends cmdline
install installkernel
1157 .
$_moddir/module-setup.sh
1160 unset check depends cmdline
install installkernel
1165 # module_install <dracut module>
1166 # execute the install() function of module-setup.sh of <dracut module>
1167 # or the "install" script, if module-setup.sh is not found
1169 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1171 [[ -d $_moddir ]] ||
return 1
1172 if [[ ! -f $_moddir/module-setup.sh
]]; then
1173 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1176 unset check depends cmdline
install installkernel
1178 .
$_moddir/module-setup.sh
1181 unset check depends cmdline
install installkernel
1186 # module_installkernel <dracut module>
1187 # execute the installkernel() function of module-setup.sh of <dracut module>
1188 # or the "installkernel" script, if module-setup.sh is not found
1189 module_installkernel
() {
1190 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1192 [[ -d $_moddir ]] ||
return 1
1193 if [[ ! -f $_moddir/module-setup.sh
]]; then
1194 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1197 unset check depends cmdline
install installkernel
1198 installkernel
() { true
; }
1199 .
$_moddir/module-setup.sh
1202 unset check depends cmdline
install installkernel
1207 # check_mount <dracut module>
1208 # check_mount checks, if a dracut module is needed for the given
1209 # device and filesystem types in "${host_fs_types[@]}"
1212 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1216 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1218 # If we are already scheduled to be loaded, no need to check again.
1219 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1220 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1222 # This should never happen, but...
1223 [[ -d $_moddir ]] ||
return 1
1225 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1227 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1231 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1232 module_check_mount
$_mod; ret
=$?
1234 # explicit module, so also accept ret=255
1235 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1237 # module not in our list
1238 if [[ $dracutmodules = all
]]; then
1239 # check, if we can and should install this module
1240 module_check_mount
$_mod ||
return 1
1248 for _moddep
in $
(module_depends
$_mod); do
1249 # handle deps as if they were manually added
1250 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1251 add_dracutmodules
+=" $_moddep "
1252 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1253 force_add_dracutmodules
+=" $_moddep "
1254 # if a module we depend on fail, fail also
1255 if ! check_module
$_moddep; then
1256 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1261 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1262 mods_to_load
+=" $_mod "
1267 # check_module <dracut module> [<use_as_dep>]
1268 # check if a dracut module is to be used in the initramfs process
1269 # if <use_as_dep> is set, then the process also keeps track
1270 # that the modules were checked for the dependency tracking process
1273 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1276 # If we are already scheduled to be loaded, no need to check again.
1277 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1278 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1280 # This should never happen, but...
1281 [[ -d $_moddir ]] ||
return 1
1283 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1285 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1286 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1290 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1291 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1292 module_check
$_mod 1; ret
=$?
1294 module_check
$_mod 0; ret
=$?
1296 # explicit module, so also accept ret=255
1297 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1299 # module not in our list
1300 if [[ $dracutmodules = all
]]; then
1301 # check, if we can and should install this module
1302 module_check
$_mod ||
return 1
1309 for _moddep
in $
(module_depends
$_mod); do
1310 # handle deps as if they were manually added
1311 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1312 add_dracutmodules
+=" $_moddep "
1313 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1314 force_add_dracutmodules
+=" $_moddep "
1315 # if a module we depend on fail, fail also
1316 if ! check_module
$_moddep; then
1317 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1322 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1323 mods_to_load
+=" $_mod "
1328 # for_each_module_dir <func>
1329 # execute "<func> <dracut module> 1"
1330 for_each_module_dir
() {
1336 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1337 [[ -d $_moddir ]] ||
continue;
1338 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1339 -e $_moddir/module-setup.sh
]] ||
continue
1340 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1344 # Report any missing dracut modules, the user has specified
1345 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1346 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1347 for _mod
in $_modcheck; do
1348 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1349 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1350 derror
"dracut module '$_mod' cannot be found or installed."
1354 # Install a single kernel module along with any firmware it may require.
1355 # $1 = full path to kernel module to install
1356 install_kmod_with_fw
() {
1357 # no need to go further if the module is already installed
1359 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1362 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1363 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1367 if [[ $omit_drivers ]]; then
1368 local _kmod
=${1##*/}
1371 if [[ "$_kmod" =~
$omit_drivers ]]; then
1372 dinfo
"Omitting driver $_kmod"
1375 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1376 dinfo
"Omitting driver $_kmod"
1381 if [[ $silent_omit_drivers ]]; then
1382 local _kmod
=${1##*/}
1385 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1386 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1389 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1391 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1392 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1393 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1394 (($ret != 0)) && return $ret
1396 local _modname
=${1##*/} _fwdir _found _fw
1397 _modname
=${_modname%.ko*}
1398 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1400 for _fwdir
in $fw_dir; do
1401 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1402 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1406 if [[ $_found != yes ]]; then
1407 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1408 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1409 "\"${_modname}.ko\""
1411 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1412 "\"${_modname}.ko\""
1419 # Do something with all the dependencies of a kernel module.
1420 # Note that kernel modules depend on themselves using the technique we use
1421 # $1 = function to call for each dependency we find
1422 # It will be passed the full path to the found kernel module
1423 # $2 = module to get dependencies for
1424 # rest of args = arguments to modprobe
1425 # _fderr specifies FD passed from surrounding scope
1426 for_each_kmod_dep
() {
1427 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1429 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1430 while read _cmd _modpath _options
; do
1431 [[ $_cmd = insmod
]] ||
continue
1432 $_func ${_modpath} ||
exit $?
1437 dracut_kernel_post
() {
1438 local _moddirname
=${srcmods%%/lib/modules/*}
1441 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1442 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1443 --ignore-install --show-depends --set-version $kernel \
1444 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1446 |
while read _cmd _modpath _options
; do
1447 [[ $_cmd = insmod
]] ||
continue
1449 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1452 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1453 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1455 while read _modpath
; do
1456 local _destpath
=$_modpath
1457 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1458 _destpath
=${_destpath##*/lib/modules/$kernel/}
1459 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1460 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1463 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1466 if [[ $DRACUT_INSTALL ]]; then
1467 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1468 |
while read line
; do
1469 for _fwdir
in $fw_dir; do
1472 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1474 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1475 for _fwdir
in $fw_dir; do
1476 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1477 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1487 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1488 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1491 # generate module dependencies for the initrd
1492 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1493 ! depmod
-a -b "$initdir" $kernel; then
1494 dfatal
"\"depmod -a $kernel\" failed."
1498 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1501 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1503 module_is_host_only
() {
1505 local _modenc a i _k _s _v _aliases
1508 _modenc
=${_mod//-/_}
1510 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1512 # check if module is loaded
1513 [[ ${host_modules["$_modenc"]} ]] && return 0
1515 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1517 if [[ "$kernel_current" != "$kernel" ]]; then
1518 # check if module is loadable on the current kernel
1519 # this covers the case, where a new module is introduced
1520 # or a module was renamed
1521 # or a module changed from builtin to a module
1523 if [[ -d /lib
/modules
/$kernel_current ]]; then
1524 # if the modinfo can be parsed, but the module
1525 # is not loaded, then we can safely return 1
1526 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1529 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1531 # if the module has no aliases, install it
1532 [[ $_aliases ]] ||
return 0
1534 # finally check all modalias
1535 for a
in $_aliases; do
1536 for i
in "${!host_modalias[@]}"; do
1537 [[ $i == $a ]] && return 0
1546 find_kernel_modules_by_path
() {
1549 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1553 while read a rest
; do
1554 [[ $a = */$1/* ]] ||
continue
1555 printf "%s\n" "$srcmods/$a"
1556 done < "$srcmods/modules.dep"
1561 find_kernel_modules
() {
1562 find_kernel_modules_by_path drivers
1565 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1566 # instmods [-c [-s]] <kernel subsystem>
1567 # install kernel modules along with all their dependencies.
1568 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1570 [[ $no_kernel = yes ]] && return
1571 # called [sub]functions inherit _fderr
1575 if [[ $1 = '-c' ]]; then
1580 if [[ $1 = '-s' ]]; then
1585 function inst1mod
() {
1586 local _ret
=0 _mod
="$1"
1589 ( [[ "$_mpargs" ]] && echo $_mpargs
1590 find_kernel_modules_by_path
"${_mod#=}" ) \
1594 --*) _mpargs
+=" $_mod" ;;
1597 # if we are already installed, skip this module and go on
1599 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1600 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1601 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1606 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1607 dinfo
"Omitting driver ${_mod##$srcmods}"
1611 # If we are building a host-specific initramfs and this
1612 # module is not already loaded, move on to the next one.
1614 && ! module_is_host_only
"$_mod" \
1617 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1618 # We use '-d' option in modprobe only if modules prefix path
1619 # differs from default '/'. This allows us to use dracut with
1620 # old version of modprobe which doesn't have '-d' option.
1621 local _moddirname
=${srcmods%%/lib/modules/*}
1622 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1624 # ok, load the module, all its dependencies, and any firmware
1626 for_each_kmod_dep install_kmod_with_fw
$_mod \
1627 --set-version $kernel ${_moddirname} $_mpargs
1630 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1631 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1638 function instmods_1
() {
1640 if (($# == 0)); then # filenames from stdin
1642 inst1mod
"${_mod%.ko*}" ||
{
1643 if [[ "$_check" == "yes" ]]; then
1644 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1650 while (($# > 0)); do # filenames as arguments
1651 inst1mod
${1%.ko*} ||
{
1652 if [[ "$_check" == "yes" ]]; then
1653 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1662 local _ret _filter_not_found
='FATAL: Module .* not found.'
1663 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1664 # redirections, but that would make dracut require bash4 at least.
1665 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1666 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1671 # Only two values are returned: AMD or Intel
1674 if grep -qE AMD
/proc
/cpuinfo
; then
1677 if grep -qE Intel
/proc
/cpuinfo
; then
1683 # Get the hosts' ucode file based on the /proc/cpuinfo
1686 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1687 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1688 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1690 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1691 # If family greater or equal than 0x15
1692 if [[ $family -ge 21 ]]; then
1693 printf "microcode_amd_fam15h.bin"
1695 printf "microcode_amd.bin"
1698 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1699 # The /proc/cpuinfo are in decimal.
1700 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1704 # Not every device in /dev/mapper should be examined.
1705 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1706 lvm_internal_dev
() {
1707 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1708 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1709 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1710 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1711 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1712 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]