]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut-functions.sh
use "rm --" to guard against filenames beginning with "-"
[thirdparty/dracut.git] / dracut-functions.sh
CommitLineData
04b56f3a 1#!/bin/bash
cc02093d
HH
2# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3# ex: ts=8 sw=4 sts=4 et filetype=sh
04b56f3a 4#
33ee031c 5# functions used by dracut and other tools.
04b56f3a 6#
33ee031c 7# Copyright 2005-2009 Red Hat, Inc. All rights reserved.
04b56f3a
JK
8#
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.
13#
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.
18#
19# You should have received a copy of the GNU General Public License
0f9c78c1 20# along with this program. If not, see <http://www.gnu.org/licenses/>.
04b56f3a 21#
258de828 22export LC_MESSAGES=C
f4031e8a
HH
23
24if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
25 if ! [[ -d "$initdir/.kernelmodseen" ]]; then
26 mkdir -p "$initdir/.kernelmodseen"
27 fi
28 DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen"
29fi
ec1aa3bc 30
eaa924b6
HH
31if [[ $initdir ]] && ! [[ -d $initdir ]]; then
32 mkdir -p "$initdir"
33fi
34
8d95b8b3 35# Generic substring function. If $2 is in $1, return 0.
520047c3 36strstr() { [[ $1 = *$2* ]]; }
8d95b8b3 37
f4031e8a
HH
38# find a binary. If we were not passed the full path directly,
39# search in the usual places to find the binary.
40find_binary() {
41 if [[ -z ${1##/*} ]]; then
42 if [[ -x $1 ]] || { strstr "$1" ".so" && ldd $1 &>/dev/null; }; then
43 echo $1
44 return 0
45 fi
46 fi
47
7e0d5080 48 type -P ${1##*/}
f4031e8a
HH
49}
50
0874654c
HH
51if ! [[ $dracutbasedir ]]; then
52 dracutbasedir=${BASH_SOURCE[0]%/*}
53 [[ $dracutbasedir = "dracut-functions" ]] && dracutbasedir="."
54 [[ $dracutbasedir ]] || dracutbasedir="."
55 dracutbasedir="$(readlink -f $dracutbasedir)"
56fi
57
f4031e8a
HH
58if ! [[ $DRACUT_INSTALL ]]; then
59 DRACUT_INSTALL=$(find_binary dracut-install)
60fi
61
62if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
63 DRACUT_INSTALL=$dracutbasedir/dracut-install
64fi
65
8d95b8b3
HH
66# Detect lib paths
67if ! [[ $libdirs ]] ; then
68 if strstr "$(ldd /bin/sh)" "/lib64/" &>/dev/null \
69 && [[ -d /lib64 ]]; then
70 libdirs+=" /lib64"
71 [[ -d /usr/lib64 ]] && libdirs+=" /usr/lib64"
72 else
73 libdirs+=" /lib"
74 [[ -d /usr/lib ]] && libdirs+=" /usr/lib"
75 fi
76 export libdirs
77fi
78
79if ! [[ $kernel ]]; then
80 kernel=$(uname -r)
81 export kernel
82fi
83
84srcmods="/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.'
88 exit 1
89 fi
90 srcmods="$drivers_dir"
91}
92export srcmods
93
d6d53f60 94if ! type dinfo >/dev/null 2>&1; then
552ecca6 95 . "$dracutbasedir/dracut-logger.sh"
e103615b
96 dlog_init
97fi
98
593b315c
HH
99if ! [[ $initdir ]]; then
100 dfatal "initdir not set"
101 exit 1
102fi
103
7e2bca48
HH
104# export standard hookdirs
105[[ $hookdirs ]] || {
4fed3ddf 106 hookdirs="cmdline pre-udev pre-trigger netroot "
6e3cc00f 107 hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
eef7649e 108 hookdirs+="pre-mount pre-pivot cleanup mount "
2b6dd6a1 109 hookdirs+="emergency shutdown-emergency pre-shutdown shutdown "
7e2bca48
HH
110 export hookdirs
111}
112
8d85429a
HH
113dracut_need_initqueue() {
114 >"$initdir/lib/dracut/need-initqueue"
115}
116
117dracut_module_included() {
118 strstr "$mods_to_load $modules_loaded" "$@"
119}
120
87122afc
121# Create all subdirectories for given path without creating the last element.
122# $1 = path
f8be7528 123mksubdirs() { [[ -e ${1%/*} ]] || mkdir -m 0755 -p ${1%/*}; }
87122afc 124
22ecea45
125# Version comparision function. Assumes Linux style version scheme.
126# $1 = version a
127# $2 = comparision op (gt, ge, eq, le, lt, ne)
128# $3 = version b
ecf42850 129vercmp() {
29b10e65 130 local _n1=(${1//./ }) _op=$2 _n2=(${3//./ }) _i _res
ecf42850 131
29b10e65 132 for ((_i=0; ; _i++))
22ecea45 133 do
29b10e65
HH
134 if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res=0
135 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res=1
136 elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res=2
22ecea45
137 else continue
138 fi
139 break
ecf42850 140 done
ecf42850 141
29b10e65
HH
142 case $_op in
143 gt) ((_res == 1));;
144 ge) ((_res != 2));;
145 eq) ((_res == 0));;
146 le) ((_res != 1));;
147 lt) ((_res == 2));;
148 ne) ((_res != 0));;
22ecea45 149 esac
ecf42850
150}
151
7e2bca48
HH
152# is_func <command>
153# Check whether $1 is a function.
95d2dabc 154is_func() {
0b706743 155 [[ $(type -t $1) = "function" ]]
95d2dabc
HH
156}
157
87122afc
158# Function prints global variables in format name=value line by line.
159# $@ = list of global variables' name
160print_vars() {
29b10e65 161 local _var _value
87122afc 162
29b10e65 163 for _var in $@
87122afc 164 do
29b10e65
HH
165 _value=$(eval echo \$$_var)
166 [[ ${_value} ]] && echo "${_var}=\"${_value}\""
87122afc
167 done
168}
169
7e2bca48
HH
170# normalize_path <path>
171# Prints the normalized path, where it removes any duplicated
172# and trailing slashes.
173# Example:
174# $ normalize_path ///test/test//
175# /test/test
626d9eba 176normalize_path() {
c44e3cb4
MS
177 shopt -q -s extglob
178 set -- "${1//+(\/)//}"
179 shopt -q -u extglob
180 echo "${1%/}"
626d9eba 181}
d4bb4316 182
7e2bca48
HH
183# convert_abs_rel <from> <to>
184# Prints the relative path, when creating a symlink to <to> from <from>.
185# Example:
186# $ convert_abs_rel /usr/bin/test /bin/test-2
187# ../../bin/test-2
188# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
d4bb4316 189convert_abs_rel() {
6d2a7942 190 local __current __absolute __abssize __cursize __newpath
c44e3cb4 191 local -i __i __level
d4bb4316 192
c44e3cb4
MS
193 set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
194
c1609dd4
MS
195 # corner case #1 - self looping link
196 [[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
197
198 # corner case #2 - own dir link
199 [[ "${1%/*}" == "$2" ]] && { echo "."; return; }
200
6d2a7942
HH
201 IFS="/" __current=($1)
202 IFS="/" __absolute=($2)
d4bb4316
HH
203
204 __abssize=${#__absolute[@]}
205 __cursize=${#__current[@]}
206
207 while [[ ${__absolute[__level]} == ${__current[__level]} ]]
208 do
209 (( __level++ ))
210 if (( __level > __abssize || __level > __cursize ))
211 then
212 break
213 fi
214 done
215
216 for ((__i = __level; __i < __cursize-1; __i++))
217 do
218 if ((__i > __level))
219 then
220 __newpath=$__newpath"/"
221 fi
222 __newpath=$__newpath".."
223 done
224
225 for ((__i = __level; __i < __abssize; __i++))
226 do
227 if [[ -n $__newpath ]]
228 then
229 __newpath=$__newpath"/"
230 fi
231 __newpath=$__newpath${__absolute[__i]}
232 done
233
234 echo "$__newpath"
235}
236
7224913d 237if strstr "$(ln --help)" "--relative"; then
a20d24de
HH
238 ln_r() {
239 ln -sfnr "${initdir}/$1" "${initdir}/$2"
240 }
241else
242 ln_r() {
243 local _source=$1
244 local _dest=$2
245 [[ -d "${_dest%/*}" ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
246 ln -sfn $(convert_abs_rel "${_dest}" "${_source}") "${initdir}/${_dest}"
247 }
248fi
249
ff063663
DY
250get_persistent_dev() {
251 local i _tmp _dev
252
253 _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
254 [ -z "$_dev" ] && return
255
9037b63e 256 for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
15c5c072 257 [[ $i == /dev/mapper/mpath* ]] && continue
ff063663
DY
258 _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
259 if [ "$_tmp" = "$_dev" ]; then
260 echo $i
261 return
262 fi
263 done
264}
265
7e2bca48
HH
266# get_fs_env <device>
267# Get and set the ID_FS_TYPE and ID_FS_UUID variable from udev for a device.
268# Example:
269# $ get_fs_env /dev/sda2; echo $ID_FS_TYPE; echo $ID_FS_UUID
270# ext4
271# 551a39aa-4ae9-4e70-a262-ef665cadb574
9ede1929 272get_fs_env() {
0e979d48
HH
273 local evalstr
274 local found
275
7c179686 276 [[ $1 ]] || return
29b10e65
HH
277 unset ID_FS_TYPE
278 unset ID_FS_UUID
0e979d48
HH
279 if evalstr=$(udevadm info --query=env --name=$1 \
280 | { while read line; do
281 strstr "$line" "DEVPATH" && found=1;
282 strstr "$line" "ID_FS_TYPE=" && { echo $line; exit 0;}
283 done; [[ $found ]] && exit 0; exit 1; }) ; then
284 eval $evalstr
285 [[ $ID_FS_TYPE ]] && return 0
286 return 1
287 fi
d8b9844c 288
0e979d48 289 # Fallback, if we don't have udev information
a5cde2dd 290 if find_binary blkid >/dev/null; then
66b750a0 291 eval $(blkid -o udev $1 \
a5cde2dd
HH
292 | while read line; do
293 strstr "$line" "ID_FS_TYPE=" && echo $line;
294 done)
295 [[ $ID_FS_TYPE ]] && return 0
7c179686 296 fi
a5cde2dd
HH
297 return 1
298}
9ede1929 299
7e2bca48
HH
300# get_maj_min <device>
301# Prints the major and minor of a device node.
302# Example:
303# $ get_maj_min /dev/sda2
304# 8:2
480d772f
HH
305get_maj_min() {
306 local _dev
74132a10 307 _dev=$(stat -L -c '$((0x%t)):$((0x%T))' "$1" 2>/dev/null)
480d772f
HH
308 _dev=$(eval "echo $_dev")
309 echo $_dev
310}
311
7e2bca48
HH
312# find_block_device <mountpoint>
313# Prints the major and minor number of the block device
314# for a given mountpoint.
315# Unless $use_fstab is set to "yes" the functions
316# uses /proc/self/mountinfo as the primary source of the
317# information and only falls back to /etc/fstab, if the mountpoint
318# is not found there.
319# Example:
320# $ find_block_device /usr
321# 8:4
f76ef3aa 322find_block_device() {
9d36d4fb 323 local _majmin _dev _majmin _find_mpt
c8d685c9 324 _find_mpt="$1"
0b706743 325 if [[ $use_fstab != yes ]]; then
9d36d4fb
HH
326 [[ -d $_find_mpt/. ]]
327 while read _majmin _dev; do
328 if [[ -b $_dev ]]; then
329 if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
330 read _majmin < <(get_maj_min $_dev)
331 fi
332 if [[ $_majmin ]]; then
333 echo $_majmin
334 else
335 echo $_dev
336 fi
337 return 0
338 fi
339 if [[ $_dev = *:* ]]; then
340 echo $_dev
341 return 0
cc02093d 342 fi
5e601454 343 done < <(findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
7c179686 344 fi
0b706743 345 # fall back to /etc/fstab
9d36d4fb
HH
346
347 while read _majmin _dev; do
348 if ! [[ $_dev ]]; then
349 _dev="$_majmin"
350 unset _majmin
cc02093d 351 fi
9d36d4fb
HH
352 if [[ -b $_dev ]]; then
353 [[ $_majmin ]] || read _majmin < <(get_maj_min $_dev)
354 if [[ $_majmin ]]; then
355 echo $_majmin
356 else
357 echo $_dev
358 fi
359 return 0
360 fi
361 if [[ $_dev = *:* ]]; then
362 echo $_dev
363 return 0
364 fi
5e601454 365 done < <(findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt")
0b706743
366
367 return 1
17829e94
VL
368}
369
9d36d4fb
HH
370# find_mp_fstype <mountpoint>
371# Echo the filesystem type for a given mountpoint.
7e2bca48
HH
372# /proc/self/mountinfo is taken as the primary source of information
373# and /etc/fstab is used as a fallback.
374# No newline is appended!
375# Example:
9d36d4fb 376# $ find_mp_fstype /;echo
7e2bca48 377# ext4
9d36d4fb
HH
378find_mp_fstype() {
379 local _fs
7ae5d9d1 380
9d36d4fb
HH
381 if [[ $use_fstab != yes ]]; then
382 while read _fs; do
383 [[ $_fs ]] || continue
384 [[ $_fs = "autofs" ]] && continue
385 echo -n $_fs
386 return 0
5e601454 387 done < <(findmnt -e -v -n -o 'FSTYPE' --target "$1")
9d36d4fb
HH
388 fi
389
390 while read _fs; do
391 [[ $_fs ]] || continue
392 [[ $_fs = "autofs" ]] && continue
393 echo -n $_fs
394 return 0
5e601454 395 done < <(findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1")
7ae5d9d1
HH
396
397 return 1
398}
399
9d36d4fb
HH
400# find_dev_fstype <device>
401# Echo the filesystem type for a given device.
81672479
HH
402# /proc/self/mountinfo is taken as the primary source of information
403# and /etc/fstab is used as a fallback.
404# No newline is appended!
405# Example:
9d36d4fb 406# $ find_dev_fstype /dev/sda2;echo
81672479 407# ext4
9d36d4fb 408find_dev_fstype() {
5e601454 409 local _find_dev _fs
9d36d4fb
HH
410 _find_dev="$1"
411 [[ "$_find_dev" = /dev* ]] || _find_dev="/dev/block/$_find_dev"
5e601454
HH
412
413 if [[ $use_fstab != yes ]]; then
414 while read _fs; do
415 [[ $_fs ]] || continue
416 [[ $_fs = "autofs" ]] && continue
417 echo -n $_fs
418 return 0
419 done < <(findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev")
420 fi
421
422 while read _fs; do
423 [[ $_fs ]] || continue
424 [[ $_fs = "autofs" ]] && continue
425 echo -n $_fs
426 return 0
427 done < <(findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev")
428
429 return 1
430
81672479
HH
431}
432
7ae5d9d1 433# finds the major:minor of the block device backing the root filesystem.
f76ef3aa
VL
434find_root_block_device() { find_block_device /; }
435
7e2bca48 436# for_each_host_dev_fs <func>
d351541e 437# Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
7e2bca48 438# in ${host_fs_types[@]}
480d772f
HH
439for_each_host_dev_fs()
440{
441 local _func="$1"
d0096de7 442 local _dev
2efa546f 443 local _ret=1
fd191a7b
HH
444
445 [[ "${!host_fs_types[@]}" ]] || return 0
446
d351541e
HH
447 for _dev in "${!host_fs_types[@]}"; do
448 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
480d772f 449 done
2efa546f 450 return $_ret
480d772f
HH
451}
452
fd191a7b
HH
453host_fs_all()
454{
455 echo "${host_fs_types[@]}"
456}
457
17829e94
VL
458# Walk all the slave relationships for a given block device.
459# Stop when our helper function returns success
460# $1 = function to call on every found block device
461# $2 = block device in major:minor format
0b706743 462check_block_and_slaves() {
29b10e65 463 local _x
17829e94
VL
464 [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
465 "$1" $2 && return
533d7dc4 466 check_vol_slaves "$@" && return 0
3478b314 467 if [[ -f /sys/dev/block/$2/../dev ]]; then
0b706743 468 check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
a3afcf2a 469 fi
17829e94 470 [[ -d /sys/dev/block/$2/slaves ]] || return 1
29b10e65 471 for _x in /sys/dev/block/$2/slaves/*/dev; do
d82e0d7d 472 [[ -f $_x ]] || continue
29b10e65 473 check_block_and_slaves $1 $(cat "$_x") && return 0
17829e94
VL
474 done
475 return 1
476}
477
83e0dc7a
DY
478check_block_and_slaves_all() {
479 local _x _ret=1
480 [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
481 if "$1" $2; then
482 _ret=0
483 fi
484 check_vol_slaves "$@" && return 0
485 if [[ -f /sys/dev/block/$2/../dev ]]; then
486 check_block_and_slaves_all $1 $(cat "/sys/dev/block/$2/../dev") && _ret=0
487 fi
488 [[ -d /sys/dev/block/$2/slaves ]] || return 1
489 for _x in /sys/dev/block/$2/slaves/*/dev; do
490 [[ -f $_x ]] || continue
491 check_block_and_slaves_all $1 $(cat "$_x") && _ret=0
492 done
493 return $_ret
494}
495# for_each_host_dev_and_slaves <func>
496# Execute "<func> <dev>" for every "<dev>" found
497# in ${host_devs[@]} and their slaves
498for_each_host_dev_and_slaves_all()
499{
500 local _func="$1"
501 local _dev
502 local _ret=1
fd191a7b
HH
503
504 [[ "${host_devs[@]}" ]] || return 0
505
83e0dc7a
DY
506 for _dev in ${host_devs[@]}; do
507 [[ -b "$_dev" ]] || continue
83e0dc7a
DY
508 if check_block_and_slaves_all $_func $(get_maj_min $_dev); then
509 _ret=0
510 fi
511 done
512 return $_ret
513}
514
515for_each_host_dev_and_slaves()
516{
517 local _func="$1"
518 local _dev
fd191a7b
HH
519
520 [[ "${host_devs[@]}" ]] || return 0
521
83e0dc7a
DY
522 for _dev in ${host_devs[@]}; do
523 [[ -b "$_dev" ]] || continue
a999414e 524 check_block_and_slaves $_func $(get_maj_min $_dev) && return 0
83e0dc7a
DY
525 done
526 return 1
527}
528
533d7dc4
HH
529# ugly workaround for the lvm design
530# There is no volume group device,
531# so, there are no slave devices for volume groups.
532# Logical volumes only have the slave devices they really live on,
533# but you cannot create the logical volume without the volume group.
95bde758 534# And the volume group might be bigger than the devices the LV needs.
533d7dc4 535check_vol_slaves() {
29b10e65 536 local _lv _vg _pv
0b706743 537 for i in /dev/mapper/*; do
c4e48eae 538 _lv=$(get_maj_min $i)
29b10e65
HH
539 if [[ $_lv = $2 ]]; then
540 _vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
cc02093d 541 # strip space
29b10e65
HH
542 _vg=$(echo $_vg)
543 if [[ $_vg ]]; then
544 for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null)
0b706743 545 do
c4e48eae 546 check_block_and_slaves $1 $(get_maj_min $_pv) && return 0
cc02093d
HH
547 done
548 fi
549 fi
533d7dc4
HH
550 done
551 return 1
552}
553
8aa99268
HH
554# fs_get_option <filesystem options> <search for option>
555# search for a specific option in a bunch of filesystem options
556# and return the value
557fs_get_option() {
558 local _fsopts=$1
559 local _option=$2
560 local OLDIFS="$IFS"
561 IFS=,
562 set -- $_fsopts
563 IFS="$OLDIFS"
564 while [ $# -gt 0 ]; do
565 case $1 in
566 $_option=*)
567 echo ${1#${_option}=}
568 break
569 esac
570 shift
571 done
572}
573
f4031e8a 574if [[ $DRACUT_INSTALL ]]; then
89d44e72
HH
575 [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
576 inst_dir() {
577 [[ -e ${initdir}/"$1" ]] && return 0 # already there
f4031e8a
HH
578 $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@"
579 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -d "$@" || :
89d44e72 580 }
19612483 581
89d44e72
HH
582 inst() {
583 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
f4031e8a
HH
584 #dinfo "$DRACUT_INSTALL -l $@"
585 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
586 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
89d44e72
HH
587 }
588
589 inst_simple() {
590 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
591 [[ -e $1 ]] || return 1 # no source
f4031e8a
HH
592 $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@"
593 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} "$@" || :
89d44e72
HH
594 }
595
596 inst_symlink() {
597 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
598 [[ -L $1 ]] || return 1
f4031e8a
HH
599 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
600 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
89d44e72
HH
601 }
602
603 dracut_install() {
06e9f887 604 local ret
f4031e8a
HH
605 #dinfo "initdir=$initdir $DRACUT_INSTALL -l $@"
606 $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
06e9f887
DY
607 ret=$?
608 (($ret != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} -a ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
609 return $ret
89d44e72
HH
610 }
611
612 inst_library() {
613 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
614 [[ -e $1 ]] || return 1 # no source
f4031e8a
HH
615 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
616 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
89d44e72
HH
617 }
618
619 inst_binary() {
f4031e8a
HH
620 $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@"
621 (($? != 0)) && derror $DRACUT_INSTALL ${initdir+-D "$initdir"} ${DRACUT_RESOLVE_DEPS+-l} ${DRACUT_FIPS_MODE+-H} "$@" || :
89d44e72
HH
622 }
623
624 inst_script() {
f4031e8a
HH
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} "$@" || :
89d44e72
HH
627 }
628
629else
630
631 # Install a directory, keeping symlinks as on the original system.
632 # Example: if /lib points to /lib64 on the host, "inst_dir /lib/file"
633 # will create ${initdir}/lib64, ${initdir}/lib64/file,
634 # and a symlink ${initdir}/lib -> lib64.
635 inst_dir() {
636 [[ -e ${initdir}/"$1" ]] && return 0 # already there
637
638 local _dir="$1" _part="${1%/*}" _file
639 while [[ "$_part" != "${_part%/*}" ]] && ! [[ -e "${initdir}/${_part}" ]]; do
640 _dir="$_part $_dir"
641 _part=${_part%/*}
642 done
643
644 # iterate over parent directories
645 for _file in $_dir; do
646 [[ -e "${initdir}/$_file" ]] && continue
647 if [[ -L $_file ]]; then
648 inst_symlink "$_file"
649 else
19612483 650 # create directory
89d44e72
HH
651 mkdir -m 0755 -p "${initdir}/$_file" || return 1
652 [[ -e "$_file" ]] && chmod --reference="$_file" "${initdir}/$_file"
653 chmod u+w "${initdir}/$_file"
654 fi
655 done
656 }
657
658 # $1 = file to copy to ramdisk
659 # $2 (optional) Name for the file on the ramdisk
660 # Location of the image dir is assumed to be $initdir
661 # We never overwrite the target if it exists.
662 inst_simple() {
663 [[ -f "$1" ]] || return 1
664 strstr "$1" "/" || return 1
665 local _src=$1 _target="${2:-$1}"
666
667 [[ -L $_src ]] && { inst_symlink $_src $_target; return $?; }
668
669 if ! [[ -d ${initdir}/$_target ]]; then
670 [[ -e ${initdir}/$_target ]] && return 0
671 [[ -L ${initdir}/$_target ]] && return 0
672 [[ -d "${initdir}/${_target%/*}" ]] || inst_dir "${_target%/*}"
19612483 673 fi
89d44e72
HH
674 if [[ $DRACUT_FIPS_MODE ]]; then
675 # install checksum files also
676 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
677 inst "${_src%/*}/.${_src##*/}.hmac" "${_target%/*}/.${_target##*/}.hmac"
678 fi
00083a09
MB
679 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
680 inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_target##*/}.hmac"
681 fi
682 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
683 inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_target##*/}.hmac"
684 fi
89d44e72
HH
685 fi
686 ddebug "Installing $_src"
687 cp --reflink=auto --sparse=auto -pfL "$_src" "${initdir}/$_target"
688 }
19612483 689
89d44e72
HH
690 # same as above, but specialized for symlinks
691 inst_symlink() {
692 local _src=$1 _target=${2:-$1} _realsrc
693 strstr "$1" "/" || return 1
694 [[ -L $1 ]] || return 1
695 [[ -L $initdir/$_target ]] && return 0
696 _realsrc=$(readlink -f "$_src")
697 if ! [[ -e $initdir/$_realsrc ]]; then
698 if [[ -d $_realsrc ]]; then
699 inst_dir "$_realsrc"
700 else
701 inst "$_realsrc"
702 fi
703 fi
704 [[ ! -e $initdir/${_target%/*} ]] && inst_dir "${_target%/*}"
3f590c78 705
89d44e72
HH
706 ln_r "${_realsrc}" "${_target}"
707 }
22048b44 708
89d44e72
HH
709 # Same as above, but specialized to handle dynamic libraries.
710 # It handles making symlinks according to how the original library
711 # is referenced.
712 inst_library() {
713 local _src="$1" _dest=${2:-$1} _lib _reallib _symlink
714 strstr "$1" "/" || return 1
715 [[ -e $initdir/$_dest ]] && return 0
716 if [[ -L $_src ]]; then
717 if [[ $DRACUT_FIPS_MODE ]]; then
718 # install checksum files also
719 if [[ -e "${_src%/*}/.${_src##*/}.hmac" ]]; then
720 inst "${_src%/*}/.${_src##*/}.hmac" "${_dest%/*}/.${_dest##*/}.hmac"
721 fi
00083a09
MB
722 if [[ -e "/lib/fipscheck/${_src##*/}.hmac" ]]; then
723 inst "/lib/fipscheck/${_src##*/}.hmac" "/lib/fipscheck/${_dest##*/}.hmac"
724 fi
725 if [[ -e "/lib64/fipscheck/${_src##*/}.hmac" ]]; then
726 inst "/lib64/fipscheck/${_src##*/}.hmac" "/lib64/fipscheck/${_dest##*/}.hmac"
727 fi
89d44e72
HH
728 fi
729 _reallib=$(readlink -f "$_src")
730 inst_simple "$_reallib" "$_reallib"
731 inst_dir "${_dest%/*}"
732 ln_r "${_reallib}" "${_dest}"
733 else
734 inst_simple "$_src" "$_dest"
735 fi
22048b44 736
89d44e72
HH
737 # Create additional symlinks. See rev_symlinks description.
738 for _symlink in $(rev_lib_symlinks $_src) $(rev_lib_symlinks $_reallib); do
739 [[ ! -e $initdir/$_symlink ]] && {
740 ddebug "Creating extra symlink: $_symlink"
741 inst_symlink $_symlink
742 }
743 done
744 }
745
746 # Same as above, but specialized to install binary executables.
747 # Install binary executable, and all shared library dependencies, if any.
748 inst_binary() {
749 local _bin _target
750 _bin=$(find_binary "$1") || return 1
751 _target=${2:-$_bin}
752 [[ -e $initdir/$_target ]] && return 0
753 local _file _line
754 local _so_regex='([^ ]*/lib[^/]*/[^ ]*\.so[^ ]*)'
755 # I love bash!
756 LC_ALL=C ldd "$_bin" 2>/dev/null | while read _line; do
757 [[ $_line = 'not a dynamic executable' ]] && break
758
759 if [[ $_line =~ $_so_regex ]]; then
760 _file=${BASH_REMATCH[1]}
761 [[ -e ${initdir}/$_file ]] && continue
762 inst_library "$_file"
763 continue
764 fi
765
766 if [[ $_line =~ not\ found ]]; then
767 dfatal "Missing a shared library required by $_bin."
768 dfatal "Run \"ldd $_bin\" to find out what it is."
769 dfatal "$_line"
770 dfatal "dracut cannot create an initrd."
771 exit 1
772 fi
773 done
774 inst_simple "$_bin" "$_target"
775 }
776
777 # same as above, except for shell scripts.
778 # If your shell script does not start with shebang, it is not a shell script.
779 inst_script() {
780 local _bin
781 _bin=$(find_binary "$1") || return 1
782 shift
783 local _line _shebang_regex
784 read -r -n 80 _line <"$_bin"
785 # If debug is set, clean unprintable chars to prevent messing up the term
786 [[ $debug ]] && _line=$(echo -n "$_line" | tr -c -d '[:print:][:space:]')
787 _shebang_regex='(#! *)(/[^ ]+).*'
788 [[ $_line =~ $_shebang_regex ]] || return 1
789 inst "${BASH_REMATCH[2]}" && inst_simple "$_bin" "$@"
790 }
791
792 # general purpose installation function
793 # Same args as above.
794 inst() {
795 local _x
796
797 case $# in
798 1) ;;
799 2) [[ ! $initdir && -d $2 ]] && export initdir=$2
800 [[ $initdir = $2 ]] && set $1;;
801 3) [[ -z $initdir ]] && export initdir=$2
802 set $1 $3;;
803 *) dfatal "inst only takes 1 or 2 or 3 arguments"
804 exit 1;;
805 esac
806 for _x in inst_symlink inst_script inst_binary inst_simple; do
807 $_x "$@" && return 0
808 done
809 return 1
810 }
811
812 # dracut_install [-o ] <file> [<file> ... ]
813 # Install <file> to the initramfs image
814 # -o optionally install the <file> and don't fail, if it is not there
815 dracut_install() {
816 local _optional=no
817 if [[ $1 = '-o' ]]; then
818 _optional=yes
819 shift
820 fi
821 while (($# > 0)); do
822 if ! inst "$1" ; then
823 if [[ $_optional = yes ]]; then
824 dinfo "Skipping program $1 as it cannot be found and is" \
825 "flagged to be optional"
826 else
827 dfatal "Failed to install $1"
828 exit 1
829 fi
830 fi
831 shift
832 done
833 }
834
835fi
36b24d7c 836
a10a1416
837# find symlinks linked to given library file
838# $1 = library file
839# Function searches for symlinks by stripping version numbers appended to
840# library filename, checks if it points to the same target and finally
841# prints the list of symlinks to stdout.
842#
843# Example:
844# rev_lib_symlinks libfoo.so.8.1
845# output: libfoo.so.8 libfoo.so
846# (Only if libfoo.so.8 and libfoo.so exists on host system.)
847rev_lib_symlinks() {
848 [[ ! $1 ]] && return 0
849
850 local fn="$1" orig="$(readlink -f "$1")" links=''
851
852 [[ ${fn} =~ .*\.so\..* ]] || return 1
853
854 until [[ ${fn##*.} == so ]]; do
855 fn="${fn%.*}"
856 [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
857 done
858
0b706743 859 echo "${links}"
a10a1416
860}
861
62073c30
CG
862# attempt to install any programs specified in a udev rule
863inst_rule_programs() {
864 local _prog _bin
865
866 if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
867 for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
76d5c79e 868 _bin=""
604d1eb2
HH
869 if [ -x ${udevdir}/$_prog ]; then
870 _bin=${udevdir}/$_prog
34bd2be2 871 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
604d1eb2 872 _bin=$(find_binary "$_prog") || {
cc218087 873 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
604d1eb2
HH
874 continue;
875 }
876 fi
877
76d5c79e 878 [[ $_bin ]] && dracut_install "$_bin"
604d1eb2
HH
879 done
880 fi
da9c5181
HH
881 if grep -qE 'RUN[+=]=?"[^ "]+' "$1"; then
882 for _prog in $(grep -E 'RUN[+=]=?"[^ "]+' "$1" | sed -r 's/.*RUN[+=]=?"([^ "]+).*/\1/'); do
76d5c79e 883 _bin=""
604d1eb2
HH
884 if [ -x ${udevdir}/$_prog ]; then
885 _bin=${udevdir}/$_prog
34bd2be2 886 elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
604d1eb2 887 _bin=$(find_binary "$_prog") || {
cc218087 888 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
604d1eb2
HH
889 continue;
890 }
891 fi
892
76d5c79e 893 [[ $_bin ]] && dracut_install "$_bin"
604d1eb2
HH
894 done
895 fi
65d1a8a4
HH
896 if grep -qE 'IMPORT\{program\}==?"[^ "]+' "$1"; then
897 for _prog in $(grep -E 'IMPORT\{program\}==?"[^ "]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/'); do
76d5c79e 898 _bin=""
604d1eb2
HH
899 if [ -x ${udevdir}/$_prog ]; then
900 _bin=${udevdir}/$_prog
34bd2be2 901 elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
62073c30 902 _bin=$(find_binary "$_prog") || {
cc218087 903 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
62073c30
CG
904 continue;
905 }
906 fi
907
76d5c79e 908 [[ $_bin ]] && dracut_install "$_bin"
62073c30
CG
909 done
910 fi
911}
912
e0a39336
HH
913# attempt to install any programs specified in a udev rule
914inst_rule_group_owner() {
915 local i
916
917 if grep -qE 'OWNER=?"[^ "]+' "$1"; then
918 for i in $(grep -E 'OWNER=?"[^ "]+' "$1" | sed -r 's/.*OWNER=?"([^ "]+).*/\1/'); do
919 if ! egrep -q "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
920 egrep "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
921 fi
922 done
923 fi
924 if grep -qE 'GROUP=?"[^ "]+' "$1"; then
925 for i in $(grep -E 'GROUP=?"[^ "]+' "$1" | sed -r 's/.*GROUP=?"([^ "]+).*/\1/'); do
926 if ! egrep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then
927 egrep "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
928 fi
929 done
930 fi
931}
932
8d85429a
HH
933inst_rule_initqueue() {
934 if grep -q -F initqueue "$1"; then
935 dracut_need_initqueue
936 fi
937}
938
f04dc5f3
VL
939# udev rules always get installed in the same place, so
940# create a function to install them to make life simpler.
0b706743 941inst_rules() {
29b10e65 942 local _target=/etc/udev/rules.d _rule _found
fd2312e0 943
604d1eb2 944 inst_dir "${udevdir}/rules.d"
29b10e65
HH
945 inst_dir "$_target"
946 for _rule in "$@"; do
256cba18 947 if [ "${_rule#/}" = "$_rule" ]; then
604d1eb2 948 for r in ${udevdir}/rules.d /etc/udev/rules.d; do
76f5fa54
HH
949 if [[ -f $r/$_rule ]]; then
950 _found="$r/$_rule"
62073c30 951 inst_rule_programs "$_found"
e0a39336 952 inst_rule_group_owner "$_found"
8d85429a 953 inst_rule_initqueue "$_found"
604d1eb2 954 inst_simple "$_found"
76f5fa54
HH
955 fi
956 done
957 fi
c97e1a76 958 for r in '' ./ $dracutbasedir/rules.d/; do
29b10e65
HH
959 if [[ -f ${r}$_rule ]]; then
960 _found="${r}$_rule"
62073c30 961 inst_rule_programs "$_found"
e0a39336 962 inst_rule_group_owner "$_found"
8d85429a 963 inst_rule_initqueue "$_found"
604d1eb2 964 inst_simple "$_found" "$_target/${_found##*/}"
c97e1a76
HH
965 fi
966 done
29b10e65 967 [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
f04dc5f3
VL
968 done
969}
970
c46cda82
HH
971prepare_udev_rules() {
972 [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version)
973
974 for f in "$@"; do
975 f="${initdir}/etc/udev/rules.d/$f"
976 [ -e "$f" ] || continue
977 while read line; do
978 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
979 if [ $UDEVVERSION -ge 174 ]; then
980 printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
981 else
982 printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
983 fi
984 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
985 if [ $UDEVVERSION -ge 176 ]; then
986 printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
987 else
988 printf '%sIMPORT{program}="/sbin/blkid -o udev -p $tempnode"\n' "${line%%IMPORT BLKID}"
989 fi
990 else
991 echo "$line"
992 fi
993 done < "${f}" > "${f}.new"
994 mv "${f}.new" "$f"
995 done
996}
997
53f95456
VL
998# install function specialized for hooks
999# $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
1000# All hooks should be POSIX/SuS compliant, they will be sourced by init.
1001inst_hook() {
cdad82fd 1002 if ! [[ -f $3 ]]; then
e27770e1
1003 dfatal "Cannot install a hook ($3) that does not exist."
1004 dfatal "Aborting initrd creation."
cc02093d 1005 exit 1
cdad82fd 1006 elif ! strstr "$hookdirs" "$1"; then
3b403b32 1007 dfatal "No such hook type $1. Aborting initrd creation."
cc02093d 1008 exit 1
cdad82fd 1009 fi
5a84ac3f 1010 inst_simple "$3" "/lib/dracut/hooks/${1}/${2}-${3##*/}"
53f95456
VL
1011}
1012
3378a54f
1013# install any of listed files
1014#
1015# If first argument is '-d' and second some destination path, first accessible
1016# source is installed into this path, otherwise it will installed in the same
1017# path as source. If none of listed files was installed, function return 1.
1018# On first successful installation it returns with 0 status.
1019#
1020# Example:
1021#
1022# inst_any -d /bin/foo /bin/bar /bin/baz
1023#
1024# Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
1025# initramfs.
1026inst_any() {
1027 local to f
1028
1029 [[ $1 = '-d' ]] && to="$2" && shift 2
1030
1031 for f in "$@"; do
1032 if [[ -e $f ]]; then
1033 [[ $to ]] && inst "$f" "$to" && return 0
1034 inst "$f" && return 0
1035 fi
1036 done
1037
1038 return 1
1039}
1040
c9143a63
JAH
1041
1042# inst_libdir_file [-n <pattern>] <file> [<file>...]
1043# Install a <file> located on a lib directory to the initramfs image
cacaa90c 1044# -n <pattern> install matching files
c9143a63 1045inst_libdir_file() {
0c6565c8 1046 local _files
c9143a63 1047 if [[ "$1" == "-n" ]]; then
cacaa90c 1048 local _pattern=$2
c9143a63
JAH
1049 shift 2
1050 for _dir in $libdirs; do
7828692f 1051 for _i in "$@"; do
c9143a63 1052 for _f in "$_dir"/$_i; do
7828692f 1053 [[ "$_f" =~ $_pattern ]] || continue
0c6565c8 1054 [[ -e "$_f" ]] && _files+="$_f "
c9143a63
JAH
1055 done
1056 done
1057 done
1058 else
1059 for _dir in $libdirs; do
7828692f 1060 for _i in "$@"; do
c9143a63 1061 for _f in "$_dir"/$_i; do
0c6565c8 1062 [[ -e "$_f" ]] && _files+="$_f "
c9143a63
JAH
1063 done
1064 done
1065 done
1066 fi
0c6565c8 1067 [[ $_files ]] && dracut_install $_files
c9143a63
JAH
1068}
1069
1070
87122afc
1071# install function decompressing the target and handling symlinks
1072# $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
1073#
1074# Function install targets in the same paths inside overlay but decompressed
1075# and without extensions (.gz, .bz2).
1076inst_decompress() {
b19c5d51 1077 local _src _cmd
87122afc 1078
29b10e65 1079 for _src in $@
87122afc 1080 do
29b10e65 1081 case ${_src} in
c62b9461 1082 *.gz) _cmd='gzip -f -d' ;;
29b10e65 1083 *.bz2) _cmd='bzip2 -d' ;;
87122afc
1084 *) return 1 ;;
1085 esac
b19c5d51 1086 inst_simple ${_src}
87122afc
1087 # Decompress with chosen tool. We assume that tool changes name e.g.
1088 # from 'name.gz' to 'name'.
29b10e65 1089 ${_cmd} "${initdir}${_src}"
87122afc
1090 done
1091}
1092
1093# It's similar to above, but if file is not compressed, performs standard
1094# install.
1095# $@ = list of files
1096inst_opt_decompress() {
29b10e65 1097 local _src
87122afc 1098
29b10e65 1099 for _src in $@
87122afc 1100 do
29b10e65 1101 inst_decompress "${_src}" || inst "${_src}"
87122afc
1102 done
1103}
1104
7e2bca48
HH
1105# module_check <dracut module>
1106# execute the check() function of module-setup.sh of <dracut module>
1107# or the "check" script, if module-setup.sh is not found
1108# "check $hostonly" is called
95d2dabc 1109module_check() {
29b10e65
HH
1110 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1111 local _ret
31f1c02d
AW
1112 local _forced=0
1113 local _hostonly=$hostonly
1114 [ $# -eq 2 ] && _forced=$2
29b10e65
HH
1115 [[ -d $_moddir ]] || return 1
1116 if [[ ! -f $_moddir/module-setup.sh ]]; then
95d2dabc 1117 # if we do not have a check script, we are unconditionally included
29b10e65 1118 [[ -x $_moddir/check ]] || return 0
31f1c02d 1119 [ $_forced -ne 0 ] && unset hostonly
29b10e65 1120 $_moddir/check $hostonly
31f1c02d 1121 _ret=$?
95d2dabc
HH
1122 else
1123 unset check depends install installkernel
29b10e65 1124 . $_moddir/module-setup.sh
95d2dabc 1125 is_func check || return 0
31f1c02d
AW
1126 [ $_forced -ne 0 ] && unset hostonly
1127 check $hostonly
29b10e65 1128 _ret=$?
95d2dabc 1129 unset check depends install installkernel
0c2e3d12 1130 fi
31f1c02d
AW
1131 hostonly=$_hostonly
1132 return $_ret
0c2e3d12
VL
1133}
1134
7e2bca48
HH
1135# module_check_mount <dracut module>
1136# execute the check() function of module-setup.sh of <dracut module>
1137# or the "check" script, if module-setup.sh is not found
1138# "mount_needs=1 check 0" is called
1139module_check_mount() {
1140 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1141 local _ret
1142 mount_needs=1
1143 [[ -d $_moddir ]] || return 1
1144 if [[ ! -f $_moddir/module-setup.sh ]]; then
1145 # if we do not have a check script, we are unconditionally included
1146 [[ -x $_moddir/check ]] || return 0
1147 mount_needs=1 $_moddir/check 0
1148 _ret=$?
1149 else
1150 unset check depends install installkernel
1151 . $_moddir/module-setup.sh
1152 is_func check || return 1
1153 check 0
1154 _ret=$?
1155 unset check depends install installkernel
1156 fi
1157 unset mount_needs
1158 return $_ret
1159}
1160
1161# module_depends <dracut module>
1162# execute the depends() function of module-setup.sh of <dracut module>
1163# or the "depends" script, if module-setup.sh is not found
95d2dabc 1164module_depends() {
29b10e65
HH
1165 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1166 local _ret
1167 [[ -d $_moddir ]] || return 1
1168 if [[ ! -f $_moddir/module-setup.sh ]]; then
95d2dabc 1169 # if we do not have a check script, we have no deps
29b10e65
HH
1170 [[ -x $_moddir/check ]] || return 0
1171 $_moddir/check -d
95d2dabc
HH
1172 return $?
1173 else
1174 unset check depends install installkernel
29b10e65 1175 . $_moddir/module-setup.sh
95d2dabc
HH
1176 is_func depends || return 0
1177 depends
29b10e65 1178 _ret=$?
95d2dabc 1179 unset check depends install installkernel
29b10e65 1180 return $_ret
33ee031c 1181 fi
0c2e3d12
VL
1182}
1183
7e2bca48
HH
1184# module_install <dracut module>
1185# execute the install() function of module-setup.sh of <dracut module>
1186# or the "install" script, if module-setup.sh is not found
95d2dabc 1187module_install() {
29b10e65
HH
1188 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1189 local _ret
1190 [[ -d $_moddir ]] || return 1
1191 if [[ ! -f $_moddir/module-setup.sh ]]; then
1192 [[ -x $_moddir/install ]] && . "$_moddir/install"
95d2dabc
HH
1193 return $?
1194 else
1195 unset check depends install installkernel
29b10e65 1196 . $_moddir/module-setup.sh
95d2dabc
HH
1197 is_func install || return 0
1198 install
29b10e65 1199 _ret=$?
95d2dabc 1200 unset check depends install installkernel
29b10e65 1201 return $_ret
95d2dabc
HH
1202 fi
1203}
1204
7e2bca48
HH
1205# module_installkernel <dracut module>
1206# execute the installkernel() function of module-setup.sh of <dracut module>
1207# or the "installkernel" script, if module-setup.sh is not found
95d2dabc 1208module_installkernel() {
29b10e65
HH
1209 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1210 local _ret
1211 [[ -d $_moddir ]] || return 1
1212 if [[ ! -f $_moddir/module-setup.sh ]]; then
1213 [[ -x $_moddir/installkernel ]] && . "$_moddir/installkernel"
95d2dabc
HH
1214 return $?
1215 else
1216 unset check depends install installkernel
29b10e65 1217 . $_moddir/module-setup.sh
95d2dabc
HH
1218 is_func installkernel || return 0
1219 installkernel
29b10e65 1220 _ret=$?
95d2dabc 1221 unset check depends install installkernel
29b10e65 1222 return $_ret
95d2dabc
HH
1223 fi
1224}
1225
7e2bca48
HH
1226# check_mount <dracut module>
1227# check_mount checks, if a dracut module is needed for the given
1228# device and filesystem types in "${host_fs_types[@]}"
1b7fd0fa
AW
1229check_mount() {
1230 local _mod=$1
1231 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1232 local _ret
1233 local _moddep
ecfa02bd
HH
1234
1235 [ "${#host_fs_types[*]}" -le 0 ] && return 1
1236
1b7fd0fa
AW
1237 # If we are already scheduled to be loaded, no need to check again.
1238 strstr " $mods_to_load " " $_mod " && return 0
1239 strstr " $mods_checked_as_dep " " $_mod " && return 1
1240
1241 # This should never happen, but...
1242 [[ -d $_moddir ]] || return 1
1243
1244 [[ $2 ]] || mods_checked_as_dep+=" $_mod "
1245
0f283709 1246 if strstr " $omit_dracutmodules " " $_mod "; then
600c8769 1247 dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
0f283709
HH
1248 return 1
1249 fi
1b7fd0fa 1250
ecfa02bd
HH
1251 if strstr " $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1252 module_check_mount $_mod; ret=$?
1253
1254 # explicit module, so also accept ret=255
1255 [[ $ret = 0 || $ret = 255 ]] || return 1
1b7fd0fa 1256 else
ecfa02bd
HH
1257 # module not in our list
1258 if [[ $dracutmodules = all ]]; then
1259 # check, if we can and should install this module
1260 module_check_mount $_mod || return 1
1261 else
1262 # skip this module
1263 return 1
1264 fi
1b7fd0fa
AW
1265 fi
1266
ecfa02bd 1267
1b7fd0fa
AW
1268 for _moddep in $(module_depends $_mod); do
1269 # handle deps as if they were manually added
1270 strstr " $add_dracutmodules " " $_moddep " || \
1271 add_dracutmodules+=" $_moddep "
1272 strstr " $force_add_dracutmodules " " $_moddep " || \
1273 force_add_dracutmodules+=" $_moddep "
1274 # if a module we depend on fail, fail also
0f283709 1275 if ! check_module $_moddep; then
600c8769 1276 derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
0f283709
HH
1277 return 1
1278 fi
1b7fd0fa
AW
1279 done
1280
1281 strstr " $mods_to_load " " $_mod " || \
1282 mods_to_load+=" $_mod "
1283
1284 return 0
1285}
1286
7e2bca48
HH
1287# check_module <dracut module> [<use_as_dep>]
1288# check if a dracut module is to be used in the initramfs process
1289# if <use_as_dep> is set, then the process also keeps track
1290# that the modules were checked for the dependency tracking process
95d2dabc 1291check_module() {
29b10e65
HH
1292 local _mod=$1
1293 local _moddir=$(echo ${dracutbasedir}/modules.d/??${1})
1294 local _ret
1295 local _moddep
95d2dabc 1296 # If we are already scheduled to be loaded, no need to check again.
29b10e65
HH
1297 strstr " $mods_to_load " " $_mod " && return 0
1298 strstr " $mods_checked_as_dep " " $_mod " && return 1
95d2dabc
HH
1299
1300 # This should never happen, but...
29b10e65 1301 [[ -d $_moddir ]] || return 1
95d2dabc 1302
29b10e65 1303 [[ $2 ]] || mods_checked_as_dep+=" $_mod "
95d2dabc 1304
0f283709 1305 if strstr " $omit_dracutmodules " " $_mod "; then
600c8769 1306 dinfo "dracut module '$_mod' will not be installed, because it's in the list to be omitted!"
0f283709
HH
1307 return 1
1308 fi
95d2dabc 1309
31f1c02d
AW
1310 if strstr " $dracutmodules $add_dracutmodules $force_add_dracutmodules" " $_mod "; then
1311 if strstr " $force_add_dracutmodules" " $_mod"; then
1312 module_check $_mod 1; ret=$?
1313 else
1314 module_check $_mod 0; ret=$?
1315 fi
95d2dabc
HH
1316 # explicit module, so also accept ret=255
1317 [[ $ret = 0 || $ret = 255 ]] || return 1
1318 else
1319 # module not in our list
1320 if [[ $dracutmodules = all ]]; then
1321 # check, if we can and should install this module
29b10e65 1322 module_check $_mod || return 1
cc02093d 1323 else
95d2dabc
HH
1324 # skip this module
1325 return 1
970e646b 1326 fi
95d2dabc 1327 fi
bb764545 1328
29b10e65 1329 for _moddep in $(module_depends $_mod); do
95d2dabc 1330 # handle deps as if they were manually added
29b10e65
HH
1331 strstr " $add_dracutmodules " " $_moddep " || \
1332 add_dracutmodules+=" $_moddep "
31f1c02d
AW
1333 strstr " $force_add_dracutmodules " " $_moddep " || \
1334 force_add_dracutmodules+=" $_moddep "
95d2dabc 1335 # if a module we depend on fail, fail also
0f283709 1336 if ! check_module $_moddep; then
600c8769 1337 derror "dracut module '$_mod' depends on '$_moddep', which can't be installed"
0f283709
HH
1338 return 1
1339 fi
0c2e3d12 1340 done
70503db4 1341
29b10e65
HH
1342 strstr " $mods_to_load " " $_mod " || \
1343 mods_to_load+=" $_mod "
95d2dabc
HH
1344
1345 return 0
1346}
1347
7e2bca48
HH
1348# for_each_module_dir <func>
1349# execute "<func> <dracut module> 1"
1b7fd0fa 1350for_each_module_dir() {
29b10e65
HH
1351 local _modcheck
1352 local _mod
1353 local _moddir
1b7fd0fa
AW
1354 local _func
1355 _func=$1
29b10e65
HH
1356 for _moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1357 _mod=${_moddir##*/}; _mod=${_mod#[0-9][0-9]}
1b7fd0fa 1358 $_func $_mod 1
70503db4 1359 done
724b87a6
HH
1360
1361 # Report any missing dracut modules, the user has specified
31f1c02d 1362 _modcheck="$add_dracutmodules $force_add_dracutmodules"
29b10e65
HH
1363 [[ $dracutmodules != all ]] && _modcheck="$m $dracutmodules"
1364 for _mod in $_modcheck; do
1365 strstr "$mods_to_load" "$_mod" && continue
1366 strstr "$omit_dracutmodules" "$_mod" && continue
600c8769 1367 derror "dracut module '$_mod' cannot be found or installed."
724b87a6 1368 done
0c2e3d12
VL
1369}
1370
ddfd1d10
VL
1371# Install a single kernel module along with any firmware it may require.
1372# $1 = full path to kernel module to install
1373install_kmod_with_fw() {
0b440844 1374 # no need to go further if the module is already installed
379c34d2 1375
0b706743
1376 [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
1377 && return 0
fcbcb252 1378
f4031e8a
HH
1379 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -e "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}" ]]; then
1380 read ret < "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
d8aeb3a7
HH
1381 return $ret
1382 fi
379c34d2 1383
fcbcb252
HH
1384 if [[ $omit_drivers ]]; then
1385 local _kmod=${1##*/}
1386 _kmod=${_kmod%.ko}
1387 _kmod=${_kmod/-/_}
34248c92
HH
1388 if [[ "$_kmod" =~ $omit_drivers ]]; then
1389 dinfo "Omitting driver $_kmod"
7abd4264 1390 return 0
34248c92
HH
1391 fi
1392 if [[ "${1##*/lib/modules/$kernel/}" =~ $omit_drivers ]]; then
fcbcb252 1393 dinfo "Omitting driver $_kmod"
7abd4264 1394 return 0
fcbcb252
HH
1395 fi
1396 fi
1397
d8aeb3a7
HH
1398 inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
1399 ret=$?
f4031e8a
HH
1400 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1401 [[ -d "$DRACUT_KERNEL_LAZY_HASHDIR" ]] && \
1402 echo $ret > "$DRACUT_KERNEL_LAZY_HASHDIR/${1##*/}"
d8aeb3a7 1403 (($ret != 0)) && return $ret
e6024e00
JR
1404
1405 local _modname=${1##*/} _fwdir _found _fw
1406 _modname=${_modname%.ko*}
29b10e65
HH
1407 for _fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
1408 _found=''
1409 for _fwdir in $fw_dir; do
1410 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1411 inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
1412 _found=yes
cc02093d
HH
1413 fi
1414 done
29b10e65 1415 if [[ $_found != yes ]]; then
fe1484f3 1416 if ! [[ -d $(echo /sys/module/${_modname//-/_}|{ read a b; echo $a; }) ]]; then
29b10e65
HH
1417 dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
1418 "\"${_modname}.ko\""
e2cdb570 1419 else
29b10e65
HH
1420 dwarn "Possible missing firmware \"${_fw}\" for kernel module" \
1421 "\"${_modname}.ko\""
e2cdb570 1422 fi
cc02093d 1423 fi
ddfd1d10 1424 done
0b440844 1425 return 0
ddfd1d10
VL
1426}
1427
1428# Do something with all the dependencies of a kernel module.
1429# Note that kernel modules depend on themselves using the technique we use
0b706743
1430# $1 = function to call for each dependency we find
1431# It will be passed the full path to the found kernel module
ddfd1d10
VL
1432# $2 = module to get dependencies for
1433# rest of args = arguments to modprobe
c32bda6b 1434# _fderr specifies FD passed from surrounding scope
ddfd1d10 1435for_each_kmod_dep() {
7abd4264 1436 local _func=$1 _kmod=$2 _cmd _modpath _options
ddfd1d10 1437 shift 2
c32bda6b 1438 modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
29b10e65
HH
1439 while read _cmd _modpath _options; do
1440 [[ $_cmd = insmod ]] || continue
1441 $_func ${_modpath} || exit $?
0b706743 1442 done
0b706743 1443 )
ddfd1d10
VL
1444}
1445
70c6b773 1446dracut_kernel_post() {
d8aeb3a7
HH
1447 local _moddirname=${srcmods%%/lib/modules/*}
1448
f4031e8a 1449 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" ]]; then
ec61f0a3
HH
1450 xargs -r modprobe -a ${_moddirname+-d ${_moddirname}/} \
1451 --ignore-install --show-depends --set-version $kernel \
f4031e8a 1452 < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist" 2>/dev/null \
89d44e72
HH
1453 | sort -u \
1454 | while read _cmd _modpath _options; do
1455 [[ $_cmd = insmod ]] || continue
1456 echo "$_modpath"
f4031e8a 1457 done > "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
d8aeb3a7 1458
89d44e72 1459 (
73575f11
HH
1460 if [[ $DRACUT_INSTALL ]] && [[ -z $_moddirname ]]; then
1461 xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
89d44e72
HH
1462 else
1463 while read _modpath; do
1464 local _destpath=$_modpath
1465 [[ $_moddirname ]] && _destpath=${_destpath##$_moddirname/}
1466 _destpath=${_destpath##*/lib/modules/$kernel/}
1467 inst_simple "$_modpath" "/lib/modules/$kernel/${_destpath}" || exit $?
f4031e8a 1468 done < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"
89d44e72
HH
1469 fi
1470 ) &
d8aeb3a7 1471
73575f11
HH
1472 if [[ $DRACUT_INSTALL ]]; then
1473 xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep" \
89d44e72
HH
1474 | while read line; do
1475 for _fwdir in $fw_dir; do
1476 echo $_fwdir/$line;
1477 done;
73575f11 1478 done | xargs -r $DRACUT_INSTALL ${initdir+-D "$initdir"} -a -o
89d44e72 1479 else
73575f11 1480 for _fw in $(xargs -r modinfo -k $kernel -F firmware < "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist.dep"); do
89d44e72
HH
1481 for _fwdir in $fw_dir; do
1482 if [[ -d $_fwdir && -f $_fwdir/$_fw ]]; then
1483 inst_simple "$_fwdir/$_fw" "/lib/firmware/$_fw"
1484 break
1485 fi
1486 done
1487 done
1488 fi
d8aeb3a7 1489
89d44e72
HH
1490 wait
1491 fi
70c6b773
HH
1492
1493 for _f in modules.builtin.bin modules.builtin; do
1494 [[ $srcmods/$_f ]] && break
1495 done || {
1496 dfatal "No modules.builtin.bin and modules.builtin found!"
1497 return 1
1498 }
1499
1500 for _f in modules.builtin.bin modules.builtin modules.order; do
1501 [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
1502 done
1503
1504 # generate module dependencies for the initrd
1505 if [[ -d $initdir/lib/modules/$kernel ]] && \
1506 ! depmod -a -b "$initdir" $kernel; then
1507 dfatal "\"depmod -a $kernel\" failed."
1508 exit 1
1509 fi
1510
32bd2fbb 1511 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
d8aeb3a7 1512}
fe1484f3 1513
080d1b71
HH
1514module_is_host_only() (
1515 local _mod=$1
1516 _mod=${_mod##*/}
1517 _mod=${_mod%.ko}
1518
1519 [[ "$add_drivers" =~ " ${_mod} " ]] && return 0
1520
1521 # check if module is loaded
1522 [[ -d $(echo /sys/module/${_mod//-/_}|{ read a b; echo $a; }) ]] && return 0
1523
1524 # check if module is loadable on the current kernel
1525 # this covers the case, where a new module is introduced
1526 # or a module was renamed
1527 # or a module changed from builtin to a module
1528 modinfo -F filename "$_mod" &>/dev/null || return 0
1529
1530 return 1
1531)
1532
881eda69 1533find_kernel_modules_by_path () (
74405477 1534 local _OLDIFS
5db6ca5a
HH
1535
1536 [[ -f $srcmods/modules.dep ]] || return 0
1537
1538 _OLDIFS=$IFS
1539 IFS=:
1540 while read a rest; do
1541 [[ $a = */$1/* ]] || continue
1542 echo $srcmods/$a
1543 done < $srcmods/modules.dep
1544 IFS=$_OLDIFS
74405477 1545 return 0
881eda69 1546)
4073c815 1547
881eda69
JR
1548find_kernel_modules () {
1549 find_kernel_modules_by_path drivers
1550}
1551
338b43cd
HH
1552# instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1553# instmods [-c [-s]] <kernel subsystem>
ddfd1d10 1554# install kernel modules along with all their dependencies.
7e2bca48 1555# <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
6fa0c3d6 1556instmods() {
0c1a8ebc 1557 [[ $no_kernel = yes ]] && return
c32bda6b
MS
1558 # called [sub]functions inherit _fderr
1559 local _fderr=9
a6d3be9d 1560 local _check=no
338b43cd 1561 local _silent=no
a6d3be9d
AW
1562 if [[ $1 = '-c' ]]; then
1563 _check=yes
1564 shift
1565 fi
881eda69 1566
338b43cd
HH
1567 if [[ $1 = '-s' ]]; then
1568 _silent=yes
1569 shift
1570 fi
1571
881eda69 1572 function inst1mod() {
a6d3be9d 1573 local _ret=0 _mod="$1"
29b10e65 1574 case $_mod in
0b706743 1575 =*)
d8aeb3a7
HH
1576 ( [[ "$_mpargs" ]] && echo $_mpargs
1577 find_kernel_modules_by_path "${_mod#=}" ) \
1578 | instmods
1579 ((_ret+=$?))
cc02093d 1580 ;;
0024702f 1581 --*) _mpargs+=" $_mod" ;;
34248c92 1582 *)
379c34d2 1583 _mod=${_mod##*/}
6568d86a 1584 # if we are already installed, skip this module and go on
cc02093d 1585 # to the next one.
f4031e8a
HH
1586 if [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1587 [[ -f "$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko" ]]; then
1588 read _ret <"$DRACUT_KERNEL_LAZY_HASHDIR/${_mod%.ko}.ko"
d8aeb3a7
HH
1589 return $_ret
1590 fi
881eda69 1591
34248c92
HH
1592 if [[ $omit_drivers ]] && [[ "$1" =~ $omit_drivers ]]; then
1593 dinfo "Omitting driver ${_mod##$srcmods}"
7abd4264 1594 return 0
34248c92 1595 fi
080d1b71 1596
cc02093d
HH
1597 # If we are building a host-specific initramfs and this
1598 # module is not already loaded, move on to the next one.
fe1484f3 1599 [[ $hostonly ]] \
080d1b71 1600 && ! module_is_host_only "$_mod" \
7abd4264 1601 && return 0
04b56f3a 1602
f4031e8a 1603 if [[ "$_check" = "yes" ]] || ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then
d8aeb3a7 1604 # We use '-d' option in modprobe only if modules prefix path
600c8769 1605 # differs from default '/'. This allows us to use dracut with
d8aeb3a7
HH
1606 # old version of modprobe which doesn't have '-d' option.
1607 local _moddirname=${srcmods%%/lib/modules/*}
1608 [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
1609
1610 # ok, load the module, all its dependencies, and any firmware
1611 # it may require
1612 for_each_kmod_dep install_kmod_with_fw $_mod \
1613 --set-version $kernel ${_moddirname} $_mpargs
1614 ((_ret+=$?))
1615 else
f4031e8a
HH
1616 [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && \
1617 echo $_mod >> "$DRACUT_KERNEL_LAZY_HASHDIR/lazylist"
d8aeb3a7 1618 fi
cc02093d 1619 ;;
0b706743 1620 esac
a6d3be9d 1621 return $_ret
881eda69
JR
1622 }
1623
f9708da2 1624 function instmods_1() {
a6d3be9d 1625 local _mod _mpargs
f9708da2
JR
1626 if (($# == 0)); then # filenames from stdin
1627 while read _mod; do
a6d3be9d 1628 inst1mod "${_mod%.ko*}" || {
338b43cd 1629 if [[ "$_check" == "yes" ]]; then
19b5c109 1630 [[ "$_silent" == "no" ]] && dfatal "Failed to install module $_mod"
a6d3be9d
AW
1631 return 1
1632 fi
1633 }
f9708da2
JR
1634 done
1635 fi
1636 while (($# > 0)); do # filenames as arguments
a6d3be9d 1637 inst1mod ${1%.ko*} || {
338b43cd 1638 if [[ "$_check" == "yes" ]]; then
19b5c109 1639 [[ "$_silent" == "no" ]] && dfatal "Failed to install module $1"
a6d3be9d
AW
1640 return 1
1641 fi
1642 }
f9708da2 1643 shift
881eda69 1644 done
a6d3be9d 1645 return 0
f9708da2
JR
1646 }
1647
a6d3be9d 1648 local _ret _filter_not_found='FATAL: Module .* not found.'
c32bda6b
MS
1649 # Capture all stderr from modprobe to _fderr. We could use {var}>...
1650 # redirections, but that would make dracut require bash4 at least.
1651 eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
86191581 1652 | while read line; do [[ "$line" =~ $_filter_not_found ]] || echo $line;done | derror
a6d3be9d 1653 _ret=$?
a6d3be9d 1654 return $_ret
0b706743 1655}