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"
293 # Fallback, if we don't have udev information
294 if find_binary blkid
>/dev
/null
; then
295 ID_FS_TYPE
=$
(blkid
-u filesystem
-o export -- "$1" \
296 |
while read line
; do
297 if [[ "$line" == TYPE\
=* ]]; then
298 printf "%s" "${line#TYPE=}";
302 if [[ $ID_FS_TYPE ]]; then
303 printf "%s" "$ID_FS_TYPE"
310 # get_maj_min <device>
311 # Prints the major and minor of a device node.
313 # $ get_maj_min /dev/sda2
317 read _maj _min
< <(stat
-L -c '%t %T' "$1" 2>/dev
/null
)
318 printf "%s" "$((0x$_maj)):$((0x$_min))"
321 # find_block_device <mountpoint>
322 # Prints the major and minor number of the block device
323 # for a given mountpoint.
324 # Unless $use_fstab is set to "yes" the functions
325 # uses /proc/self/mountinfo as the primary source of the
326 # information and only falls back to /etc/fstab, if the mountpoint
327 # is not found there.
329 # $ find_block_device /usr
331 find_block_device
() {
332 local _majmin _dev _majmin _find_mpt
334 if [[ $use_fstab != yes ]]; then
335 [[ -d $_find_mpt/.
]]
336 while read _majmin _dev
; do
337 if [[ -b $_dev ]]; then
338 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
339 read _majmin
< <(get_maj_min
$_dev)
341 if [[ $_majmin ]]; then
348 if [[ $_dev = *:* ]]; then
352 done < <(findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
354 # fall back to /etc/fstab
356 while read _majmin _dev
; do
357 if ! [[ $_dev ]]; then
361 if [[ -b $_dev ]]; then
362 [[ $_majmin ]] ||
read _majmin
< <(get_maj_min
$_dev)
363 if [[ $_majmin ]]; then
370 if [[ $_dev = *:* ]]; then
374 done < <(findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
379 # find_mp_fstype <mountpoint>
380 # Echo the filesystem type for a given mountpoint.
381 # /proc/self/mountinfo is taken as the primary source of information
382 # and /etc/fstab is used as a fallback.
383 # No newline is appended!
385 # $ find_mp_fstype /;echo
390 if [[ $use_fstab != yes ]]; then
392 [[ $_fs ]] ||
continue
393 [[ $_fs = "autofs" ]] && continue
396 done < <(findmnt
-e -v -n -o 'FSTYPE' --target "$1")
400 [[ $_fs ]] ||
continue
401 [[ $_fs = "autofs" ]] && continue
404 done < <(findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1")
409 # find_dev_fstype <device>
410 # Echo the filesystem type for a given device.
411 # /proc/self/mountinfo is taken as the primary source of information
412 # and /etc/fstab is used as a fallback.
413 # No newline is appended!
415 # $ find_dev_fstype /dev/sda2;echo
420 [[ "$_find_dev" = /dev
* ]] || _find_dev
="/dev/block/$_find_dev"
422 if [[ $use_fstab != yes ]]; then
424 [[ $_fs ]] ||
continue
425 [[ $_fs = "autofs" ]] && continue
428 done < <(findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev")
432 [[ $_fs ]] ||
continue
433 [[ $_fs = "autofs" ]] && continue
436 done < <(findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev")
442 # finds the major:minor of the block device backing the root filesystem.
443 find_root_block_device
() { find_block_device
/; }
445 # for_each_host_dev_fs <func>
446 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
447 # in ${host_fs_types[@]}
448 for_each_host_dev_fs
()
454 [[ "${!host_fs_types[@]}" ]] ||
return 0
456 for _dev
in "${!host_fs_types[@]}"; do
457 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
464 echo "${host_fs_types[@]}"
467 # Walk all the slave relationships for a given block device.
468 # Stop when our helper function returns success
469 # $1 = function to call on every found block device
470 # $2 = block device in major:minor format
471 check_block_and_slaves
() {
473 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
475 check_vol_slaves
"$@" && return 0
476 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
477 check_block_and_slaves
$1 $
(cat "/sys/dev/block/$2/../dev") && return 0
479 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
480 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
481 [[ -f $_x ]] ||
continue
482 check_block_and_slaves
$1 $
(cat "$_x") && return 0
487 check_block_and_slaves_all
() {
489 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
493 check_vol_slaves
"$@" && return 0
494 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
495 check_block_and_slaves_all
$1 $
(cat "/sys/dev/block/$2/../dev") && _ret
=0
497 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
498 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
499 [[ -f $_x ]] ||
continue
500 check_block_and_slaves_all
$1 $
(cat "$_x") && _ret
=0
504 # for_each_host_dev_and_slaves <func>
505 # Execute "<func> <dev>" for every "<dev>" found
506 # in ${host_devs[@]} and their slaves
507 for_each_host_dev_and_slaves_all
()
513 [[ "${host_devs[@]}" ]] ||
return 0
515 for _dev
in ${host_devs[@]}; do
516 [[ -b "$_dev" ]] ||
continue
517 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
524 for_each_host_dev_and_slaves
()
529 [[ "${host_devs[@]}" ]] ||
return 0
531 for _dev
in ${host_devs[@]}; do
532 [[ -b "$_dev" ]] ||
continue
533 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
538 # ugly workaround for the lvm design
539 # There is no volume group device,
540 # so, there are no slave devices for volume groups.
541 # Logical volumes only have the slave devices they really live on,
542 # but you cannot create the logical volume without the volume group.
543 # And the volume group might be bigger than the devices the LV needs.
546 for i
in /dev
/mapper
/*; do
547 _lv
=$
(get_maj_min
$i)
548 if [[ $_lv = $2 ]]; then
549 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
553 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
555 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
563 # fs_get_option <filesystem options> <search for option>
564 # search for a specific option in a bunch of filesystem options
565 # and return the value
573 while [ $# -gt 0 ]; do
576 echo ${1#${_option}=}
583 if [[ $DRACUT_INSTALL ]]; then
584 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
586 [[ -e ${initdir}/"$1" ]] && return 0 # already there
587 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
588 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" ||
:
592 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
593 #dinfo "$DRACUT_INSTALL -l $@"
594 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
595 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
599 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
600 [[ -e $1 ]] ||
return 1 # no source
601 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
602 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" ||
:
606 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
607 [[ -L $1 ]] ||
return 1
608 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
609 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
614 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
615 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
617 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
622 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
623 [[ -e $1 ]] ||
return 1 # no source
624 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
625 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
629 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
630 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
634 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
635 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
640 # Install a directory, keeping symlinks as on the original system.
641 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
642 # will create ${initdir}/lib64, ${initdir}/lib64/file,
643 # and a symlink ${initdir}/lib -> lib64.
645 [[ -e ${initdir}/"$1" ]] && return 0 # already there
647 local _dir
="$1" _part
="${1%/*}" _file
648 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
653 # iterate over parent directories
654 for _file
in $_dir; do
655 [[ -e "${initdir}/$_file" ]] && continue
656 if [[ -L $_file ]]; then
657 inst_symlink
"$_file"
660 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
661 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
662 chmod u
+w
"${initdir}/$_file"
667 # $1 = file to copy to ramdisk
668 # $2 (optional) Name for the file on the ramdisk
669 # Location of the image dir is assumed to be $initdir
670 # We never overwrite the target if it exists.
672 [[ -f "$1" ]] ||
return 1
673 [[ "$1" == */* ]] ||
return 1
674 local _src
=$1 _target
="${2:-$1}"
676 [[ -L $_src ]] && { inst_symlink
$_src $_target; return $?
; }
678 if ! [[ -d ${initdir}/$_target ]]; then
679 [[ -e ${initdir}/$_target ]] && return 0
680 [[ -L ${initdir}/$_target ]] && return 0
681 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
683 if [[ $DRACUT_FIPS_MODE ]]; then
684 # install checksum files also
685 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
686 inst
"${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
688 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
689 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
691 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
692 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
695 ddebug
"Installing $_src"
696 cp --reflink=auto
--sparse=auto
-pfL "$_src" "${initdir}/$_target"
699 # same as above, but specialized for symlinks
701 local _src
=$1 _target
=${2:-$1} _realsrc
702 [[ "$1" == */* ]] ||
return 1
703 [[ -L $1 ]] ||
return 1
704 [[ -L $initdir/$_target ]] && return 0
705 _realsrc
=$
(readlink
-f "$_src")
706 if ! [[ -e $initdir/$_realsrc ]]; then
707 if [[ -d $_realsrc ]]; then
713 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
715 ln_r
"${_realsrc}" "${_target}"
718 # Same as above, but specialized to handle dynamic libraries.
719 # It handles making symlinks according to how the original library
722 local _src
="$1" _dest
=${2:-$1} _lib _reallib _symlink
723 [[ "$1" == */* ]] ||
return 1
724 [[ -e $initdir/$_dest ]] && return 0
725 if [[ -L $_src ]]; then
726 if [[ $DRACUT_FIPS_MODE ]]; then
727 # install checksum files also
728 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
729 inst
"${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
731 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
732 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
734 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
735 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
738 _reallib
=$
(readlink
-f "$_src")
739 inst_simple
"$_reallib" "$_reallib"
740 inst_dir
"${_dest%/*}"
741 ln_r
"${_reallib}" "${_dest}"
743 inst_simple
"$_src" "$_dest"
746 # Create additional symlinks. See rev_symlinks description.
747 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
748 [[ ! -e $initdir/$_symlink ]] && {
749 ddebug
"Creating extra symlink: $_symlink"
750 inst_symlink
$_symlink
755 # Same as above, but specialized to install binary executables.
756 # Install binary executable, and all shared library dependencies, if any.
759 _bin
=$
(find_binary
"$1") ||
return 1
761 [[ -e $initdir/$_target ]] && return 0
763 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
765 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
766 [[ $_line = 'not a dynamic executable' ]] && break
768 if [[ $_line =~
$_so_regex ]]; then
769 _file
=${BASH_REMATCH[1]}
770 [[ -e ${initdir}/$_file ]] && continue
771 inst_library
"$_file"
775 if [[ $_line == *not\ found
* ]]; then
776 dfatal
"Missing a shared library required by $_bin."
777 dfatal
"Run \"ldd $_bin\" to find out what it is."
779 dfatal
"dracut cannot create an initrd."
783 inst_simple
"$_bin" "$_target"
786 # same as above, except for shell scripts.
787 # If your shell script does not start with shebang, it is not a shell script.
790 _bin
=$
(find_binary
"$1") ||
return 1
792 local _line _shebang_regex
793 read -r -n 80 _line
<"$_bin"
794 # If debug is set, clean unprintable chars to prevent messing up the term
795 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
796 _shebang_regex
='(#! *)(/[^ ]+).*'
797 [[ $_line =~
$_shebang_regex ]] ||
return 1
798 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
801 # general purpose installation function
802 # Same args as above.
808 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
809 [[ $initdir = $2 ]] && set $1;;
810 3) [[ -z $initdir ]] && export initdir
=$2
812 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
815 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
821 # dracut_install [-o ] <file> [<file> ... ]
822 # Install <file> to the initramfs image
823 # -o optionally install the <file> and don't fail, if it is not there
826 if [[ $1 = '-o' ]]; then
831 if ! inst
"$1" ; then
832 if [[ $_optional = yes ]]; then
833 dinfo
"Skipping program $1 as it cannot be found and is" \
834 "flagged to be optional"
836 dfatal
"Failed to install $1"
846 # find symlinks linked to given library file
848 # Function searches for symlinks by stripping version numbers appended to
849 # library filename, checks if it points to the same target and finally
850 # prints the list of symlinks to stdout.
853 # rev_lib_symlinks libfoo.so.8.1
854 # output: libfoo.so.8 libfoo.so
855 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
857 [[ ! $1 ]] && return 0
859 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
861 [[ ${fn} == *.so.
* ]] ||
return 1
863 until [[ ${fn##*.} == so
]]; do
865 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
871 # attempt to install any programs specified in a udev rule
872 inst_rule_programs() {
875 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
876 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
878 if [ -x ${udevdir}/$_prog ]; then
879 _bin=${udevdir}/$_prog
880 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
881 _bin=$(find_binary "$_prog") || {
882 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
887 [[ $_bin ]] && dracut_install "$_bin"
890 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
891 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
893 if [ -x ${udevdir}/$_prog ]; then
894 _bin=${udevdir}/$_prog
895 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
896 _bin=$(find_binary "$_prog") || {
897 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
902 [[ $_bin ]] && dracut_install "$_bin"
905 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
906 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
908 if [ -x ${udevdir}/$_prog ]; then
909 _bin=${udevdir}/$_prog
910 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
911 _bin=$(find_binary "$_prog") || {
912 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
917 [[ $_bin ]] && dracut_install "$_bin"
922 # attempt to install any programs specified in a udev rule
923 inst_rule_group_owner() {
926 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
927 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
928 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
929 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
933 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
934 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
935 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
936 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
942 inst_rule_initqueue() {
943 if grep -q -F initqueue "$1"; then
944 dracut_need_initqueue
948 # udev rules always get installed in the same place, so
949 # create a function to install them to make life simpler.
951 local _target=/etc/udev/rules.d _rule _found
953 inst_dir "${udevdir}/rules.d
"
955 for _rule in "$@
"; do
956 if [ "${_rule#/}" = "$_rule" ]; then
957 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
958 if [[ -f $r/$_rule ]]; then
960 inst_rule_programs "$_found"
961 inst_rule_group_owner "$_found"
962 inst_rule_initqueue "$_found"
963 inst_simple "$_found"
967 for r in '' ./ $dracutbasedir/rules.d/; do
968 if [[ -f ${r}$_rule ]]; then
970 inst_rule_programs "$_found"
971 inst_rule_group_owner "$_found"
972 inst_rule_initqueue "$_found"
973 inst_simple "$_found" "$_target/${_found##*/}"
976 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
980 prepare_udev_rules() {
981 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
984 f="${initdir}/etc
/udev
/rules.d
/$f"
985 [ -e "$f" ] || continue
987 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
988 if [ $UDEVVERSION -ge 174 ]; then
989 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
991 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
993 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
994 if [ $UDEVVERSION -ge 176 ]; then
995 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
997 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1002 done < "${f}" > "${f}.new
"
1007 # install function specialized for hooks
1008 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1009 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1011 if ! [[ -f $3 ]]; then
1012 dfatal "Cannot
install a hook
($3) that does not exist.
"
1013 dfatal "Aborting initrd creation.
"
1015 elif ! [[ "$hookdirs" == *$1* ]]; then
1016 dfatal "No such hook
type $1. Aborting initrd creation.
"
1019 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1022 # install any of listed files
1024 # If first argument is '-d' and second some destination path, first accessible
1025 # source is installed into this path, otherwise it will installed in the same
1026 # path as source. If none of listed files was installed, function return 1.
1027 # On first successful installation it returns with 0 status.
1031 # inst_any -d /bin/foo /bin/bar /bin/baz
1033 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1038 [[ $1 = '-d' ]] && to="$2" && shift 2
1041 if [[ -e $f ]]; then
1042 [[ $to ]] && inst "$f" "$to" && return 0
1043 inst "$f" && return 0
1051 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1052 # Install a <file> located on a lib directory to the initramfs image
1053 # -n <pattern> install matching files
1054 inst_libdir_file() {
1056 if [[ "$1" == "-n" ]]; then
1059 for _dir in $libdirs; do
1061 for _f in "$_dir"/$_i; do
1062 [[ "$_f" =~ $_pattern ]] || continue
1063 [[ -e "$_f" ]] && _files+="$_f "
1068 for _dir in $libdirs; do
1070 for _f in "$_dir"/$_i; do
1071 [[ -e "$_f" ]] && _files+="$_f "
1076 [[ $_files ]] && dracut_install $_files
1080 # install function decompressing the target and handling symlinks
1081 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1083 # Function install targets in the same paths inside overlay but decompressed
1084 # and without extensions (.gz, .bz2).
1091 *.gz) _cmd='gzip -f -d' ;;
1092 *.bz2) _cmd='bzip2 -d' ;;
1096 # Decompress with chosen tool. We assume that tool changes name e.g.
1097 # from 'name.gz' to 'name'.
1098 ${_cmd} "${initdir}${_src}"
1102 # It's similar to above, but if file is not compressed, performs standard
1104 # $@ = list of files
1105 inst_opt_decompress
() {
1110 inst_decompress
"${_src}" || inst
"${_src}"
1114 # module_check <dracut module>
1115 # execute the check() function of module-setup.sh of <dracut module>
1116 # or the "check" script, if module-setup.sh is not found
1117 # "check $hostonly" is called
1119 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1122 local _hostonly
=$hostonly
1123 [ $# -eq 2 ] && _forced
=$2
1124 [[ -d $_moddir ]] ||
return 1
1125 if [[ ! -f $_moddir/module-setup.sh
]]; then
1126 # if we do not have a check script, we are unconditionally included
1127 [[ -x $_moddir/check
]] ||
return 0
1128 [ $_forced -ne 0 ] && unset hostonly
1129 $_moddir/check
$hostonly
1132 unset check depends
install installkernel
1134 .
$_moddir/module-setup.sh
1135 is_func check ||
return 0
1136 [ $_forced -ne 0 ] && unset hostonly
1139 unset check depends
install installkernel
1145 # module_check_mount <dracut module>
1146 # execute the check() function of module-setup.sh of <dracut module>
1147 # or the "check" script, if module-setup.sh is not found
1148 # "mount_needs=1 check 0" is called
1149 module_check_mount
() {
1150 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1153 [[ -d $_moddir ]] ||
return 1
1154 if [[ ! -f $_moddir/module-setup.sh
]]; then
1155 # if we do not have a check script, we are unconditionally included
1156 [[ -x $_moddir/check
]] ||
return 0
1157 mount_needs
=1 $_moddir/check
0
1160 unset check depends
install installkernel
1162 .
$_moddir/module-setup.sh
1165 unset check depends
install installkernel
1171 # module_depends <dracut module>
1172 # execute the depends() function of module-setup.sh of <dracut module>
1173 # or the "depends" script, if module-setup.sh is not found
1175 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1177 [[ -d $_moddir ]] ||
return 1
1178 if [[ ! -f $_moddir/module-setup.sh
]]; then
1179 # if we do not have a check script, we have no deps
1180 [[ -x $_moddir/check
]] ||
return 0
1184 unset check depends
install installkernel
1186 .
$_moddir/module-setup.sh
1189 unset check depends
install installkernel
1194 # module_install <dracut module>
1195 # execute the install() function of module-setup.sh of <dracut module>
1196 # or the "install" 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 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1205 unset check depends
install installkernel
1207 .
$_moddir/module-setup.sh
1210 unset check depends
install installkernel
1215 # module_installkernel <dracut module>
1216 # execute the installkernel() function of module-setup.sh of <dracut module>
1217 # or the "installkernel" script, if module-setup.sh is not found
1218 module_installkernel
() {
1219 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1221 [[ -d $_moddir ]] ||
return 1
1222 if [[ ! -f $_moddir/module-setup.sh
]]; then
1223 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1226 unset check depends
install installkernel
1227 installkernel
() { true
; }
1228 .
$_moddir/module-setup.sh
1231 unset check depends
install installkernel
1236 # check_mount <dracut module>
1237 # check_mount checks, if a dracut module is needed for the given
1238 # device and filesystem types in "${host_fs_types[@]}"
1241 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1245 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1247 # If we are already scheduled to be loaded, no need to check again.
1248 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1249 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1251 # This should never happen, but...
1252 [[ -d $_moddir ]] ||
return 1
1254 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1256 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1260 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1261 module_check_mount
$_mod; ret
=$?
1263 # explicit module, so also accept ret=255
1264 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1266 # module not in our list
1267 if [[ $dracutmodules = all
]]; then
1268 # check, if we can and should install this module
1269 module_check_mount
$_mod ||
return 1
1277 for _moddep
in $
(module_depends
$_mod); do
1278 # handle deps as if they were manually added
1279 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1280 add_dracutmodules
+=" $_moddep "
1281 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1282 force_add_dracutmodules
+=" $_moddep "
1283 # if a module we depend on fail, fail also
1284 if ! check_module
$_moddep; then
1285 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1290 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1291 mods_to_load
+=" $_mod "
1296 # check_module <dracut module> [<use_as_dep>]
1297 # check if a dracut module is to be used in the initramfs process
1298 # if <use_as_dep> is set, then the process also keeps track
1299 # that the modules were checked for the dependency tracking process
1302 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1305 # If we are already scheduled to be loaded, no need to check again.
1306 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1307 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1309 # This should never happen, but...
1310 [[ -d $_moddir ]] ||
return 1
1312 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1314 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1315 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1319 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1320 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1321 module_check
$_mod 1; ret
=$?
1323 module_check
$_mod 0; ret
=$?
1325 # explicit module, so also accept ret=255
1326 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1328 # module not in our list
1329 if [[ $dracutmodules = all
]]; then
1330 # check, if we can and should install this module
1331 module_check
$_mod ||
return 1
1338 for _moddep
in $
(module_depends
$_mod); do
1339 # handle deps as if they were manually added
1340 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1341 add_dracutmodules
+=" $_moddep "
1342 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1343 force_add_dracutmodules
+=" $_moddep "
1344 # if a module we depend on fail, fail also
1345 if ! check_module
$_moddep; then
1346 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1351 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1352 mods_to_load
+=" $_mod "
1357 # for_each_module_dir <func>
1358 # execute "<func> <dracut module> 1"
1359 for_each_module_dir
() {
1365 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1366 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1370 # Report any missing dracut modules, the user has specified
1371 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1372 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1373 for _mod
in $_modcheck; do
1374 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1375 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1376 derror
"dracut module '$_mod' cannot be found or installed."
1380 # Install a single kernel module along with any firmware it may require.
1381 # $1 = full path to kernel module to install
1382 install_kmod_with_fw
() {
1383 # no need to go further if the module is already installed
1385 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1388 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1389 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1393 if [[ $omit_drivers ]]; then
1394 local _kmod
=${1##*/}
1397 if [[ "$_kmod" =~
$omit_drivers ]]; then
1398 dinfo
"Omitting driver $_kmod"
1401 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1402 dinfo
"Omitting driver $_kmod"
1407 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1409 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1410 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1411 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1412 (($ret != 0)) && return $ret
1414 local _modname
=${1##*/} _fwdir _found _fw
1415 _modname
=${_modname%.ko*}
1416 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1418 for _fwdir
in $fw_dir; do
1419 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1420 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1424 if [[ $_found != yes ]]; then
1425 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1426 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1427 "\"${_modname}.ko\""
1429 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1430 "\"${_modname}.ko\""
1437 # Do something with all the dependencies of a kernel module.
1438 # Note that kernel modules depend on themselves using the technique we use
1439 # $1 = function to call for each dependency we find
1440 # It will be passed the full path to the found kernel module
1441 # $2 = module to get dependencies for
1442 # rest of args = arguments to modprobe
1443 # _fderr specifies FD passed from surrounding scope
1444 for_each_kmod_dep
() {
1445 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1447 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1448 while read _cmd _modpath _options
; do
1449 [[ $_cmd = insmod
]] ||
continue
1450 $_func ${_modpath} ||
exit $?
1455 dracut_kernel_post
() {
1456 local _moddirname
=${srcmods%%/lib/modules/*}
1459 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1460 xargs -r modprobe
-a ${_moddirname+-d ${_moddirname}/} \
1461 --ignore-install --show-depends --set-version $kernel \
1462 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1464 |
while read _cmd _modpath _options
; do
1465 [[ $_cmd = insmod
]] ||
continue
1467 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1470 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1471 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1473 while read _modpath
; do
1474 local _destpath
=$_modpath
1475 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1476 _destpath
=${_destpath##*/lib/modules/$kernel/}
1477 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1478 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1481 while read a
; do _pid
=$a;done < <(jobs -p)
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}