]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
add parameter --print-cmdline
[thirdparty/dracut.git] / dracut.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 #
5 # Generator script for a dracut initramfs
6 # Tries to retain some degree of compatibility with the command line
7 # of the various mkinitrd implementations out there
8 #
9
10 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
11 #
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #
25
26 # store for logging
27 dracut_args=( "$@" )
28
29 set -o pipefail
30
31 usage() {
32 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
33 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
34 . $dracutbasedir/dracut-version.sh
35 fi
36
37 # 80x25 linebreak here ^
38 cat << EOF
39 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
40
41 Version: $DRACUT_VERSION
42
43 Creates initial ramdisk images for preloading modules
44
45 -h, --help Display all options
46
47 If a [LIST] has multiple arguments, then you have to put these in quotes.
48
49 For example:
50
51 # dracut --add-drivers "module1 module2" ...
52
53 EOF
54 }
55
56 long_usage() {
57 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
58 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
59 . $dracutbasedir/dracut-version.sh
60 fi
61
62 # 80x25 linebreak here ^
63 cat << EOF
64 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
65
66 Version: $DRACUT_VERSION
67
68 Creates initial ramdisk images for preloading modules
69
70 --kver [VERSION] Set kernel version to [VERSION].
71 -f, --force Overwrite existing initramfs file.
72 -a, --add [LIST] Add a space-separated list of dracut modules.
73 -m, --modules [LIST] Specify a space-separated list of dracut modules to
74 call when building the initramfs. Modules are located
75 in /usr/lib/dracut/modules.d.
76 -o, --omit [LIST] Omit a space-separated list of dracut modules.
77 --force-add [LIST] Force to add a space-separated list of dracut modules
78 to the default set of modules, when -H is specified.
79 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
80 exclusively include in the initramfs.
81 --add-drivers [LIST] Specify a space-separated list of kernel
82 modules to add to the initramfs.
83 --omit-drivers [LIST] Specify a space-separated list of kernel
84 modules not to add to the initramfs.
85 --filesystems [LIST] Specify a space-separated list of kernel filesystem
86 modules to exclusively include in the generic
87 initramfs.
88 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
89 modules
90 --fwdir [DIR] Specify additional directories, where to look for
91 firmwares, separated by :
92 --kernel-only Only install kernel drivers and firmware files
93 --no-kernel Do not install kernel drivers and firmware files
94 --print-cmdline Print the kernel command line for the given disk layout
95 --early-microcode Combine early microcode with ramdisk
96 --no-early-microcode Do not combine early microcode with ramdisk
97 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
98 --strip Strip binaries in the initramfs
99 --nostrip Do not strip binaries in the initramfs
100 --hardlink Hardlink files in the initramfs
101 --nohardlink Do not hardlink files in the initramfs
102 --prefix [DIR] Prefix initramfs files with [DIR]
103 --noprefix Do not prefix initramfs files
104 --mdadmconf Include local /etc/mdadm.conf
105 --nomdadmconf Do not include local /etc/mdadm.conf
106 --lvmconf Include local /etc/lvm/lvm.conf
107 --nolvmconf Do not include local /etc/lvm/lvm.conf
108 --fscks [LIST] Add a space-separated list of fsck helpers.
109 --nofscks Inhibit installation of any fsck helpers.
110 --ro-mnt Mount / and /usr read-only by default.
111 -h, --help This message
112 --debug Output debug information of the build process
113 --profile Output profile information of the build process
114 -L, --stdlog [0-6] Specify logging level (to standard error)
115 0 - suppress any messages
116 1 - only fatal errors
117 2 - all errors
118 3 - warnings
119 4 - info
120 5 - debug info (here starts lots of output)
121 6 - trace info (and even more)
122 -v, --verbose Increase verbosity level
123 -q, --quiet Decrease verbosity level
124 -c, --conf [FILE] Specify configuration file to use.
125 Default: /etc/dracut.conf
126 --confdir [DIR] Specify configuration directory to use *.conf files
127 from. Default: /etc/dracut.conf.d
128 --tmpdir [DIR] Temporary directory to be used instead of default
129 /var/tmp.
130 -l, --local Local mode. Use modules from the current working
131 directory instead of the system-wide installed in
132 /usr/lib/dracut/modules.d.
133 Useful when running dracut from a git checkout.
134 -H, --hostonly Host-Only mode: Install only what is needed for
135 booting the local host instead of a generic host.
136 -N, --no-hostonly Disables Host-Only mode
137 --fstab Use /etc/fstab to determine the root device.
138 --add-fstab [FILE] Add file to the initramfs fstab
139 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
140 Mount device [DEV] on mountpoint [MP] with filesystem
141 [FSTYPE] and options [FSOPTS] in the initramfs
142 --add-device "[DEV]" Bring up [DEV] in initramfs
143 -i, --include [SOURCE] [TARGET]
144 Include the files in the SOURCE directory into the
145 Target directory in the final initramfs.
146 If SOURCE is a file, it will be installed to TARGET
147 in the final initramfs.
148 -I, --install [LIST] Install the space separated list of files into the
149 initramfs.
150 --gzip Compress the generated initramfs using gzip.
151 This will be done by default, unless another
152 compression option or --no-compress is passed.
153 --bzip2 Compress the generated initramfs using bzip2.
154 Make sure your kernel has bzip2 decompression support
155 compiled in, otherwise you will not be able to boot.
156 --lzma Compress the generated initramfs using lzma.
157 Make sure your kernel has lzma support compiled in,
158 otherwise you will not be able to boot.
159 --xz Compress the generated initramfs using xz.
160 Make sure that your kernel has xz support compiled
161 in, otherwise you will not be able to boot.
162 --compress [COMPRESSION] Compress the generated initramfs with the
163 passed compression program. Make sure your kernel
164 knows how to decompress the generated initramfs,
165 otherwise you will not be able to boot.
166 --no-compress Do not compress the generated initramfs. This will
167 override any other compression options.
168 --list-modules List all available dracut modules.
169 -M, --show-modules Print included module's name to standard output during
170 build.
171 --keep Keep the temporary initramfs for debugging purposes
172 --printsize Print out the module install size
173 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
174
175 If [LIST] has multiple arguments, then you have to put these in quotes.
176
177 For example:
178
179 # dracut --add-drivers "module1 module2" ...
180
181 EOF
182 }
183
184 # function push()
185 # push values to a stack
186 # $1 = stack variable
187 # $2.. values
188 # example:
189 # push stack 1 2 "3 4"
190 push() {
191 local _i
192 local __stack=$1; shift
193 for _i in "$@"; do
194 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
195 done
196 }
197
198 # function pop()
199 # pops the last value from a stack
200 # assigns value to second argument variable
201 # or echo to stdout, if no second argument
202 # $1 = stack variable
203 # $2 = optional variable to store the value
204 # example:
205 # pop stack val
206 # val=$(pop stack)
207 pop() {
208 local __stack=$1; shift
209 local __resultvar=$1
210 local _value;
211 # check for empty stack
212 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
213
214 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
215
216 if [[ "$__resultvar" ]]; then
217 eval $__resultvar="'$_value'"
218 else
219 printf "%s" "$_value"
220 fi
221 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
222 return 0
223 }
224
225 # Little helper function for reading args from the commandline.
226 # it automatically handles -a b and -a=b variants, and returns 1 if
227 # we need to shift $3.
228 read_arg() {
229 # $1 = arg name
230 # $2 = arg value
231 # $3 = arg parameter
232 local rematch='^[^=]*=(.*)$'
233 if [[ $2 =~ $rematch ]]; then
234 read "$1" <<< "${BASH_REMATCH[1]}"
235 else
236 read "$1" <<< "$3"
237 # There is no way to shift our callers args, so
238 # return 1 to indicate they should do it instead.
239 return 1
240 fi
241 }
242
243 dropindirs_sort()
244 {
245 local suffix=$1; shift
246 local -a files
247 local f d
248
249 for d in "$@"; do
250 for i in "$d/"*"$suffix"; do
251 if [[ -e "$i" ]]; then
252 printf "%s\n" "${i##*/}"
253 fi
254 done
255 done | sort -Vu | {
256 readarray -t files
257
258 for f in "${files[@]}"; do
259 for d in "$@"; do
260 if [[ -e "$d/$f" ]]; then
261 printf "%s\n" "$d/$f"
262 continue 2
263 fi
264 done
265 done
266 }
267 }
268
269 verbosity_mod_l=0
270 unset kernel
271 unset outfile
272
273 # Workaround -i, --include taking 2 arguments
274 set -- "${@/--include/++include}"
275
276 # This prevents any long argument ending with "-i"
277 # -i, like --opt-i but I think we can just prevent that
278 set -- "${@/%-i/++include}"
279
280 TEMP=$(unset POSIXLY_CORRECT; getopt \
281 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
282 --long kver: \
283 --long add: \
284 --long force-add: \
285 --long add-drivers: \
286 --long omit-drivers: \
287 --long modules: \
288 --long omit: \
289 --long drivers: \
290 --long filesystems: \
291 --long install: \
292 --long fwdir: \
293 --long libdirs: \
294 --long fscks: \
295 --long add-fstab: \
296 --long mount: \
297 --long device: \
298 --long nofscks: \
299 --long ro-mnt \
300 --long kmoddir: \
301 --long conf: \
302 --long confdir: \
303 --long tmpdir: \
304 --long stdlog: \
305 --long compress: \
306 --long prefix: \
307 --long force \
308 --long kernel-only \
309 --long no-kernel \
310 --long print-cmdline \
311 --long kernel-cmdline: \
312 --long strip \
313 --long nostrip \
314 --long hardlink \
315 --long nohardlink \
316 --long noprefix \
317 --long mdadmconf \
318 --long nomdadmconf \
319 --long lvmconf \
320 --long nolvmconf \
321 --long debug \
322 --long profile \
323 --long sshkey: \
324 --long verbose \
325 --long quiet \
326 --long local \
327 --long hostonly \
328 --long host-only \
329 --long no-hostonly \
330 --long no-host-only \
331 --long fstab \
332 --long help \
333 --long bzip2 \
334 --long lzma \
335 --long xz \
336 --long no-compress \
337 --long gzip \
338 --long list-modules \
339 --long show-modules \
340 --long keep \
341 --long printsize \
342 --long regenerate-all \
343 --long noimageifnotneeded \
344 -- "$@")
345
346 if (( $? != 0 )); then
347 usage
348 exit 1
349 fi
350
351 eval set -- "$TEMP"
352
353 while :; do
354 case $1 in
355 --kver) kernel="$2"; shift;;
356 -a|--add) push add_dracutmodules_l "$2"; shift;;
357 --force-add) push force_add_dracutmodules_l "$2"; shift;;
358 --add-drivers) push add_drivers_l "$2"; shift;;
359 --omit-drivers) push omit_drivers_l "$2"; shift;;
360 -m|--modules) push dracutmodules_l "$2"; shift;;
361 -o|--omit) push omit_dracutmodules_l "$2"; shift;;
362 -d|--drivers) push drivers_l "$2"; shift;;
363 --filesystems) push filesystems_l "$2"; shift;;
364 -I|--install) push install_items_l "$2"; shift;;
365 --fwdir) push fw_dir_l "$2"; shift;;
366 --libdirs) push libdirs_l "$2"; shift;;
367 --fscks) push fscks_l "$2"; shift;;
368 --add-fstab) push add_fstab_l "$2"; shift;;
369 --mount) push fstab_lines "$2"; shift;;
370 --add-device|--device)
371 push add_device_l "$2"; shift;;
372 --kernel-cmdline) push kernel_cmdline_l "$2"; shift;;
373 --nofscks) nofscks_l="yes";;
374 --ro-mnt) ro_mnt_l="yes";;
375 -k|--kmoddir) drivers_dir_l="$2"; shift;;
376 -c|--conf) conffile="$2"; shift;;
377 --confdir) confdir="$2"; shift;;
378 --tmpdir) tmpdir_l="$2"; shift;;
379 -L|--stdlog) stdloglvl_l="$2"; shift;;
380 --compress) compress_l="$2"; shift;;
381 --prefix) prefix_l="$2"; shift;;
382 -f|--force) force=yes;;
383 --kernel-only) kernel_only="yes"; no_kernel="no";;
384 --no-kernel) kernel_only="no"; no_kernel="yes";;
385 --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
386 --early-microcode) early_microcode="yes";;
387 --no-early-microcode) early_microcode="no";;
388 --strip) do_strip_l="yes";;
389 --nostrip) do_strip_l="no";;
390 --hardlink) do_hardlink_l="yes";;
391 --nohardlink) do_hardlink_l="no";;
392 --noprefix) prefix_l="/";;
393 --mdadmconf) mdadmconf_l="yes";;
394 --nomdadmconf) mdadmconf_l="no";;
395 --lvmconf) lvmconf_l="yes";;
396 --nolvmconf) lvmconf_l="no";;
397 --debug) debug="yes";;
398 --profile) profile="yes";;
399 --sshkey) sshkey="$2"; shift;;
400 -v|--verbose) ((verbosity_mod_l++));;
401 -q|--quiet) ((verbosity_mod_l--));;
402 -l|--local)
403 allowlocal="yes"
404 [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
405 && dracutbasedir="$(readlink -f "${0%/*}")"
406 ;;
407 -H|--hostonly|--host-only)
408 hostonly_l="yes" ;;
409 -N|--no-hostonly|--no-host-only)
410 hostonly_l="no" ;;
411 --fstab) use_fstab_l="yes" ;;
412 -h|--help) long_usage; exit 1 ;;
413 -i|--include) push include_src "$2"
414 shift;;
415 --bzip2) compress_l="bzip2";;
416 --lzma) compress_l="lzma";;
417 --xz) compress_l="xz";;
418 --no-compress) _no_compress_l="cat";;
419 --gzip) compress_l="gzip";;
420 --list-modules) do_list="yes";;
421 -M|--show-modules)
422 show_modules_l="yes"
423 ;;
424 --keep) keep="yes";;
425 --printsize) printsize="yes";;
426 --regenerate-all) regenerate_all="yes";;
427 --noimageifnotneeded) noimageifnotneeded="yes";;
428
429 --) shift; break;;
430
431 *) # should not even reach this point
432 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
433 esac
434 shift
435 done
436
437 # getopt cannot handle multiple arguments, so just handle "-I,--include"
438 # the old fashioned way
439
440 while (($# > 0)); do
441 case ${1%%=*} in
442 ++include) push include_src "$2"
443 push include_target "$3"
444 shift 2;;
445 *)
446 if ! [[ ${outfile+x} ]]; then
447 outfile=$1
448 elif ! [[ ${kernel+x} ]]; then
449 kernel=$1
450 else
451 printf "\nUnknown arguments: %s\n\n" "$*" >&2
452 usage; exit 1;
453 fi
454 ;;
455 esac
456 shift
457 done
458
459 if [[ $regenerate_all == "yes" ]]; then
460 ret=0
461 if [[ $kernel ]]; then
462 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
463 exit 1
464 fi
465
466 if [[ $outfile ]]; then
467 printf -- "--regenerate-all cannot be called with a image file\n" >&2
468 exit 1
469 fi
470
471 ((len=${#dracut_args[@]}))
472 for ((i=0; i < len; i++)); do
473 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
474 unset dracut_args[$i]
475 done
476
477 cd /lib/modules
478 for i in *; do
479 [[ -f $i/modules.builtin ]] || continue
480 dracut --kver="$i" "${dracut_args[@]}"
481 ((ret+=$?))
482 done
483 exit $ret
484 elif [[ $kernel ]]; then
485 if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then
486 printf -- "Kernel version $kernel has no modules in /lib/modules/$kernel\n" >&2
487 exit 1
488 fi
489 fi
490
491 if ! [[ $kernel ]]; then
492 kernel=$(uname -r)
493 fi
494
495 if ! [[ $outfile ]]; then
496 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
497
498 if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
499 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
500 else
501 outfile="/boot/initramfs-$kernel.img"
502 fi
503 fi
504
505 for i in /usr/sbin /sbin /usr/bin /bin; do
506 rl=$i
507 if [ -L "$i" ]; then
508 rl=$(readlink -f $i)
509 fi
510 if [[ "$NPATH" != "*:$rl*" ]] ; then
511 NPATH+=":$rl"
512 fi
513 done
514 export PATH="${NPATH#:}"
515 unset LC_MESSAGES
516 unset LC_CTYPE
517 export LC_ALL=C
518 export LANG=C
519 unset NPATH
520 unset LD_LIBRARY_PATH
521 unset GREP_OPTIONS
522
523 export DRACUT_LOG_LEVEL=warning
524 [[ $debug ]] && {
525 export DRACUT_LOG_LEVEL=debug
526 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
527 set -x
528 }
529
530 [[ $profile ]] && {
531 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
532 set -x
533 debug=yes
534 }
535
536 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
537
538 # if we were not passed a config file, try the default one
539 if [[ ! -f $conffile ]]; then
540 if [[ $allowlocal ]]; then
541 conffile="$dracutbasedir/dracut.conf"
542 else
543 conffile="/etc/dracut.conf"
544 fi
545 fi
546
547 if [[ ! -d $confdir ]]; then
548 if [[ $allowlocal ]]; then
549 confdir="$dracutbasedir/dracut.conf.d"
550 else
551 confdir="/etc/dracut.conf.d"
552 fi
553 fi
554
555 # source our config file
556 [[ -f $conffile ]] && . "$conffile"
557
558 # source our config dir
559 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
560 [[ -e $f ]] && . "$f"
561 done
562
563 # these optins add to the stuff in the config file
564 if (( ${#add_dracutmodules_l[@]} )); then
565 while pop add_dracutmodules_l val; do
566 add_dracutmodules+=" $val "
567 done
568 fi
569
570 if (( ${#force_add_dracutmodules_l[@]} )); then
571 while pop force_add_dracutmodules_l val; do
572 force_add_dracutmodules+=" $val "
573 done
574 fi
575
576 if (( ${#fscks_l[@]} )); then
577 while pop fscks_l val; do
578 fscks+=" $val "
579 done
580 fi
581
582 if (( ${#add_fstab_l[@]} )); then
583 while pop add_fstab_l val; do
584 add_fstab+=" $val "
585 done
586 fi
587
588 if (( ${#fstab_lines_l[@]} )); then
589 while pop fstab_lines_l val; do
590 push fstab_lines $val
591 done
592 fi
593
594 if (( ${#install_items_l[@]} )); then
595 while pop install_items_l val; do
596 install_items+=" $val "
597 done
598 fi
599
600 # these options override the stuff in the config file
601 if (( ${#dracutmodules_l[@]} )); then
602 dracutmodules=''
603 while pop dracutmodules_l val; do
604 dracutmodules+="$val "
605 done
606 fi
607
608 if (( ${#omit_dracutmodules_l[@]} )); then
609 omit_dracutmodules=''
610 while pop omit_dracutmodules_l val; do
611 omit_dracutmodules+="$val "
612 done
613 fi
614
615 if (( ${#filesystems_l[@]} )); then
616 filesystems=''
617 while pop filesystems_l val; do
618 filesystems+="$val "
619 done
620 fi
621
622 if (( ${#fw_dir_l[@]} )); then
623 fw_dir=''
624 while pop fw_dir_l val; do
625 fw_dir+="$val "
626 done
627 fi
628
629 if (( ${#libdirs_l[@]} )); then
630 libdirs=''
631 while pop libdirs_l val; do
632 libdirs+="$val "
633 done
634 fi
635
636 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
637 [[ ! $stdloglvl ]] && stdloglvl=4
638 stdloglvl=$((stdloglvl + verbosity_mod_l))
639 ((stdloglvl > 6)) && stdloglvl=6
640 ((stdloglvl < 0)) && stdloglvl=0
641
642 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
643 [[ $do_strip_l ]] && do_strip=$do_strip_l
644 [[ $do_strip ]] || do_strip=yes
645 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
646 [[ $do_hardlink ]] || do_hardlink=yes
647 [[ $prefix_l ]] && prefix=$prefix_l
648 [[ $prefix = "/" ]] && unset prefix
649 [[ $hostonly_l ]] && hostonly=$hostonly_l
650 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
651 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
652 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
653 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
654 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
655 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
656 [[ $tmpdir ]] || tmpdir=/var/tmp
657 [[ $compress_l ]] && compress=$compress_l
658 [[ $show_modules_l ]] && show_modules=$show_modules_l
659 [[ $nofscks_l ]] && nofscks="yes"
660 [[ $ro_mnt_l ]] && ro_mnt="yes"
661 # eliminate IFS hackery when messing with fw_dir
662 fw_dir=${fw_dir//:/ }
663
664 # handle compression options.
665 [[ $compress ]] || compress="gzip"
666 case $compress in
667 bzip2) compress="bzip2 -9";;
668 lzma) compress="lzma -9";;
669 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
670 gzip) compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
671 esac
672 if [[ $_no_compress_l = "cat" ]]; then
673 compress="cat"
674 fi
675
676 [[ $hostonly = yes ]] && hostonly="-h"
677 [[ $hostonly != "-h" ]] && unset hostonly
678
679 readonly TMPDIR="$tmpdir"
680 readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
681 [ -d "$initdir" ] || {
682 printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
683 exit 1
684 }
685
686 if [[ $early_microcode = yes ]]; then
687 readonly microcode_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_microcode.XXXXXX)"
688 [ -d "$microcode_dir" ] || {
689 printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_microcode.XXXXXX failed." >&2
690 exit 1
691 }
692 fi
693 # clean up after ourselves no matter how we die.
694 trap '
695 ret=$?;
696 [[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";
697 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
698 [[ $keep ]] && echo "Not removing $microcode_dir." >&2 || { [[ $microcode_dir ]] && rm -Rf -- "$microcode_dir"; };
699 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
700 exit $ret;
701 ' EXIT
702
703 # clean up after ourselves no matter how we die.
704 trap 'exit 1;' SIGINT
705
706 export DRACUT_KERNEL_LAZY="1"
707 export DRACUT_RESOLVE_LAZY="1"
708
709 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
710 . $dracutbasedir/dracut-functions.sh
711 else
712 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
713 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
714 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
715 exit 1
716 fi
717
718 if ! [[ $print_cmdline ]]; then
719 inst /bin/sh
720 if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
721 unset DRACUT_RESOLVE_LAZY
722 export DRACUT_RESOLVE_DEPS=1
723 fi
724 rm -fr -- ${initdir}/*
725 fi
726
727 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
728 . $dracutbasedir/dracut-version.sh
729 fi
730
731 # Verify bash version, current minimum is 3.1
732 if (( BASH_VERSINFO[0] < 4 )); then
733 dfatal 'You need at least Bash 4 to use dracut, sorry.'
734 exit 1
735 fi
736
737 dracutfunctions=$dracutbasedir/dracut-functions.sh
738 export dracutfunctions
739
740 if (( ${#drivers_l[@]} )); then
741 drivers=''
742 while pop drivers_l val; do
743 drivers+="$val "
744 done
745 fi
746 drivers=${drivers/-/_}
747
748 if (( ${#add_drivers_l[@]} )); then
749 while pop add_drivers_l val; do
750 add_drivers+=" $val "
751 done
752 fi
753 add_drivers=${add_drivers/-/_}
754
755 if (( ${#omit_drivers_l[@]} )); then
756 while pop omit_drivers_l val; do
757 omit_drivers+=" $val "
758 done
759 fi
760 omit_drivers=${omit_drivers/-/_}
761
762 if (( ${#kernel_cmdline_l[@]} )); then
763 while pop kernel_cmdline_l val; do
764 kernel_cmdline+=" $val "
765 done
766 fi
767
768 omit_drivers_corrected=""
769 for d in $omit_drivers; do
770 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
771 omit_drivers_corrected+="$d|"
772 done
773 omit_drivers="${omit_drivers_corrected%|}"
774 unset omit_drivers_corrected
775
776 # prepare args for logging
777 for ((i=0; i < ${#dracut_args[@]}; i++)); do
778 [[ "${dracut_args[$i]}" == *\ * ]] && \
779 dracut_args[$i]="\"${dracut_args[$i]}\""
780 #" keep vim happy
781 done
782 dinfo "Executing: $0 ${dracut_args[@]}"
783
784 [[ $do_list = yes ]] && {
785 for mod in $dracutbasedir/modules.d/*; do
786 [[ -d $mod ]] || continue;
787 [[ -e $mod/install || -e $mod/installkernel || \
788 -e $mod/module-setup.sh ]] || continue
789 printf "%s\n" "${mod##*/??}"
790 done
791 exit 0
792 }
793
794 # This is kinda legacy -- eventually it should go away.
795 case $dracutmodules in
796 ""|auto) dracutmodules="all" ;;
797 esac
798
799 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
800
801 if [[ -d $srcmods ]]; then
802 [[ -f $srcmods/modules.dep ]] || {
803 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
804 }
805 fi
806
807 if [[ -f $outfile && ! $force && ! $print_cmdline ]]; then
808 dfatal "Will not override existing initramfs ($outfile) without --force"
809 exit 1
810 fi
811
812 outdir=${outfile%/*}
813 [[ $outdir ]] || outdir="/"
814
815 if [[ ! -d "$outdir" ]]; then
816 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
817 exit 1
818 elif [[ ! -w "$outdir" ]]; then
819 dfatal "No permission to write to $outdir."
820 exit 1
821 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
822 dfatal "No permission to write $outfile."
823 exit 1
824 fi
825
826 # Need to be able to have non-root users read stuff (rpcbind etc)
827 chmod 755 "$initdir"
828
829 if [[ $hostonly ]]; then
830 for i in /sys /proc /run /dev; do
831 if ! findmnt --target "$i" &>/dev/null; then
832 dwarning "Turning off host-only mode: '$i' is not mounted!"
833 unset hostonly
834 fi
835 done
836 fi
837
838 declare -A host_fs_types
839
840 for line in "${fstab_lines[@]}"; do
841 set -- $line
842 #dev mp fs fsopts
843 push host_devs "$1"
844 host_fs_types["$1"]="$3"
845 done
846
847 for f in $add_fstab; do
848 [[ -e $f ]] || continue
849 while read dev rest; do
850 push host_devs "$dev"
851 done < "$f"
852 done
853
854 for dev in $add_device; do
855 push host_devs "$dev"
856 done
857
858 if (( ${#add_device_l[@]} )); then
859 while pop add_device_l val; do
860 add_device+=" $val "
861 push host_devs "$val"
862 done
863 fi
864
865 if [[ $hostonly ]]; then
866 # in hostonly mode, determine all devices, which have to be accessed
867 # and examine them for filesystem types
868
869 for mp in \
870 "/" \
871 "/etc" \
872 "/bin" \
873 "/sbin" \
874 "/lib" \
875 "/lib64" \
876 "/usr" \
877 "/usr/bin" \
878 "/usr/sbin" \
879 "/usr/lib" \
880 "/usr/lib64" \
881 "/boot";
882 do
883 mp=$(readlink -f "$mp")
884 mountpoint "$mp" >/dev/null 2>&1 || continue
885 _dev=$(find_block_device "$mp")
886 _bdev=$(readlink -f "/dev/block/$_dev")
887 [[ -b $_bdev ]] && _dev=$_bdev
888 push host_devs $_dev
889 [[ "$_mp" == "/" ]] && root_dev="$_dev"
890 push host_devs "$_dev"
891 done
892
893 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
894 while read dev type rest; do
895 [[ -b $dev ]] || continue
896 [[ "$type" == "partition" ]] || continue
897
898 while read _d _m _t _o _r; do
899 [[ "$_d" == \#* ]] && continue
900 [[ $_d ]] || continue
901 [[ $_t != "swap" ]] || [[ $_m != "swap" ]] && continue
902 [[ "$_o" == *noauto* ]] && continue
903 [[ "$_d" == UUID\=* ]] && _d="/dev/disk/by-uuid/${_d#UUID=}"
904 [[ "$_d" == LABEL\=* ]] && _d="/dev/disk/by-label/$_d#LABEL=}"
905 [[ "$_d" -ef "$dev" ]] || continue
906
907 if [[ -f /etc/crypttab ]]; then
908 while read _mapper _a _p _o; do
909 [[ $_mapper = \#* ]] && continue
910 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
911 [[ "$_o" ]] || _o="$_p"
912 # skip mkswap swap
913 [[ $_o == *swap* ]] && continue 2
914 done < /etc/crypttab
915 fi
916
917 push host_devs "$(readlink -f "$dev")"
918 break
919 done < /etc/fstab
920 done < /proc/swaps
921 fi
922 fi
923
924 _get_fs_type() {
925 [[ $1 ]] || return
926 if [[ -b /dev/block/$1 ]] && ID_FS_TYPE=$(get_fs_env "/dev/block/$1"); then
927 host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
928 return 1
929 fi
930 if [[ -b $1 ]] && ID_FS_TYPE=$(get_fs_env "$1"); then
931 host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
932 return 1
933 fi
934 if fstype=$(find_dev_fstype "$1"); then
935 host_fs_types["$1"]="$fstype"
936 return 1
937 fi
938 return 1
939 }
940
941 for dev in ${host_devs[@]}; do
942 _get_fs_type "$dev"
943 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
944 done
945
946 for dev in "${!host_fs_types[@]}"; do
947 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
948 rootopts=$(find_dev_fsopts "$dev")
949 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
950 journaldev=$(fs_get_option $rootopts "jdev")
951 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
952 journaldev=$(fs_get_option $rootopts "logdev")
953 fi
954 if [[ $journaldev ]]; then
955 dev="$(readlink -f "$dev")"
956 push host_devs "$dev"
957 _get_fs_type "$dev"
958 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
959 fi
960 done
961
962 [[ -d $udevdir ]] \
963 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
964 if ! [[ -d "$udevdir" ]]; then
965 [[ -d /lib/udev ]] && udevdir=/lib/udev
966 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
967 fi
968
969 [[ -d $systemdutildir ]] \
970 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
971
972 if ! [[ -d "$systemdutildir" ]]; then
973 [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
974 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
975 fi
976
977 [[ -d $systemdsystemunitdir ]] \
978 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
979
980 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
981
982 [[ -d $systemdsystemconfdir ]] \
983 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
984
985 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
986
987 export initdir dracutbasedir dracutmodules \
988 fw_dir drivers_dir debug no_kernel kernel_only \
989 omit_drivers mdadmconf lvmconf root_dev \
990 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
991 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
992 debug host_fs_types host_devs sshkey add_fstab \
993 DRACUT_VERSION udevdir prefix filesystems drivers \
994 systemdutildir systemdsystemunitdir systemdsystemconfdir
995
996 mods_to_load=""
997 # check all our modules to see if they should be sourced.
998 # This builds a list of modules that we will install next.
999 for_each_module_dir check_module
1000 for_each_module_dir check_mount
1001
1002 [[ "$mods_to_load " == *01fips\ * ]] && export DRACUT_FIPS_MODE=1
1003
1004 if [[ $print_cmdline ]]; then
1005 modules_loaded=" "
1006 # source our modules.
1007 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1008 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1009 module_cmdline "$_d_mod"
1010 done
1011 unset moddir
1012 printf "\n"
1013 exit 0
1014 fi
1015
1016 # Create some directory structure first
1017 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1018
1019 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1020 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1021
1022 if [[ $prefix ]]; then
1023 for d in bin etc lib sbin tmp usr var $libdirs; do
1024 [[ "$d" == */* ]] && continue
1025 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1026 done
1027 fi
1028
1029 if [[ $kernel_only != yes ]]; then
1030 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
1031 [[ -e "${initdir}${prefix}/$d" ]] && continue
1032 if [ -L "/$d" ]; then
1033 inst_symlink "/$d" "${prefix}/$d"
1034 else
1035 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1036 fi
1037 done
1038
1039 for d in dev proc sys sysroot root run run/lock run/initramfs; do
1040 if [ -L "/$d" ]; then
1041 inst_symlink "/$d"
1042 else
1043 mkdir -m 0755 -p "$initdir/$d"
1044 fi
1045 done
1046
1047 ln -sfn ../run "$initdir/var/run"
1048 ln -sfn ../run/lock "$initdir/var/lock"
1049 ln -sfn ../run/log "$initdir/var/log"
1050 else
1051 for d in lib "$libdir"; do
1052 [[ -e "${initdir}${prefix}/$d" ]] && continue
1053 if [ -h "/$d" ]; then
1054 inst "/$d" "${prefix}/$d"
1055 else
1056 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1057 fi
1058 done
1059 fi
1060
1061 if [[ $kernel_only != yes ]]; then
1062 mkdir -p "${initdir}/etc/cmdline.d"
1063 for _d in $hookdirs; do
1064 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1065 done
1066 if [[ "$UID" = "0" ]]; then
1067 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1068 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1069 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1070 fi
1071 fi
1072
1073 _isize=0 #initramfs size
1074 modules_loaded=" "
1075 # source our modules.
1076 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1077 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1078 if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
1079 if [[ $show_modules = yes ]]; then
1080 printf "%s\n" "$_d_mod"
1081 else
1082 dinfo "*** Including module: $_d_mod ***"
1083 fi
1084 if [[ $kernel_only == yes ]]; then
1085 module_installkernel "$_d_mod" || {
1086 dfatal "installkernel failed in module $_d_mod"
1087 exit 1
1088 }
1089 else
1090 module_install "$_d_mod"
1091 if [[ $no_kernel != yes ]]; then
1092 module_installkernel "$_d_mod" || {
1093 dfatal "installkernel failed in module $_d_mod"
1094 exit 1
1095 }
1096 fi
1097 fi
1098 mods_to_load=${mods_to_load// $_d_mod /}
1099 modules_loaded+="$_d_mod "
1100
1101 #print the module install size
1102 if [ -n "$printsize" ]; then
1103 _isize_new=$(du -sk ${initdir}|cut -f1)
1104 _isize_delta=$((_isize_new - _isize))
1105 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1106 _isize=$_isize_new
1107 fi
1108 fi
1109 done
1110 unset moddir
1111
1112 for i in $modules_loaded; do
1113 mkdir -p $initdir/lib/dracut
1114 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1115 done
1116
1117 dinfo "*** Including modules done ***"
1118
1119 ## final stuff that has to happen
1120 if [[ $no_kernel != yes ]]; then
1121
1122 if [[ $drivers ]]; then
1123 hostonly='' instmods $drivers
1124 fi
1125
1126 if [[ $add_drivers ]]; then
1127 hostonly='' instmods -c $add_drivers
1128 fi
1129 if [[ $filesystems ]]; then
1130 hostonly='' instmods -c $filesystems
1131 fi
1132
1133 dinfo "*** Installing kernel module dependencies and firmware ***"
1134 dracut_kernel_post
1135 dinfo "*** Installing kernel module dependencies and firmware done ***"
1136
1137 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1138 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1139 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1140 for i in ${initdir}/etc/cmdline.d/*.conf; do
1141 # We need no initramfs image and do not generate one.
1142 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1143 done
1144 fi
1145 fi
1146 fi
1147
1148 if [[ $kernel_only != yes ]]; then
1149 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1150
1151 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1152
1153 while pop fstab_lines line; do
1154 printf "%s\n" "$line 0 0" >> "${initdir}/etc/fstab"
1155 done
1156
1157 for f in $add_fstab; do
1158 cat "$f" >> "${initdir}/etc/fstab"
1159 done
1160
1161 if [ -d ${initdir}/$systemdutildir ]; then
1162 mkdir -p ${initdir}/etc/conf.d
1163 {
1164 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1165 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1166 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1167 } > ${initdir}/etc/conf.d/systemd.conf
1168 fi
1169
1170 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1171 dinfo "*** Resolving executable dependencies ***"
1172 find "$initdir" -type f \
1173 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1174 -not -path '*.ko' -print0 \
1175 | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H} --
1176 dinfo "*** Resolving executable dependencies done***"
1177 fi
1178 fi
1179
1180 while pop include_src src && pop include_target tgt; do
1181 if [[ $src && $tgt ]]; then
1182 if [[ -f $src ]]; then
1183 inst $src $tgt
1184 else
1185 ddebug "Including directory: $src"
1186 mkdir -p "${initdir}/${tgt}"
1187 # check for preexisting symlinks, so we can cope with the
1188 # symlinks to $prefix
1189 for i in "$src"/*; do
1190 [[ -e "$i" || -h "$i" ]] || continue
1191 s=${initdir}/${tgt}/${i#$src/}
1192 if [[ -d "$i" ]]; then
1193 if ! [[ -e "$s" ]]; then
1194 mkdir -m 0755 -p "$s"
1195 chmod --reference="$i" "$s"
1196 fi
1197 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
1198 else
1199 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
1200 fi
1201 done
1202 fi
1203 fi
1204 done
1205
1206 if [[ $kernel_only != yes ]]; then
1207 # make sure that library links are correct and up to date
1208 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1209 [[ -f $f ]] && inst_simple "$f"
1210 done
1211 if ! ldconfig -r "$initdir"; then
1212 if [[ $UID = 0 ]]; then
1213 derror "ldconfig exited ungracefully"
1214 else
1215 derror "ldconfig might need uid=0 (root) for chroot()"
1216 fi
1217 fi
1218 fi
1219
1220 PRELINK_BIN="$(command -v prelink)"
1221 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1222 if [[ $DRACUT_FIPS_MODE ]]; then
1223 dinfo "*** Installing prelink files ***"
1224 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1225 else
1226 dinfo "*** Pre-linking files ***"
1227 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1228 chroot "$initdir" "$PRELINK_BIN" -a
1229 rm -f -- "$initdir/$PRELINK_BIN"
1230 rm -fr -- "$initdir"/etc/prelink.*
1231 dinfo "*** Pre-linking files done ***"
1232 fi
1233 fi
1234
1235 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1236 dinfo "*** Hardlinking files ***"
1237 hardlink "$initdir" 2>&1
1238 dinfo "*** Hardlinking files done ***"
1239 fi
1240
1241 # strip binaries
1242 if [[ $do_strip = yes ]] ; then
1243 for p in strip xargs find; do
1244 if ! type -P $p >/dev/null; then
1245 dinfo "Could not find '$p'. Not stripping the initramfs."
1246 do_strip=no
1247 fi
1248 done
1249 fi
1250
1251 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1252 dinfo "*** Stripping files ***"
1253 find "$initdir" -type f \
1254 -executable -not -path '*/lib/modules/*.ko' -print0 \
1255 | xargs -r -0 strip -g 2>/dev/null
1256
1257 # strip kernel modules, but do not touch signed modules
1258 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1259 | while read -r -d $'\0' f; do
1260 SIG=$(tail -c 28 "$f")
1261 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1262 done | xargs -r -0 strip -g
1263
1264 dinfo "*** Stripping files done ***"
1265 fi
1266 if [[ $early_microcode = yes ]]; then
1267 dinfo "*** Generating early-microcode cpio image ***"
1268 ucode_dir=(amd-ucode intel-ucode)
1269 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1270 _dest_dir="$microcode_dir/d/kernel/x86/microcode"
1271 _dest_idx="0 1"
1272 mkdir -p $_dest_dir
1273 if [[ $hostonly ]]; then
1274 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1275 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1276 fi
1277 for idx in $_dest_idx; do
1278 _fw=${ucode_dir[$idx]}
1279 for _fwdir in $fw_dir; do
1280 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1281 _src="*"
1282 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1283 if [[ $hostonly ]]; then
1284 _src=$(get_ucode_file)
1285 fi
1286 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1287 fi
1288 done
1289 done
1290 (cd "$microcode_dir/d"; find . -print0 | cpio --null -o -H newc --quiet >../ucode.cpio)
1291 fi
1292
1293 rm -f -- "$outfile"
1294 dinfo "*** Creating image file ***"
1295 if [[ $early_microcode = yes ]]; then
1296 # The microcode blob is _before_ the initramfs blob, not after
1297 mv $microcode_dir/ucode.cpio $outfile.$$
1298 fi
1299 if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null -R 0:0 -H newc -o --quiet| \
1300 $compress >> "$outfile.$$"; ); then
1301 dfatal "dracut: creation of $outfile.$$ failed"
1302 exit 1
1303 fi
1304 mv -- "$outfile.$$" "$outfile"
1305 dinfo "*** Creating image file done ***"
1306
1307 if (( maxloglvl >= 5 )); then
1308 if [[ $allowlocal ]]; then
1309 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1310 else
1311 lsinitrd "$outfile"| ddebug
1312 fi
1313 fi
1314
1315 exit 0