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
316 local _maj _min _majmin
317 _majmin
="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
318 printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
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 findmnt
-e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
337 while read _majmin _dev
; do
338 if [[ -b $_dev ]]; then
339 if ! [[ $_majmin ]] ||
[[ $_majmin == 0:* ]]; then
340 _majmin
=$
(get_maj_min
$_dev)
342 if [[ $_majmin ]]; then
349 if [[ $_dev = *:* ]]; then
353 done; return 1; } && return 0
355 # fall back to /etc/fstab
357 findmnt
-e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" |
{ \
358 while read _majmin _dev
; do
359 if ! [[ $_dev ]]; then
363 if [[ -b $_dev ]]; then
364 [[ $_majmin ]] || _majmin
=$
(get_maj_min
$_dev)
365 if [[ $_majmin ]]; then
372 if [[ $_dev = *:* ]]; then
376 done; return 1; } && return 0
381 # find_mp_fstype <mountpoint>
382 # Echo the filesystem type for a given mountpoint.
383 # /proc/self/mountinfo is taken as the primary source of information
384 # and /etc/fstab is used as a fallback.
385 # No newline is appended!
387 # $ find_mp_fstype /;echo
392 if [[ $use_fstab != yes ]]; then
393 findmnt
-e -v -n -o 'FSTYPE' --target "$1" |
{ \
395 [[ $_fs ]] ||
continue
396 [[ $_fs = "autofs" ]] && continue
399 done; return 1; } && return 0
402 findmnt
--fstab -e -v -n -o 'FSTYPE' --target "$1" |
{ \
404 [[ $_fs ]] ||
continue
405 [[ $_fs = "autofs" ]] && continue
408 done; return 1; } && return 0
413 # find_dev_fstype <device>
414 # Echo the filesystem type for a given device.
415 # /proc/self/mountinfo is taken as the primary source of information
416 # and /etc/fstab is used as a fallback.
417 # No newline is appended!
419 # $ find_dev_fstype /dev/sda2;echo
424 [[ "$_find_dev" = /dev
* ]] || _find_dev
="/dev/block/$_find_dev"
426 if [[ $use_fstab != yes ]]; then
427 findmnt
-e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
429 [[ $_fs ]] ||
continue
430 [[ $_fs = "autofs" ]] && continue
433 done; return 1; } && return 0
436 findmnt
--fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" |
{ \
438 [[ $_fs ]] ||
continue
439 [[ $_fs = "autofs" ]] && continue
442 done; return 1; } && return 0
448 # finds the major:minor of the block device backing the root filesystem.
449 find_root_block_device
() { find_block_device
/; }
451 # for_each_host_dev_fs <func>
452 # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
453 # in ${host_fs_types[@]}
454 for_each_host_dev_fs
()
460 [[ "${!host_fs_types[@]}" ]] ||
return 0
462 for _dev
in "${!host_fs_types[@]}"; do
463 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret
=0
470 echo "${host_fs_types[@]}"
473 # Walk all the slave relationships for a given block device.
474 # Stop when our helper function returns success
475 # $1 = function to call on every found block device
476 # $2 = block device in major:minor format
477 check_block_and_slaves
() {
479 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
481 check_vol_slaves
"$@" && return 0
482 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
483 check_block_and_slaves
$1 $
(<"/sys/dev/block/$2/../dev") && return 0
485 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
486 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
487 [[ -f $_x ]] ||
continue
488 check_block_and_slaves
$1 $
(<"$_x") && return 0
493 check_block_and_slaves_all
() {
495 [[ -b /dev
/block
/$2 ]] ||
return 1 # Not a block device? So sorry.
499 check_vol_slaves
"$@" && return 0
500 if [[ -f /sys
/dev
/block
/$2/..
/dev
]]; then
501 check_block_and_slaves_all
$1 $
(<"/sys/dev/block/$2/../dev") && _ret
=0
503 [[ -d /sys
/dev
/block
/$2/slaves
]] ||
return 1
504 for _x
in /sys
/dev
/block
/$2/slaves
/*/dev
; do
505 [[ -f $_x ]] ||
continue
506 check_block_and_slaves_all
$1 $
(<"$_x") && _ret
=0
510 # for_each_host_dev_and_slaves <func>
511 # Execute "<func> <dev>" for every "<dev>" found
512 # in ${host_devs[@]} and their slaves
513 for_each_host_dev_and_slaves_all
()
519 [[ "${host_devs[@]}" ]] ||
return 0
521 for _dev
in ${host_devs[@]}; do
522 [[ -b "$_dev" ]] ||
continue
523 if check_block_and_slaves_all
$_func $
(get_maj_min
$_dev); then
530 for_each_host_dev_and_slaves
()
535 [[ "${host_devs[@]}" ]] ||
return 0
537 for _dev
in ${host_devs[@]}; do
538 [[ -b "$_dev" ]] ||
continue
539 check_block_and_slaves
$_func $
(get_maj_min
$_dev) && return 0
544 # ugly workaround for the lvm design
545 # There is no volume group device,
546 # so, there are no slave devices for volume groups.
547 # Logical volumes only have the slave devices they really live on,
548 # but you cannot create the logical volume without the volume group.
549 # And the volume group might be bigger than the devices the LV needs.
552 for i
in /dev
/mapper
/*; do
553 _lv
=$
(get_maj_min
$i)
554 if [[ $_lv = $2 ]]; then
555 _vg
=$
(lvm lvs
--noheadings -o vg_name
$i 2>/dev
/null
)
559 for _pv
in $
(lvm vgs
--noheadings -o pv_name
"$_vg" 2>/dev
/null
)
561 check_block_and_slaves
$1 $
(get_maj_min
$_pv) && return 0
569 # fs_get_option <filesystem options> <search for option>
570 # search for a specific option in a bunch of filesystem options
571 # and return the value
579 while [ $# -gt 0 ]; do
582 echo ${1#${_option}=}
589 if [[ $DRACUT_INSTALL ]]; then
590 [[ $DRACUT_RESOLVE_LAZY ]] ||
export DRACUT_RESOLVE_DEPS
=1
592 [[ -e ${initdir}/"$1" ]] && return 0 # already there
593 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
594 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" ||
:
598 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
599 #dinfo "$DRACUT_INSTALL -l $@"
600 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
601 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
605 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
606 [[ -e $1 ]] ||
return 1 # no source
607 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
608 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" ||
:
612 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
613 [[ -L $1 ]] ||
return 1
614 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
615 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
620 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
621 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
623 (($ret != 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
628 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
629 [[ -e $1 ]] ||
return 1 # no source
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} "$@" ||
:
640 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
641 (($?
!= 0)) && derror
$DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" ||
:
646 # Install a directory, keeping symlinks as on the original system.
647 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
648 # will create ${initdir}/lib64, ${initdir}/lib64/file,
649 # and a symlink ${initdir}/lib -> lib64.
651 [[ -e ${initdir}/"$1" ]] && return 0 # already there
653 local _dir
="$1" _part
="${1%/*}" _file
654 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
659 # iterate over parent directories
660 for _file
in $_dir; do
661 [[ -e "${initdir}/$_file" ]] && continue
662 if [[ -L $_file ]]; then
663 inst_symlink
"$_file"
666 mkdir
-m 0755 -p "${initdir}/$_file" ||
return 1
667 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
668 chmod u
+w
"${initdir}/$_file"
673 # $1 = file to copy to ramdisk
674 # $2 (optional) Name for the file on the ramdisk
675 # Location of the image dir is assumed to be $initdir
676 # We never overwrite the target if it exists.
678 [[ -f "$1" ]] ||
return 1
679 [[ "$1" == */* ]] ||
return 1
680 local _src
=$1 _target
="${2:-$1}"
682 [[ -L $_src ]] && { inst_symlink
$_src $_target; return $?
; }
684 if ! [[ -d ${initdir}/$_target ]]; then
685 [[ -e ${initdir}/$_target ]] && return 0
686 [[ -L ${initdir}/$_target ]] && return 0
687 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
689 if [[ $DRACUT_FIPS_MODE ]]; then
690 # install checksum files also
691 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
692 inst
"${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
694 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
695 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
697 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
698 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
701 ddebug
"Installing $_src"
702 cp --reflink=auto
--sparse=auto
-pfL "$_src" "${initdir}/$_target"
705 # same as above, but specialized for symlinks
707 local _src
=$1 _target
=${2:-$1} _realsrc
708 [[ "$1" == */* ]] ||
return 1
709 [[ -L $1 ]] ||
return 1
710 [[ -L $initdir/$_target ]] && return 0
711 _realsrc
=$
(readlink
-f "$_src")
712 if ! [[ -e $initdir/$_realsrc ]]; then
713 if [[ -d $_realsrc ]]; then
719 [[ ! -e $initdir/${_target%/*} ]] && inst_dir
"${_target%/*}"
721 ln_r
"${_realsrc}" "${_target}"
724 # Same as above, but specialized to handle dynamic libraries.
725 # It handles making symlinks according to how the original library
728 local _src
="$1" _dest
=${2:-$1} _lib _reallib _symlink
729 [[ "$1" == */* ]] ||
return 1
730 [[ -e $initdir/$_dest ]] && return 0
731 if [[ -L $_src ]]; then
732 if [[ $DRACUT_FIPS_MODE ]]; then
733 # install checksum files also
734 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
735 inst
"${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
737 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
738 inst
"/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
740 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
741 inst
"/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
744 _reallib
=$
(readlink
-f "$_src")
745 inst_simple
"$_reallib" "$_reallib"
746 inst_dir
"${_dest%/*}"
747 ln_r
"${_reallib}" "${_dest}"
749 inst_simple
"$_src" "$_dest"
752 # Create additional symlinks. See rev_symlinks description.
753 for _symlink
in $
(rev_lib_symlinks
$_src) $
(rev_lib_symlinks
$_reallib); do
754 [[ ! -e $initdir/$_symlink ]] && {
755 ddebug
"Creating extra symlink: $_symlink"
756 inst_symlink
$_symlink
761 # Same as above, but specialized to install binary executables.
762 # Install binary executable, and all shared library dependencies, if any.
765 _bin
=$
(find_binary
"$1") ||
return 1
767 [[ -e $initdir/$_target ]] && return 0
769 local _so_regex
='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
771 LC_ALL
=C ldd
"$_bin" 2>/dev
/null |
while read _line
; do
772 [[ $_line = 'not a dynamic executable' ]] && break
774 if [[ $_line =~
$_so_regex ]]; then
775 _file
=${BASH_REMATCH[1]}
776 [[ -e ${initdir}/$_file ]] && continue
777 inst_library
"$_file"
781 if [[ $_line == *not\ found
* ]]; then
782 dfatal
"Missing a shared library required by $_bin."
783 dfatal
"Run \"ldd $_bin\" to find out what it is."
785 dfatal
"dracut cannot create an initrd."
789 inst_simple
"$_bin" "$_target"
792 # same as above, except for shell scripts.
793 # If your shell script does not start with shebang, it is not a shell script.
796 _bin
=$
(find_binary
"$1") ||
return 1
798 local _line _shebang_regex
799 read -r -n 80 _line
<"$_bin"
800 # If debug is set, clean unprintable chars to prevent messing up the term
801 [[ $debug ]] && _line
=$
(echo -n "$_line" |
tr -c -d '[:print:][:space:]')
802 _shebang_regex
='(#! *)(/[^ ]+).*'
803 [[ $_line =~
$_shebang_regex ]] ||
return 1
804 inst
"${BASH_REMATCH[2]}" && inst_simple
"$_bin" "$@"
807 # general purpose installation function
808 # Same args as above.
814 2) [[ ! $initdir && -d $2 ]] && export initdir
=$2
815 [[ $initdir = $2 ]] && set $1;;
816 3) [[ -z $initdir ]] && export initdir
=$2
818 *) dfatal
"inst only takes 1 or 2 or 3 arguments"
821 for _x
in inst_symlink inst_script inst_binary inst_simple
; do
827 # dracut_install [-o ] <file> [<file> ... ]
828 # Install <file> to the initramfs image
829 # -o optionally install the <file> and don't fail, if it is not there
832 if [[ $1 = '-o' ]]; then
837 if ! inst
"$1" ; then
838 if [[ $_optional = yes ]]; then
839 dinfo
"Skipping program $1 as it cannot be found and is" \
840 "flagged to be optional"
842 dfatal
"Failed to install $1"
852 # find symlinks linked to given library file
854 # Function searches for symlinks by stripping version numbers appended to
855 # library filename, checks if it points to the same target and finally
856 # prints the list of symlinks to stdout.
859 # rev_lib_symlinks libfoo.so.8.1
860 # output: libfoo.so.8 libfoo.so
861 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
863 [[ ! $1 ]] && return 0
865 local fn
="$1" orig
="$(readlink -f "$1")" links
=''
867 [[ ${fn} == *.so.
* ]] ||
return 1
869 until [[ ${fn##*.} == so
]]; do
871 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
877 # attempt to install any programs specified in a udev rule
878 inst_rule_programs() {
881 if grep -qE 'PROGRAM==?"[^
"]+' "$1"; then
882 for _prog in $(grep -E 'PROGRAM==?"[^
"]+' "$1" | sed -r 's/.*PROGRAM==?"([^
"]+).*/\1/'); do
884 if [ -x ${udevdir}/$_prog ]; then
885 _bin=${udevdir}/$_prog
886 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
887 _bin=$(find_binary "$_prog") || {
888 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
893 [[ $_bin ]] && dracut_install "$_bin"
896 if grep -qE 'RUN[+=]=?"[^
"]+' "$1"; then
897 for _prog in $(grep -E 'RUN[+=]=?"[^
"]+' "$1" | sed -r 's/.*RUN[+=]=?"([^
"]+).*/\1/'); do
899 if [ -x ${udevdir}/$_prog ]; then
900 _bin=${udevdir}/$_prog
901 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin
/initqueue
" ]]; then
902 _bin=$(find_binary "$_prog") || {
903 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
908 [[ $_bin ]] && dracut_install "$_bin"
911 if grep -qE 'IMPORT\{program\}==?"[^
"]+' "$1"; then
912 for _prog in $(grep -E 'IMPORT\{program\}==?"[^
"]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^
"]+).*/\1/'); do
914 if [ -x ${udevdir}/$_prog ]; then
915 _bin=${udevdir}/$_prog
916 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
917 _bin=$(find_binary "$_prog") || {
918 dinfo "Skipping program
$_prog using
in udev rule
${1##*/} as it cannot be found
"
923 [[ $_bin ]] && dracut_install "$_bin"
928 # attempt to install any programs specified in a udev rule
929 inst_rule_group_owner() {
932 if grep -qE 'OWNER=?"[^
"]+' "$1"; then
933 for i in $(grep -E 'OWNER=?"[^
"]+' "$1" | sed -r 's/.*OWNER=?"([^
"]+).*/\1/'); do
934 if ! egrep -q "^
$i:" "$initdir/etc
/passwd
" 2>/dev/null; then
935 egrep "^
$i:" /etc/passwd 2>/dev/null >> "$initdir/etc
/passwd
"
939 if grep -qE 'GROUP=?"[^
"]+' "$1"; then
940 for i in $(grep -E 'GROUP=?"[^
"]+' "$1" | sed -r 's/.*GROUP=?"([^
"]+).*/\1/'); do
941 if ! egrep -q "^
$i:" "$initdir/etc
/group
" 2>/dev/null; then
942 egrep "^
$i:" /etc/group 2>/dev/null >> "$initdir/etc
/group
"
948 inst_rule_initqueue() {
949 if grep -q -F initqueue "$1"; then
950 dracut_need_initqueue
954 # udev rules always get installed in the same place, so
955 # create a function to install them to make life simpler.
957 local _target=/etc/udev/rules.d _rule _found
959 inst_dir "${udevdir}/rules.d
"
961 for _rule in "$@
"; do
962 if [ "${_rule#/}" = "$_rule" ]; then
963 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
964 if [[ -f $r/$_rule ]]; then
966 inst_rule_programs "$_found"
967 inst_rule_group_owner "$_found"
968 inst_rule_initqueue "$_found"
969 inst_simple "$_found"
973 for r in '' ./ $dracutbasedir/rules.d/; do
974 if [[ -f ${r}$_rule ]]; then
976 inst_rule_programs "$_found"
977 inst_rule_group_owner "$_found"
978 inst_rule_initqueue "$_found"
979 inst_simple "$_found" "$_target/${_found##*/}"
982 [[ $_found ]] || dinfo "Skipping udev rule
: $_rule"
986 prepare_udev_rules() {
987 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
990 f="${initdir}/etc
/udev
/rules.d
/$f"
991 [ -e "$f" ] || continue
993 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
994 if [ $UDEVVERSION -ge 174 ]; then
995 printf '%sIMPORT{builtin}="path_id
"\n' "${line%%IMPORT PATH_ID}"
997 printf '%sIMPORT{program}="path_id
%%p
"\n' "${line%%IMPORT PATH_ID}"
999 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
1000 if [ $UDEVVERSION -ge 176 ]; then
1001 printf '%sIMPORT{builtin}="blkid
"\n' "${line%%IMPORT BLKID}"
1003 printf '%sIMPORT{program}="/sbin
/blkid
-o udev
-p $tempnode"\n' "${line%%IMPORT BLKID}"
1008 done < "${f}" > "${f}.new
"
1013 # install function specialized for hooks
1014 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1015 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
1017 if ! [[ -f $3 ]]; then
1018 dfatal "Cannot
install a hook
($3) that does not exist.
"
1019 dfatal "Aborting initrd creation.
"
1021 elif ! [[ "$hookdirs" == *$1* ]]; then
1022 dfatal "No such hook
type $1. Aborting initrd creation.
"
1025 inst_simple "$3" "/lib
/dracut
/hooks
/${1}/${2}-${3##*/}"
1028 # install any of listed files
1030 # If first argument is '-d' and second some destination path, first accessible
1031 # source is installed into this path, otherwise it will installed in the same
1032 # path as source. If none of listed files was installed, function return 1.
1033 # On first successful installation it returns with 0 status.
1037 # inst_any -d /bin/foo /bin/bar /bin/baz
1039 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1044 [[ $1 = '-d' ]] && to="$2" && shift 2
1047 if [[ -e $f ]]; then
1048 [[ $to ]] && inst "$f" "$to" && return 0
1049 inst "$f" && return 0
1057 # inst_libdir_file [-n <pattern>] <file> [<file>...]
1058 # Install a <file> located on a lib directory to the initramfs image
1059 # -n <pattern> install matching files
1060 inst_libdir_file() {
1062 if [[ "$1" == "-n" ]]; then
1065 for _dir in $libdirs; do
1067 for _f in "$_dir"/$_i; do
1068 [[ "$_f" =~ $_pattern ]] || continue
1069 [[ -e "$_f" ]] && _files+="$_f "
1074 for _dir in $libdirs; do
1076 for _f in "$_dir"/$_i; do
1077 [[ -e "$_f" ]] && _files+="$_f "
1082 [[ $_files ]] && dracut_install $_files
1086 # install function decompressing the target and handling symlinks
1087 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1089 # Function install targets in the same paths inside overlay but decompressed
1090 # and without extensions (.gz, .bz2).
1097 *.gz) _cmd='gzip -f -d' ;;
1098 *.bz2) _cmd='bzip2 -d' ;;
1102 # Decompress with chosen tool. We assume that tool changes name e.g.
1103 # from 'name.gz' to 'name'.
1104 ${_cmd} "${initdir}${_src}"
1108 # It's similar to above, but if file is not compressed, performs standard
1110 # $@ = list of files
1111 inst_opt_decompress
() {
1116 inst_decompress
"${_src}" || inst
"${_src}"
1120 # module_check <dracut module>
1121 # execute the check() function of module-setup.sh of <dracut module>
1122 # or the "check" script, if module-setup.sh is not found
1123 # "check $hostonly" is called
1125 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1128 local _hostonly
=$hostonly
1129 [ $# -eq 2 ] && _forced
=$2
1130 [[ -d $_moddir ]] ||
return 1
1131 if [[ ! -f $_moddir/module-setup.sh
]]; then
1132 # if we do not have a check script, we are unconditionally included
1133 [[ -x $_moddir/check
]] ||
return 0
1134 [ $_forced -ne 0 ] && unset hostonly
1135 $_moddir/check
$hostonly
1138 unset check depends
install installkernel
1140 .
$_moddir/module-setup.sh
1141 is_func check ||
return 0
1142 [ $_forced -ne 0 ] && unset hostonly
1145 unset check depends
install installkernel
1151 # module_check_mount <dracut module>
1152 # execute the check() function of module-setup.sh of <dracut module>
1153 # or the "check" script, if module-setup.sh is not found
1154 # "mount_needs=1 check 0" is called
1155 module_check_mount
() {
1156 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1159 [[ -d $_moddir ]] ||
return 1
1160 if [[ ! -f $_moddir/module-setup.sh
]]; then
1161 # if we do not have a check script, we are unconditionally included
1162 [[ -x $_moddir/check
]] ||
return 0
1163 mount_needs
=1 $_moddir/check
0
1166 unset check depends
install installkernel
1168 .
$_moddir/module-setup.sh
1171 unset check depends
install installkernel
1177 # module_depends <dracut module>
1178 # execute the depends() function of module-setup.sh of <dracut module>
1179 # or the "depends" script, if module-setup.sh is not found
1181 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1183 [[ -d $_moddir ]] ||
return 1
1184 if [[ ! -f $_moddir/module-setup.sh
]]; then
1185 # if we do not have a check script, we have no deps
1186 [[ -x $_moddir/check
]] ||
return 0
1190 unset check depends
install installkernel
1192 .
$_moddir/module-setup.sh
1195 unset check depends
install installkernel
1200 # module_install <dracut module>
1201 # execute the install() function of module-setup.sh of <dracut module>
1202 # or the "install" script, if module-setup.sh is not found
1204 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1206 [[ -d $_moddir ]] ||
return 1
1207 if [[ ! -f $_moddir/module-setup.sh
]]; then
1208 [[ -x $_moddir/install ]] && .
"$_moddir/install"
1211 unset check depends
install installkernel
1213 .
$_moddir/module-setup.sh
1216 unset check depends
install installkernel
1221 # module_installkernel <dracut module>
1222 # execute the installkernel() function of module-setup.sh of <dracut module>
1223 # or the "installkernel" script, if module-setup.sh is not found
1224 module_installkernel
() {
1225 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1227 [[ -d $_moddir ]] ||
return 1
1228 if [[ ! -f $_moddir/module-setup.sh
]]; then
1229 [[ -x $_moddir/installkernel
]] && .
"$_moddir/installkernel"
1232 unset check depends
install installkernel
1233 installkernel
() { true
; }
1234 .
$_moddir/module-setup.sh
1237 unset check depends
install installkernel
1242 # check_mount <dracut module>
1243 # check_mount checks, if a dracut module is needed for the given
1244 # device and filesystem types in "${host_fs_types[@]}"
1247 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1251 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1253 # If we are already scheduled to be loaded, no need to check again.
1254 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1255 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1257 # This should never happen, but...
1258 [[ -d $_moddir ]] ||
return 1
1260 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1262 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1266 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1267 module_check_mount
$_mod; ret
=$?
1269 # explicit module, so also accept ret=255
1270 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1272 # module not in our list
1273 if [[ $dracutmodules = all
]]; then
1274 # check, if we can and should install this module
1275 module_check_mount
$_mod ||
return 1
1283 for _moddep
in $
(module_depends
$_mod); do
1284 # handle deps as if they were manually added
1285 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1286 add_dracutmodules
+=" $_moddep "
1287 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1288 force_add_dracutmodules
+=" $_moddep "
1289 # if a module we depend on fail, fail also
1290 if ! check_module
$_moddep; then
1291 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1296 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1297 mods_to_load
+=" $_mod "
1302 # check_module <dracut module> [<use_as_dep>]
1303 # check if a dracut module is to be used in the initramfs process
1304 # if <use_as_dep> is set, then the process also keeps track
1305 # that the modules were checked for the dependency tracking process
1308 local _moddir
=$
(echo ${dracutbasedir}/modules.d
/??
${1})
1311 # If we are already scheduled to be loaded, no need to check again.
1312 [[ " $mods_to_load " == *\
$_mod\
* ]] && return 0
1313 [[ " $mods_checked_as_dep " == *\
$_mod\
* ]] && return 1
1315 # This should never happen, but...
1316 [[ -d $_moddir ]] ||
return 1
1318 [[ $2 ]] || mods_checked_as_dep
+=" $_mod "
1320 if [[ " $omit_dracutmodules " == *\
$_mod\
* ]]; then
1321 dinfo
"dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
1325 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\
$_mod\
* ]]; then
1326 if [[ " $force_add_dracutmodules " == *\
$_mod\
* ]]; then
1327 module_check
$_mod 1; ret
=$?
1329 module_check
$_mod 0; ret
=$?
1331 # explicit module, so also accept ret=255
1332 [[ $ret = 0 ||
$ret = 255 ]] ||
return 1
1334 # module not in our list
1335 if [[ $dracutmodules = all
]]; then
1336 # check, if we can and should install this module
1337 module_check
$_mod ||
return 1
1344 for _moddep
in $
(module_depends
$_mod); do
1345 # handle deps as if they were manually added
1346 [[ " $add_dracutmodules " == *\
$_moddep\
* ]] || \
1347 add_dracutmodules
+=" $_moddep "
1348 [[ " $force_add_dracutmodules " == *\
$_moddep\
* ]] || \
1349 force_add_dracutmodules
+=" $_moddep "
1350 # if a module we depend on fail, fail also
1351 if ! check_module
$_moddep; then
1352 derror
"dracut module '$_mod' depends on '$_moddep', which can't be installed"
1357 [[ " $mods_to_load " == *\
$_mod\
* ]] || \
1358 mods_to_load
+=" $_mod "
1363 # for_each_module_dir <func>
1364 # execute "<func> <dracut module> 1"
1365 for_each_module_dir
() {
1371 for _moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1372 _mod
=${_moddir##*/}; _mod
=${_mod#[0-9][0-9]}
1376 # Report any missing dracut modules, the user has specified
1377 _modcheck
="$add_dracutmodules $force_add_dracutmodules"
1378 [[ $dracutmodules != all
]] && _modcheck
="$m $dracutmodules"
1379 for _mod
in $_modcheck; do
1380 [[ " $mods_to_load " == *\
$_mod\
* ]] && continue
1381 [[ " $omit_dracutmodules " == *\
$_mod\
* ]] && continue
1382 derror
"dracut module '$_mod' cannot be found or installed."
1386 # Install a single kernel module along with any firmware it may require.
1387 # $1 = full path to kernel module to install
1388 install_kmod_with_fw
() {
1389 # no need to go further if the module is already installed
1391 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1394 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1395 read ret
< "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1399 if [[ $omit_drivers ]]; then
1400 local _kmod
=${1##*/}
1403 if [[ "$_kmod" =~
$omit_drivers ]]; then
1404 dinfo
"Omitting driver $_kmod"
1407 if [[ "${1##*/lib/modules/$kernel/}" =~
$omit_drivers ]]; then
1408 dinfo
"Omitting driver $_kmod"
1413 inst_simple
"$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1415 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1416 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1417 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
1418 (($ret != 0)) && return $ret
1420 local _modname
=${1##*/} _fwdir _found _fw
1421 _modname
=${_modname%.ko*}
1422 for _fw
in $
(modinfo
-k $kernel -F firmware
$1 2>/dev
/null
); do
1424 for _fwdir
in $fw_dir; do
1425 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1426 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1430 if [[ $_found != yes ]]; then
1431 if ! [[ -d $
(echo /sys
/module
/${_modname//-/_}|
{ read a b
; echo $a; }) ]]; then
1432 dinfo
"Possible missing firmware \"${_fw}\" for kernel module" \
1433 "\"${_modname}.ko\""
1435 dwarn
"Possible missing firmware \"${_fw}\" for kernel module" \
1436 "\"${_modname}.ko\""
1443 # Do something with all the dependencies of a kernel module.
1444 # Note that kernel modules depend on themselves using the technique we use
1445 # $1 = function to call for each dependency we find
1446 # It will be passed the full path to the found kernel module
1447 # $2 = module to get dependencies for
1448 # rest of args = arguments to modprobe
1449 # _fderr specifies FD passed from surrounding scope
1450 for_each_kmod_dep
() {
1451 local _func
=$1 _kmod
=$2 _cmd _modpath _options
1453 modprobe
"$@" --ignore-install --show-depends $_kmod 2>&${_fderr} |
(
1454 while read _cmd _modpath _options
; do
1455 [[ $_cmd = insmod
]] ||
continue
1456 $_func ${_modpath} ||
exit $?
1461 dracut_kernel_post
() {
1462 local _moddirname
=${srcmods%%/lib/modules/*}
1465 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
1466 xargs -r modprobe
-a ${_moddirname+-d ${_moddirname}/} \
1467 --ignore-install --show-depends --set-version $kernel \
1468 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev
/null \
1470 |
while read _cmd _modpath _options
; do
1471 [[ $_cmd = insmod
]] ||
continue
1473 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1476 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1477 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1479 while read _modpath
; do
1480 local _destpath
=$_modpath
1481 [[ $_moddirname ]] && _destpath
=${_destpath##$_moddirname/}
1482 _destpath
=${_destpath##*/lib/modules/$kernel/}
1483 inst_simple
"$_modpath" "/lib/modules/$kernel/${_destpath}" ||
exit $?
1484 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
1487 _pid
=$
(jobs -p |
while read a
; do printf ":$a";done)
1490 if [[ $DRACUT_INSTALL ]]; then
1491 xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
1492 |
while read line
; do
1493 for _fwdir
in $fw_dir; do
1496 done |
xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
1498 for _fw
in $
(xargs -r modinfo
-k $kernel -F firmware
< "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
1499 for _fwdir
in $fw_dir; do
1500 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1501 inst_simple
"$_fwdir/$_fw" "/lib/firmware/$_fw"
1511 for _f
in modules.
builtin.bin modules.
builtin; do
1512 [[ $srcmods/$_f ]] && break
1514 dfatal
"No modules.builtin.bin and modules.builtin found!"
1518 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
1519 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
1522 # generate module dependencies for the initrd
1523 if [[ -d $initdir/lib
/modules
/$kernel ]] && \
1524 ! depmod
-a -b "$initdir" $kernel; then
1525 dfatal
"\"depmod -a $kernel\" failed."
1529 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
1532 module_is_host_only
() {
1537 [[ " $add_drivers " == *\
${_mod}\
* ]] && return 0
1539 # check if module is loaded
1540 for i
in /sys
/module
/${_mod//-/_}; do
1541 [[ -d $i ]] && return 0
1544 # check if module is loadable on the current kernel
1545 # this covers the case, where a new module is introduced
1546 # or a module was renamed
1547 # or a module changed from builtin to a module
1548 modinfo
-F filename
"$_mod" &>/dev
/null ||
return 0
1553 find_kernel_modules_by_path
() {
1556 [[ -f "$srcmods/modules.dep" ]] ||
return 0
1560 while read a rest
; do
1561 [[ $a = */$1/* ]] ||
continue
1562 printf "%s\n" "$srcmods/$a"
1563 done < "$srcmods/modules.dep"
1568 find_kernel_modules
() {
1569 find_kernel_modules_by_path drivers
1572 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1573 # instmods [-c [-s]] <kernel subsystem>
1574 # install kernel modules along with all their dependencies.
1575 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1577 [[ $no_kernel = yes ]] && return
1578 # called [sub]functions inherit _fderr
1582 if [[ $1 = '-c' ]]; then
1587 if [[ $1 = '-s' ]]; then
1592 function inst1mod
() {
1593 local _ret
=0 _mod
="$1"
1596 ( [[ "$_mpargs" ]] && echo $_mpargs
1597 find_kernel_modules_by_path
"${_mod#=}" ) \
1601 --*) _mpargs
+=" $_mod" ;;
1604 # if we are already installed, skip this module and go on
1606 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1607 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1608 read _ret
<"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
1612 if [[ $omit_drivers ]] && [[ "$1" =~
$omit_drivers ]]; then
1613 dinfo
"Omitting driver ${_mod##$srcmods}"
1617 # If we are building a host-specific initramfs and this
1618 # module is not already loaded, move on to the next one.
1620 && ! module_is_host_only
"$_mod" \
1623 if [[ "$_check" = "yes" ]] ||
! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
1624 # We use '-d' option in modprobe only if modules prefix path
1625 # differs from default '/'. This allows us to use dracut with
1626 # old version of modprobe which doesn't have '-d' option.
1627 local _moddirname
=${srcmods%%/lib/modules/*}
1628 [[ -n ${_moddirname} ]] && _moddirname
="-d ${_moddirname}/"
1630 # ok, load the module, all its dependencies, and any firmware
1632 for_each_kmod_dep install_kmod_with_fw
$_mod \
1633 --set-version $kernel ${_moddirname} $_mpargs
1636 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1637 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
1644 function instmods_1
() {
1646 if (($# == 0)); then # filenames from stdin
1648 inst1mod
"${_mod%.ko*}" ||
{
1649 if [[ "$_check" == "yes" ]]; then
1650 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $_mod"
1656 while (($# > 0)); do # filenames as arguments
1657 inst1mod
${1%.ko*} ||
{
1658 if [[ "$_check" == "yes" ]]; then
1659 [[ "$_silent" == "no" ]] && dfatal
"Failed to install module $1"
1668 local _ret _filter_not_found
='FATAL: Module .* not found.'
1669 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1670 # redirections, but that would make dracut require bash4 at least.
1671 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
1672 |
while read line
; do [[ "$line" =~
$_filter_not_found ]] ||
echo $line;done | derror
1677 # Only two values are returned: AMD or Intel
1680 if grep -qE AMD
/proc
/cpuinfo
; then
1683 if grep -qE Intel
/proc
/cpuinfo
; then
1689 # Get the hosts' ucode file based on the /proc/cpuinfo
1692 local family
=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1693 local model
=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //`
1694 local stepping
=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`
1696 if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
1697 # If family greater or equal than 0x15
1698 if [[ $family -ge 21 ]]; then
1699 printf "microcode_amd_fam15h.bin"
1701 printf "microcode_amd.bin"
1704 if [[ "$(get_cpu_vendor)" == "Intel" ]]; then
1705 # The /proc/cpuinfo are in decimal.
1706 printf "%02x-%02x-%02x" ${family} ${model} ${stepping}