2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # functions used by dracut and other tools.
7 # Copyright 2005-2009 Red Hat, Inc. All rights reserved.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
25 if ! [[ -d "$initdir/.kernelmodseen" ]]; then
26 mkdir
-p "$initdir/.kernelmodseen"
28 DRACUT_KERNEL_LAZY_HASHDIR
="$initdir/.kernelmodseen"
31 if [[ $initdir ]] && ! [[ -d $initdir ]]; then
35 # Generic substring function. If $2 is in $1, return 0.
36 strstr
() { [[ $1 = *$2* ]]; }
38 # find a binary. If we were not passed the full path directly,
39 # search in the usual places to find the binary.
41 if [[ -z ${1##/*} ]]; then
42 if [[ -x $1 ]] ||
{ [[ "$1" == *.so
* ]] && ldd
"$1" &>/dev
/null
; }; then
51 if ! [[ $dracutbasedir ]]; then
52 dracutbasedir
=${BASH_SOURCE[0]%/*}
53 [[ $dracutbasedir = "dracut-functions" ]] && dracutbasedir
="."
54 [[ $dracutbasedir ]] || dracutbasedir
="."
55 dracutbasedir
="$(readlink -f $dracutbasedir)"
58 if ! [[ $DRACUT_INSTALL ]]; then
59 DRACUT_INSTALL
=$
(find_binary dracut-install
)
62 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install
]]; then
63 DRACUT_INSTALL
=$dracutbasedir/dracut-install
67 if ! [[ $libdirs ]] ; then
68 if [[ "$(ldd /bin/sh)" == */lib64
/* ]] &>/dev
/null \
69 && [[ -d /lib64
]]; then
71 [[ -d /usr
/lib64
]] && libdirs
+=" /usr/lib64"
74 [[ -d /usr
/lib
]] && libdirs
+=" /usr/lib"
79 if ! [[ $kernel ]]; then
84 srcmods
="/lib/modules/$kernel/"
85 [[ $drivers_dir ]] && {
86 if vercmp
"$(modprobe --version | cut -d' ' -f3)" lt
3.7; then
87 dfatal
'To use --kmoddir option module-init-tools >= 3.7 is required.'
90 srcmods
="$drivers_dir"
94 if ! type dinfo
>/dev
/null
2>&1; then
95 .
"$dracutbasedir/dracut-logger.sh"
99 if ! [[ $initdir ]]; then
100 dfatal
"initdir not set"
104 # export standard hookdirs
106 hookdirs
="cmdline pre-udev pre-trigger netroot "
107 hookdirs
+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
108 hookdirs
+="pre-mount pre-pivot cleanup mount "
109 hookdirs
+="emergency shutdown-emergency pre-shutdown shutdown "
113 dracut_need_initqueue
() {
114 >"$initdir/lib/dracut/need-initqueue"
117 dracut_module_included
() {
118 [[ "$mods_to_load $modules_loaded" == *$@
* ]]
121 # Create all subdirectories for given path without creating the last element.
124 [[ -e ${1%/*} ]] || mkdir
-m 0755 -p -- "${1%/*}"
127 # Version comparision function. Assumes Linux style version scheme.
129 # $2 = comparision op (gt, ge, eq, le, lt, ne)
132 local _n1
=${1//./ } _op
=$2 _n2
=${3//./ } _i _res
136 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res
=0
137 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res
=1
138 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res
=2
155 # Check whether $1 is a function.
157 [[ "$(type -t "$1")" = "function" ]]
160 # Function prints global variables in format name=value line by line.
161 # $@ = list of global variables' name
167 eval printf -v _value
"%s" "\$$_var"
168 [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
172 # normalize_path <path>
173 # Prints the normalized path, where it removes any duplicated
174 # and trailing slashes.
176 # $ normalize_path ///test/test//
180 set -- "${1//+(\/)//}"
185 # convert_abs_rel <from> <to>
186 # Prints the relative path, when creating a symlink to <to> from <from>.
188 # $ convert_abs_rel /usr/bin/test /bin/test-2
190 # $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
192 local __current __absolute __abssize __cursize __newpath
195 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
197 # corner case #1 - self looping link
198 [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
200 # corner case #2 - own dir link
201 [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
203 IFS
="/" __current
=($1)
204 IFS
="/" __absolute
=($2)
206 __abssize
=${#__absolute[@]}
207 __cursize
=${#__current[@]}
209 while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
212 if (( __level
> __abssize || __level
> __cursize
))
218 for ((__i
= __level
; __i
< __cursize-1
; __i
++))
222 __newpath
=$__newpath"/"
224 __newpath
=$__newpath".."
227 for ((__i
= __level
; __i
< __abssize
; __i
++))
229 if [[ -n $__newpath ]]
231 __newpath
=$__newpath"/"
233 __newpath
=$__newpath${__absolute[__i]}
239 if [[ "$(ln --help)" == *--relative* ]]; then
241 ln -sfnr "${initdir}/$1" "${initdir}/$2"
247 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
248 ln -sfn -- "$
(convert_abs_rel
"${_dest}" "${_source}")" "${initdir}/${_dest}"
252 get_persistent_dev
() {
255 _dev
=$
(udevadm info
--query=name
--name="$1" 2>/dev
/null
)
256 [ -z "$_dev" ] && return
258 for i
in /dev
/mapper
/* /dev
/disk
/by-uuid
/* /dev
/disk
/by-id
/*; do
259 [[ $i == /dev
/mapper
/mpath
* ]] && continue
260 _tmp
=$
(udevadm info
--query=name
--name="$i" 2>/dev
/null
)
261 if [ "$_tmp" = "$_dev" ]; then
268 # get_fs_env <device>
269 # Get and set the ID_FS_TYPE variable from udev for a device.
271 # $ get_fs_env /dev/sda2; echo $ID_FS_TYPE
279 if ID_FS_TYPE
=$
(udevadm info
--query=env
--name="$1" \
280 |
{ while read line
; do
281 [[ "$line" == DEVPATH\
=* ]] && found
=1;
282 if [[ "$line" == ID_FS_TYPE\
=* ]]; then
283 printf "%s" "${line#ID_FS_TYPE=}";
286 done; [[ $found ]] && exit 0; exit 1; }) ; then
287 if [[ $ID_FS_TYPE ]]; then
288 printf "%s" "$ID_FS_TYPE"
294 # Fallback, if we don't have udev information
295 if find_binary blkid
>/dev
/null
; then
296 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
297 |
while read line
; do
298 if [[ "$line" == TYPE\
=* ]]; then
299 printf "%s" "${line#TYPE=}";
303 if [[ $ID_FS_TYPE ]]; then
304 printf "%s" "$ID_FS_TYPE"
311 # get_maj_min <device>
312 # Prints the major and minor of a device node.
314 # $ get_maj_min /dev/sda2
318 read _maj _min
< <(stat
-L -c '%t %T' "$1" 2>/dev
/null
)
319 printf "%s" "$((0x$_maj)):$((0x$_min))"
322 # find_block_device <mountpoint>
323 # Prints the major and minor number of the block device
324 # for a given mountpoint.
325 # Unless $use_fstab is set to "yes" the functions
326 # uses /proc/self/mountinfo as the primary source of the
327 # information and only falls back to /etc/fstab, if the mountpoint
328 # is not found there.
330 # $ find_block_device /usr
332 find_block_device
() {
333 local _majmin _dev _majmin _find_mpt
335 if [[ $use_fstab != yes ]]; then
336 [[ -d $_find_mpt/.
]]
337 while read _majmin _dev
; do
338 if [[ -b $_dev ]]; then
339 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
340 read _majmin
< <(get_maj_min
$_dev)
342 if [[ $_majmin ]]; then
349 if [[ $_dev = *:* ]]; then
353 done < <(findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
355 # fall back to /etc/fstab
357 while read _majmin _dev
; do
358 if ! [[ $_dev ]]; then
362 if [[ -b $_dev ]]; then
363 [[ $_majmin ]] ||
read _majmin
< <(get_maj_min
$_dev)
364 if [[ $_majmin ]]; then
371 if [[ $_dev = *:* ]]; then
375 done < <(findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
380 # find_mp_fstype <mountpoint>
381 # Echo the filesystem type for a given mountpoint.
382 # /proc/self/mountinfo is taken as the primary source of information
383 # and /etc/fstab is used as a fallback.
384 # No newline is appended!
386 # $ find_mp_fstype /;echo
391 if [[ $use_fstab != yes ]]; then
393 [[ $_fs ]] ||
continue
394 [[ $_fs = "autofs" ]] && continue
397 done < <(findmnt
-e -v -n -o 'FSTYPE' --target "$1")
401 [[ $_fs ]] ||
continue
402 [[ $_fs = "autofs" ]] && continue
405 done < <(findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1")
410 # find_dev_fstype <device>
411 # Echo the filesystem type for a given device.
412 # /proc/self/mountinfo is taken as the primary source of information
413 # and /etc/fstab is used as a fallback.
414 # No newline is appended!
416 # $ find_dev_fstype /dev/sda2;echo
421 [[ "$_find_dev" = /dev
* ]] || _find_dev
="/dev/block/$_find_dev"
423 if [[ $use_fstab != yes ]]; then
425 [[ $_fs ]] ||
continue
426 [[ $_fs = "autofs" ]] && continue
429 done < <(findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev")
433 [[ $_fs ]] ||
continue
434 [[ $_fs = "autofs" ]] && continue
437 done < <(findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev")
443 # finds the major:minor of the block device backing the root filesystem.
444 find_root_block_device
() { find_block_device
/; }
446 # for_each_host_dev_fs <func>
447 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
448 # in ${host_fs_types[@]}
449 for_each_host_dev_fs
()
455 [[ "${!host_fs_types[@]}" ]] ||
return 0
457 for _dev
in "${!host_fs_types[@]}"; do
458 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
465 echo "${host_fs_types[@]}"
468 # Walk all the slave relationships for a given block device.
469 # Stop when our helper function returns success
470 # $1 = function to call on every found block device
471 # $2 = block device in major:minor format
472 check_block_and_slaves
() {
474 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
476 check_vol_slaves
"$@" && return 0
477 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
478 check_block_and_slaves
$1 $
(cat "/sys/dev/block/$2/../dev") && return 0
480 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
481 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
482 [[ -f $_x ]] ||
continue
483 check_block_and_slaves
$1 $
(cat "$_x") && return 0
488 check_block_and_slaves_all
() {
490 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
494 check_vol_slaves
"$@" && return 0
495 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
496 check_block_and_slaves_all
$1 $
(cat "/sys/dev/block/$2/../dev") && _ret
=0
498 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
499 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
500 [[ -f $_x ]] ||
continue
501 check_block_and_slaves_all
$1 $
(cat "$_x") && _ret
=0
505 # for_each_host_dev_and_slaves <func>
506 # Execute "<func> <dev>" for every "<dev>" found
507 # in ${host_devs[@]} and their slaves
508 for_each_host_dev_and_slaves_all
()
514 [[ "${host_devs[@]}" ]] ||
return 0
516 for _dev
in ${host_devs[@]}; do
517 [[ -b "$_dev" ]] ||
continue
518 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
525 for_each_host_dev_and_slaves
()
530 [[ "${host_devs[@]}" ]] ||
return 0
532 for _dev
in ${host_devs[@]}; do
533 [[ -b "$_dev" ]] ||
continue
534 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
539 # ugly workaround for the lvm design
540 # There is no volume group device,
541 # so, there are no slave devices for volume groups.
542 # Logical volumes only have the slave devices they really live on,
543 # but you cannot create the logical volume without the volume group.
544 # And the volume group might be bigger than the devices the LV needs.
547 for i
in /dev
/mapper
/*; do
548 _lv
=$
(get_maj_min
$i)
549 if [[ $_lv = $2 ]]; then
550 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
554 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
556 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
564 # fs_get_option <filesystem options> <search for option>
565 # search for a specific option in a bunch of filesystem options
566 # and return the value
574 while [ $# -gt 0 ]; do
577 echo ${1#${_option}=}
584 if [[ $DRACUT_INSTALL ]]; then
585 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
587 [[ -e ${initdir}/"$1" ]] && return 0 # already there
588 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
589 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" ||
:
593 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
594 #dinfo "$DRACUT_INSTALL -l $@"
595 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
596 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
600 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
601 [[ -e $1 ]] ||
return 1 # no source
602 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
603 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" ||
:
607 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
608 [[ -L $1 ]] ||
return 1
609 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
610 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
615 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
616 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
618 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
623 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
624 [[ -e $1 ]] ||
return 1 # no source
625 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
626 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
630 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
631 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
635 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
636 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
641 # Install a directory, keeping symlinks as on the original system.
642 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
643 # will create ${initdir}/lib64, ${initdir}/lib64/file,
644 # and a symlink ${initdir}/lib -> lib64.
646 [[ -e ${initdir}/"$1" ]] && return 0 # already there
648 local _dir
="$1" _part
="${1%/*}" _file
649 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
654 # iterate over parent directories
655 for _file
in $_dir; do
656 [[ -e "${initdir}/$_file" ]] && continue
657 if [[ -L $_file ]]; then
658 inst_symlink
"$_file"
661 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
662 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
663 chmod u
+w
"${initdir}/$_file"
668 # $1 = file to copy to ramdisk
669 # $2 (optional) Name for the file on the ramdisk
670 # Location of the image dir is assumed to be $initdir
671 # We never overwrite the target if it exists.
673 [[ -f "$1" ]] ||
return 1
674 [[ "$1" == */* ]] ||
return 1
675 local _src
=$1 _target
="${2:-$1}"
677 [[ -L $_src ]] && { inst_symlink
$_src $_target; return $?
; }
679 if ! [[ -d ${initdir}/$_target ]]; then
680 [[ -e ${initdir}/$_target ]] && return 0
681 [[ -L ${initdir}/$_target ]] && return 0
682 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
684 if [[ $DRACUT_FIPS_MODE ]]; then
685 # install checksum files also
686 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
687 inst
"${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
689 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
690 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
692 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
693 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
696 ddebug
"Installing $_src"
697 cp --reflink=auto
--sparse=auto
-pfL "$_src" "${initdir}/$_target"
700 # same as above, but specialized for symlinks
702 local _src
=$1 _target
=${2:-$1} _realsrc
703 [[ "$1" == */* ]] ||
return 1
704 [[ -L $1 ]] ||
return 1
705 [[ -L $initdir/$_target ]] && return 0
706 _realsrc
=$
(readlink
-f "$_src")
707 if ! [[ -e $initdir/$_realsrc ]]; then
708 if [[ -d $_realsrc ]]; then
714 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
716 ln_r
"${_realsrc}" "${_target}"
719 # Same as above, but specialized to handle dynamic libraries.
720 # It handles making symlinks according to how the original library
723 local _src
="$1" _dest
=${2:-$1} _lib _reallib _symlink
724 [[ "$1" == */* ]] ||
return 1
725 [[ -e $initdir/$_dest ]] && return 0
726 if [[ -L $_src ]]; then
727 if [[ $DRACUT_FIPS_MODE ]]; then
728 # install checksum files also
729 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
730 inst
"${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
732 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
733 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
735 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
736 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
739 _reallib
=$
(readlink
-f "$_src")
740 inst_simple
"$_reallib" "$_reallib"
741 inst_dir
"${_dest%/*}"
742 ln_r
"${_reallib}" "${_dest}"
744 inst_simple
"$_src" "$_dest"
747 # Create additional symlinks. See rev_symlinks description.
748 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
749 [[ ! -e $initdir/$_symlink ]] && {
750 ddebug
"Creating extra symlink: $_symlink"
751 inst_symlink
$_symlink
756 # Same as above, but specialized to install binary executables.
757 # Install binary executable, and all shared library dependencies, if any.
760 _bin
=$
(find_binary
"$1") ||
return 1
762 [[ -e $initdir/$_target ]] && return 0
764 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
766 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
767 [[ $_line = 'not a dynamic executable' ]] && break
769 if [[ $_line =~
$_so_regex ]]; then
770 _file
=${BASH_REMATCH[1]}
771 [[ -e ${initdir}/$_file ]] && continue
772 inst_library
"$_file"
776 if [[ $_line == *not\ found
* ]]; then
777 dfatal
"Missing a shared library required by $_bin."
778 dfatal
"Run \"ldd $_bin\" to find out what it is."
780 dfatal
"dracut cannot create an initrd."
784 inst_simple
"$_bin" "$_target"
787 # same as above, except for shell scripts.
788 # If your shell script does not start with shebang, it is not a shell script.
791 _bin
=$
(find_binary
"$1") ||
return 1
793 local _line _shebang_regex
794 read -r -n 80 _line
<"$_bin"
795 # If debug is set, clean unprintable chars to prevent messing up the term
796 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
797 _shebang_regex
='(#! *)(/[^ ]+).*'
798 [[ $_line =~
$_shebang_regex ]] ||
return 1
799 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
802 # general purpose installation function
803 # Same args as above.
809 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
810 [[ $initdir = $2 ]] && set $1;;
811 3) [[ -z $initdir ]] && export initdir
=$2
813 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
816 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
822 # dracut_install [-o ] <file> [<file> ... ]
823 # Install <file> to the initramfs image
824 # -o optionally install the <file> and don't fail, if it is not there
827 if [[ $1 = '-o' ]]; then
832 if ! inst
"$1" ; then
833 if [[ $_optional = yes ]]; then
834 dinfo
"Skipping program $1 as it cannot be found and is" \
835 "flagged to be optional"
837 dfatal
"Failed to install $1"
847 # find symlinks linked to given library file
849 # Function searches for symlinks by stripping version numbers appended to
850 # library filename, checks if it points to the same target and finally
851 # prints the list of symlinks to stdout.
854 # rev_lib_symlinks libfoo.so.8.1
855 # output: libfoo.so.8 libfoo.so
856 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
858 [[ ! $1 ]] && return 0
860 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
862 [[ ${fn} == *.so.
* ]] ||
return 1
864 until [[ ${fn##*.} == so
]]; do
866 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
872 # attempt to install any programs specified in a udev rule
873 inst_rule_programs() {
876 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
877 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
879 if [ -x ${udevdir}/$_prog ]; then
880 _bin=${udevdir}/$_prog
881 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
882 _bin=$(find_binary "$_prog") || {
883 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
888 [[ $_bin ]] && dracut_install "$_bin"
891 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
892 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
894 if [ -x ${udevdir}/$_prog ]; then
895 _bin=${udevdir}/$_prog
896 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
897 _bin=$(find_binary "$_prog") || {
898 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
903 [[ $_bin ]] && dracut_install "$_bin"
906 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
907 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
909 if [ -x ${udevdir}/$_prog ]; then
910 _bin=${udevdir}/$_prog
911 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
912 _bin=$(find_binary "$_prog") || {
913 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
918 [[ $_bin ]] && dracut_install "$_bin"
923 # attempt to install any programs specified in a udev rule
924 inst_rule_group_owner() {
927 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
928 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
929 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
930 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
934 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
935 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
936 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
937 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
943 inst_rule_initqueue() {
944 if grep -q -F initqueue "$1"; then
945 dracut_need_initqueue
949 # udev rules always get installed in the same place, so
950 # create a function to install them to make life simpler.
952 local _target=/etc/udev/rules.d _rule _found
954 inst_dir "${udevdir}/rules.d
"
956 for _rule in "$@
"; do
957 if [ "${_rule#/}" = "$_rule" ]; then
958 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
959 if [[ -f $r/$_rule ]]; then
961 inst_rule_programs "$_found"
962 inst_rule_group_owner "$_found"
963 inst_rule_initqueue "$_found"
964 inst_simple "$_found"
968 for r in '' ./ $dracutbasedir/rules.d/; do
969 if [[ -f ${r}$_rule ]]; then
971 inst_rule_programs "$_found"
972 inst_rule_group_owner "$_found"
973 inst_rule_initqueue "$_found"
974 inst_simple "$_found" "$_target/${_found##*/}"
977 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
981 prepare_udev_rules() {
982 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
985 f="${initdir}/etc
/udev
/rules.d
/$f"
986 [ -e "$f" ] || continue
988 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
989 if [ $UDEVVERSION -ge 174 ]; then
990 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
992 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
994 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
995 if [ $UDEVVERSION -ge 176 ]; then
996 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
998 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1003 done < "${f}" > "${f}.new
"
1008 # install function specialized for hooks
1009 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1010 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1012 if ! [[ -f $3 ]]; then
1013 dfatal "Cannot
install a hook
($3) that does not exist.
"
1014 dfatal "Aborting initrd creation.
"
1016 elif ! [[ "$hookdirs" == *$1* ]]; then
1017 dfatal "No such hook
type $1. Aborting initrd creation.
"
1020 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1023 # install any of listed files
1025 # If first argument is '-d' and second some destination path, first accessible
1026 # source is installed into this path, otherwise it will installed in the same
1027 # path as source. If none of listed files was installed, function return 1.
1028 # On first successful installation it returns with 0 status.
1032 # inst_any -d /bin/foo /bin/bar /bin/baz
1034 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1039 [[ $1 = '-d' ]] && to="$2" && shift 2
1042 if [[ -e $f ]]; then
1043 [[ $to ]] && inst "$f" "$to" && return 0
1044 inst "$f" && return 0
1052 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1053 # Install a <file> located on a lib directory to the initramfs image
1054 # -n <pattern> install matching files
1055 inst_libdir_file() {
1057 if [[ "$1" == "-n" ]]; then
1060 for _dir in $libdirs; do
1062 for _f in "$_dir"/$_i; do
1063 [[ "$_f" =~ $_pattern ]] || continue
1064 [[ -e "$_f" ]] && _files+="$_f "
1069 for _dir in $libdirs; do
1071 for _f in "$_dir"/$_i; do
1072 [[ -e "$_f" ]] && _files+="$_f "
1077 [[ $_files ]] && dracut_install $_files
1081 # install function decompressing the target and handling symlinks
1082 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1084 # Function install targets in the same paths inside overlay but decompressed
1085 # and without extensions (.gz, .bz2).
1092 *.gz) _cmd='gzip -f -d' ;;
1093 *.bz2) _cmd='bzip2 -d' ;;
1097 # Decompress with chosen tool. We assume that tool changes name e.g.
1098 # from 'name.gz' to 'name'.
1099 ${_cmd} "${initdir}${_src}"
1103 # It's similar to above, but if file is not compressed, performs standard
1105 # $@ = list of files
1106 inst_opt_decompress
() {
1111 inst_decompress
"${_src}" || inst
"${_src}"
1115 # module_check <dracut module>
1116 # execute the check() function of module-setup.sh of <dracut module>
1117 # or the "check" script, if module-setup.sh is not found
1118 # "check $hostonly" is called
1120 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1123 local _hostonly
=$hostonly
1124 [ $# -eq 2 ] && _forced
=$2
1125 [[ -d $_moddir ]] ||
return 1
1126 if [[ ! -f $_moddir/module-setup.sh
]]; then
1127 # if we do not have a check script, we are unconditionally included
1128 [[ -x $_moddir/check
]] ||
return 0
1129 [ $_forced -ne 0 ] && unset hostonly
1130 $_moddir/check
$hostonly
1133 unset check depends
install installkernel
1135 .
$_moddir/module-setup.sh
1136 is_func check ||
return 0
1137 [ $_forced -ne 0 ] && unset hostonly
1140 unset check depends
install installkernel
1146 # module_check_mount <dracut module>
1147 # execute the check() function of module-setup.sh of <dracut module>
1148 # or the "check" script, if module-setup.sh is not found
1149 # "mount_needs=1 check 0" is called
1150 module_check_mount
() {
1151 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1154 [[ -d $_moddir ]] ||
return 1
1155 if [[ ! -f $_moddir/module-setup.sh
]]; then
1156 # if we do not have a check script, we are unconditionally included
1157 [[ -x $_moddir/check
]] ||
return 0
1158 mount_needs
=1 $_moddir/check
0
1161 unset check depends
install installkernel
1163 .
$_moddir/module-setup.sh
1166 unset check depends
install installkernel
1172 # module_depends <dracut module>
1173 # execute the depends() function of module-setup.sh of <dracut module>
1174 # or the "depends" script, if module-setup.sh is not found
1176 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1178 [[ -d $_moddir ]] ||
return 1
1179 if [[ ! -f $_moddir/module-setup.sh
]]; then
1180 # if we do not have a check script, we have no deps
1181 [[ -x $_moddir/check
]] ||
return 0
1185 unset check depends
install installkernel
1187 .
$_moddir/module-setup.sh
1190 unset check depends
install installkernel
1195 # module_install <dracut module>
1196 # execute the install() function of module-setup.sh of <dracut module>
1197 # or the "install" script, if module-setup.sh is not found
1199 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1201 [[ -d $_moddir ]] ||
return 1
1202 if [[ ! -f $_moddir/module-setup.sh
]]; then
1203 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1206 unset check depends
install installkernel
1208 .
$_moddir/module-setup.sh
1211 unset check depends
install installkernel
1216 # module_installkernel <dracut module>
1217 # execute the installkernel() function of module-setup.sh of <dracut module>
1218 # or the "installkernel" script, if module-setup.sh is not found
1219 module_installkernel
() {
1220 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1222 [[ -d $_moddir ]] ||
return 1
1223 if [[ ! -f $_moddir/module-setup.sh
]]; then
1224 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1227 unset check depends
install installkernel
1228 installkernel
() { true
; }
1229 .
$_moddir/module-setup.sh
1232 unset check depends
install installkernel
1237 # check_mount <dracut module>
1238 # check_mount checks, if a dracut module is needed for the given
1239 # device and filesystem types in "${host_fs_types[@]}"
1242 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1246 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1248 # If we are already scheduled to be loaded, no need to check again.
1249 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1250 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1252 # This should never happen, but...
1253 [[ -d $_moddir ]] ||
return 1
1255 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1257 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1258 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1262 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1263 module_check_mount
$_mod; ret
=$?
1265 # explicit module, so also accept ret=255
1266 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1268 # module not in our list
1269 if [[ $dracutmodules = all
]]; then
1270 # check, if we can and should install this module
1271 module_check_mount
$_mod ||
return 1
1279 for _moddep
in $
(module_depends
$_mod); do
1280 # handle deps as if they were manually added
1281 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1282 add_dracutmodules
+=" $_moddep "
1283 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1284 force_add_dracutmodules
+=" $_moddep "
1285 # if a module we depend on fail, fail also
1286 if ! check_module
$_moddep; then
1287 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1292 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1293 mods_to_load
+=" $_mod "
1298 # check_module <dracut module> [<use_as_dep>]
1299 # check if a dracut module is to be used in the initramfs process
1300 # if <use_as_dep> is set, then the process also keeps track
1301 # that the modules were checked for the dependency tracking process
1304 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1307 # If we are already scheduled to be loaded, no need to check again.
1308 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1309 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1311 # This should never happen, but...
1312 [[ -d $_moddir ]] ||
return 1
1314 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1316 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1317 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1321 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1322 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1323 module_check
$_mod 1; ret
=$?
1325 module_check
$_mod 0; ret
=$?
1327 # explicit module, so also accept ret=255
1328 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1330 # module not in our list
1331 if [[ $dracutmodules = all
]]; then
1332 # check, if we can and should install this module
1333 module_check
$_mod ||
return 1
1340 for _moddep
in $
(module_depends
$_mod); do
1341 # handle deps as if they were manually added
1342 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1343 add_dracutmodules
+=" $_moddep "
1344 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1345 force_add_dracutmodules
+=" $_moddep "
1346 # if a module we depend on fail, fail also
1347 if ! check_module
$_moddep; then
1348 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1353 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1354 mods_to_load
+=" $_mod "
1359 # for_each_module_dir <func>
1360 # execute "<func> <dracut module> 1"
1361 for_each_module_dir
() {
1367 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1368 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1372 # Report any missing dracut modules, the user has specified
1373 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1374 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1375 for _mod
in $_modcheck; do
1376 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1377 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1378 derror
"dracut module '$_mod' cannot be found or installed."
1382 # Install a single kernel module along with any firmware it may require.
1383 # $1 = full path to kernel module to install
1384 install_kmod_with_fw
() {
1385 # no need to go further if the module is already installed
1387 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1390 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1391 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1395 if [[ $omit_drivers ]]; then
1396 local _kmod
=${1##*/}
1399 if [[ "$_kmod" =~
$omit_drivers ]]; then
1400 dinfo
"Omitting driver $_kmod"
1403 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1404 dinfo
"Omitting driver $_kmod"
1409 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1411 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1412 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1413 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1414 (($ret != 0)) && return $ret
1416 local _modname
=${1##*/} _fwdir _found _fw
1417 _modname
=${_modname%.ko*}
1418 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1420 for _fwdir
in $fw_dir; do
1421 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1422 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1426 if [[ $_found != yes ]]; then
1427 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1428 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1429 "\"${_modname}.ko\""
1431 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1432 "\"${_modname}.ko\""
1439 # Do something with all the dependencies of a kernel module.
1440 # Note that kernel modules depend on themselves using the technique we use
1441 # $1 = function to call for each dependency we find
1442 # It will be passed the full path to the found kernel module
1443 # $2 = module to get dependencies for
1444 # rest of args = arguments to modprobe
1445 # _fderr specifies FD passed from surrounding scope
1446 for_each_kmod_dep
() {
1447 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1449 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1450 while read _cmd _modpath _options
; do
1451 [[ $_cmd = insmod
]] ||
continue
1452 $_func ${_modpath} ||
exit $?
1457 dracut_kernel_post
() {
1458 local _moddirname
=${srcmods%%/lib/modules/*}
1460 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1461 xargs -r modprobe
-a ${_moddirname+-d ${_moddirname}/} \
1462 --ignore-install --show-depends --set-version $kernel \
1463 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1465 |
while read _cmd _modpath _options
; do
1466 [[ $_cmd = insmod
]] ||
continue
1468 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1471 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1472 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1474 while read _modpath
; do
1475 local _destpath
=$_modpath
1476 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1477 _destpath
=${_destpath##*/lib/modules/$kernel/}
1478 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1479 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1483 if [[ $DRACUT_INSTALL ]]; then
1484 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1485 |
while read line
; do
1486 for _fwdir
in $fw_dir; do
1489 done |
xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
1491 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1492 for _fwdir
in $fw_dir; do
1493 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1494 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1504 for _f
in modules.
builtin.bin modules.
builtin; do
1505 [[ $srcmods/$_f ]] && break
1507 dfatal
"No modules.builtin.bin and modules.builtin found!"
1511 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1512 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1515 # generate module dependencies for the initrd
1516 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1517 ! depmod
-a -b "$initdir" $kernel; then
1518 dfatal
"\"depmod -a $kernel\" failed."
1522 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1525 module_is_host_only
() { (
1530 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1532 # check if module is loaded
1533 for i
in /sys
/module
/${_mod//-/_}; do
1534 [[ -d $i ]] && return 0
1537 # check if module is loadable on the current kernel
1538 # this covers the case, where a new module is introduced
1539 # or a module was renamed
1540 # or a module changed from builtin to a module
1541 modinfo
-F filename
"$_mod" &>/dev
/null ||
return 0
1547 find_kernel_modules_by_path
() {
1550 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1554 while read a rest
; do
1555 [[ $a = */$1/* ]] ||
continue
1556 printf "%s\n" "$srcmods/$a"
1557 done < "$srcmods/modules.dep"
1562 find_kernel_modules
() {
1563 find_kernel_modules_by_path drivers
1566 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1567 # instmods [-c [-s]] <kernel subsystem>
1568 # install kernel modules along with all their dependencies.
1569 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1571 [[ $no_kernel = yes ]] && return
1572 # called [sub]functions inherit _fderr
1576 if [[ $1 = '-c' ]]; then
1581 if [[ $1 = '-s' ]]; then
1586 function inst1mod
() {
1587 local _ret
=0 _mod
="$1"
1590 ( [[ "$_mpargs" ]] && echo $_mpargs
1591 find_kernel_modules_by_path
"${_mod#=}" ) \
1595 --*) _mpargs
+=" $_mod" ;;
1598 # if we are already installed, skip this module and go on
1600 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1601 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1602 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1606 if [[ $omit_drivers ]] && [[ "$1" =~
$omit_drivers ]]; then
1607 dinfo
"Omitting driver ${_mod##$srcmods}"
1611 # If we are building a host-specific initramfs and this
1612 # module is not already loaded, move on to the next one.
1614 && ! module_is_host_only
"$_mod" \
1617 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1618 # We use '-d' option in modprobe only if modules prefix path
1619 # differs from default '/'. This allows us to use dracut with
1620 # old version of modprobe which doesn't have '-d' option.
1621 local _moddirname
=${srcmods%%/lib/modules/*}
1622 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1624 # ok, load the module, all its dependencies, and any firmware
1626 for_each_kmod_dep install_kmod_with_fw
$_mod \
1627 --set-version $kernel ${_moddirname} $_mpargs
1630 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1631 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1638 function instmods_1
() {
1640 if (($# == 0)); then # filenames from stdin
1642 inst1mod
"${_mod%.ko*}" ||
{
1643 if [[ "$_check" == "yes" ]]; then
1644 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1650 while (($# > 0)); do # filenames as arguments
1651 inst1mod
${1%.ko*} ||
{
1652 if [[ "$_check" == "yes" ]]; then
1653 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1662 local _ret _filter_not_found
='FATAL: Module .* not found.'
1663 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1664 # redirections, but that would make dracut require bash4 at least.
1665 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1666 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1671 # Only two values are returned: AMD or Intel
1674 if grep -qE AMD
/proc
/cpuinfo
; then
1677 if grep -qE Intel
/proc
/cpuinfo
; then
1683 # Get the hosts' ucode file based on the /proc/cpuinfo
1686 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1687 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1688 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1690 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1691 # If family greater or equal than 0x15
1692 if [[ $family -ge 21 ]]; then
1693 printf "microcode_amd_fam15h.bin"
1695 printf "microcode_amd.bin"
1698 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1699 # The /proc/cpuinfo are in decimal.
1700 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}