]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut-init.sh
fix(nvmf): support /etc/nvme/config.json
[thirdparty/dracut.git] / dracut-init.sh
1 #!/bin/bash
2 #
3 # functions used only by dracut and dracut modules
4 #
5 # Copyright 2005-2009 Red Hat, Inc. All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20 export LC_MESSAGES=C
21
22 if [[ $EUID == "0" ]] && ! [[ $DRACUT_NO_XATTR ]]; then
23 export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,xattr,links -dfr"
24 else
25 export DRACUT_CP="cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr"
26 fi
27
28 # is_func <command>
29 # Check whether $1 is a function.
30 is_func() {
31 [[ "$(type -t "$1")" == "function" ]]
32 }
33
34 if ! [[ $dracutbasedir ]]; then
35 dracutbasedir=${BASH_SOURCE[0]%/*}
36 [[ $dracutbasedir == dracut-functions* ]] && dracutbasedir="."
37 [[ $dracutbasedir ]] || dracutbasedir="."
38 dracutbasedir="$(readlink -f $dracutbasedir)"
39 fi
40
41 if ! is_func dinfo > /dev/null 2>&1; then
42 # shellcheck source=./dracut-logger.sh
43 . "$dracutbasedir/dracut-logger.sh"
44 dlog_init
45 fi
46
47 # shellcheck disable=SC2154
48 if ! [[ $initdir ]]; then
49 dfatal "initdir not set"
50 exit 1
51 fi
52
53 if ! [[ -d $initdir ]]; then
54 mkdir -p "$initdir"
55 fi
56
57 if ! [[ $kernel ]]; then
58 kernel=$(uname -r)
59 export kernel
60 fi
61
62 # shellcheck disable=SC2154
63 srcmods="$dracutsysrootdir/lib/modules/$kernel/"
64
65 # shellcheck disable=SC2154
66 [[ $drivers_dir ]] && {
67 if ! command -v kmod &> /dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
68 dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
69 exit 1
70 fi
71 srcmods="$drivers_dir"
72 }
73 export srcmods
74
75 # export standard hookdirs
76 [[ $hookdirs ]] || {
77 hookdirs="cmdline pre-udev pre-trigger netroot "
78 hookdirs+="initqueue initqueue/settled initqueue/online initqueue/finished initqueue/timeout "
79 hookdirs+="pre-mount pre-pivot cleanup mount "
80 hookdirs+="emergency shutdown-emergency pre-shutdown shutdown "
81 export hookdirs
82 }
83
84 DRACUT_LDD=${DRACUT_LDD:-ldd}
85 DRACUT_TESTBIN=${DRACUT_TESTBIN:-/bin/sh}
86 DRACUT_LDCONFIG=${DRACUT_LDCONFIG:-ldconfig}
87
88 # shellcheck source=./dracut-functions.sh
89 . "$dracutbasedir"/dracut-functions.sh
90
91 # Detect lib paths
92 if ! [[ $libdirs ]]; then
93 if [[ $("$DRACUT_LDD" "$dracutsysrootdir$DRACUT_TESTBIN") == */lib64/* ]] &> /dev/null \
94 && [[ -d $dracutsysrootdir/lib64 ]]; then
95 libdirs+=" /lib64"
96 [[ -d $dracutsysrootdir/usr/lib64 ]] && libdirs+=" /usr/lib64"
97 else
98 libdirs+=" /lib"
99 [[ -d $dracutsysrootdir/usr/lib ]] && libdirs+=" /usr/lib"
100 fi
101
102 libdirs+=" $(ldconfig_paths)"
103
104 export libdirs
105 fi
106
107 # helper function for check() in module-setup.sh
108 # to check for required installed binaries
109 # issues a standardized warning message
110 require_binaries() {
111 # shellcheck disable=SC2154
112 local _module_name="${moddir##*/}"
113 local _ret=0
114
115 if [[ $1 == "-m" ]]; then
116 _module_name="$2"
117 shift 2
118 fi
119
120 for cmd in "$@"; do
121 if ! find_binary "$cmd" &> /dev/null; then
122 dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
123 ((_ret++))
124 fi
125 done
126 return "$_ret"
127 }
128
129 require_any_binary() {
130 local _module_name="${moddir##*/}"
131 local _ret=1
132
133 if [[ $1 == "-m" ]]; then
134 _module_name="$2"
135 shift 2
136 fi
137
138 for cmd in "$@"; do
139 if find_binary "$cmd" &> /dev/null; then
140 _ret=0
141 break
142 fi
143 done
144
145 if ((_ret != 0)); then
146 dinfo "$_module_name: Could not find any command of '$*'!"
147 return 1
148 fi
149
150 return 0
151 }
152
153 # helper function for check() in module-setup.sh
154 # to check for required kernel modules
155 # issues a standardized warning message
156 require_kernel_modules() {
157 # shellcheck disable=SC2154
158 local _module_name="${moddir##*/}"
159 local _ret=0
160
161 # Ignore kernel module requirement for no-kernel build
162 [[ $no_kernel == yes ]] && return 0
163
164 if [[ $1 == "-m" ]]; then
165 _module_name="$2"
166 shift 2
167 fi
168
169 for mod in "$@"; do
170 if ! check_kernel_module "$mod" &> /dev/null; then
171 dinfo "Module '${_module_name#[0-9][0-9]}' will not be installed, because kernel module '$mod' is not available!"
172 ((_ret++))
173 fi
174 done
175 return "$_ret"
176 }
177
178 dracut_need_initqueue() {
179 : > "$initdir/lib/dracut/need-initqueue"
180 }
181
182 dracut_module_included() {
183 # shellcheck disable=SC2154
184 [[ " $mods_to_load $modules_loaded " == *\ $*\ * ]]
185 }
186
187 dracut_no_switch_root() {
188 : > "$initdir/lib/dracut/no-switch-root"
189 }
190
191 dracut_module_path() {
192 local _dir
193
194 # shellcheck disable=SC2231
195 for _dir in "${dracutbasedir}"/modules.d/??${1}; do
196 echo "$_dir"
197 return 0
198 done
199 return 1
200 }
201
202 if ! [[ $DRACUT_INSTALL ]]; then
203 DRACUT_INSTALL=$(find_binary dracut-install)
204 fi
205
206 if ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/dracut-install ]]; then
207 DRACUT_INSTALL=$dracutbasedir/dracut-install
208 elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/src/install/dracut-install ]]; then
209 DRACUT_INSTALL=$dracutbasedir/src/install/dracut-install
210 fi
211
212 # Test if dracut-install is a standalone executable with no options.
213 # E.g. DRACUT_INSTALL may be set externally as:
214 # DRACUT_INSTALL="valgrind dracut-install"
215 # or
216 # DRACUT_INSTALL="dracut-install --debug"
217 # in which case the string cannot be tested for being executable.
218 DRINSTALLPARTS=0
219 for i in $DRACUT_INSTALL; do
220 DRINSTALLPARTS=$((DRINSTALLPARTS + 1))
221 done
222
223 if [[ $DRINSTALLPARTS == 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev/null 2>&1; then
224 dfatal "dracut-install not found!"
225 exit 10
226 fi
227
228 if [[ $hostonly == "-h" ]]; then
229 if ! [[ $DRACUT_KERNEL_MODALIASES ]] || ! [[ -f $DRACUT_KERNEL_MODALIASES ]]; then
230 export DRACUT_KERNEL_MODALIASES="${DRACUT_TMPDIR}/modaliases"
231 $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
232 fi
233 fi
234
235 [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
236 inst_dir() {
237 local _ret
238 [[ -e ${initdir}/"$1" ]] && return 0 # already there
239 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then
240 return 0
241 else
242 _ret=$?
243 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
244 return $_ret
245 fi
246 }
247
248 inst() {
249 local _ret _hostonly_install
250 if [[ $1 == "-H" ]]; then
251 _hostonly_install="-H"
252 shift
253 fi
254 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
255 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
256 return 0
257 else
258 _ret=$?
259 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
260 return $_ret
261 fi
262 }
263
264 inst_simple() {
265 local _ret _hostonly_install
266 if [[ $1 == "-H" ]]; then
267 _hostonly_install="-H"
268 shift
269 fi
270 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
271 [[ -e $1 ]] || return 1 # no source
272 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
273 return 0
274 else
275 _ret=$?
276 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
277 return $_ret
278 fi
279 }
280
281 inst_symlink() {
282 local _ret _hostonly_install
283 if [[ $1 == "-H" ]]; then
284 _hostonly_install="-H"
285 shift
286 fi
287 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
288 [[ -L $1 ]] || return 1
289 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
290 return 0
291 else
292 _ret=$?
293 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
294 return $_ret
295 fi
296 }
297
298 inst_multiple() {
299 local _ret _hostonly_install
300 if [[ $1 == "-H" ]]; then
301 _hostonly_install="-H"
302 shift
303 fi
304 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
305 return 0
306 else
307 _ret=$?
308 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
309 return $_ret
310 fi
311 }
312
313 dracut_install() {
314 inst_multiple "$@"
315 }
316
317 dracut_instmods() {
318 local _ret _silent=0
319 local i
320 # shellcheck disable=SC2154
321 [[ $no_kernel == yes ]] && return
322 for i in "$@"; do
323 [[ $i == "--silent" ]] && _silent=1
324 done
325
326 if $DRACUT_INSTALL \
327 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
328 ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"; then
329 return 0
330 else
331 _ret=$?
332 if ((_silent == 0)); then
333 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
334 fi
335 return $_ret
336 fi
337 }
338
339 inst_library() {
340 local _ret _hostonly_install
341 if [[ $1 == "-H" ]]; then
342 _hostonly_install="-H"
343 shift
344 fi
345 [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
346 [[ -e $1 ]] || return 1 # no source
347 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
348 return 0
349 else
350 _ret=$?
351 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
352 return $_ret
353 fi
354 }
355
356 inst_binary() {
357 local _ret
358 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
359 return 0
360 else
361 _ret=$?
362 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
363 return $_ret
364 fi
365 }
366
367 inst_script() {
368 local _ret
369 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
370 return 0
371 else
372 _ret=$?
373 derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
374 return $_ret
375 fi
376 }
377
378 inst_fsck_help() {
379 local _ret _helper="/run/dracut/fsck/fsck_help_$1.txt"
380 if $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"; then
381 return 0
382 else
383 _ret=$?
384 derror "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"
385 return $_ret
386 fi
387 }
388
389 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
390 # If hostonly mode is set to "strict", hostonly restrictions will still
391 # be applied, else will ignore hostonly mode and try to install all
392 # given modules.
393 optional_hostonly() {
394 # shellcheck disable=SC2154
395 if [[ $hostonly_mode == "strict" ]]; then
396 printf -- "%s" "$hostonly"
397 else
398 printf ""
399 fi
400 }
401
402 mark_hostonly() {
403 for i in "$@"; do
404 echo "$i" >> "$initdir/lib/dracut/hostonly-files"
405 done
406 }
407
408 # find symlinks linked to given library file
409 # $1 = library file
410 # Function searches for symlinks by stripping version numbers appended to
411 # library filename, checks if it points to the same target and finally
412 # prints the list of symlinks to stdout.
413 #
414 # Example:
415 # rev_lib_symlinks libfoo.so.8.1
416 # output: libfoo.so.8 libfoo.so
417 # (Only if libfoo.so.8 and libfoo.so exists on host system.)
418 rev_lib_symlinks() {
419 local _fn
420 local _orig
421 local _links
422
423 [[ ! $1 ]] && return 0
424
425 _fn="$1"
426 _orig="$(readlink -f "$1")"
427 _links=()
428
429 [[ ${_fn} == *.so.* ]] || return 1
430
431 until [[ ${_fn##*.} == so ]]; do
432 _fn="${_fn%.*}"
433 [[ -L ${_fn} ]] && [[ $(readlink -f "${_fn}") == "${_orig}" ]] && _links+=("${_fn}")
434 done
435
436 echo "${_links[*]}}"
437 }
438
439 # attempt to install any programs specified in a udev rule
440 inst_rule_programs() {
441 local _prog _bin
442
443 # shellcheck disable=SC2013
444 for _prog in $(sed -nr 's/.*PROGRAM==?"([^ "]+).*/\1/p' "$1"); do
445 _bin=""
446 # shellcheck disable=SC2154
447 if [[ -x ${udevdir}/$_prog ]]; then
448 _bin="${udevdir}"/$_prog
449 elif [[ ${_prog/\$env\{/} == "$_prog" ]]; then
450 _bin=$(find_binary "$_prog") || {
451 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
452 continue
453 }
454 fi
455
456 [[ $_bin ]] && inst_binary "$_bin"
457 done
458
459 # shellcheck disable=SC2013
460 for _prog in $(sed -nr 's/.*RUN[+=]=?"([^ "]+).*/\1/p' "$1"); do
461 _bin=""
462 if [[ -x ${udevdir}/$_prog ]]; then
463 _bin=${udevdir}/$_prog
464 elif [[ ${_prog/\$env\{/} == "$_prog" ]] && [[ ${_prog} != "/sbin/initqueue" ]]; then
465 _bin=$(find_binary "$_prog") || {
466 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
467 continue
468 }
469 fi
470
471 [[ $_bin ]] && inst_binary "$_bin"
472 done
473
474 # shellcheck disable=SC2013
475 for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/p' "$1"); do
476 _bin=""
477 if [[ -x ${udevdir}/$_prog ]]; then
478 _bin=${udevdir}/$_prog
479 elif [[ ${_prog/\$env\{/} == "$_prog" ]]; then
480 _bin=$(find_binary "$_prog") || {
481 dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
482 continue
483 }
484 fi
485
486 [[ $_bin ]] && dracut_install "$_bin"
487 done
488 }
489
490 # attempt to create any groups and users specified in a udev rule
491 inst_rule_group_owner() {
492 local i
493
494 # shellcheck disable=SC2013
495 for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p' "$1"); do
496 if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2> /dev/null; then
497 grep -E "^$i:" "$dracutsysrootdir"/etc/passwd 2> /dev/null >> "$initdir/etc/passwd"
498 fi
499 done
500
501 # shellcheck disable=SC2013
502 for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do
503 if ! grep -Eq "^$i:" "$initdir/etc/group" 2> /dev/null; then
504 grep -E "^$i:" "$dracutsysrootdir"/etc/group 2> /dev/null >> "$initdir/etc/group"
505 fi
506 done
507 }
508
509 inst_rule_initqueue() {
510 if grep -q -F initqueue "$1"; then
511 dracut_need_initqueue
512 fi
513 }
514
515 # udev rules always get installed in the same place, so
516 # create a function to install them to make life simpler.
517 inst_rules() {
518 local _target=/etc/udev/rules.d _rule _found
519
520 inst_dir "${udevdir}/rules.d"
521 inst_dir "$_target"
522 for _rule in "$@"; do
523 if [ "${_rule#/}" = "$_rule" ]; then
524 for r in "$dracutsysrootdir${udevdir}/rules.d" ${hostonly:+"$dracutsysrootdir"/etc/udev/rules.d}; do
525 [[ -e $r/$_rule ]] || continue
526 _found="$r/$_rule"
527 inst_rule_programs "$_found"
528 inst_rule_group_owner "$_found"
529 inst_rule_initqueue "$_found"
530 inst_simple "$_found"
531 done
532 fi
533 for r in '' "$dracutsysrootdir$dracutbasedir/rules.d/"; do
534 # skip rules without an absolute path
535 [[ "${r}$_rule" != /* ]] && continue
536 [[ -f ${r}$_rule ]] || continue
537 _found="${r}$_rule"
538 inst_rule_programs "$_found"
539 inst_rule_group_owner "$_found"
540 inst_rule_initqueue "$_found"
541 inst_simple "$_found" "$_target/${_found##*/}"
542 done
543 [[ $_found ]] || ddebug "Skipping udev rule: $_rule"
544 done
545 }
546
547 inst_rules_wildcard() {
548 local _target=/etc/udev/rules.d _rule _found
549
550 inst_dir "${udevdir}/rules.d"
551 inst_dir "$_target"
552 for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1; do
553 [[ -e $_rule ]] || continue
554 inst_rule_programs "$_rule"
555 inst_rule_group_owner "$_rule"
556 inst_rule_initqueue "$_rule"
557 inst_simple "$_rule"
558 _found=$_rule
559 done
560 if [[ -n ${hostonly} ]]; then
561 for _rule in ${_target}/$1; do
562 [[ -f $_rule ]] || continue
563 inst_rule_programs "$_rule"
564 inst_rule_group_owner "$_rule"
565 inst_rule_initqueue "$_rule"
566 inst_simple "$_rule"
567 _found=$_rule
568 done
569 fi
570 [[ $_found ]] || ddebug "Skipping udev rule: $_rule"
571 }
572
573 # make sure that library links are correct and up to date
574 build_ld_cache() {
575 for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
576 [[ -f $f ]] && inst_simple "${f#"$dracutsysrootdir"}"
577 done
578 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
579 if [[ $EUID == 0 ]]; then
580 derror "ldconfig exited ungracefully"
581 else
582 derror "ldconfig might need uid=0 (root) for chroot()"
583 fi
584 fi
585 }
586
587 prepare_udev_rules() {
588 dwarn "prepare_udev_rules: deprecated and will be removed"
589
590 if [ -z "$UDEVVERSION" ]; then
591 UDEVVERSION=$(udevadm --version)
592 export UDEVVERSION
593 fi
594
595 if [ -z "$UDEVVERSION" ]; then
596 derror "Failed to detect udev version!"
597 return 1
598 fi
599 if [ -z "${UDEVVERSION##*[!0-9]*}" ]; then
600 derror "udevadm --version did not report an integer, udev version cannot be determined!"
601 return 1
602 fi
603
604 for f in "$@"; do
605 f="${initdir}/etc/udev/rules.d/$f"
606 [ -e "$f" ] || continue
607 while read -r line || [ -n "$line" ]; do
608 if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
609 if ((UDEVVERSION >= 174)); then
610 printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
611 else
612 printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
613 fi
614 elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
615 if ((UDEVVERSION >= 176)); then
616 printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
617 else
618 # shellcheck disable=SC2016
619 printf '%sIMPORT{program}="/sbin/blkid -o udev -p $tempnode"\n' "${line%%IMPORT BLKID}"
620 fi
621 else
622 echo "$line"
623 fi
624 done < "${f}" > "${f}.new"
625 mv "${f}.new" "$f"
626 done
627 }
628
629 # install function specialized for hooks
630 # $1 = type of hook, $2 = hook priority (lower runs first), $3 = hook
631 # All hooks should be POSIX/SuS compliant, they will be sourced by init.
632 inst_hook() {
633 local hook
634 if ! [[ -f $3 ]]; then
635 dfatal "Cannot install a hook ($3) that does not exist."
636 dfatal "Aborting initrd creation."
637 exit 1
638 elif ! [[ $hookdirs == *$1* ]]; then
639 dfatal "No such hook type $1. Aborting initrd creation."
640 exit 1
641 fi
642 hook="/lib/dracut/hooks/${1}/${2}-${3##*/}"
643 inst_simple "$3" "$hook"
644 chmod u+x "$initdir/$hook"
645 }
646
647 # install any of listed files
648 #
649 # If first argument is '-d' and second some destination path, first accessible
650 # source is installed into this path, otherwise it will installed in the same
651 # path as source. If none of listed files was installed, function return 1.
652 # On first successful installation it returns with 0 status.
653 #
654 # Example:
655 #
656 # inst_any -d /bin/foo /bin/bar /bin/baz
657 #
658 # Lets assume that /bin/baz exists, so it will be installed as /bin/foo in
659 # initramfs.
660 inst_any() {
661 local to f
662
663 [[ $1 == '-d' ]] && to="$2" && shift 2
664
665 for f in "$@"; do
666 [[ -e $f ]] || continue
667 [[ $to ]] && inst "$f" "$to" && return 0
668 inst "$f" && return 0
669 done
670
671 return 1
672 }
673
674 # inst_libdir_dir <dir> [<dir>...]
675 # Install a <dir> located on a lib directory to the initramfs image
676 inst_libdir_dir() {
677 local -a _dirs
678 for _dir in $libdirs; do
679 for _i in "$@"; do
680 for _d in "$dracutsysrootdir$_dir"/$_i; do
681 [[ -d $_d ]] && _dirs+=("${_d#"$dracutsysrootdir"}")
682 done
683 done
684 done
685 for _dir in "${_dirs[@]}"; do
686 inst_dir "$_dir"
687 done
688 }
689
690 # inst_libdir_file [-n <pattern>] <file> [<file>...]
691 # Install a <file> located on a lib directory to the initramfs image
692 # -n <pattern> install matching files
693 inst_libdir_file() {
694 local -a _files
695 if [[ $1 == "-n" ]]; then
696 local _pattern=$2
697 shift 2
698 for _dir in $libdirs; do
699 for _i in "$@"; do
700 for _f in "$dracutsysrootdir$_dir"/$_i; do
701 [[ ${_f#"$dracutsysrootdir"} =~ $_pattern ]] || continue
702 [[ -e $_f ]] && _files+=("${_f#"$dracutsysrootdir"}")
703 done
704 done
705 done
706 else
707 for _dir in $libdirs; do
708 for _i in "$@"; do
709 for _f in "$dracutsysrootdir$_dir"/$_i; do
710 [[ -e $_f ]] && _files+=("${_f#"$dracutsysrootdir"}")
711 done
712 done
713 done
714 fi
715 [[ ${#_files[@]} -gt 0 ]] && inst_multiple "${_files[@]}"
716 }
717
718 # get a command to decompress the given file
719 get_decompress_cmd() {
720 case "$1" in
721 *.gz) echo 'gzip -f -d' ;;
722 *.bz2) echo 'bzip2 -d' ;;
723 *.xz) echo 'xz -f -d' ;;
724 *.zst) echo 'zstd -f -d ' ;;
725 esac
726 }
727
728 # install function decompressing the target and handling symlinks
729 # $@ = list of compressed (gz or bz2) files or symlinks pointing to such files
730 #
731 # Function install targets in the same paths inside overlay but decompressed
732 # and without extensions (.gz, .bz2).
733 inst_decompress() {
734 local _src _cmd
735
736 for _src in "$@"; do
737 _cmd=$(get_decompress_cmd "${_src}")
738 [[ -z ${_cmd} ]] && return 1
739 inst_simple "${_src}"
740 # Decompress with chosen tool. We assume that tool changes name e.g.
741 # from 'name.gz' to 'name'.
742 ${_cmd} "${initdir}${_src}"
743 done
744 }
745
746 # It's similar to above, but if file is not compressed, performs standard
747 # install.
748 # $@ = list of files
749 inst_opt_decompress() {
750 local _src
751
752 for _src in "$@"; do
753 inst_decompress "${_src}" || inst "${_src}"
754 done
755 }
756
757 # module_check <dracut module> [<forced>] [<module path>]
758 # execute the check() function of module-setup.sh of <dracut module>
759 # or the "check" script, if module-setup.sh is not found
760 # "check $hostonly" is called
761 module_check() {
762 local _moddir=$3
763 local _ret
764 local _forced=0
765 local _hostonly=$hostonly
766 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
767 [ $# -eq 2 ] && _forced=$2
768 [[ -d $_moddir ]] || return 1
769 if [[ ! -f $_moddir/module-setup.sh ]]; then
770 # if we do not have a check script, we are unconditionally included
771 [[ -x $_moddir/check ]] || return 0
772 [[ $_forced != 0 ]] && unset hostonly
773 # don't quote $hostonly to leave argument empty
774 # shellcheck disable=SC2086
775 "$_moddir"/check $hostonly
776 _ret=$?
777 else
778 unset check depends cmdline install installkernel
779 check() { true; }
780 # shellcheck disable=SC1090
781 . "$_moddir"/module-setup.sh
782 is_func check || return 0
783 [[ $_forced != 0 ]] && unset hostonly
784 # don't quote $hostonly to leave argument empty
785 # shellcheck disable=SC2086
786 moddir="$_moddir" check $hostonly
787 _ret=$?
788 unset check depends cmdline install installkernel
789 fi
790 hostonly=$_hostonly
791 return $_ret
792 }
793
794 # module_check_mount <dracut module> [<module path>]
795 # execute the check() function of module-setup.sh of <dracut module>
796 # or the "check" script, if module-setup.sh is not found
797 # "mount_needs=1 check 0" is called
798 module_check_mount() {
799 local _moddir=$2
800 local _ret
801 export mount_needs=1
802 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
803 [[ -d $_moddir ]] || return 1
804 if [[ ! -f $_moddir/module-setup.sh ]]; then
805 # if we do not have a check script, we are unconditionally included
806 [[ -x $_moddir/check ]] || return 0
807 mount_needs=1 "$_moddir"/check 0
808 _ret=$?
809 else
810 unset check depends cmdline install installkernel
811 check() { false; }
812 # shellcheck disable=SC1090
813 . "$_moddir"/module-setup.sh
814 moddir=$_moddir check 0
815 _ret=$?
816 unset check depends cmdline install installkernel
817 fi
818 unset mount_needs
819 return "$_ret"
820 }
821
822 # module_depends <dracut module> [<module path>]
823 # execute the depends() function of module-setup.sh of <dracut module>
824 # or the "depends" script, if module-setup.sh is not found
825 module_depends() {
826 local _moddir=$2
827 local _ret
828 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
829 [[ -d $_moddir ]] || return 1
830 if [[ ! -f $_moddir/module-setup.sh ]]; then
831 # if we do not have a check script, we have no deps
832 [[ -x $_moddir/check ]] || return 0
833 "$_moddir"/check -d
834 return $?
835 else
836 unset check depends cmdline install installkernel
837 depends() { true; }
838 # shellcheck disable=SC1090
839 . "$_moddir"/module-setup.sh
840 moddir=$_moddir depends
841 _ret=$?
842 unset check depends cmdline install installkernel
843 return $_ret
844 fi
845 }
846
847 # module_cmdline <dracut module> [<module path>]
848 # execute the cmdline() function of module-setup.sh of <dracut module>
849 # or the "cmdline" script, if module-setup.sh is not found
850 module_cmdline() {
851 local _moddir=$2
852 local _ret
853 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
854 [[ -d $_moddir ]] || return 1
855 if [[ ! -f $_moddir/module-setup.sh ]]; then
856 # shellcheck disable=SC1090
857 [[ -x $_moddir/cmdline ]] && . "$_moddir/cmdline"
858 return $?
859 else
860 unset check depends cmdline install installkernel
861 cmdline() { true; }
862 # shellcheck disable=SC1090
863 . "$_moddir"/module-setup.sh
864 moddir="$_moddir" cmdline
865 _ret=$?
866 unset check depends cmdline install installkernel
867 return $_ret
868 fi
869 }
870
871 # module_install <dracut module> [<module path>]
872 # execute the install() function of module-setup.sh of <dracut module>
873 # or the "install" script, if module-setup.sh is not found
874 module_install() {
875 local _moddir=$2
876 local _ret
877 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
878 [[ -d $_moddir ]] || return 1
879 if [[ ! -f $_moddir/module-setup.sh ]]; then
880 # shellcheck disable=SC1090
881 [[ -x $_moddir/install ]] && . "$_moddir/install"
882 return $?
883 else
884 unset check depends cmdline install installkernel
885 install() { true; }
886 # shellcheck disable=SC1090
887 . "$_moddir"/module-setup.sh
888 moddir="$_moddir" install
889 _ret=$?
890 unset check depends cmdline install installkernel
891 return $_ret
892 fi
893 }
894
895 # module_installkernel <dracut module> [<module path>]
896 # execute the installkernel() function of module-setup.sh of <dracut module>
897 # or the "installkernel" script, if module-setup.sh is not found
898 module_installkernel() {
899 local _moddir=$2
900 local _ret
901 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
902 [[ -d $_moddir ]] || return 1
903 if [[ ! -f $_moddir/module-setup.sh ]]; then
904 # shellcheck disable=SC1090
905 [[ -x $_moddir/installkernel ]] && . "$_moddir/installkernel"
906 return $?
907 else
908 unset check depends cmdline install installkernel
909 installkernel() { true; }
910 # shellcheck disable=SC1090
911 . "$_moddir"/module-setup.sh
912 moddir="$_moddir" installkernel
913 _ret=$?
914 unset check depends cmdline install installkernel
915 return $_ret
916 fi
917 }
918
919 # check_mount <dracut module> [<use_as_dep>] [<module path>]
920 # check_mount checks, if a dracut module is needed for the given
921 # device and filesystem types in "${host_fs_types[@]}"
922 check_mount() {
923 local _mod=$1
924 local _moddir=$3
925 local _ret
926 local _moddep
927
928 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
929 # shellcheck disable=SC2154
930 [ "${#host_fs_types[@]}" -le 0 ] && return 1
931
932 # If we are already scheduled to be loaded, no need to check again.
933 [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
934 [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
935
936 # This should never happen, but...
937 [[ -d $_moddir ]] || return 1
938
939 [[ $2 ]] || mods_checked_as_dep+=" $_mod "
940
941 # shellcheck disable=SC2154
942 if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
943 return 1
944 fi
945
946 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
947 module_check_mount "$_mod" "$_moddir"
948 ret=$?
949
950 # explicit module, so also accept ret=255
951 [[ $ret == 0 || $ret == 255 ]] || return 1
952 else
953 # module not in our list
954 if [[ $dracutmodules == all ]]; then
955 # check, if we can and should install this module
956 module_check_mount "$_mod" "$_moddir" || return 1
957 else
958 # skip this module
959 return 1
960 fi
961 fi
962
963 for _moddep in $(module_depends "$_mod" "$_moddir"); do
964 # handle deps as if they were manually added
965 [[ " $dracutmodules " == *\ $_mod\ * ]] \
966 && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
967 && dracutmodules+=" $_moddep "
968 [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
969 && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
970 && add_dracutmodules+=" $_moddep "
971 [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
972 && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
973 && force_add_dracutmodules+=" $_moddep "
974 # if a module we depend on fail, fail also
975 if ! check_module "$_moddep"; then
976 derror "Module '$_mod' depends on '$_moddep', which can't be installed"
977 return 1
978 fi
979 done
980
981 [[ " $mods_to_load " == *\ $_mod\ * ]] \
982 || mods_to_load+=" $_mod "
983
984 return 0
985 }
986
987 # check_module <dracut module> [<use_as_dep>] [<module path>]
988 # check if a dracut module is to be used in the initramfs process
989 # if <use_as_dep> is set, then the process also keeps track
990 # that the modules were checked for the dependency tracking process
991 check_module() {
992 local _mod=$1
993 local _moddir=$3
994 local _ret
995 local _moddep
996
997 [[ -z $_moddir ]] && _moddir=$(dracut_module_path "$1")
998 # If we are already scheduled to be loaded, no need to check again.
999 [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0
1000 [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1
1001
1002 # This should never happen, but...
1003 [[ -d $_moddir ]] || return 1
1004
1005 [[ $2 ]] || mods_checked_as_dep+=" $_mod "
1006
1007 if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then
1008 ddebug "Module '$_mod' will not be installed, because it's in the list to be omitted!"
1009 return 1
1010 fi
1011
1012 if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
1013 if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
1014 module_check "$_mod" 1 "$_moddir"
1015 ret=$?
1016 else
1017 module_check "$_mod" 0 "$_moddir"
1018 ret=$?
1019 fi
1020 # explicit module, so also accept ret=255
1021 [[ $ret == 0 || $ret == 255 ]] || return 1
1022 else
1023 # module not in our list
1024 if [[ $dracutmodules == all ]]; then
1025 # check, if we can and should install this module
1026 module_check "$_mod" 0 "$_moddir"
1027 ret=$?
1028 if [[ $ret != 0 ]]; then
1029 [[ $2 ]] && return 1
1030 [[ $ret != 255 ]] && return 1
1031 fi
1032 else
1033 # skip this module
1034 return 1
1035 fi
1036 fi
1037
1038 for _moddep in $(module_depends "$_mod" "$_moddir"); do
1039 # handle deps as if they were manually added
1040 [[ " $dracutmodules " == *\ $_mod\ * ]] \
1041 && [[ " $dracutmodules " != *\ $_moddep\ * ]] \
1042 && dracutmodules+=" $_moddep "
1043 [[ " $add_dracutmodules " == *\ $_mod\ * ]] \
1044 && [[ " $add_dracutmodules " != *\ $_moddep\ * ]] \
1045 && add_dracutmodules+=" $_moddep "
1046 [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] \
1047 && [[ " $force_add_dracutmodules " != *\ $_moddep\ * ]] \
1048 && force_add_dracutmodules+=" $_moddep "
1049 # if a module we depend on fail, fail also
1050 if ! check_module "$_moddep"; then
1051 derror "Module '$_mod' depends on '$_moddep', which can't be installed"
1052 return 1
1053 fi
1054 done
1055
1056 [[ " $mods_to_load " == *\ $_mod\ * ]] \
1057 || mods_to_load+=" $_mod "
1058
1059 return 0
1060 }
1061
1062 # for_each_module_dir <func>
1063 # execute "<func> <dracut module> 1 <module path>"
1064 for_each_module_dir() {
1065 local _modcheck
1066 local _mod
1067 local _moddir
1068 local _func
1069 local _reason
1070 _func=$1
1071 for _moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1072 [[ -d $_moddir ]] || continue
1073 [[ -e $_moddir/install || -e $_moddir/installkernel || -e $_moddir/module-setup.sh ]] || continue
1074 _mod=${_moddir##*/}
1075 _mod=${_mod#[0-9][0-9]}
1076 $_func "$_mod" 1 "$_moddir"
1077 done
1078
1079 # Report any missing dracut modules, the user has specified
1080 _modcheck="$add_dracutmodules $force_add_dracutmodules"
1081 [[ $dracutmodules != all ]] && _modcheck="$_modcheck $dracutmodules"
1082 for _mod in $_modcheck; do
1083 [[ " $mods_to_load " == *\ $_mod\ * ]] && continue
1084
1085 [[ " $force_add_dracutmodules " != *\ $_mod\ * ]] \
1086 && [[ " $dracutmodules " != *\ $_mod\ * ]] \
1087 && [[ " $omit_dracutmodules " == *\ $_mod\ * ]] \
1088 && continue
1089
1090 [[ -d $(echo "$dracutbasedir/modules.d"/[0-9][0-9]"$_mod") ]] \
1091 && _reason="installed" \
1092 || _reason="found"
1093 derror "Module '$_mod' cannot be $_reason."
1094 [[ " $force_add_dracutmodules " == *\ $_mod\ * ]] && exit 1
1095 [[ " $dracutmodules " == *\ $_mod\ * ]] && exit 1
1096 [[ " $add_dracutmodules " == *\ $_mod\ * ]] && exit 1
1097 done
1098 }
1099
1100 dracut_kernel_post() {
1101 for _f in modules.builtin modules.builtin.alias modules.builtin.modinfo modules.order; do
1102 [[ -e $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
1103 done
1104
1105 # generate module dependencies for the initrd
1106 if [[ -d $initdir/lib/modules/$kernel ]] \
1107 && ! depmod -a -b "$initdir" "$kernel"; then
1108 dfatal "\"depmod -a $kernel\" failed."
1109 exit 1
1110 fi
1111
1112 }
1113
1114 instmods() {
1115 # instmods [-c [-s]] <kernel module> [<kernel module> ... ]
1116 # instmods [-c [-s]] <kernel subsystem>
1117 # install kernel modules along with all their dependencies.
1118 # <kernel subsystem> can be e.g. "=block" or "=drivers/usb/storage"
1119 # -c check
1120 # -s silent
1121 local _optional="-o"
1122 local _silent
1123 local _ret
1124
1125 [[ $no_kernel == yes ]] && return
1126
1127 if [[ $1 == '-c' ]]; then
1128 unset _optional
1129 shift
1130 fi
1131 if [[ $1 == '-s' ]]; then
1132 _silent=1
1133 shift
1134 fi
1135
1136 if (($# == 0)); then
1137 read -r -d '' -a args
1138 set -- "${args[@]}"
1139 fi
1140
1141 if (($# == 0)); then
1142 return 0
1143 fi
1144
1145 $DRACUT_INSTALL \
1146 ${initdir:+-D "$initdir"} \
1147 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
1148 ${loginstall:+-L "$loginstall"} \
1149 ${hostonly:+-H} \
1150 ${omit_drivers:+-N "$omit_drivers"} \
1151 ${srcmods:+--kerneldir "$srcmods"} \
1152 ${_optional:+-o} \
1153 ${_silent:+--silent} \
1154 -m "$@"
1155 _ret=$?
1156
1157 if ((_ret != 0)) && [[ -z $_silent ]]; then
1158 derror "FAILED: " \
1159 "$DRACUT_INSTALL" \
1160 ${initdir:+-D "$initdir"} \
1161 ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
1162 ${loginstall:+-L "$loginstall"} \
1163 ${hostonly:+-H} \
1164 ${omit_drivers:+-N "$omit_drivers"} \
1165 ${srcmods:+--kerneldir "$srcmods"} \
1166 ${_optional:+-o} \
1167 ${_silent:+--silent} \
1168 -m "$@"
1169 fi
1170
1171 [[ "$_optional" ]] && return 0
1172 return $_ret
1173 }
1174
1175 if [[ "$(ln --help)" == *--relative* ]]; then
1176 ln_r() {
1177 ln -sfnr "${initdir}/$1" "${initdir}/$2"
1178 }
1179 else
1180 ln_r() {
1181 local _source=$1
1182 local _dest=$2
1183 [[ -d ${_dest%/*} ]] && _dest=$(readlink -f "${_dest%/*}")/${_dest##*/}
1184 ln -sfn -- "$(convert_abs_rel "${_dest}" "${_source}")" "${initdir}/${_dest}"
1185 }
1186 fi
1187
1188 is_qemu_virtualized() {
1189 # 0 if a virt environment was detected
1190 # 1 if a virt environment could not be detected
1191 # 255 if any error was encountered
1192 if type -P systemd-detect-virt > /dev/null 2>&1; then
1193 if ! vm=$(systemd-detect-virt --vm 2> /dev/null); then
1194 return 255
1195 fi
1196 [[ $vm == "qemu" ]] && return 0
1197 [[ $vm == "kvm" ]] && return 0
1198 [[ $vm == "bochs" ]] && return 0
1199 fi
1200
1201 for i in /sys/class/dmi/id/*_vendor; do
1202 [[ -f $i ]] || continue
1203 read -r vendor < "$i"
1204 [[ $vendor == "QEMU" ]] && return 0
1205 [[ $vendor == "Red Hat" ]] && return 0
1206 [[ $vendor == "Bochs" ]] && return 0
1207 done
1208 return 1
1209 }