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 |
grep -F '=>' |
grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' |
while read a b c d
; do
119 printf "%s\n" ${!a[@]}
123 if ! [[ $libdirs ]] ; then
124 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
125 && [[ -d /lib64
]]; then
127 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
130 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
133 libdirs
+=" $(ldconfig_paths)"
138 if ! [[ $kernel ]]; then
143 # Version comparision function. Assumes Linux style version scheme.
145 # $2 = comparision op (gt, ge, eq, le, lt, ne)
148 local _n1
=(${1//./ }) _op
=$2 _n2
=(${3//./ }) _i _res
152 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
153 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
154 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
170 srcmods
="/lib/modules/$kernel/"
172 [[ $drivers_dir ]] && {
173 if ! command -v kmod
&>/dev
/null
&& vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
174 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
177 srcmods
="$drivers_dir"
181 if ! type dinfo
>/dev
/null
2>&1; then
182 .
"$dracutbasedir/dracut-logger.sh"
186 if ! [[ $initdir ]]; then
187 dfatal
"initdir not set"
191 # export standard hookdirs
193 hookdirs
="cmdline pre-udev pre-trigger netroot "
194 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
195 hookdirs
+="pre-mount pre-pivot cleanup mount "
196 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
200 dracut_need_initqueue
() {
201 >"$initdir/lib/dracut/need-initqueue"
204 dracut_module_included
() {
205 [[ " $mods_to_load $modules_loaded " == *\ $
*\
* ]]
208 # Create all subdirectories for given path without creating the last element.
211 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
215 # Check whether $1 is a function.
217 [[ "$(type -t "$1")" = "function" ]]
220 # Function prints global variables in format name=value line by line.
221 # $@ = list of global variables' name
227 eval printf -v _value
"%s" \""\$$_var"\"
228 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
232 # normalize_path <path>
233 # Prints the normalized path, where it removes any duplicated
234 # and trailing slashes.
236 # $ normalize_path ///test/test//
240 set -- "${1//+(\/)//}"
242 printf "%s\n" "${1%/}"
245 # convert_abs_rel <from> <to>
246 # Prints the relative path, when creating a symlink to <to> from <from>.
248 # $ convert_abs_rel /usr/bin/test /bin/test-2
250 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
252 local __current __absolute __abssize __cursize __newpath
255 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
257 # corner case #1 - self looping link
258 [[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
260 # corner case #2 - own dir link
261 [[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
263 IFS
="/" __current
=($1)
264 IFS
="/" __absolute
=($2)
266 __abssize
=${#__absolute[@]}
267 __cursize
=${#__current[@]}
269 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
272 if (( __level
> __abssize || __level
> __cursize
))
278 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
282 __newpath
=$__newpath"/"
284 __newpath
=$__newpath".."
287 for ((__i
= __level
; __i
< __abssize
; __i
++))
289 if [[ -n $__newpath ]]
291 __newpath
=$__newpath"/"
293 __newpath
=$__newpath${__absolute[__i]}
296 printf "%s\n" "$__newpath"
299 if [[ "$(ln --help)" == *--relative* ]]; then
301 ln -sfnr "${initdir}/$1" "${initdir}/$2"
307 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
308 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
312 # get_fs_env <device>
313 # Get and the ID_FS_TYPE variable from udev for a device.
315 # $ get_fs_env /dev/sda2
323 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
324 |
while read line
; do
325 if [[ "$line" == TYPE\
=* ]]; then
326 printf "%s" "${line#TYPE=}";
330 if [[ $ID_FS_TYPE ]]; then
331 printf "%s" "$ID_FS_TYPE"
337 # get_maj_min <device>
338 # Prints the major and minor of a device node.
340 # $ get_maj_min /dev/sda2
343 local _maj _min _majmin
344 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
345 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
349 # get_devpath_block <device>
350 # get the DEVPATH in /sys of a block device
351 get_devpath_block
() {
353 _majmin
=$
(get_maj_min
"$1")
355 for _i
in /sys
/block
/*/dev
/sys
/block
/*/*/dev
; do
356 [[ -e "$_i" ]] ||
continue
357 if [[ "$_majmin" == "$(<"$_i")" ]]; then
358 printf "%s" "${_i%/dev}"
365 # get a persistent path from a device
366 get_persistent_dev
() {
369 _dev
=$
(get_maj_min
"$1")
370 [ -z "$_dev" ] && return
374 /dev
/disk
/${persistent_policy:-by-uuid}/* \
375 /dev
/disk
/by-uuid
/* \
376 /dev
/disk
/by-label
/* \
377 /dev
/disk
/by-partuuid
/* \
378 /dev
/disk
/by-partlabel
/* \
380 /dev
/disk
/by-path
/* \
382 [[ -e "$i" ]] ||
continue
383 [[ $i == /dev
/mapper
/control
]] && continue
384 [[ $i == /dev
/mapper
/mpath
* ]] && continue
385 _tmp
=$
(get_maj_min
"$i")
386 if [ "$_tmp" = "$_dev" ]; then
393 expand_persistent_dev
() {
398 _dev
="/dev/disk/by-label/${_dev#LABEL=}"
403 _dev
="/dev/disk/by-uuid/${_dev}"
406 _dev
="${_dev#PARTUUID=}"
408 _dev
="/dev/disk/by-partuuid/${_dev}"
411 _dev
="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
417 shorten_persistent_dev
() {
421 printf "%s" "UUID=${_dev##*/}";;
422 /dev
/disk
/by-label
/*)
423 printf "%s" "LABEL=${_dev##*/}";;
424 /dev
/disk
/by-partuuid
/*)
425 printf "%s" "PARTUUID=${_dev##*/}";;
426 /dev
/disk
/by-partlabel
/*)
427 printf "%s" "PARTLABEL=${_dev##*/}";;
429 printf "%s" "$_dev";;
433 # find_block_device <mountpoint>
434 # Prints the major and minor number of the block device
435 # for a given mountpoint.
436 # Unless $use_fstab is set to "yes" the functions
437 # uses /proc/self/mountinfo as the primary source of the
438 # information and only falls back to /etc/fstab, if the mountpoint
439 # is not found there.
441 # $ find_block_device /usr
443 find_block_device
() {
444 local _majmin _dev _majmin _find_mpt
446 if [[ $use_fstab != yes ]]; then
447 [[ -d $_find_mpt/.
]]
448 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
449 while read _majmin _dev
; do
450 if [[ -b $_dev ]]; then
451 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
452 _majmin
=$
(get_maj_min
$_dev)
454 if [[ $_majmin ]]; then
455 printf "%s\n" "$_majmin"
457 printf "%s\n" "$_dev"
461 if [[ $_dev = *:* ]]; then
462 printf "%s\n" "$_dev"
465 done; return 1; } && return 0
467 # fall back to /etc/fstab
469 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
470 while read _majmin _dev
; do
471 if ! [[ $_dev ]]; then
475 if [[ -b $_dev ]]; then
476 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
477 if [[ $_majmin ]]; then
478 printf "%s\n" "$_majmin"
480 printf "%s\n" "$_dev"
484 if [[ $_dev = *:* ]]; then
485 printf "%s\n" "$_dev"
488 done; return 1; } && return 0
493 # find_mp_fstype <mountpoint>
494 # Echo the filesystem type for a given mountpoint.
495 # /proc/self/mountinfo is taken as the primary source of information
496 # and /etc/fstab is used as a fallback.
497 # No newline is appended!
499 # $ find_mp_fstype /;echo
504 if [[ $use_fstab != yes ]]; then
505 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
507 [[ $_fs ]] ||
continue
508 [[ $_fs = "autofs" ]] && continue
511 done; return 1; } && return 0
514 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
516 [[ $_fs ]] ||
continue
517 [[ $_fs = "autofs" ]] && continue
520 done; return 1; } && return 0
525 # find_dev_fstype <device>
526 # Echo the filesystem type for a given device.
527 # /proc/self/mountinfo is taken as the primary source of information
528 # and /etc/fstab is used as a fallback.
529 # No newline is appended!
531 # $ find_dev_fstype /dev/sda2;echo
536 if ! [[ "$_find_dev" = /dev
* ]]; then
537 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
540 if [[ $use_fstab != yes ]]; then
541 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
543 [[ $_fs ]] ||
continue
544 [[ $_fs = "autofs" ]] && continue
547 done; return 1; } && return 0
550 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
552 [[ $_fs ]] ||
continue
553 [[ $_fs = "autofs" ]] && continue
556 done; return 1; } && return 0
561 # find_mp_fsopts <mountpoint>
562 # Echo the filesystem options for a given mountpoint.
563 # /proc/self/mountinfo is taken as the primary source of information
564 # and /etc/fstab is used as a fallback.
565 # No newline is appended!
567 # $ find_mp_fsopts /;echo
568 # rw,relatime,discard,data=ordered
570 if [[ $use_fstab != yes ]]; then
571 findmnt
-e -v -n -o 'OPTIONS' --target "$1" 2>/dev
/null
&& return 0
574 findmnt
--fstab -e -v -n -o 'OPTIONS' --target "$1"
577 # find_dev_fsopts <device>
578 # Echo the filesystem options for a given device.
579 # /proc/self/mountinfo is taken as the primary source of information
580 # and /etc/fstab is used as a fallback.
582 # $ find_dev_fsopts /dev/sda2
583 # rw,relatime,discard,data=ordered
585 local _find_dev _opts
587 if ! [[ "$_find_dev" = /dev
* ]]; then
588 [[ -b "/dev/block/$_find_dev" ]] && _find_dev
="/dev/block/$_find_dev"
591 if [[ $use_fstab != yes ]]; then
592 findmnt
-e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev
/null
&& return 0
595 findmnt
--fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
599 # finds the major:minor of the block device backing the root filesystem.
600 find_root_block_device
() { find_block_device
/; }
602 # for_each_host_dev_fs <func>
603 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
604 # in ${host_fs_types[@]}
605 for_each_host_dev_fs
()
611 [[ "${!host_fs_types[@]}" ]] ||
return 0
613 for _dev
in "${!host_fs_types[@]}"; do
614 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
621 printf "%s\n" "${host_fs_types[@]}"
624 # Walk all the slave relationships for a given block device.
625 # Stop when our helper function returns success
626 # $1 = function to call on every found block device
627 # $2 = block device in major:minor format
628 check_block_and_slaves
() {
630 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
631 if ! lvm_internal_dev
$2; then "$1" $2 && return; fi
632 check_vol_slaves
"$@" && return 0
633 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
634 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
636 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
637 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
638 [[ -f $_x ]] ||
continue
639 check_block_and_slaves
$1 $
(<"$_x") && return 0
644 check_block_and_slaves_all
() {
646 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
647 if ! lvm_internal_dev
$2 && "$1" $2; then
650 check_vol_slaves
"$@" && return 0
651 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
652 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
654 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
655 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
656 [[ -f $_x ]] ||
continue
657 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
661 # for_each_host_dev_and_slaves <func>
662 # Execute "<func> <dev>" for every "<dev>" found
663 # in ${host_devs[@]} and their slaves
664 for_each_host_dev_and_slaves_all
()
670 [[ "${host_devs[@]}" ]] ||
return 0
672 for _dev
in ${host_devs[@]}; do
673 [[ -b "$_dev" ]] ||
continue
674 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
681 for_each_host_dev_and_slaves
()
686 [[ "${host_devs[@]}" ]] ||
return 0
688 for _dev
in ${host_devs[@]}; do
689 [[ -b "$_dev" ]] ||
continue
690 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
695 # ugly workaround for the lvm design
696 # There is no volume group device,
697 # so, there are no slave devices for volume groups.
698 # Logical volumes only have the slave devices they really live on,
699 # but you cannot create the logical volume without the volume group.
700 # And the volume group might be bigger than the devices the LV needs.
703 for i
in /dev
/mapper
/*; do
704 [[ $i == /dev
/mapper
/control
]] && continue
705 _lv
=$
(get_maj_min
$i)
706 if [[ $_lv = $2 ]]; then
707 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
709 _vg
=$
(printf "%s\n" "$_vg")
711 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
713 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
721 # fs_get_option <filesystem options> <search for option>
722 # search for a specific option in a bunch of filesystem options
723 # and return the value
731 while [ $# -gt 0 ]; do
734 echo ${1#${_option}=}
742 if ! [[ $DRACUT_INSTALL ]]; then
743 DRACUT_INSTALL
=$
(find_binary dracut-install
)
746 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
747 DRACUT_INSTALL
=$dracutbasedir/dracut-install
750 if ! [[ -x $DRACUT_INSTALL ]]; then
751 dfatal
"dracut-install not found!"
755 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
757 [[ -e ${initdir}/"$1" ]] && return 0 # already there
758 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
759 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" ||
:
763 local _hostonly_install
764 if [[ "$1" == "-H" ]]; then
765 _hostonly_install
="-H"
768 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
769 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
770 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
774 local _hostonly_install
775 if [[ "$1" == "-H" ]]; then
776 _hostonly_install
="-H"
779 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
780 [[ -e $1 ]] ||
return 1 # no source
781 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@"
782 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@" ||
:
786 local _hostonly_install
787 if [[ "$1" == "-H" ]]; then
788 _hostonly_install
="-H"
791 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
792 [[ -L $1 ]] ||
return 1
793 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
794 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
799 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
801 (($_ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
810 local _hostonly_install
811 if [[ "$1" == "-H" ]]; then
812 _hostonly_install
="-H"
815 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
816 [[ -e $1 ]] ||
return 1 # no source
817 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
818 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
822 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
823 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
827 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
828 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
833 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
837 # find symlinks linked to given library file
839 # Function searches for symlinks by stripping version numbers appended to
840 # library filename, checks if it points to the same target and finally
841 # prints the list of symlinks to stdout.
844 # rev_lib_symlinks libfoo.so.8.1
845 # output: libfoo.so.8 libfoo.so
846 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
848 [[ ! $1 ]] && return 0
850 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
852 [[ ${fn} == *.so.
* ]] ||
return 1
854 until [[ ${fn##*.} == so
]]; do
856 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
862 # attempt to install any programs specified in a udev rule
863 inst_rule_programs() {
866 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
867 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
869 if [ -x ${udevdir}/$_prog ]; then
870 _bin=${udevdir}/$_prog
871 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
872 _bin=$(find_binary "$_prog") || {
873 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
878 [[ $_bin ]] && inst_binary "$_bin"
881 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
882 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
884 if [ -x ${udevdir}/$_prog ]; then
885 _bin=${udevdir}/$_prog
886 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
887 _bin=$(find_binary "$_prog") || {
888 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
893 [[ $_bin ]] && inst_binary "$_bin"
896 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
897 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
899 if [ -x ${udevdir}/$_prog ]; then
900 _bin=${udevdir}/$_prog
901 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
902 _bin=$(find_binary "$_prog") || {
903 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
908 [[ $_bin ]] && dracut_install "$_bin"
913 # attempt to install any programs specified in a udev rule
914 inst_rule_group_owner() {
917 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
918 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
919 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
920 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
924 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
925 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
926 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
927 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
933 inst_rule_initqueue() {
934 if grep -q -F initqueue "$1"; then
935 dracut_need_initqueue
939 # udev rules always get installed in the same place, so
940 # create a function to install them to make life simpler.
942 local _target=/etc/udev/rules.d _rule _found
944 inst_dir "${udevdir}/rules.d
"
946 for _rule in "$@
"; do
947 if [ "${_rule#/}" = "$_rule" ]; then
948 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
949 if [[ -e $r/$_rule ]]; then
951 inst_rule_programs "$_found"
952 inst_rule_group_owner "$_found"
953 inst_rule_initqueue "$_found"
954 inst_simple "$_found"
958 for r in '' $dracutbasedir/rules.d/; do
959 # skip rules without an absolute path
960 [[ "${r}$_rule" != /* ]] && continue
962 if [[ -f ${r}$_rule ]]; then
964 inst_rule_programs "$_found"
965 inst_rule_group_owner "$_found"
966 inst_rule_initqueue "$_found"
967 inst_simple "$_found" "$_target/${_found##*/}"
970 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
974 inst_rules_wildcard() {
975 local _target=/etc/udev/rules.d _rule _found
977 inst_dir "${udevdir}/rules.d
"
979 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
980 if [[ -e $_rule ]]; then
981 inst_rule_programs "$_rule"
982 inst_rule_group_owner "$_rule"
983 inst_rule_initqueue "$_rule"
988 if [ -n ${hostonly} ] ; then
989 for _rule in ${_target}/$1 ; do
990 if [[ -f $_rule ]]; then
991 inst_rule_programs "$_rule"
992 inst_rule_group_owner "$_rule"
993 inst_rule_initqueue "$_rule"
999 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
1002 prepare_udev_rules() {
1003 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
1006 f="${initdir}/etc
/udev
/rules.d
/$f"
1007 [ -e "$f" ] || continue
1009 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
1010 if [ $UDEVVERSION -ge 174 ]; then
1011 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
1013 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
1015 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
1016 if [ $UDEVVERSION -ge 176 ]; then
1017 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
1019 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1024 done < "${f}" > "${f}.new
"
1029 # install function specialized for hooks
1030 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1031 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1033 if ! [[ -f $3 ]]; then
1034 dfatal "Cannot
install a hook
($3) that does not exist.
"
1035 dfatal "Aborting initrd creation.
"
1037 elif ! [[ "$hookdirs" == *$1* ]]; then
1038 dfatal "No such hook
type $1. Aborting initrd creation.
"
1041 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1044 # install any of listed files
1046 # If first argument is '-d' and second some destination path, first accessible
1047 # source is installed into this path, otherwise it will installed in the same
1048 # path as source. If none of listed files was installed, function return 1.
1049 # On first successful installation it returns with 0 status.
1053 # inst_any -d /bin/foo /bin/bar /bin/baz
1055 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1060 [[ $1 = '-d' ]] && to="$2" && shift 2
1063 if [[ -e $f ]]; then
1064 [[ $to ]] && inst "$f" "$to" && return 0
1065 inst "$f" && return 0
1073 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1074 # Install a <file> located on a lib directory to the initramfs image
1075 # -n <pattern> install matching files
1076 inst_libdir_file() {
1078 if [[ "$1" == "-n" ]]; then
1081 for _dir in $libdirs; do
1083 for _f in "$_dir"/$_i; do
1084 [[ "$_f" =~ $_pattern ]] || continue
1085 [[ -e "$_f" ]] && _files+="$_f "
1090 for _dir in $libdirs; do
1092 for _f in "$_dir"/$_i; do
1093 [[ -e "$_f" ]] && _files+="$_f "
1098 [[ $_files ]] && inst_multiple $_files
1102 # install function decompressing the target and handling symlinks
1103 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1105 # Function install targets in the same paths inside overlay but decompressed
1106 # and without extensions (.gz, .bz2).
1113 *.gz) _cmd='gzip -f -d' ;;
1114 *.bz2) _cmd='bzip2 -d' ;;
1118 # Decompress with chosen tool. We assume that tool changes name e.g.
1119 # from 'name.gz' to 'name'.
1120 ${_cmd} "${initdir}${_src}"
1124 # It's similar to above, but if file is not compressed, performs standard
1126 # $@ = list of files
1127 inst_opt_decompress
() {
1132 inst_decompress
"${_src}" || inst
"${_src}"
1136 # module_check <dracut module>
1137 # execute the check() function of module-setup.sh of <dracut module>
1138 # or the "check" script, if module-setup.sh is not found
1139 # "check $hostonly" is called
1141 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1144 local _hostonly
=$hostonly
1145 [ $# -eq 2 ] && _forced
=$2
1146 [[ -d $_moddir ]] ||
return 1
1147 if [[ ! -f $_moddir/module-setup.sh
]]; then
1148 # if we do not have a check script, we are unconditionally included
1149 [[ -x $_moddir/check
]] ||
return 0
1150 [ $_forced -ne 0 ] && unset hostonly
1151 $_moddir/check
$hostonly
1154 unset check depends cmdline
install installkernel
1156 .
$_moddir/module-setup.sh
1157 is_func check ||
return 0
1158 [ $_forced -ne 0 ] && unset hostonly
1159 moddir
=$_moddir check
$hostonly
1161 unset check depends cmdline
install installkernel
1167 # module_check_mount <dracut module>
1168 # execute the check() function of module-setup.sh of <dracut module>
1169 # or the "check" script, if module-setup.sh is not found
1170 # "mount_needs=1 check 0" is called
1171 module_check_mount
() {
1172 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1175 [[ -d $_moddir ]] ||
return 1
1176 if [[ ! -f $_moddir/module-setup.sh
]]; then
1177 # if we do not have a check script, we are unconditionally included
1178 [[ -x $_moddir/check
]] ||
return 0
1179 mount_needs
=1 $_moddir/check
0
1182 unset check depends cmdline
install installkernel
1184 .
$_moddir/module-setup.sh
1185 moddir
=$_moddir check
0
1187 unset check depends cmdline
install installkernel
1193 # module_depends <dracut module>
1194 # execute the depends() function of module-setup.sh of <dracut module>
1195 # or the "depends" 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 # if we do not have a check script, we have no deps
1202 [[ -x $_moddir/check
]] ||
return 0
1206 unset check depends cmdline
install installkernel
1208 .
$_moddir/module-setup.sh
1209 moddir
=$_moddir depends
1211 unset check depends cmdline
install installkernel
1216 # module_cmdline <dracut module>
1217 # execute the cmdline() function of module-setup.sh of <dracut module>
1218 # or the "cmdline" script, if module-setup.sh is not found
1220 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1222 [[ -d $_moddir ]] ||
return 1
1223 if [[ ! -f $_moddir/module-setup.sh
]]; then
1224 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1227 unset check depends cmdline
install installkernel
1229 .
$_moddir/module-setup.sh
1230 moddir
=$_moddir cmdline
1232 unset check depends cmdline
install installkernel
1237 # module_install <dracut module>
1238 # execute the install() function of module-setup.sh of <dracut module>
1239 # or the "install" script, if module-setup.sh is not found
1241 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1243 [[ -d $_moddir ]] ||
return 1
1244 if [[ ! -f $_moddir/module-setup.sh
]]; then
1245 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1248 unset check depends cmdline
install installkernel
1250 .
$_moddir/module-setup.sh
1251 moddir
=$_moddir install
1253 unset check depends cmdline
install installkernel
1258 # module_installkernel <dracut module>
1259 # execute the installkernel() function of module-setup.sh of <dracut module>
1260 # or the "installkernel" script, if module-setup.sh is not found
1261 module_installkernel
() {
1262 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1264 [[ -d $_moddir ]] ||
return 1
1265 if [[ ! -f $_moddir/module-setup.sh
]]; then
1266 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1269 unset check depends cmdline
install installkernel
1270 installkernel
() { true
; }
1271 .
$_moddir/module-setup.sh
1272 moddir
=$_moddir installkernel
1274 unset check depends cmdline
install installkernel
1279 # check_mount <dracut module>
1280 # check_mount checks, if a dracut module is needed for the given
1281 # device and filesystem types in "${host_fs_types[@]}"
1284 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1288 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1290 # If we are already scheduled to be loaded, no need to check again.
1291 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1292 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1294 # This should never happen, but...
1295 [[ -d $_moddir ]] ||
return 1
1297 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1299 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1303 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1304 module_check_mount
$_mod; ret
=$?
1306 # explicit module, so also accept ret=255
1307 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1309 # module not in our list
1310 if [[ $dracutmodules = all
]]; then
1311 # check, if we can and should install this module
1312 module_check_mount
$_mod ||
return 1
1320 for _moddep
in $
(module_depends
$_mod); do
1321 # handle deps as if they were manually added
1322 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1323 add_dracutmodules
+=" $_moddep "
1324 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1325 force_add_dracutmodules
+=" $_moddep "
1326 # if a module we depend on fail, fail also
1327 if ! check_module
$_moddep; then
1328 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1333 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1334 mods_to_load
+=" $_mod "
1339 # check_module <dracut module> [<use_as_dep>]
1340 # check if a dracut module is to be used in the initramfs process
1341 # if <use_as_dep> is set, then the process also keeps track
1342 # that the modules were checked for the dependency tracking process
1345 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1348 # If we are already scheduled to be loaded, no need to check again.
1349 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1350 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1352 # This should never happen, but...
1353 [[ -d $_moddir ]] ||
return 1
1355 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1357 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1358 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1362 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1363 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1364 module_check
$_mod 1; ret
=$?
1366 module_check
$_mod 0; ret
=$?
1368 # explicit module, so also accept ret=255
1369 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1371 # module not in our list
1372 if [[ $dracutmodules = all
]]; then
1373 # check, if we can and should install this module
1374 module_check
$_mod ||
return 1
1381 for _moddep
in $
(module_depends
$_mod); do
1382 # handle deps as if they were manually added
1383 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1384 add_dracutmodules
+=" $_moddep "
1385 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1386 force_add_dracutmodules
+=" $_moddep "
1387 # if a module we depend on fail, fail also
1388 if ! check_module
$_moddep; then
1389 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1394 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1395 mods_to_load
+=" $_mod "
1400 # for_each_module_dir <func>
1401 # execute "<func> <dracut module> 1"
1402 for_each_module_dir
() {
1408 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1409 [[ -d $_moddir ]] ||
continue;
1410 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1411 -e $_moddir/module-setup.sh
]] ||
continue
1412 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1416 # Report any missing dracut modules, the user has specified
1417 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1418 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1419 for _mod
in $_modcheck; do
1420 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1421 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1422 derror
"dracut module '$_mod' cannot be found or installed."
1426 # Install a single kernel module along with any firmware it may require.
1427 # $1 = full path to kernel module to install
1428 install_kmod_with_fw
() {
1429 # no need to go further if the module is already installed
1431 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1434 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1435 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1439 if [[ $omit_drivers ]]; then
1440 local _kmod
=${1##*/}
1443 if [[ "$_kmod" =~
$omit_drivers ]]; then
1444 dinfo
"Omitting driver $_kmod"
1447 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1448 dinfo
"Omitting driver $_kmod"
1453 if [[ $silent_omit_drivers ]]; then
1454 local _kmod
=${1##*/}
1457 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1458 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1461 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1463 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1464 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1465 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1466 (($ret != 0)) && return $ret
1468 local _modname
=${1##*/} _fwdir _found _fw
1469 _modname
=${_modname%.ko*}
1470 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1472 for _fwdir
in $fw_dir; do
1473 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1474 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1478 if [[ $_found != yes ]]; then
1479 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1480 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1481 "\"${_modname}.ko\""
1483 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1484 "\"${_modname}.ko\""
1491 # Do something with all the dependencies of a kernel module.
1492 # Note that kernel modules depend on themselves using the technique we use
1493 # $1 = function to call for each dependency we find
1494 # It will be passed the full path to the found kernel module
1495 # $2 = module to get dependencies for
1496 # rest of args = arguments to modprobe
1497 # _fderr specifies FD passed from surrounding scope
1498 for_each_kmod_dep
() {
1499 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1501 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1502 while read _cmd _modpath _options
; do
1503 [[ $_cmd = insmod
]] ||
continue
1504 $_func ${_modpath} ||
exit $?
1509 dracut_kernel_post
() {
1510 local _moddirname
=${srcmods%%/lib/modules/*}
1513 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1514 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1515 --ignore-install --show-depends --set-version $kernel \
1516 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1518 |
while read _cmd _modpath _options
; do
1519 [[ $_cmd = insmod
]] ||
continue
1521 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1524 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1525 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1527 while read _modpath
; do
1528 local _destpath
=$_modpath
1529 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1530 _destpath
=${_destpath##*/lib/modules/$kernel/}
1531 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1532 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1535 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1538 if [[ $DRACUT_INSTALL ]]; then
1539 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1540 |
while read line
; do
1541 for _fwdir
in $fw_dir; do
1544 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1546 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1547 for _fwdir
in $fw_dir; do
1548 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1549 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1559 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1560 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1563 # generate module dependencies for the initrd
1564 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1565 ! depmod
-a -b "$initdir" $kernel; then
1566 dfatal
"\"depmod -a $kernel\" failed."
1570 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1573 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1575 module_is_host_only
() {
1577 local _modenc a i _k _s _v _aliases
1580 _modenc
=${_mod//-/_}
1582 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1584 # check if module is loaded
1585 [[ ${host_modules["$_modenc"]} ]] && return 0
1587 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1589 if [[ "$kernel_current" != "$kernel" ]]; then
1590 # check if module is loadable on the current kernel
1591 # this covers the case, where a new module is introduced
1592 # or a module was renamed
1593 # or a module changed from builtin to a module
1595 if [[ -d /lib
/modules
/$kernel_current ]]; then
1596 # if the modinfo can be parsed, but the module
1597 # is not loaded, then we can safely return 1
1598 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1601 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1603 # if the module has no aliases, install it
1604 [[ $_aliases ]] ||
return 0
1606 # finally check all modalias
1607 for a
in $_aliases; do
1608 for i
in "${!host_modalias[@]}"; do
1609 [[ $i == $a ]] && return 0
1618 find_kernel_modules_by_path
() {
1621 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1625 while read a rest
; do
1626 [[ $a = */$1/* ]] ||
[[ $a = updates
/* ]] ||
continue
1627 printf "%s\n" "$srcmods/$a"
1628 done < "$srcmods/modules.dep"
1633 find_kernel_modules
() {
1634 find_kernel_modules_by_path drivers
1637 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1638 # instmods [-c [-s]] <kernel subsystem>
1639 # install kernel modules along with all their dependencies.
1640 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1642 [[ $no_kernel = yes ]] && return
1643 # called [sub]functions inherit _fderr
1647 if [[ $1 = '-c' ]]; then
1652 if [[ $1 = '-s' ]]; then
1657 function inst1mod
() {
1658 local _ret
=0 _mod
="$1"
1661 ( [[ "$_mpargs" ]] && echo $_mpargs
1662 find_kernel_modules_by_path
"${_mod#=}" ) \
1666 --*) _mpargs
+=" $_mod" ;;
1669 # if we are already installed, skip this module and go on
1671 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1672 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1673 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1678 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1679 dinfo
"Omitting driver ${_mod##$srcmods}"
1683 # If we are building a host-specific initramfs and this
1684 # module is not already loaded, move on to the next one.
1686 && ! module_is_host_only
"$_mod" \
1689 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1690 # We use '-d' option in modprobe only if modules prefix path
1691 # differs from default '/'. This allows us to use dracut with
1692 # old version of modprobe which doesn't have '-d' option.
1693 local _moddirname
=${srcmods%%/lib/modules/*}
1694 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1696 # ok, load the module, all its dependencies, and any firmware
1698 for_each_kmod_dep install_kmod_with_fw
$_mod \
1699 --set-version $kernel ${_moddirname} $_mpargs
1702 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1703 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1710 function instmods_1
() {
1712 if (($# == 0)); then # filenames from stdin
1714 inst1mod
"${_mod%.ko*}" ||
{
1715 if [[ "$_check" == "yes" ]]; then
1716 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1722 while (($# > 0)); do # filenames as arguments
1723 inst1mod
${1%.ko*} ||
{
1724 if [[ "$_check" == "yes" ]]; then
1725 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1734 local _ret _filter_not_found
='FATAL: Module .* not found.'
1735 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1736 # redirections, but that would make dracut require bash4 at least.
1737 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1738 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1743 # Only two values are returned: AMD or Intel
1746 if grep -qE AMD
/proc
/cpuinfo
; then
1749 if grep -qE Intel
/proc
/cpuinfo
; then
1755 # Get the hosts' ucode file based on the /proc/cpuinfo
1758 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1759 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1760 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1762 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1763 # If family greater or equal than 0x15
1764 if [[ $family -ge 21 ]]; then
1765 printf "microcode_amd_fam15h.bin"
1767 printf "microcode_amd.bin"
1770 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1771 # The /proc/cpuinfo are in decimal.
1772 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1776 # Not every device in /dev/mapper should be examined.
1777 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1778 lvm_internal_dev
() {
1779 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1780 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1781 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1782 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1783 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1784 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]