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"* ]]; }
37 # Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
38 strglobin
() { [[ $1 = *$2* ]]; }
39 # Generic glob matching function. If glob pattern $2 matches all of $1, OK
40 strglob
() { [[ $1 = $2 ]]; }
42 # helper function for check() in module-setup.sh
43 # to check for required installed binaries
44 # issues a standardized warning message
46 local _module_name
="${moddir##*/}"
49 if [[ "$1" = "-m" ]]; then
55 if ! find_binary
"$cmd" &>/dev
/null
; then
56 dinfo
"dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
63 require_any_binary
() {
64 local _module_name
="${moddir##*/}"
67 if [[ "$1" = "-m" ]]; then
73 if find_binary
"$cmd" &>/dev
/null
; then
79 if (( $_ret != 0 )); then
80 dinfo
"$_module_name: Could not find any command of '$@'!"
87 # find a binary. If we were not passed the full path directly,
88 # search in the usual places to find the binary.
90 if [[ -z ${1##/*} ]]; then
91 if [[ -x $1 ]] ||
{ [[ "$1" == *.so
* ]] && ldd
"$1" &>/dev
/null
; }; then
100 if ! [[ $dracutbasedir ]]; then
101 dracutbasedir
=${BASH_SOURCE[0]%/*}
102 [[ $dracutbasedir = "dracut-functions" ]] && dracutbasedir
="."
103 [[ $dracutbasedir ]] || dracutbasedir
="."
104 dracutbasedir
="$(readlink -f $dracutbasedir)"
112 ldconfig
-pN 2>/dev
/null |
while read a b c d
; do
113 [[ "$c" != "=>" ]] && continue
114 printf "%s\n" ${d%/*};
117 [[ "$i" = "/lib" ||
"$i" = "/usr/lib" ||
"$i" = "/lib64" ||
"$i" = "/usr/lib64" ]] && continue
120 printf "%s\n" ${!a[@]}
124 if ! [[ $libdirs ]] ; then
125 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
126 && [[ -d /lib64
]]; then
128 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
131 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
134 libdirs
+=" $(ldconfig_paths)"
139 if ! [[ $kernel ]]; then
144 # Version comparision function. Assumes Linux style version scheme.
146 # $2 = comparision op (gt, ge, eq, le, lt, ne)
149 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
153 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
154 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
155 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
171 srcmods
="/lib/modules/$kernel/"
173 [[ $drivers_dir ]] && {
174 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
175 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
178 srcmods
="$drivers_dir"
182 if ! type dinfo
>/dev
/null
2>&1; then
183 .
"$dracutbasedir/dracut-logger.sh"
187 if ! [[ $initdir ]]; then
188 dfatal
"initdir not set"
192 # export standard hookdirs
194 hookdirs
="cmdline pre-udev pre-trigger netroot "
195 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
196 hookdirs
+="pre-mount pre-pivot cleanup mount "
197 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
201 dracut_need_initqueue
() {
202 >"$initdir/lib/dracut/need-initqueue"
205 dracut_module_included
() {
206 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
209 # Create all subdirectories for given path without creating the last element.
212 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
216 # Check whether $1 is a function.
218 [[ "$(type -t "$1")" = "function" ]]
221 # Function prints global variables in format name=value line by line.
222 # $@ = list of global variables' name
228 eval printf -v _value
"%s" \""\$$_var"\"
229 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
233 # normalize_path <path>
234 # Prints the normalized path, where it removes any duplicated
235 # and trailing slashes.
237 # $ normalize_path ///test/test//
241 set -- "${1//+(\/)//}"
243 printf "%s\n" "${1%/}"
246 # convert_abs_rel <from> <to>
247 # Prints the relative path, when creating a symlink to <to> from <from>.
249 # $ convert_abs_rel /usr/bin/test /bin/test-2
251 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
253 local __current __absolute __abssize __cursize __newpath
256 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
258 # corner case #1 - self looping link
259 [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
261 # corner case #2 - own dir link
262 [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
264 IFS
="/" __current
=($1)
265 IFS
="/" __absolute
=($2)
267 __abssize
=${#__absolute[@]}
268 __cursize
=${#__current[@]}
270 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
273 if (( __level
> __abssize || __level
> __cursize
))
279 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
283 __newpath
=$__newpath"/"
285 __newpath
=$__newpath".."
288 for ((__i
= __level
; __i
< __abssize
; __i
++))
290 if [[ -n $__newpath ]]
292 __newpath
=$__newpath"/"
294 __newpath
=$__newpath${__absolute[__i]}
297 printf "%s\n" "$__newpath"
300 if [[ "$(ln --help)" == *--relative* ]]; then
302 ln -sfnr "${initdir}/$1" "${initdir}/$2"
308 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
309 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
313 # get_fs_env <device>
314 # Get and the ID_FS_TYPE variable from udev for a device.
316 # $ get_fs_env /dev/sda2
324 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
325 |
while read line
; do
326 if [[ "$line" == TYPE\
=* ]]; then
327 printf "%s" "${line#TYPE=}";
331 if [[ $ID_FS_TYPE ]]; then
332 printf "%s" "$ID_FS_TYPE"
338 # get_maj_min <device>
339 # Prints the major and minor of a device node.
341 # $ get_maj_min /dev/sda2
344 local _maj _min _majmin
345 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
346 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
350 # get_devpath_block <device>
351 # get the DEVPATH in /sys of a block device
352 get_devpath_block
() {
354 _majmin
=$
(get_maj_min
"$1")
356 for _i
in /sys
/block
/*/dev
/sys
/block
/*/*/dev
; do
357 [[ -e "$_i" ]] ||
continue
358 if [[ "$_majmin" == "$(<"$_i")" ]]; then
359 printf "%s" "${_i%/dev}"
366 # get a persistent path from a device
367 get_persistent_dev
() {
370 _dev
=$
(get_maj_min
"$1")
371 [ -z "$_dev" ] && return
375 /dev
/disk
/${persistent_policy:-by-uuid}/* \
376 /dev
/disk
/by-uuid
/* \
377 /dev
/disk
/by-label
/* \
378 /dev
/disk
/by-partuuid
/* \
379 /dev
/disk
/by-partlabel
/* \
381 /dev
/disk
/by-path
/* \
383 [[ -e "$i" ]] ||
continue
384 [[ $i == /dev
/mapper
/control
]] && continue
385 [[ $i == /dev
/mapper
/mpath
* ]] && continue
386 _tmp
=$
(get_maj_min
"$i")
387 if [ "$_tmp" = "$_dev" ]; then
394 expand_persistent_dev
() {
399 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
404 _dev
="/dev/disk/by-uuid/${_dev}"
407 _dev
="${_dev#PARTUUID=}"
409 _dev
="/dev/disk/by-partuuid/${_dev}"
412 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
418 shorten_persistent_dev
() {
422 printf "%s" "UUID=${_dev##*/}";;
423 /dev
/disk
/by-label
/*)
424 printf "%s" "LABEL=${_dev##*/}";;
425 /dev
/disk
/by-partuuid
/*)
426 printf "%s" "PARTUUID=${_dev##*/}";;
427 /dev
/disk
/by-partlabel
/*)
428 printf "%s" "PARTLABEL=${_dev##*/}";;
430 printf "%s" "$_dev";;
434 # find_block_device <mountpoint>
435 # Prints the major and minor number of the block device
436 # for a given mountpoint.
437 # Unless $use_fstab is set to "yes" the functions
438 # uses /proc/self/mountinfo as the primary source of the
439 # information and only falls back to /etc/fstab, if the mountpoint
440 # is not found there.
442 # $ find_block_device /usr
444 find_block_device
() {
445 local _majmin _dev _majmin _find_mpt
447 if [[ $use_fstab != yes ]]; then
448 [[ -d $_find_mpt/.
]]
449 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
450 while read _majmin _dev
; do
451 if [[ -b $_dev ]]; then
452 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
453 _majmin
=$
(get_maj_min
$_dev)
455 if [[ $_majmin ]]; then
456 printf "%s\n" "$_majmin"
458 printf "%s\n" "$_dev"
462 if [[ $_dev = *:* ]]; then
463 printf "%s\n" "$_dev"
466 done; return 1; } && return 0
468 # fall back to /etc/fstab
470 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
471 while read _majmin _dev
; do
472 if ! [[ $_dev ]]; then
476 if [[ -b $_dev ]]; then
477 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
478 if [[ $_majmin ]]; then
479 printf "%s\n" "$_majmin"
481 printf "%s\n" "$_dev"
485 if [[ $_dev = *:* ]]; then
486 printf "%s\n" "$_dev"
489 done; return 1; } && return 0
494 # find_mp_fstype <mountpoint>
495 # Echo the filesystem type for a given mountpoint.
496 # /proc/self/mountinfo is taken as the primary source of information
497 # and /etc/fstab is used as a fallback.
498 # No newline is appended!
500 # $ find_mp_fstype /;echo
505 if [[ $use_fstab != yes ]]; then
506 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
508 [[ $_fs ]] ||
continue
509 [[ $_fs = "autofs" ]] && continue
512 done; return 1; } && return 0
515 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
517 [[ $_fs ]] ||
continue
518 [[ $_fs = "autofs" ]] && continue
521 done; return 1; } && return 0
526 # find_dev_fstype <device>
527 # Echo the filesystem type for a given device.
528 # /proc/self/mountinfo is taken as the primary source of information
529 # and /etc/fstab is used as a fallback.
530 # No newline is appended!
532 # $ find_dev_fstype /dev/sda2;echo
537 if ! [[ "$_find_dev" = /dev
* ]]; then
538 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
541 if [[ $use_fstab != yes ]]; then
542 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
544 [[ $_fs ]] ||
continue
545 [[ $_fs = "autofs" ]] && continue
548 done; return 1; } && return 0
551 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
553 [[ $_fs ]] ||
continue
554 [[ $_fs = "autofs" ]] && continue
557 done; return 1; } && return 0
562 # find_mp_fsopts <mountpoint>
563 # Echo the filesystem options for a given mountpoint.
564 # /proc/self/mountinfo is taken as the primary source of information
565 # and /etc/fstab is used as a fallback.
566 # No newline is appended!
568 # $ find_mp_fsopts /;echo
569 # rw,relatime,discard,data=ordered
571 if [[ $use_fstab != yes ]]; then
572 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
575 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
578 # find_dev_fsopts <device>
579 # Echo the filesystem options for a given device.
580 # /proc/self/mountinfo is taken as the primary source of information
581 # and /etc/fstab is used as a fallback.
583 # $ find_dev_fsopts /dev/sda2
584 # rw,relatime,discard,data=ordered
586 local _find_dev _opts
588 if ! [[ "$_find_dev" = /dev
* ]]; then
589 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
592 if [[ $use_fstab != yes ]]; then
593 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
596 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
600 # finds the major:minor of the block device backing the root filesystem.
601 find_root_block_device
() { find_block_device
/; }
603 # for_each_host_dev_fs <func>
604 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
605 # in ${host_fs_types[@]}
606 for_each_host_dev_fs
()
612 [[ "${!host_fs_types[@]}" ]] ||
return 0
614 for _dev
in "${!host_fs_types[@]}"; do
615 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
622 printf "%s\n" "${host_fs_types[@]}"
625 # Walk all the slave relationships for a given block device.
626 # Stop when our helper function returns success
627 # $1 = function to call on every found block device
628 # $2 = block device in major:minor format
629 check_block_and_slaves
() {
631 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
632 if ! lvm_internal_dev
$2; then "$1" $2 && return; fi
633 check_vol_slaves
"$@" && return 0
634 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
635 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
637 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
638 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
639 [[ -f $_x ]] ||
continue
640 check_block_and_slaves
$1 $
(<"$_x") && return 0
645 check_block_and_slaves_all
() {
647 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
648 if ! lvm_internal_dev
$2 && "$1" $2; then
651 check_vol_slaves
"$@" && return 0
652 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
653 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
655 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
656 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
657 [[ -f $_x ]] ||
continue
658 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
662 # for_each_host_dev_and_slaves <func>
663 # Execute "<func> <dev>" for every "<dev>" found
664 # in ${host_devs[@]} and their slaves
665 for_each_host_dev_and_slaves_all
()
671 [[ "${host_devs[@]}" ]] ||
return 0
673 for _dev
in ${host_devs[@]}; do
674 [[ -b "$_dev" ]] ||
continue
675 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
682 for_each_host_dev_and_slaves
()
687 [[ "${host_devs[@]}" ]] ||
return 0
689 for _dev
in ${host_devs[@]}; do
690 [[ -b "$_dev" ]] ||
continue
691 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
696 # ugly workaround for the lvm design
697 # There is no volume group device,
698 # so, there are no slave devices for volume groups.
699 # Logical volumes only have the slave devices they really live on,
700 # but you cannot create the logical volume without the volume group.
701 # And the volume group might be bigger than the devices the LV needs.
704 for i
in /dev
/mapper
/*; do
705 [[ $i == /dev
/mapper
/control
]] && continue
706 _lv
=$
(get_maj_min
$i)
707 if [[ $_lv = $2 ]]; then
708 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
710 _vg
=$
(printf "%s\n" "$_vg")
712 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
714 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
722 # fs_get_option <filesystem options> <search for option>
723 # search for a specific option in a bunch of filesystem options
724 # and return the value
732 while [ $# -gt 0 ]; do
735 echo ${1#${_option}=}
743 if ! [[ $DRACUT_INSTALL ]]; then
744 DRACUT_INSTALL
=$
(find_binary dracut-install
)
747 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
748 DRACUT_INSTALL
=$dracutbasedir/dracut-install
751 if ! [[ -x $DRACUT_INSTALL ]]; then
752 dfatal
"dracut-install not found!"
756 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
758 [[ -e ${initdir}/"$1" ]] && return 0 # already there
759 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
760 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
764 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
765 #dinfo "$DRACUT_INSTALL -l $@"
766 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
767 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
771 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
772 [[ -e $1 ]] ||
return 1 # no source
773 $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
774 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" ||
:
778 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
779 [[ -L $1 ]] ||
return 1
780 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
781 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
786 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
787 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
789 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
798 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
799 [[ -e $1 ]] ||
return 1 # no source
800 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
801 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
805 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
806 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
810 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
811 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
814 # find symlinks linked to given library file
816 # Function searches for symlinks by stripping version numbers appended to
817 # library filename, checks if it points to the same target and finally
818 # prints the list of symlinks to stdout.
821 # rev_lib_symlinks libfoo.so.8.1
822 # output: libfoo.so.8 libfoo.so
823 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
825 [[ ! $1 ]] && return 0
827 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
829 [[ ${fn} == *.so.
* ]] ||
return 1
831 until [[ ${fn##*.} == so
]]; do
833 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
839 # attempt to install any programs specified in a udev rule
840 inst_rule_programs() {
843 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
844 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
846 if [ -x ${udevdir}/$_prog ]; then
847 _bin=${udevdir}/$_prog
848 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
849 _bin=$(find_binary "$_prog") || {
850 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
855 [[ $_bin ]] && inst_binary "$_bin"
858 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
859 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
861 if [ -x ${udevdir}/$_prog ]; then
862 _bin=${udevdir}/$_prog
863 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
864 _bin=$(find_binary "$_prog") || {
865 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
870 [[ $_bin ]] && inst_binary "$_bin"
873 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
874 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
876 if [ -x ${udevdir}/$_prog ]; then
877 _bin=${udevdir}/$_prog
878 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
879 _bin=$(find_binary "$_prog") || {
880 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
885 [[ $_bin ]] && dracut_install "$_bin"
890 # attempt to install any programs specified in a udev rule
891 inst_rule_group_owner() {
894 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
895 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
896 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
897 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
901 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
902 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
903 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
904 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
910 inst_rule_initqueue() {
911 if grep -q -F initqueue "$1"; then
912 dracut_need_initqueue
916 # udev rules always get installed in the same place, so
917 # create a function to install them to make life simpler.
919 local _target=/etc/udev/rules.d _rule _found
921 inst_dir "${udevdir}/rules.d
"
923 for _rule in "$@
"; do
924 if [ "${_rule#/}" = "$_rule" ]; then
925 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
926 if [[ -e $r/$_rule ]]; then
928 inst_rule_programs "$_found"
929 inst_rule_group_owner "$_found"
930 inst_rule_initqueue "$_found"
931 inst_simple "$_found"
935 for r in '' $dracutbasedir/rules.d/; do
936 # skip rules without an absolute path
937 [[ "${r}$_rule" != /* ]] && continue
939 if [[ -f ${r}$_rule ]]; then
941 inst_rule_programs "$_found"
942 inst_rule_group_owner "$_found"
943 inst_rule_initqueue "$_found"
944 inst_simple "$_found" "$_target/${_found##*/}"
947 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
951 inst_rules_wildcard() {
952 local _target=/etc/udev/rules.d _rule _found
954 inst_dir "${udevdir}/rules.d
"
956 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
957 if [[ -e $_rule ]]; then
958 inst_rule_programs "$_rule"
959 inst_rule_group_owner "$_rule"
960 inst_rule_initqueue "$_rule"
965 if [ -n ${hostonly} ] ; then
966 for _rule in ${_target}/$1 ; do
967 if [[ -f $_rule ]]; then
968 inst_rule_programs "$_rule"
969 inst_rule_group_owner "$_rule"
970 inst_rule_initqueue "$_rule"
976 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
979 prepare_udev_rules() {
980 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
983 f="${initdir}/etc
/udev
/rules.d
/$f"
984 [ -e "$f" ] || continue
986 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
987 if [ $UDEVVERSION -ge 174 ]; then
988 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
990 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
992 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
993 if [ $UDEVVERSION -ge 176 ]; then
994 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
996 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1001 done < "${f}" > "${f}.new
"
1006 # install function specialized for hooks
1007 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1008 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1010 if ! [[ -f $3 ]]; then
1011 dfatal "Cannot
install a hook
($3) that does not exist.
"
1012 dfatal "Aborting initrd creation.
"
1014 elif ! [[ "$hookdirs" == *$1* ]]; then
1015 dfatal "No such hook
type $1. Aborting initrd creation.
"
1018 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1021 # install any of listed files
1023 # If first argument is '-d' and second some destination path, first accessible
1024 # source is installed into this path, otherwise it will installed in the same
1025 # path as source. If none of listed files was installed, function return 1.
1026 # On first successful installation it returns with 0 status.
1030 # inst_any -d /bin/foo /bin/bar /bin/baz
1032 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1037 [[ $1 = '-d' ]] && to="$2" && shift 2
1040 if [[ -e $f ]]; then
1041 [[ $to ]] && inst "$f" "$to" && return 0
1042 inst "$f" && return 0
1050 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1051 # Install a <file> located on a lib directory to the initramfs image
1052 # -n <pattern> install matching files
1053 inst_libdir_file() {
1055 if [[ "$1" == "-n" ]]; then
1058 for _dir in $libdirs; do
1060 for _f in "$_dir"/$_i; do
1061 [[ "$_f" =~ $_pattern ]] || continue
1062 [[ -e "$_f" ]] && _files+="$_f "
1067 for _dir in $libdirs; do
1069 for _f in "$_dir"/$_i; do
1070 [[ -e "$_f" ]] && _files+="$_f "
1075 [[ $_files ]] && inst_multiple $_files
1079 # install function decompressing the target and handling symlinks
1080 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1082 # Function install targets in the same paths inside overlay but decompressed
1083 # and without extensions (.gz, .bz2).
1090 *.gz) _cmd='gzip -f -d' ;;
1091 *.bz2) _cmd='bzip2 -d' ;;
1095 # Decompress with chosen tool. We assume that tool changes name e.g.
1096 # from 'name.gz' to 'name'.
1097 ${_cmd} "${initdir}${_src}"
1101 # It's similar to above, but if file is not compressed, performs standard
1103 # $@ = list of files
1104 inst_opt_decompress
() {
1109 inst_decompress
"${_src}" || inst
"${_src}"
1113 # module_check <dracut module>
1114 # execute the check() function of module-setup.sh of <dracut module>
1115 # or the "check" script, if module-setup.sh is not found
1116 # "check $hostonly" is called
1118 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1121 local _hostonly
=$hostonly
1122 [ $# -eq 2 ] && _forced
=$2
1123 [[ -d $_moddir ]] ||
return 1
1124 if [[ ! -f $_moddir/module-setup.sh
]]; then
1125 # if we do not have a check script, we are unconditionally included
1126 [[ -x $_moddir/check
]] ||
return 0
1127 [ $_forced -ne 0 ] && unset hostonly
1128 $_moddir/check
$hostonly
1131 unset check depends cmdline
install installkernel
1133 .
$_moddir/module-setup.sh
1134 is_func check ||
return 0
1135 [ $_forced -ne 0 ] && unset hostonly
1136 moddir
=$_moddir check
$hostonly
1138 unset check depends cmdline
install installkernel
1144 # module_check_mount <dracut module>
1145 # execute the check() function of module-setup.sh of <dracut module>
1146 # or the "check" script, if module-setup.sh is not found
1147 # "mount_needs=1 check 0" is called
1148 module_check_mount
() {
1149 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1152 [[ -d $_moddir ]] ||
return 1
1153 if [[ ! -f $_moddir/module-setup.sh
]]; then
1154 # if we do not have a check script, we are unconditionally included
1155 [[ -x $_moddir/check
]] ||
return 0
1156 mount_needs
=1 $_moddir/check
0
1159 unset check depends cmdline
install installkernel
1161 .
$_moddir/module-setup.sh
1162 moddir
=$_moddir check
0
1164 unset check depends cmdline
install installkernel
1170 # module_depends <dracut module>
1171 # execute the depends() function of module-setup.sh of <dracut module>
1172 # or the "depends" script, if module-setup.sh is not found
1174 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1176 [[ -d $_moddir ]] ||
return 1
1177 if [[ ! -f $_moddir/module-setup.sh
]]; then
1178 # if we do not have a check script, we have no deps
1179 [[ -x $_moddir/check
]] ||
return 0
1183 unset check depends cmdline
install installkernel
1185 .
$_moddir/module-setup.sh
1186 moddir
=$_moddir depends
1188 unset check depends cmdline
install installkernel
1193 # module_cmdline <dracut module>
1194 # execute the cmdline() function of module-setup.sh of <dracut module>
1195 # or the "cmdline" script, if module-setup.sh is not found
1197 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1199 [[ -d $_moddir ]] ||
return 1
1200 if [[ ! -f $_moddir/module-setup.sh
]]; then
1201 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1204 unset check depends cmdline
install installkernel
1206 .
$_moddir/module-setup.sh
1207 moddir
=$_moddir cmdline
1209 unset check depends cmdline
install installkernel
1214 # module_install <dracut module>
1215 # execute the install() function of module-setup.sh of <dracut module>
1216 # or the "install" script, if module-setup.sh is not found
1218 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1220 [[ -d $_moddir ]] ||
return 1
1221 if [[ ! -f $_moddir/module-setup.sh
]]; then
1222 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1225 unset check depends cmdline
install installkernel
1227 .
$_moddir/module-setup.sh
1228 moddir
=$_moddir install
1230 unset check depends cmdline
install installkernel
1235 # module_installkernel <dracut module>
1236 # execute the installkernel() function of module-setup.sh of <dracut module>
1237 # or the "installkernel" script, if module-setup.sh is not found
1238 module_installkernel
() {
1239 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1241 [[ -d $_moddir ]] ||
return 1
1242 if [[ ! -f $_moddir/module-setup.sh
]]; then
1243 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1246 unset check depends cmdline
install installkernel
1247 installkernel
() { true
; }
1248 .
$_moddir/module-setup.sh
1249 moddir
=$_moddir installkernel
1251 unset check depends cmdline
install installkernel
1256 # check_mount <dracut module>
1257 # check_mount checks, if a dracut module is needed for the given
1258 # device and filesystem types in "${host_fs_types[@]}"
1261 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1265 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1267 # If we are already scheduled to be loaded, no need to check again.
1268 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1269 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1271 # This should never happen, but...
1272 [[ -d $_moddir ]] ||
return 1
1274 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1276 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1280 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1281 module_check_mount
$_mod; ret
=$?
1283 # explicit module, so also accept ret=255
1284 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1286 # module not in our list
1287 if [[ $dracutmodules = all
]]; then
1288 # check, if we can and should install this module
1289 module_check_mount
$_mod ||
return 1
1297 for _moddep
in $
(module_depends
$_mod); do
1298 # handle deps as if they were manually added
1299 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1300 add_dracutmodules
+=" $_moddep "
1301 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1302 force_add_dracutmodules
+=" $_moddep "
1303 # if a module we depend on fail, fail also
1304 if ! check_module
$_moddep; then
1305 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1310 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1311 mods_to_load
+=" $_mod "
1316 # check_module <dracut module> [<use_as_dep>]
1317 # check if a dracut module is to be used in the initramfs process
1318 # if <use_as_dep> is set, then the process also keeps track
1319 # that the modules were checked for the dependency tracking process
1322 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1325 # If we are already scheduled to be loaded, no need to check again.
1326 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1327 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1329 # This should never happen, but...
1330 [[ -d $_moddir ]] ||
return 1
1332 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1334 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1335 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1339 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1340 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1341 module_check
$_mod 1; ret
=$?
1343 module_check
$_mod 0; ret
=$?
1345 # explicit module, so also accept ret=255
1346 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1348 # module not in our list
1349 if [[ $dracutmodules = all
]]; then
1350 # check, if we can and should install this module
1351 module_check
$_mod ||
return 1
1358 for _moddep
in $
(module_depends
$_mod); do
1359 # handle deps as if they were manually added
1360 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1361 add_dracutmodules
+=" $_moddep "
1362 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1363 force_add_dracutmodules
+=" $_moddep "
1364 # if a module we depend on fail, fail also
1365 if ! check_module
$_moddep; then
1366 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1371 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1372 mods_to_load
+=" $_mod "
1377 # for_each_module_dir <func>
1378 # execute "<func> <dracut module> 1"
1379 for_each_module_dir
() {
1385 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1386 [[ -d $_moddir ]] ||
continue;
1387 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1388 -e $_moddir/module-setup.sh
]] ||
continue
1389 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1393 # Report any missing dracut modules, the user has specified
1394 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1395 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1396 for _mod
in $_modcheck; do
1397 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1398 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1399 derror
"dracut module '$_mod' cannot be found or installed."
1403 # Install a single kernel module along with any firmware it may require.
1404 # $1 = full path to kernel module to install
1405 install_kmod_with_fw
() {
1406 # no need to go further if the module is already installed
1408 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1411 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1412 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1416 if [[ $omit_drivers ]]; then
1417 local _kmod
=${1##*/}
1420 if [[ "$_kmod" =~
$omit_drivers ]]; then
1421 dinfo
"Omitting driver $_kmod"
1424 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1425 dinfo
"Omitting driver $_kmod"
1430 if [[ $silent_omit_drivers ]]; then
1431 local _kmod
=${1##*/}
1434 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1435 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1438 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1440 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1441 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1442 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1443 (($ret != 0)) && return $ret
1445 local _modname
=${1##*/} _fwdir _found _fw
1446 _modname
=${_modname%.ko*}
1447 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1449 for _fwdir
in $fw_dir; do
1450 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1451 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1455 if [[ $_found != yes ]]; then
1456 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1457 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1458 "\"${_modname}.ko\""
1460 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1461 "\"${_modname}.ko\""
1468 # Do something with all the dependencies of a kernel module.
1469 # Note that kernel modules depend on themselves using the technique we use
1470 # $1 = function to call for each dependency we find
1471 # It will be passed the full path to the found kernel module
1472 # $2 = module to get dependencies for
1473 # rest of args = arguments to modprobe
1474 # _fderr specifies FD passed from surrounding scope
1475 for_each_kmod_dep
() {
1476 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1478 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1479 while read _cmd _modpath _options
; do
1480 [[ $_cmd = insmod
]] ||
continue
1481 $_func ${_modpath} ||
exit $?
1486 dracut_kernel_post
() {
1487 local _moddirname
=${srcmods%%/lib/modules/*}
1490 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1491 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1492 --ignore-install --show-depends --set-version $kernel \
1493 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1495 |
while read _cmd _modpath _options
; do
1496 [[ $_cmd = insmod
]] ||
continue
1498 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1501 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1502 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1504 while read _modpath
; do
1505 local _destpath
=$_modpath
1506 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1507 _destpath
=${_destpath##*/lib/modules/$kernel/}
1508 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1509 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1512 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1515 if [[ $DRACUT_INSTALL ]]; then
1516 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1517 |
while read line
; do
1518 for _fwdir
in $fw_dir; do
1521 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1523 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1524 for _fwdir
in $fw_dir; do
1525 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1526 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1536 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1537 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1540 # generate module dependencies for the initrd
1541 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1542 ! depmod
-a -b "$initdir" $kernel; then
1543 dfatal
"\"depmod -a $kernel\" failed."
1547 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1550 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1552 module_is_host_only
() {
1554 local _modenc a i _k _s _v _aliases
1557 _modenc
=${_mod//-/_}
1559 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1561 # check if module is loaded
1562 [[ ${host_modules["$_modenc"]} ]] && return 0
1564 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1566 if [[ "$kernel_current" != "$kernel" ]]; then
1567 # check if module is loadable on the current kernel
1568 # this covers the case, where a new module is introduced
1569 # or a module was renamed
1570 # or a module changed from builtin to a module
1572 if [[ -d /lib
/modules
/$kernel_current ]]; then
1573 # if the modinfo can be parsed, but the module
1574 # is not loaded, then we can safely return 1
1575 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1578 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1580 # if the module has no aliases, install it
1581 [[ $_aliases ]] ||
return 0
1583 # finally check all modalias
1584 for a
in $_aliases; do
1585 for i
in "${!host_modalias[@]}"; do
1586 [[ $i == $a ]] && return 0
1595 find_kernel_modules_by_path
() {
1598 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1602 while read a rest
; do
1603 [[ $a = */$1/* ]] ||
[[ $a = updates
/* ]] ||
continue
1604 printf "%s\n" "$srcmods/$a"
1605 done < "$srcmods/modules.dep"
1610 find_kernel_modules
() {
1611 find_kernel_modules_by_path drivers
1614 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1615 # instmods [-c [-s]] <kernel subsystem>
1616 # install kernel modules along with all their dependencies.
1617 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1619 [[ $no_kernel = yes ]] && return
1620 # called [sub]functions inherit _fderr
1624 if [[ $1 = '-c' ]]; then
1629 if [[ $1 = '-s' ]]; then
1634 function inst1mod
() {
1635 local _ret
=0 _mod
="$1"
1638 ( [[ "$_mpargs" ]] && echo $_mpargs
1639 find_kernel_modules_by_path
"${_mod#=}" ) \
1643 --*) _mpargs
+=" $_mod" ;;
1646 # if we are already installed, skip this module and go on
1648 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1649 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1650 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1655 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1656 dinfo
"Omitting driver ${_mod##$srcmods}"
1660 # If we are building a host-specific initramfs and this
1661 # module is not already loaded, move on to the next one.
1663 && ! module_is_host_only
"$_mod" \
1666 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1667 # We use '-d' option in modprobe only if modules prefix path
1668 # differs from default '/'. This allows us to use dracut with
1669 # old version of modprobe which doesn't have '-d' option.
1670 local _moddirname
=${srcmods%%/lib/modules/*}
1671 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1673 # ok, load the module, all its dependencies, and any firmware
1675 for_each_kmod_dep install_kmod_with_fw
$_mod \
1676 --set-version $kernel ${_moddirname} $_mpargs
1679 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1680 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1687 function instmods_1
() {
1689 if (($# == 0)); then # filenames from stdin
1691 inst1mod
"${_mod%.ko*}" ||
{
1692 if [[ "$_check" == "yes" ]]; then
1693 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1699 while (($# > 0)); do # filenames as arguments
1700 inst1mod
${1%.ko*} ||
{
1701 if [[ "$_check" == "yes" ]]; then
1702 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1711 local _ret _filter_not_found
='FATAL: Module .* not found.'
1712 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1713 # redirections, but that would make dracut require bash4 at least.
1714 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1715 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1720 # Only two values are returned: AMD or Intel
1723 if grep -qE AMD
/proc
/cpuinfo
; then
1726 if grep -qE Intel
/proc
/cpuinfo
; then
1732 # Get the hosts' ucode file based on the /proc/cpuinfo
1735 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1736 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1737 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1739 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1740 # If family greater or equal than 0x15
1741 if [[ $family -ge 21 ]]; then
1742 printf "microcode_amd_fam15h.bin"
1744 printf "microcode_amd.bin"
1747 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1748 # The /proc/cpuinfo are in decimal.
1749 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1753 # Not every device in /dev/mapper should be examined.
1754 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1755 lvm_internal_dev
() {
1756 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1757 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1758 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1759 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1760 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1761 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]