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 # helper function for check() in module-setup.sh
39 # to check for required installed binaries
40 # issues a standardized warning message
42 local _module_name
="${moddir##*/}"
45 if [[ "$1" = "-m" ]]; then
51 if ! find_binary
"$cmd" &>/dev
/null
; then
52 dwarning
"$_module_name: Could not find command '$cmd'!"
59 require_any_binary
() {
60 local _module_name
="${moddir##*/}"
63 if [[ "$1" = "-m" ]]; then
69 if find_binary
"$cmd" &>/dev
/null
; then
75 if (( $_ret != 0 )); then
76 dwarning
"$_module_name: Could not find any command of '$@'!"
83 # find a binary. If we were not passed the full path directly,
84 # search in the usual places to find the binary.
86 if [[ -z ${1##/*} ]]; then
87 if [[ -x $1 ]] ||
{ [[ "$1" == *.so
* ]] && ldd
"$1" &>/dev
/null
; }; then
96 if ! [[ $dracutbasedir ]]; then
97 dracutbasedir
=${BASH_SOURCE[0]%/*}
98 [[ $dracutbasedir = "dracut-functions" ]] && dracutbasedir
="."
99 [[ $dracutbasedir ]] || dracutbasedir
="."
100 dracutbasedir
="$(readlink -f $dracutbasedir)"
108 ldconfig
-pN 2>/dev
/null |
while read a b c d
; do
109 [[ "$c" != "=>" ]] && continue
110 printf "%s\n" ${d%/*};
113 [[ "$i" = "/lib" ||
"$i" = "/usr/lib" ||
"$i" = "/lib64" ||
"$i" = "/usr/lib64" ]] && continue
116 printf "%s\n" ${!a[@]}
120 if ! [[ $libdirs ]] ; then
121 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
122 && [[ -d /lib64
]]; then
124 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
127 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
130 libdirs
+=" $(ldconfig_paths)"
135 if ! [[ $kernel ]]; then
140 # Version comparision function. Assumes Linux style version scheme.
142 # $2 = comparision op (gt, ge, eq, le, lt, ne)
145 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
149 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
150 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
151 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
167 srcmods
="/lib/modules/$kernel/"
169 [[ $drivers_dir ]] && {
170 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
171 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
174 srcmods
="$drivers_dir"
178 if ! type dinfo
>/dev
/null
2>&1; then
179 .
"$dracutbasedir/dracut-logger.sh"
183 if ! [[ $initdir ]]; then
184 dfatal
"initdir not set"
188 # export standard hookdirs
190 hookdirs
="cmdline pre-udev pre-trigger netroot "
191 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
192 hookdirs
+="pre-mount pre-pivot cleanup mount "
193 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
197 dracut_need_initqueue
() {
198 >"$initdir/lib/dracut/need-initqueue"
201 dracut_module_included
() {
202 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
205 # Create all subdirectories for given path without creating the last element.
208 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
212 # Check whether $1 is a function.
214 [[ "$(type -t "$1")" = "function" ]]
217 # Function prints global variables in format name=value line by line.
218 # $@ = list of global variables' name
224 eval printf -v _value
"%s" "\$$_var"
225 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
229 # normalize_path <path>
230 # Prints the normalized path, where it removes any duplicated
231 # and trailing slashes.
233 # $ normalize_path ///test/test//
237 set -- "${1//+(\/)//}"
239 printf "%s\n" "${1%/}"
242 # convert_abs_rel <from> <to>
243 # Prints the relative path, when creating a symlink to <to> from <from>.
245 # $ convert_abs_rel /usr/bin/test /bin/test-2
247 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
249 local __current __absolute __abssize __cursize __newpath
252 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
254 # corner case #1 - self looping link
255 [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
257 # corner case #2 - own dir link
258 [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
260 IFS
="/" __current
=($1)
261 IFS
="/" __absolute
=($2)
263 __abssize
=${#__absolute[@]}
264 __cursize
=${#__current[@]}
266 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
269 if (( __level
> __abssize || __level
> __cursize
))
275 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
279 __newpath
=$__newpath"/"
281 __newpath
=$__newpath".."
284 for ((__i
= __level
; __i
< __abssize
; __i
++))
286 if [[ -n $__newpath ]]
288 __newpath
=$__newpath"/"
290 __newpath
=$__newpath${__absolute[__i]}
293 printf "%s\n" "$__newpath"
296 if [[ "$(ln --help)" == *--relative* ]]; then
298 ln -sfnr "${initdir}/$1" "${initdir}/$2"
304 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
305 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
309 # get_fs_env <device>
310 # Get and the ID_FS_TYPE variable from udev for a device.
312 # $ get_fs_env /dev/sda2
320 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
321 |
while read line
; do
322 if [[ "$line" == TYPE\
=* ]]; then
323 printf "%s" "${line#TYPE=}";
327 if [[ $ID_FS_TYPE ]]; then
328 printf "%s" "$ID_FS_TYPE"
334 # get_maj_min <device>
335 # Prints the major and minor of a device node.
337 # $ get_maj_min /dev/sda2
340 local _maj _min _majmin
341 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
342 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
346 # get_devpath_block <device>
347 # get the DEVPATH in /sys of a block device
348 get_devpath_block
() {
350 _majmin
=$
(get_maj_min
"$1")
352 for _i
in /sys
/block
/*/dev
/sys
/block
/*/*/dev
; do
353 [[ -e "$_i" ]] ||
continue
354 if [[ "$_majmin" == "$(<"$_i")" ]]; then
355 printf "%s" "${_i%/dev}"
362 # get a persistent path from a device
363 get_persistent_dev
() {
366 _dev
=$
(get_maj_min
"$1")
367 [ -z "$_dev" ] && return
371 /dev
/disk
/${persistent_policy:-by-uuid}/* \
372 /dev
/disk
/by-uuid
/* \
373 /dev
/disk
/by-label
/* \
374 /dev
/disk
/by-partuuid
/* \
375 /dev
/disk
/by-partlabel
/* \
377 /dev
/disk
/by-path
/* \
379 [[ -e "$i" ]] ||
continue
380 [[ $i == /dev
/mapper
/control
]] && continue
381 [[ $i == /dev
/mapper
/mpath
* ]] && continue
382 _tmp
=$
(get_maj_min
"$i")
383 if [ "$_tmp" = "$_dev" ]; then
390 expand_persistent_dev
() {
395 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
400 _dev
="/dev/disk/by-uuid/${_dev}"
403 _dev
="${_dev#PARTUUID=}"
405 _dev
="/dev/disk/by-partuuid/${_dev}"
408 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
414 shorten_persistent_dev
() {
418 printf "%s" "UUID=${_dev##*/}";;
419 /dev
/disk
/by-label
/*)
420 printf "%s" "LABEL=${_dev##*/}";;
421 /dev
/disk
/by-partuuid
/*)
422 printf "%s" "PARTUUID=${_dev##*/}";;
423 /dev
/disk
/by-partlabel
/*)
424 printf "%s" "PARTLABEL=${_dev##*/}";;
426 printf "%s" "$_dev";;
430 # find_block_device <mountpoint>
431 # Prints the major and minor number of the block device
432 # for a given mountpoint.
433 # Unless $use_fstab is set to "yes" the functions
434 # uses /proc/self/mountinfo as the primary source of the
435 # information and only falls back to /etc/fstab, if the mountpoint
436 # is not found there.
438 # $ find_block_device /usr
440 find_block_device
() {
441 local _majmin _dev _majmin _find_mpt
443 if [[ $use_fstab != yes ]]; then
444 [[ -d $_find_mpt/.
]]
445 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
446 while read _majmin _dev
; do
447 if [[ -b $_dev ]]; then
448 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
449 _majmin
=$
(get_maj_min
$_dev)
451 if [[ $_majmin ]]; then
452 printf "%s\n" "$_majmin"
454 printf "%s\n" "$_dev"
458 if [[ $_dev = *:* ]]; then
459 printf "%s\n" "$_dev"
462 done; return 1; } && return 0
464 # fall back to /etc/fstab
466 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
467 while read _majmin _dev
; do
468 if ! [[ $_dev ]]; then
472 if [[ -b $_dev ]]; then
473 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
474 if [[ $_majmin ]]; then
475 printf "%s\n" "$_majmin"
477 printf "%s\n" "$_dev"
481 if [[ $_dev = *:* ]]; then
482 printf "%s\n" "$_dev"
485 done; return 1; } && return 0
490 # find_mp_fstype <mountpoint>
491 # Echo the filesystem type for a given mountpoint.
492 # /proc/self/mountinfo is taken as the primary source of information
493 # and /etc/fstab is used as a fallback.
494 # No newline is appended!
496 # $ find_mp_fstype /;echo
501 if [[ $use_fstab != yes ]]; then
502 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
504 [[ $_fs ]] ||
continue
505 [[ $_fs = "autofs" ]] && continue
508 done; return 1; } && return 0
511 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
513 [[ $_fs ]] ||
continue
514 [[ $_fs = "autofs" ]] && continue
517 done; return 1; } && return 0
522 # find_dev_fstype <device>
523 # Echo the filesystem type for a given device.
524 # /proc/self/mountinfo is taken as the primary source of information
525 # and /etc/fstab is used as a fallback.
526 # No newline is appended!
528 # $ find_dev_fstype /dev/sda2;echo
533 if ! [[ "$_find_dev" = /dev
* ]]; then
534 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
537 if [[ $use_fstab != yes ]]; then
538 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
540 [[ $_fs ]] ||
continue
541 [[ $_fs = "autofs" ]] && continue
544 done; return 1; } && return 0
547 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
549 [[ $_fs ]] ||
continue
550 [[ $_fs = "autofs" ]] && continue
553 done; return 1; } && return 0
558 # find_mp_fsopts <mountpoint>
559 # Echo the filesystem options for a given mountpoint.
560 # /proc/self/mountinfo is taken as the primary source of information
561 # and /etc/fstab is used as a fallback.
562 # No newline is appended!
564 # $ find_mp_fsopts /;echo
565 # rw,relatime,discard,data=ordered
567 if [[ $use_fstab != yes ]]; then
568 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
571 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
574 # find_dev_fsopts <device>
575 # Echo the filesystem options for a given device.
576 # /proc/self/mountinfo is taken as the primary source of information
577 # and /etc/fstab is used as a fallback.
579 # $ find_dev_fsopts /dev/sda2
580 # rw,relatime,discard,data=ordered
582 local _find_dev _opts
584 if ! [[ "$_find_dev" = /dev
* ]]; then
585 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
588 if [[ $use_fstab != yes ]]; then
589 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
592 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
596 # finds the major:minor of the block device backing the root filesystem.
597 find_root_block_device
() { find_block_device
/; }
599 # for_each_host_dev_fs <func>
600 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
601 # in ${host_fs_types[@]}
602 for_each_host_dev_fs
()
608 [[ "${!host_fs_types[@]}" ]] ||
return 0
610 for _dev
in "${!host_fs_types[@]}"; do
611 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
618 printf "%s\n" "${host_fs_types[@]}"
621 # Walk all the slave relationships for a given block device.
622 # Stop when our helper function returns success
623 # $1 = function to call on every found block device
624 # $2 = block device in major:minor format
625 check_block_and_slaves
() {
627 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
628 if ! lvm_internal_dev
$2; then "$1" $2 && return; fi
629 check_vol_slaves
"$@" && return 0
630 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
631 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
633 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
634 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
635 [[ -f $_x ]] ||
continue
636 check_block_and_slaves
$1 $
(<"$_x") && return 0
641 check_block_and_slaves_all
() {
643 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
644 if ! lvm_internal_dev
$2 && "$1" $2; then
647 check_vol_slaves
"$@" && return 0
648 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
649 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
651 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
652 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
653 [[ -f $_x ]] ||
continue
654 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
658 # for_each_host_dev_and_slaves <func>
659 # Execute "<func> <dev>" for every "<dev>" found
660 # in ${host_devs[@]} and their slaves
661 for_each_host_dev_and_slaves_all
()
667 [[ "${host_devs[@]}" ]] ||
return 0
669 for _dev
in ${host_devs[@]}; do
670 [[ -b "$_dev" ]] ||
continue
671 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
678 for_each_host_dev_and_slaves
()
683 [[ "${host_devs[@]}" ]] ||
return 0
685 for _dev
in ${host_devs[@]}; do
686 [[ -b "$_dev" ]] ||
continue
687 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
692 # ugly workaround for the lvm design
693 # There is no volume group device,
694 # so, there are no slave devices for volume groups.
695 # Logical volumes only have the slave devices they really live on,
696 # but you cannot create the logical volume without the volume group.
697 # And the volume group might be bigger than the devices the LV needs.
700 for i
in /dev
/mapper
/*; do
701 [[ $i == /dev
/mapper
/control
]] && continue
702 _lv
=$
(get_maj_min
$i)
703 if [[ $_lv = $2 ]]; then
704 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
706 _vg
=$
(printf "%s\n" "$_vg")
708 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
710 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
718 # fs_get_option <filesystem options> <search for option>
719 # search for a specific option in a bunch of filesystem options
720 # and return the value
728 while [ $# -gt 0 ]; do
731 echo ${1#${_option}=}
739 if ! [[ $DRACUT_INSTALL ]]; then
740 DRACUT_INSTALL
=$
(find_binary dracut-install
)
743 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
744 DRACUT_INSTALL
=$dracutbasedir/dracut-install
747 if ! [[ -x $DRACUT_INSTALL ]]; then
748 dfatal
"dracut-install not found!"
752 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
754 [[ -e ${initdir}/"$1" ]] && return 0 # already there
755 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
756 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
760 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
761 #dinfo "$DRACUT_INSTALL -l $@"
762 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
763 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
767 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
768 [[ -e $1 ]] ||
return 1 # no source
769 $DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@"
770 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} "$@" ||
:
774 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
775 [[ -L $1 ]] ||
return 1
776 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
777 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
782 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
783 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
785 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
794 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
795 [[ -e $1 ]] ||
return 1 # no source
796 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
797 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
801 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
802 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
806 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@"
807 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-H} "$@" ||
:
810 # find symlinks linked to given library file
812 # Function searches for symlinks by stripping version numbers appended to
813 # library filename, checks if it points to the same target and finally
814 # prints the list of symlinks to stdout.
817 # rev_lib_symlinks libfoo.so.8.1
818 # output: libfoo.so.8 libfoo.so
819 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
821 [[ ! $1 ]] && return 0
823 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
825 [[ ${fn} == *.so.
* ]] ||
return 1
827 until [[ ${fn##*.} == so
]]; do
829 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
835 # attempt to install any programs specified in a udev rule
836 inst_rule_programs() {
839 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
840 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
842 if [ -x ${udevdir}/$_prog ]; then
843 _bin=${udevdir}/$_prog
844 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
845 _bin=$(find_binary "$_prog") || {
846 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
851 [[ $_bin ]] && inst_binary "$_bin"
854 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
855 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
857 if [ -x ${udevdir}/$_prog ]; then
858 _bin=${udevdir}/$_prog
859 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
860 _bin=$(find_binary "$_prog") || {
861 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
866 [[ $_bin ]] && inst_binary "$_bin"
869 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
870 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
872 if [ -x ${udevdir}/$_prog ]; then
873 _bin=${udevdir}/$_prog
874 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
875 _bin=$(find_binary "$_prog") || {
876 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
881 [[ $_bin ]] && dracut_install "$_bin"
886 # attempt to install any programs specified in a udev rule
887 inst_rule_group_owner() {
890 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
891 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
892 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
893 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
897 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
898 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
899 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
900 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
906 inst_rule_initqueue() {
907 if grep -q -F initqueue "$1"; then
908 dracut_need_initqueue
912 # udev rules always get installed in the same place, so
913 # create a function to install them to make life simpler.
915 local _target=/etc/udev/rules.d _rule _found
917 inst_dir "${udevdir}/rules.d
"
919 for _rule in "$@
"; do
920 if [ "${_rule#/}" = "$_rule" ]; then
921 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
922 if [[ -e $r/$_rule ]]; then
924 inst_rule_programs "$_found"
925 inst_rule_group_owner "$_found"
926 inst_rule_initqueue "$_found"
927 inst_simple "$_found"
931 for r in '' $dracutbasedir/rules.d/; do
932 # skip rules without an absolute path
933 [[ "${r}$_rule" != /* ]] && continue
935 if [[ -f ${r}$_rule ]]; then
937 inst_rule_programs "$_found"
938 inst_rule_group_owner "$_found"
939 inst_rule_initqueue "$_found"
940 inst_simple "$_found" "$_target/${_found##*/}"
943 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
947 inst_rules_wildcard() {
948 local _target=/etc/udev/rules.d _rule _found
950 inst_dir "${udevdir}/rules.d
"
952 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
953 if [[ -e $_rule ]]; then
954 inst_rule_programs "$_rule"
955 inst_rule_group_owner "$_rule"
956 inst_rule_initqueue "$_rule"
961 if [ -n ${hostonly} ] ; then
962 for _rule in ${_target}/$1 ; do
963 if [[ -f $_rule ]]; then
964 inst_rule_programs "$_rule"
965 inst_rule_group_owner "$_rule"
966 inst_rule_initqueue "$_rule"
972 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
975 prepare_udev_rules() {
976 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
979 f="${initdir}/etc
/udev
/rules.d
/$f"
980 [ -e "$f" ] || continue
982 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
983 if [ $UDEVVERSION -ge 174 ]; then
984 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
986 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
988 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
989 if [ $UDEVVERSION -ge 176 ]; then
990 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
992 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
997 done < "${f}" > "${f}.new
"
1002 # install function specialized for hooks
1003 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1004 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1006 if ! [[ -f $3 ]]; then
1007 dfatal "Cannot
install a hook
($3) that does not exist.
"
1008 dfatal "Aborting initrd creation.
"
1010 elif ! [[ "$hookdirs" == *$1* ]]; then
1011 dfatal "No such hook
type $1. Aborting initrd creation.
"
1014 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1017 # install any of listed files
1019 # If first argument is '-d' and second some destination path, first accessible
1020 # source is installed into this path, otherwise it will installed in the same
1021 # path as source. If none of listed files was installed, function return 1.
1022 # On first successful installation it returns with 0 status.
1026 # inst_any -d /bin/foo /bin/bar /bin/baz
1028 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1033 [[ $1 = '-d' ]] && to="$2" && shift 2
1036 if [[ -e $f ]]; then
1037 [[ $to ]] && inst "$f" "$to" && return 0
1038 inst "$f" && return 0
1046 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1047 # Install a <file> located on a lib directory to the initramfs image
1048 # -n <pattern> install matching files
1049 inst_libdir_file() {
1051 if [[ "$1" == "-n" ]]; then
1054 for _dir in $libdirs; do
1056 for _f in "$_dir"/$_i; do
1057 [[ "$_f" =~ $_pattern ]] || continue
1058 [[ -e "$_f" ]] && _files+="$_f "
1063 for _dir in $libdirs; do
1065 for _f in "$_dir"/$_i; do
1066 [[ -e "$_f" ]] && _files+="$_f "
1071 [[ $_files ]] && inst_multiple $_files
1075 # install function decompressing the target and handling symlinks
1076 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1078 # Function install targets in the same paths inside overlay but decompressed
1079 # and without extensions (.gz, .bz2).
1086 *.gz) _cmd='gzip -f -d' ;;
1087 *.bz2) _cmd='bzip2 -d' ;;
1091 # Decompress with chosen tool. We assume that tool changes name e.g.
1092 # from 'name.gz' to 'name'.
1093 ${_cmd} "${initdir}${_src}"
1097 # It's similar to above, but if file is not compressed, performs standard
1099 # $@ = list of files
1100 inst_opt_decompress
() {
1105 inst_decompress
"${_src}" || inst
"${_src}"
1109 # module_check <dracut module>
1110 # execute the check() function of module-setup.sh of <dracut module>
1111 # or the "check" script, if module-setup.sh is not found
1112 # "check $hostonly" is called
1114 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1117 local _hostonly
=$hostonly
1118 [ $# -eq 2 ] && _forced
=$2
1119 [[ -d $_moddir ]] ||
return 1
1120 if [[ ! -f $_moddir/module-setup.sh
]]; then
1121 # if we do not have a check script, we are unconditionally included
1122 [[ -x $_moddir/check
]] ||
return 0
1123 [ $_forced -ne 0 ] && unset hostonly
1124 $_moddir/check
$hostonly
1127 unset check depends cmdline
install installkernel
1129 .
$_moddir/module-setup.sh
1130 is_func check ||
return 0
1131 [ $_forced -ne 0 ] && unset hostonly
1132 moddir
=$_moddir check
$hostonly
1134 unset check depends cmdline
install installkernel
1140 # module_check_mount <dracut module>
1141 # execute the check() function of module-setup.sh of <dracut module>
1142 # or the "check" script, if module-setup.sh is not found
1143 # "mount_needs=1 check 0" is called
1144 module_check_mount
() {
1145 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1148 [[ -d $_moddir ]] ||
return 1
1149 if [[ ! -f $_moddir/module-setup.sh
]]; then
1150 # if we do not have a check script, we are unconditionally included
1151 [[ -x $_moddir/check
]] ||
return 0
1152 mount_needs
=1 $_moddir/check
0
1155 unset check depends cmdline
install installkernel
1157 .
$_moddir/module-setup.sh
1158 moddir
=$_moddir check
0
1160 unset check depends cmdline
install installkernel
1166 # module_depends <dracut module>
1167 # execute the depends() function of module-setup.sh of <dracut module>
1168 # or the "depends" script, if module-setup.sh is not found
1170 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1172 [[ -d $_moddir ]] ||
return 1
1173 if [[ ! -f $_moddir/module-setup.sh
]]; then
1174 # if we do not have a check script, we have no deps
1175 [[ -x $_moddir/check
]] ||
return 0
1179 unset check depends cmdline
install installkernel
1181 .
$_moddir/module-setup.sh
1182 moddir
=$_moddir depends
1184 unset check depends cmdline
install installkernel
1189 # module_cmdline <dracut module>
1190 # execute the cmdline() function of module-setup.sh of <dracut module>
1191 # or the "cmdline" script, if module-setup.sh is not found
1193 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1195 [[ -d $_moddir ]] ||
return 1
1196 if [[ ! -f $_moddir/module-setup.sh
]]; then
1197 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1200 unset check depends cmdline
install installkernel
1202 .
$_moddir/module-setup.sh
1203 moddir
=$_moddir cmdline
1205 unset check depends cmdline
install installkernel
1210 # module_install <dracut module>
1211 # execute the install() function of module-setup.sh of <dracut module>
1212 # or the "install" script, if module-setup.sh is not found
1214 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1216 [[ -d $_moddir ]] ||
return 1
1217 if [[ ! -f $_moddir/module-setup.sh
]]; then
1218 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1221 unset check depends cmdline
install installkernel
1223 .
$_moddir/module-setup.sh
1224 moddir
=$_moddir install
1226 unset check depends cmdline
install installkernel
1231 # module_installkernel <dracut module>
1232 # execute the installkernel() function of module-setup.sh of <dracut module>
1233 # or the "installkernel" script, if module-setup.sh is not found
1234 module_installkernel
() {
1235 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1237 [[ -d $_moddir ]] ||
return 1
1238 if [[ ! -f $_moddir/module-setup.sh
]]; then
1239 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1242 unset check depends cmdline
install installkernel
1243 installkernel
() { true
; }
1244 .
$_moddir/module-setup.sh
1245 moddir
=$_moddir installkernel
1247 unset check depends cmdline
install installkernel
1252 # check_mount <dracut module>
1253 # check_mount checks, if a dracut module is needed for the given
1254 # device and filesystem types in "${host_fs_types[@]}"
1257 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1261 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1263 # If we are already scheduled to be loaded, no need to check again.
1264 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1265 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1267 # This should never happen, but...
1268 [[ -d $_moddir ]] ||
return 1
1270 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1272 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1276 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1277 module_check_mount
$_mod; ret
=$?
1279 # explicit module, so also accept ret=255
1280 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1282 # module not in our list
1283 if [[ $dracutmodules = all
]]; then
1284 # check, if we can and should install this module
1285 module_check_mount
$_mod ||
return 1
1293 for _moddep
in $
(module_depends
$_mod); do
1294 # handle deps as if they were manually added
1295 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1296 add_dracutmodules
+=" $_moddep "
1297 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1298 force_add_dracutmodules
+=" $_moddep "
1299 # if a module we depend on fail, fail also
1300 if ! check_module
$_moddep; then
1301 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1306 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1307 mods_to_load
+=" $_mod "
1312 # check_module <dracut module> [<use_as_dep>]
1313 # check if a dracut module is to be used in the initramfs process
1314 # if <use_as_dep> is set, then the process also keeps track
1315 # that the modules were checked for the dependency tracking process
1318 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1321 # If we are already scheduled to be loaded, no need to check again.
1322 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1323 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1325 # This should never happen, but...
1326 [[ -d $_moddir ]] ||
return 1
1328 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1330 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1331 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1335 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1336 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1337 module_check
$_mod 1; ret
=$?
1339 module_check
$_mod 0; ret
=$?
1341 # explicit module, so also accept ret=255
1342 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1344 # module not in our list
1345 if [[ $dracutmodules = all
]]; then
1346 # check, if we can and should install this module
1347 module_check
$_mod ||
return 1
1354 for _moddep
in $
(module_depends
$_mod); do
1355 # handle deps as if they were manually added
1356 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1357 add_dracutmodules
+=" $_moddep "
1358 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1359 force_add_dracutmodules
+=" $_moddep "
1360 # if a module we depend on fail, fail also
1361 if ! check_module
$_moddep; then
1362 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1367 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1368 mods_to_load
+=" $_mod "
1373 # for_each_module_dir <func>
1374 # execute "<func> <dracut module> 1"
1375 for_each_module_dir
() {
1381 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1382 [[ -d $_moddir ]] ||
continue;
1383 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1384 -e $_moddir/module-setup.sh
]] ||
continue
1385 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1389 # Report any missing dracut modules, the user has specified
1390 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1391 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1392 for _mod
in $_modcheck; do
1393 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1394 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1395 derror
"dracut module '$_mod' cannot be found or installed."
1399 # Install a single kernel module along with any firmware it may require.
1400 # $1 = full path to kernel module to install
1401 install_kmod_with_fw
() {
1402 # no need to go further if the module is already installed
1404 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1407 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1408 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1412 if [[ $omit_drivers ]]; then
1413 local _kmod
=${1##*/}
1416 if [[ "$_kmod" =~
$omit_drivers ]]; then
1417 dinfo
"Omitting driver $_kmod"
1420 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1421 dinfo
"Omitting driver $_kmod"
1426 if [[ $silent_omit_drivers ]]; then
1427 local _kmod
=${1##*/}
1430 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1431 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1434 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1436 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1437 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1438 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1439 (($ret != 0)) && return $ret
1441 local _modname
=${1##*/} _fwdir _found _fw
1442 _modname
=${_modname%.ko*}
1443 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1445 for _fwdir
in $fw_dir; do
1446 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1447 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1451 if [[ $_found != yes ]]; then
1452 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1453 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1454 "\"${_modname}.ko\""
1456 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1457 "\"${_modname}.ko\""
1464 # Do something with all the dependencies of a kernel module.
1465 # Note that kernel modules depend on themselves using the technique we use
1466 # $1 = function to call for each dependency we find
1467 # It will be passed the full path to the found kernel module
1468 # $2 = module to get dependencies for
1469 # rest of args = arguments to modprobe
1470 # _fderr specifies FD passed from surrounding scope
1471 for_each_kmod_dep
() {
1472 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1474 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1475 while read _cmd _modpath _options
; do
1476 [[ $_cmd = insmod
]] ||
continue
1477 $_func ${_modpath} ||
exit $?
1482 dracut_kernel_post
() {
1483 local _moddirname
=${srcmods%%/lib/modules/*}
1486 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1487 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1488 --ignore-install --show-depends --set-version $kernel \
1489 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1491 |
while read _cmd _modpath _options
; do
1492 [[ $_cmd = insmod
]] ||
continue
1494 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1497 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1498 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1500 while read _modpath
; do
1501 local _destpath
=$_modpath
1502 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1503 _destpath
=${_destpath##*/lib/modules/$kernel/}
1504 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1505 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1508 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1511 if [[ $DRACUT_INSTALL ]]; then
1512 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1513 |
while read line
; do
1514 for _fwdir
in $fw_dir; do
1517 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1519 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1520 for _fwdir
in $fw_dir; do
1521 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1522 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1532 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1533 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1536 # generate module dependencies for the initrd
1537 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1538 ! depmod
-a -b "$initdir" $kernel; then
1539 dfatal
"\"depmod -a $kernel\" failed."
1543 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1546 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1548 module_is_host_only
() {
1550 local _modenc a i _k _s _v _aliases
1553 _modenc
=${_mod//-/_}
1555 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1557 # check if module is loaded
1558 [[ ${host_modules["$_modenc"]} ]] && return 0
1560 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1562 if [[ "$kernel_current" != "$kernel" ]]; then
1563 # check if module is loadable on the current kernel
1564 # this covers the case, where a new module is introduced
1565 # or a module was renamed
1566 # or a module changed from builtin to a module
1568 if [[ -d /lib
/modules
/$kernel_current ]]; then
1569 # if the modinfo can be parsed, but the module
1570 # is not loaded, then we can safely return 1
1571 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1574 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1576 # if the module has no aliases, install it
1577 [[ $_aliases ]] ||
return 0
1579 # finally check all modalias
1580 for a
in $_aliases; do
1581 for i
in "${!host_modalias[@]}"; do
1582 [[ $i == $a ]] && return 0
1591 find_kernel_modules_by_path
() {
1594 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1598 while read a rest
; do
1599 [[ $a = */$1/* ]] ||
[[ $a = updates
/* ]] ||
continue
1600 printf "%s\n" "$srcmods/$a"
1601 done < "$srcmods/modules.dep"
1606 find_kernel_modules
() {
1607 find_kernel_modules_by_path drivers
1610 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1611 # instmods [-c [-s]] <kernel subsystem>
1612 # install kernel modules along with all their dependencies.
1613 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1615 [[ $no_kernel = yes ]] && return
1616 # called [sub]functions inherit _fderr
1620 if [[ $1 = '-c' ]]; then
1625 if [[ $1 = '-s' ]]; then
1630 function inst1mod
() {
1631 local _ret
=0 _mod
="$1"
1634 ( [[ "$_mpargs" ]] && echo $_mpargs
1635 find_kernel_modules_by_path
"${_mod#=}" ) \
1639 --*) _mpargs
+=" $_mod" ;;
1642 # if we are already installed, skip this module and go on
1644 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1645 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1646 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1651 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1652 dinfo
"Omitting driver ${_mod##$srcmods}"
1656 # If we are building a host-specific initramfs and this
1657 # module is not already loaded, move on to the next one.
1659 && ! module_is_host_only
"$_mod" \
1662 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1663 # We use '-d' option in modprobe only if modules prefix path
1664 # differs from default '/'. This allows us to use dracut with
1665 # old version of modprobe which doesn't have '-d' option.
1666 local _moddirname
=${srcmods%%/lib/modules/*}
1667 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1669 # ok, load the module, all its dependencies, and any firmware
1671 for_each_kmod_dep install_kmod_with_fw
$_mod \
1672 --set-version $kernel ${_moddirname} $_mpargs
1675 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1676 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1683 function instmods_1
() {
1685 if (($# == 0)); then # filenames from stdin
1687 inst1mod
"${_mod%.ko*}" ||
{
1688 if [[ "$_check" == "yes" ]]; then
1689 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1695 while (($# > 0)); do # filenames as arguments
1696 inst1mod
${1%.ko*} ||
{
1697 if [[ "$_check" == "yes" ]]; then
1698 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1707 local _ret _filter_not_found
='FATAL: Module .* not found.'
1708 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1709 # redirections, but that would make dracut require bash4 at least.
1710 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1711 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1716 # Only two values are returned: AMD or Intel
1719 if grep -qE AMD
/proc
/cpuinfo
; then
1722 if grep -qE Intel
/proc
/cpuinfo
; then
1728 # Get the hosts' ucode file based on the /proc/cpuinfo
1731 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1732 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1733 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1735 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1736 # If family greater or equal than 0x15
1737 if [[ $family -ge 21 ]]; then
1738 printf "microcode_amd_fam15h.bin"
1740 printf "microcode_amd.bin"
1743 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1744 # The /proc/cpuinfo are in decimal.
1745 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1749 # Not every device in /dev/mapper should be examined.
1750 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1751 lvm_internal_dev
() {
1752 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1753 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1754 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1755 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1756 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1757 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]