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
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 local _hostonly_install
765 if [[ "$1" == "-H" ]]; then
766 _hostonly_install
="-H"
769 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
770 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
771 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
775 local _hostonly_install
776 if [[ "$1" == "-H" ]]; then
777 _hostonly_install
="-H"
780 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
781 [[ -e $1 ]] ||
return 1 # no source
782 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@"
783 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${_hostonly_install:+-H} "$@" ||
:
787 local _hostonly_install
788 if [[ "$1" == "-H" ]]; then
789 _hostonly_install
="-H"
792 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
793 [[ -L $1 ]] ||
return 1
794 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
795 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
800 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
802 (($_ret != 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
811 local _hostonly_install
812 if [[ "$1" == "-H" ]]; then
813 _hostonly_install
="-H"
816 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
817 [[ -e $1 ]] ||
return 1 # no source
818 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
819 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" ||
:
823 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
824 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
828 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
829 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir:+-D "$initdir"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" ||
:
834 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
838 # find symlinks linked to given library file
840 # Function searches for symlinks by stripping version numbers appended to
841 # library filename, checks if it points to the same target and finally
842 # prints the list of symlinks to stdout.
845 # rev_lib_symlinks libfoo.so.8.1
846 # output: libfoo.so.8 libfoo.so
847 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
849 [[ ! $1 ]] && return 0
851 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
853 [[ ${fn} == *.so.
* ]] ||
return 1
855 until [[ ${fn##*.} == so
]]; do
857 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
863 # attempt to install any programs specified in a udev rule
864 inst_rule_programs() {
867 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
868 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
870 if [ -x ${udevdir}/$_prog ]; then
871 _bin=${udevdir}/$_prog
872 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
873 _bin=$(find_binary "$_prog") || {
874 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
879 [[ $_bin ]] && inst_binary "$_bin"
882 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
883 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
885 if [ -x ${udevdir}/$_prog ]; then
886 _bin=${udevdir}/$_prog
887 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
888 _bin=$(find_binary "$_prog") || {
889 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
894 [[ $_bin ]] && inst_binary "$_bin"
897 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
898 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
900 if [ -x ${udevdir}/$_prog ]; then
901 _bin=${udevdir}/$_prog
902 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
903 _bin=$(find_binary "$_prog") || {
904 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
909 [[ $_bin ]] && dracut_install "$_bin"
914 # attempt to install any programs specified in a udev rule
915 inst_rule_group_owner() {
918 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
919 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
920 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
921 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
925 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
926 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
927 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
928 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
934 inst_rule_initqueue() {
935 if grep -q -F initqueue "$1"; then
936 dracut_need_initqueue
940 # udev rules always get installed in the same place, so
941 # create a function to install them to make life simpler.
943 local _target=/etc/udev/rules.d _rule _found
945 inst_dir "${udevdir}/rules.d
"
947 for _rule in "$@
"; do
948 if [ "${_rule#/}" = "$_rule" ]; then
949 for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
950 if [[ -e $r/$_rule ]]; then
952 inst_rule_programs "$_found"
953 inst_rule_group_owner "$_found"
954 inst_rule_initqueue "$_found"
955 inst_simple "$_found"
959 for r in '' $dracutbasedir/rules.d/; do
960 # skip rules without an absolute path
961 [[ "${r}$_rule" != /* ]] && continue
963 if [[ -f ${r}$_rule ]]; then
965 inst_rule_programs "$_found"
966 inst_rule_group_owner "$_found"
967 inst_rule_initqueue "$_found"
968 inst_simple "$_found" "$_target/${_found##*/}"
971 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
975 inst_rules_wildcard() {
976 local _target=/etc/udev/rules.d _rule _found
978 inst_dir "${udevdir}/rules.d
"
980 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do
981 if [[ -e $_rule ]]; then
982 inst_rule_programs "$_rule"
983 inst_rule_group_owner "$_rule"
984 inst_rule_initqueue "$_rule"
989 if [ -n ${hostonly} ] ; then
990 for _rule in ${_target}/$1 ; do
991 if [[ -f $_rule ]]; then
992 inst_rule_programs "$_rule"
993 inst_rule_group_owner "$_rule"
994 inst_rule_initqueue "$_rule"
1000 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
1003 prepare_udev_rules() {
1004 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
1007 f="${initdir}/etc
/udev
/rules.d
/$f"
1008 [ -e "$f" ] || continue
1010 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
1011 if [ $UDEVVERSION -ge 174 ]; then
1012 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
1014 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
1016 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
1017 if [ $UDEVVERSION -ge 176 ]; then
1018 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
1020 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1025 done < "${f}" > "${f}.new
"
1030 # install function specialized for hooks
1031 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1032 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1034 if ! [[ -f $3 ]]; then
1035 dfatal "Cannot
install a hook
($3) that does not exist.
"
1036 dfatal "Aborting initrd creation.
"
1038 elif ! [[ "$hookdirs" == *$1* ]]; then
1039 dfatal "No such hook
type $1. Aborting initrd creation.
"
1042 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1045 # install any of listed files
1047 # If first argument is '-d' and second some destination path, first accessible
1048 # source is installed into this path, otherwise it will installed in the same
1049 # path as source. If none of listed files was installed, function return 1.
1050 # On first successful installation it returns with 0 status.
1054 # inst_any -d /bin/foo /bin/bar /bin/baz
1056 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1061 [[ $1 = '-d' ]] && to="$2" && shift 2
1064 if [[ -e $f ]]; then
1065 [[ $to ]] && inst "$f" "$to" && return 0
1066 inst "$f" && return 0
1074 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1075 # Install a <file> located on a lib directory to the initramfs image
1076 # -n <pattern> install matching files
1077 inst_libdir_file() {
1079 if [[ "$1" == "-n" ]]; then
1082 for _dir in $libdirs; do
1084 for _f in "$_dir"/$_i; do
1085 [[ "$_f" =~ $_pattern ]] || continue
1086 [[ -e "$_f" ]] && _files+="$_f "
1091 for _dir in $libdirs; do
1093 for _f in "$_dir"/$_i; do
1094 [[ -e "$_f" ]] && _files+="$_f "
1099 [[ $_files ]] && inst_multiple $_files
1103 # install function decompressing the target and handling symlinks
1104 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1106 # Function install targets in the same paths inside overlay but decompressed
1107 # and without extensions (.gz, .bz2).
1114 *.gz) _cmd='gzip -f -d' ;;
1115 *.bz2) _cmd='bzip2 -d' ;;
1119 # Decompress with chosen tool. We assume that tool changes name e.g.
1120 # from 'name.gz' to 'name'.
1121 ${_cmd} "${initdir}${_src}"
1125 # It's similar to above, but if file is not compressed, performs standard
1127 # $@ = list of files
1128 inst_opt_decompress
() {
1133 inst_decompress
"${_src}" || inst
"${_src}"
1137 # module_check <dracut module>
1138 # execute the check() function of module-setup.sh of <dracut module>
1139 # or the "check" script, if module-setup.sh is not found
1140 # "check $hostonly" is called
1142 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1145 local _hostonly
=$hostonly
1146 [ $# -eq 2 ] && _forced
=$2
1147 [[ -d $_moddir ]] ||
return 1
1148 if [[ ! -f $_moddir/module-setup.sh
]]; then
1149 # if we do not have a check script, we are unconditionally included
1150 [[ -x $_moddir/check
]] ||
return 0
1151 [ $_forced -ne 0 ] && unset hostonly
1152 $_moddir/check
$hostonly
1155 unset check depends cmdline
install installkernel
1157 .
$_moddir/module-setup.sh
1158 is_func check ||
return 0
1159 [ $_forced -ne 0 ] && unset hostonly
1160 moddir
=$_moddir check
$hostonly
1162 unset check depends cmdline
install installkernel
1168 # module_check_mount <dracut module>
1169 # execute the check() function of module-setup.sh of <dracut module>
1170 # or the "check" script, if module-setup.sh is not found
1171 # "mount_needs=1 check 0" is called
1172 module_check_mount
() {
1173 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 are unconditionally included
1179 [[ -x $_moddir/check
]] ||
return 0
1180 mount_needs
=1 $_moddir/check
0
1183 unset check depends cmdline
install installkernel
1185 .
$_moddir/module-setup.sh
1186 moddir
=$_moddir check
0
1188 unset check depends cmdline
install installkernel
1194 # module_depends <dracut module>
1195 # execute the depends() function of module-setup.sh of <dracut module>
1196 # or the "depends" script, if module-setup.sh is not found
1198 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1200 [[ -d $_moddir ]] ||
return 1
1201 if [[ ! -f $_moddir/module-setup.sh
]]; then
1202 # if we do not have a check script, we have no deps
1203 [[ -x $_moddir/check
]] ||
return 0
1207 unset check depends cmdline
install installkernel
1209 .
$_moddir/module-setup.sh
1210 moddir
=$_moddir depends
1212 unset check depends cmdline
install installkernel
1217 # module_cmdline <dracut module>
1218 # execute the cmdline() function of module-setup.sh of <dracut module>
1219 # or the "cmdline" script, if module-setup.sh is not found
1221 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1223 [[ -d $_moddir ]] ||
return 1
1224 if [[ ! -f $_moddir/module-setup.sh
]]; then
1225 [[ -x $_moddir/cmdline
]] && .
"$_moddir/cmdline"
1228 unset check depends cmdline
install installkernel
1230 .
$_moddir/module-setup.sh
1231 moddir
=$_moddir cmdline
1233 unset check depends cmdline
install installkernel
1238 # module_install <dracut module>
1239 # execute the install() function of module-setup.sh of <dracut module>
1240 # or the "install" script, if module-setup.sh is not found
1242 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1244 [[ -d $_moddir ]] ||
return 1
1245 if [[ ! -f $_moddir/module-setup.sh
]]; then
1246 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1249 unset check depends cmdline
install installkernel
1251 .
$_moddir/module-setup.sh
1252 moddir
=$_moddir install
1254 unset check depends cmdline
install installkernel
1259 # module_installkernel <dracut module>
1260 # execute the installkernel() function of module-setup.sh of <dracut module>
1261 # or the "installkernel" script, if module-setup.sh is not found
1262 module_installkernel
() {
1263 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1265 [[ -d $_moddir ]] ||
return 1
1266 if [[ ! -f $_moddir/module-setup.sh
]]; then
1267 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1270 unset check depends cmdline
install installkernel
1271 installkernel
() { true
; }
1272 .
$_moddir/module-setup.sh
1273 moddir
=$_moddir installkernel
1275 unset check depends cmdline
install installkernel
1280 # check_mount <dracut module>
1281 # check_mount checks, if a dracut module is needed for the given
1282 # device and filesystem types in "${host_fs_types[@]}"
1285 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1289 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1291 # If we are already scheduled to be loaded, no need to check again.
1292 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1293 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1295 # This should never happen, but...
1296 [[ -d $_moddir ]] ||
return 1
1298 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1300 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1304 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1305 module_check_mount
$_mod; ret
=$?
1307 # explicit module, so also accept ret=255
1308 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1310 # module not in our list
1311 if [[ $dracutmodules = all
]]; then
1312 # check, if we can and should install this module
1313 module_check_mount
$_mod ||
return 1
1321 for _moddep
in $
(module_depends
$_mod); do
1322 # handle deps as if they were manually added
1323 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1324 add_dracutmodules
+=" $_moddep "
1325 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1326 force_add_dracutmodules
+=" $_moddep "
1327 # if a module we depend on fail, fail also
1328 if ! check_module
$_moddep; then
1329 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1334 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1335 mods_to_load
+=" $_mod "
1340 # check_module <dracut module> [<use_as_dep>]
1341 # check if a dracut module is to be used in the initramfs process
1342 # if <use_as_dep> is set, then the process also keeps track
1343 # that the modules were checked for the dependency tracking process
1346 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1349 # If we are already scheduled to be loaded, no need to check again.
1350 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1351 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1353 # This should never happen, but...
1354 [[ -d $_moddir ]] ||
return 1
1356 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1358 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1359 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1363 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1364 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1365 module_check
$_mod 1; ret
=$?
1367 module_check
$_mod 0; ret
=$?
1369 # explicit module, so also accept ret=255
1370 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1372 # module not in our list
1373 if [[ $dracutmodules = all
]]; then
1374 # check, if we can and should install this module
1375 module_check
$_mod ||
return 1
1382 for _moddep
in $
(module_depends
$_mod); do
1383 # handle deps as if they were manually added
1384 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1385 add_dracutmodules
+=" $_moddep "
1386 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1387 force_add_dracutmodules
+=" $_moddep "
1388 # if a module we depend on fail, fail also
1389 if ! check_module
$_moddep; then
1390 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1395 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1396 mods_to_load
+=" $_mod "
1401 # for_each_module_dir <func>
1402 # execute "<func> <dracut module> 1"
1403 for_each_module_dir
() {
1409 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1410 [[ -d $_moddir ]] ||
continue;
1411 [[ -e $_moddir/install ||
-e $_moddir/installkernel || \
1412 -e $_moddir/module-setup.sh
]] ||
continue
1413 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1417 # Report any missing dracut modules, the user has specified
1418 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1419 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1420 for _mod
in $_modcheck; do
1421 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1422 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1423 derror
"dracut module '$_mod' cannot be found or installed."
1427 # Install a single kernel module along with any firmware it may require.
1428 # $1 = full path to kernel module to install
1429 install_kmod_with_fw
() {
1430 # no need to go further if the module is already installed
1432 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1435 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1436 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1440 if [[ $omit_drivers ]]; then
1441 local _kmod
=${1##*/}
1444 if [[ "$_kmod" =~
$omit_drivers ]]; then
1445 dinfo
"Omitting driver $_kmod"
1448 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1449 dinfo
"Omitting driver $_kmod"
1454 if [[ $silent_omit_drivers ]]; then
1455 local _kmod
=${1##*/}
1458 [[ "$_kmod" =~
$silent_omit_drivers ]] && return 0
1459 [[ "${1##*/lib/modules/$kernel/}" =~
$silent_omit_drivers ]] && return 0
1462 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1464 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1465 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1466 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1467 (($ret != 0)) && return $ret
1469 local _modname
=${1##*/} _fwdir _found _fw
1470 _modname
=${_modname%.ko*}
1471 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1473 for _fwdir
in $fw_dir; do
1474 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1475 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1479 if [[ $_found != yes ]]; then
1480 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1481 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1482 "\"${_modname}.ko\""
1484 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1485 "\"${_modname}.ko\""
1492 # Do something with all the dependencies of a kernel module.
1493 # Note that kernel modules depend on themselves using the technique we use
1494 # $1 = function to call for each dependency we find
1495 # It will be passed the full path to the found kernel module
1496 # $2 = module to get dependencies for
1497 # rest of args = arguments to modprobe
1498 # _fderr specifies FD passed from surrounding scope
1499 for_each_kmod_dep
() {
1500 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1502 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1503 while read _cmd _modpath _options
; do
1504 [[ $_cmd = insmod
]] ||
continue
1505 $_func ${_modpath} ||
exit $?
1510 dracut_kernel_post
() {
1511 local _moddirname
=${srcmods%%/lib/modules/*}
1514 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1515 xargs -r modprobe
-a ${_moddirname:+-d ${_moddirname}/} \
1516 --ignore-install --show-depends --set-version $kernel \
1517 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1519 |
while read _cmd _modpath _options
; do
1520 [[ $_cmd = insmod
]] ||
continue
1522 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1525 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1526 xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1528 while read _modpath
; do
1529 local _destpath
=$_modpath
1530 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1531 _destpath
=${_destpath##*/lib/modules/$kernel/}
1532 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1533 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1536 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1539 if [[ $DRACUT_INSTALL ]]; then
1540 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1541 |
while read line
; do
1542 for _fwdir
in $fw_dir; do
1545 done |
xargs -r $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a -o
1547 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1548 for _fwdir
in $fw_dir; do
1549 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1550 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1560 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1561 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1564 # generate module dependencies for the initrd
1565 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1566 ! depmod
-a -b "$initdir" $kernel; then
1567 dfatal
"\"depmod -a $kernel\" failed."
1571 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1574 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1576 module_is_host_only
() {
1578 local _modenc a i _k _s _v _aliases
1581 _modenc
=${_mod//-/_}
1583 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1585 # check if module is loaded
1586 [[ ${host_modules["$_modenc"]} ]] && return 0
1588 [[ "$kernel_current" ]] ||
export kernel_current
=$
(uname
-r)
1590 if [[ "$kernel_current" != "$kernel" ]]; then
1591 # check if module is loadable on the current kernel
1592 # this covers the case, where a new module is introduced
1593 # or a module was renamed
1594 # or a module changed from builtin to a module
1596 if [[ -d /lib
/modules
/$kernel_current ]]; then
1597 # if the modinfo can be parsed, but the module
1598 # is not loaded, then we can safely return 1
1599 modinfo
-F filename
"$_mod" &>/dev
/null
&& return 1
1602 _aliases
=$
(modinfo
-k $kernel -F alias $_mod 2>/dev
/null
)
1604 # if the module has no aliases, install it
1605 [[ $_aliases ]] ||
return 0
1607 # finally check all modalias
1608 for a
in $_aliases; do
1609 for i
in "${!host_modalias[@]}"; do
1610 [[ $i == $a ]] && return 0
1619 find_kernel_modules_by_path
() {
1622 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1626 while read a rest
; do
1627 [[ $a = */$1/* ]] ||
[[ $a = updates
/* ]] ||
continue
1628 printf "%s\n" "$srcmods/$a"
1629 done < "$srcmods/modules.dep"
1634 find_kernel_modules
() {
1635 find_kernel_modules_by_path drivers
1638 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1639 # instmods [-c [-s]] <kernel subsystem>
1640 # install kernel modules along with all their dependencies.
1641 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1643 [[ $no_kernel = yes ]] && return
1644 # called [sub]functions inherit _fderr
1648 if [[ $1 = '-c' ]]; then
1653 if [[ $1 = '-s' ]]; then
1658 function inst1mod
() {
1659 local _ret
=0 _mod
="$1"
1662 ( [[ "$_mpargs" ]] && echo $_mpargs
1663 find_kernel_modules_by_path
"${_mod#=}" ) \
1667 --*) _mpargs
+=" $_mod" ;;
1670 # if we are already installed, skip this module and go on
1672 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1673 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1674 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1679 if [[ $omit_drivers ]] && [[ "$_mod" =~
$omit_drivers ]]; then
1680 dinfo
"Omitting driver ${_mod##$srcmods}"
1684 # If we are building a host-specific initramfs and this
1685 # module is not already loaded, move on to the next one.
1687 && ! module_is_host_only
"$_mod" \
1690 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1691 # We use '-d' option in modprobe only if modules prefix path
1692 # differs from default '/'. This allows us to use dracut with
1693 # old version of modprobe which doesn't have '-d' option.
1694 local _moddirname
=${srcmods%%/lib/modules/*}
1695 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1697 # ok, load the module, all its dependencies, and any firmware
1699 for_each_kmod_dep install_kmod_with_fw
$_mod \
1700 --set-version $kernel ${_moddirname} $_mpargs
1703 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1704 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1711 function instmods_1
() {
1713 if (($# == 0)); then # filenames from stdin
1715 inst1mod
"${_mod%.ko*}" ||
{
1716 if [[ "$_check" == "yes" ]]; then
1717 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1723 while (($# > 0)); do # filenames as arguments
1724 inst1mod
${1%.ko*} ||
{
1725 if [[ "$_check" == "yes" ]]; then
1726 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1735 local _ret _filter_not_found
='FATAL: Module .* not found.'
1736 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1737 # redirections, but that would make dracut require bash4 at least.
1738 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1739 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1744 # Only two values are returned: AMD or Intel
1747 if grep -qE AMD
/proc
/cpuinfo
; then
1750 if grep -qE Intel
/proc
/cpuinfo
; then
1756 # Get the hosts' ucode file based on the /proc/cpuinfo
1759 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1760 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1761 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1763 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1764 # If family greater or equal than 0x15
1765 if [[ $family -ge 21 ]]; then
1766 printf "microcode_amd_fam15h.bin"
1768 printf "microcode_amd.bin"
1771 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1772 # The /proc/cpuinfo are in decimal.
1773 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}
1777 # Not every device in /dev/mapper should be examined.
1778 # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
1779 lvm_internal_dev
() {
1780 local dev_dm_dir
=/sys
/dev
/block
/$1/dm
1781 [[ ! -f $dev_dm_dir/uuid || $
(<$dev_dm_dir/uuid
) != LVM-
* ]] && return 1 # Not an LVM device
1782 local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
1783 eval $
(dmsetup splitname
--nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev
/null
)
1784 [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] ||
return 0 # Better skip this!
1785 [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]