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