]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
dracut.sh: after doing the lazy resolve always install dependencies
[thirdparty/dracut.git] / dracut.sh
1 #!/bin/bash --norc
2 #
3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
6 #
7
8 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 # store for logging
25
26 # Verify bash version, current minimum is 4
27 if (( BASH_VERSINFO[0] < 4 )); then
28 printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
29 exit 1
30 fi
31
32 dracut_args=( "$@" )
33 readonly dracut_cmd="$(readlink -f $0)"
34
35 set -o pipefail
36
37 usage() {
38 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
39 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
40 . $dracutbasedir/dracut-version.sh
41 fi
42
43 # 80x25 linebreak here ^
44 cat << EOF
45 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
46
47 Version: $DRACUT_VERSION
48
49 Creates initial ramdisk images for preloading modules
50
51 -h, --help Display all options
52
53 If a [LIST] has multiple arguments, then you have to put these in quotes.
54
55 For example:
56
57 # dracut --add-drivers "module1 module2" ...
58
59 EOF
60 }
61
62 long_usage() {
63 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
64 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
65 . $dracutbasedir/dracut-version.sh
66 fi
67
68 # 80x25 linebreak here ^
69 cat << EOF
70 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
71
72 Version: $DRACUT_VERSION
73
74 Creates initial ramdisk images for preloading modules
75
76 --kver [VERSION] Set kernel version to [VERSION].
77 -f, --force Overwrite existing initramfs file.
78 -a, --add [LIST] Add a space-separated list of dracut modules.
79 --rebuild Append arguments to those of existing image and rebuild
80 -m, --modules [LIST] Specify a space-separated list of dracut modules to
81 call when building the initramfs. Modules are located
82 in /usr/lib/dracut/modules.d.
83 -o, --omit [LIST] Omit a space-separated list of dracut modules.
84 --force-add [LIST] Force to add a space-separated list of dracut modules
85 to the default set of modules, when -H is specified.
86 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
87 exclusively include in the initramfs.
88 --add-drivers [LIST] Specify a space-separated list of kernel
89 modules to add to the initramfs.
90 --force-drivers [LIST] Specify a space-separated list of kernel
91 modules to add to the initramfs and make sure they
92 are tried to be loaded via modprobe same as passing
93 rd.driver.pre=DRIVER kernel parameter.
94 --omit-drivers [LIST] Specify a space-separated list of kernel
95 modules not to add to the initramfs.
96 --filesystems [LIST] Specify a space-separated list of kernel filesystem
97 modules to exclusively include in the generic
98 initramfs.
99 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
100 modules
101 --fwdir [DIR] Specify additional directories, where to look for
102 firmwares, separated by :
103 --kernel-only Only install kernel drivers and firmware files
104 --no-kernel Do not install kernel drivers and firmware files
105 --print-cmdline Print the kernel command line for the given disk layout
106 --early-microcode Combine early microcode with ramdisk
107 --no-early-microcode Do not combine early microcode with ramdisk
108 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
109 --strip Strip binaries in the initramfs
110 --nostrip Do not strip binaries in the initramfs
111 --prelink Prelink binaries in the initramfs
112 --noprelink Do not prelink binaries in the initramfs
113 --hardlink Hardlink files in the initramfs
114 --nohardlink Do not hardlink files in the initramfs
115 --prefix [DIR] Prefix initramfs files with [DIR]
116 --noprefix Do not prefix initramfs files
117 --mdadmconf Include local /etc/mdadm.conf
118 --nomdadmconf Do not include local /etc/mdadm.conf
119 --lvmconf Include local /etc/lvm/lvm.conf
120 --nolvmconf Do not include local /etc/lvm/lvm.conf
121 --fscks [LIST] Add a space-separated list of fsck helpers.
122 --nofscks Inhibit installation of any fsck helpers.
123 --ro-mnt Mount / and /usr read-only by default.
124 -h, --help This message
125 --debug Output debug information of the build process
126 --profile Output profile information of the build process
127 -L, --stdlog [0-6] Specify logging level (to standard error)
128 0 - suppress any messages
129 1 - only fatal errors
130 2 - all errors
131 3 - warnings
132 4 - info
133 5 - debug info (here starts lots of output)
134 6 - trace info (and even more)
135 -v, --verbose Increase verbosity level
136 -q, --quiet Decrease verbosity level
137 -c, --conf [FILE] Specify configuration file to use.
138 Default: /etc/dracut.conf
139 --confdir [DIR] Specify configuration directory to use *.conf files
140 from. Default: /etc/dracut.conf.d
141 --tmpdir [DIR] Temporary directory to be used instead of default
142 /var/tmp.
143 -l, --local Local mode. Use modules from the current working
144 directory instead of the system-wide installed in
145 /usr/lib/dracut/modules.d.
146 Useful when running dracut from a git checkout.
147 -H, --hostonly Host-Only mode: Install only what is needed for
148 booting the local host instead of a generic host.
149 -N, --no-hostonly Disables Host-Only mode
150 --hostonly-cmdline Store kernel command line arguments needed
151 in the initramfs
152 --no-hostonly-cmdline Do not store kernel command line arguments needed
153 in the initramfs
154 --no-hostonly-default-device
155 Do not generate implicit host devices like root,
156 swap, fstab, etc. Use "--mount" or "--add-device"
157 to explicitly add devices as needed.
158 --hostonly-i18n Install only needed keyboard and font files according
159 to the host configuration (default).
160 --no-hostonly-i18n Install all keyboard and font files available.
161 --persistent-policy [POLICY]
162 Use [POLICY] to address disks and partitions.
163 POLICY can be any directory name found in /dev/disk.
164 E.g. "by-uuid", "by-label"
165 --fstab Use /etc/fstab to determine the root device.
166 --add-fstab [FILE] Add file to the initramfs fstab
167 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
168 Mount device [DEV] on mountpoint [MP] with filesystem
169 [FSTYPE] and options [FSOPTS] in the initramfs
170 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
171 determined by looking at the current mounts.
172 --add-device "[DEV]" Bring up [DEV] in initramfs
173 -i, --include [SOURCE] [TARGET]
174 Include the files in the SOURCE directory into the
175 Target directory in the final initramfs.
176 If SOURCE is a file, it will be installed to TARGET
177 in the final initramfs.
178 -I, --install [LIST] Install the space separated list of files into the
179 initramfs.
180 --install-optional [LIST] Install the space separated list of files into the
181 initramfs, if they exist.
182 --gzip Compress the generated initramfs using gzip.
183 This will be done by default, unless another
184 compression option or --no-compress is passed.
185 --bzip2 Compress the generated initramfs using bzip2.
186 Make sure your kernel has bzip2 decompression support
187 compiled in, otherwise you will not be able to boot.
188 --lzma Compress the generated initramfs using lzma.
189 Make sure your kernel has lzma support compiled in,
190 otherwise you will not be able to boot.
191 --xz Compress the generated initramfs using xz.
192 Make sure that your kernel has xz support compiled
193 in, otherwise you will not be able to boot.
194 --lzo Compress the generated initramfs using lzop.
195 Make sure that your kernel has lzo support compiled
196 in, otherwise you will not be able to boot.
197 --lz4 Compress the generated initramfs using lz4.
198 Make sure that your kernel has lz4 support compiled
199 in, otherwise you will not be able to boot.
200 --zstd Compress the generated initramfs using Zstandard.
201 Make sure that your kernel has zstd support compiled
202 in, otherwise you will not be able to boot.
203 --compress [COMPRESSION] Compress the generated initramfs with the
204 passed compression program. Make sure your kernel
205 knows how to decompress the generated initramfs,
206 otherwise you will not be able to boot.
207 --no-compress Do not compress the generated initramfs. This will
208 override any other compression options.
209 --list-modules List all available dracut modules.
210 -M, --show-modules Print included module's name to standard output during
211 build.
212 --keep Keep the temporary initramfs for debugging purposes
213 --printsize Print out the module install size
214 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
215 --logfile [FILE] Logfile to use (overrides configuration setting)
216 --reproducible Create reproducible images
217 --no-reproducible Do not create reproducible images
218 --loginstall [DIR] Log all files installed from the host to [DIR]
219 --uefi Create an UEFI executable with the kernel cmdline and
220 kernel combined
221 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
222 --kernel-image [FILE] location of the kernel image
223
224 If [LIST] has multiple arguments, then you have to put these in quotes.
225
226 For example:
227
228 # dracut --add-drivers "module1 module2" ...
229
230 EOF
231 }
232
233 # Fills up host_devs stack variable and makes sure there are no duplicates
234 push_host_devs() {
235 local _dev
236 for _dev in "$@"; do
237 [[ " ${host_devs[@]} " == *" $_dev "* ]] && return
238 host_devs+=( "$_dev" )
239 done
240 }
241
242 # Little helper function for reading args from the commandline.
243 # it automatically handles -a b and -a=b variants, and returns 1 if
244 # we need to shift $3.
245 read_arg() {
246 # $1 = arg name
247 # $2 = arg value
248 # $3 = arg parameter
249 local rematch='^[^=]*=(.*)$'
250 if [[ $2 =~ $rematch ]]; then
251 read "$1" <<< "${BASH_REMATCH[1]}"
252 else
253 read "$1" <<< "$3"
254 # There is no way to shift our callers args, so
255 # return 1 to indicate they should do it instead.
256 return 1
257 fi
258 }
259
260 dropindirs_sort()
261 {
262 local suffix=$1; shift
263 local -a files
264 local f d
265
266 for d in "$@"; do
267 for i in "$d/"*"$suffix"; do
268 if [[ -e "$i" ]]; then
269 printf "%s\n" "${i##*/}"
270 fi
271 done
272 done | sort -Vu | {
273 readarray -t files
274
275 for f in "${files[@]}"; do
276 for d in "$@"; do
277 if [[ -e "$d/$f" ]]; then
278 printf "%s\n" "$d/$f"
279 continue 2
280 fi
281 done
282 done
283 }
284 }
285
286 rearrange_params()
287 {
288 # Workaround -i, --include taking 2 arguments
289 set -- "${@/--include/++include}"
290
291 # This prevents any long argument ending with "-i"
292 # -i, like --opt-i but I think we can just prevent that
293 set -- "${@/%-i/++include}"
294
295 TEMP=$(unset POSIXLY_CORRECT; getopt \
296 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
297 --long kver: \
298 --long add: \
299 --long force-add: \
300 --long add-drivers: \
301 --long force-drivers: \
302 --long omit-drivers: \
303 --long modules: \
304 --long omit: \
305 --long drivers: \
306 --long filesystems: \
307 --long install: \
308 --long install-optional: \
309 --long fwdir: \
310 --long libdirs: \
311 --long fscks: \
312 --long add-fstab: \
313 --long mount: \
314 --long device: \
315 --long add-device: \
316 --long nofscks \
317 --long ro-mnt \
318 --long kmoddir: \
319 --long conf: \
320 --long confdir: \
321 --long tmpdir: \
322 --long stdlog: \
323 --long compress: \
324 --long prefix: \
325 --long rebuild: \
326 --long force \
327 --long kernel-only \
328 --long no-kernel \
329 --long print-cmdline \
330 --long kernel-cmdline: \
331 --long strip \
332 --long nostrip \
333 --long prelink \
334 --long noprelink \
335 --long hardlink \
336 --long nohardlink \
337 --long noprefix \
338 --long mdadmconf \
339 --long nomdadmconf \
340 --long lvmconf \
341 --long nolvmconf \
342 --long debug \
343 --long profile \
344 --long sshkey: \
345 --long logfile: \
346 --long verbose \
347 --long quiet \
348 --long local \
349 --long hostonly \
350 --long host-only \
351 --long no-hostonly \
352 --long no-host-only \
353 --long hostonly-cmdline \
354 --long no-hostonly-cmdline \
355 --long no-hostonly-default-device \
356 --long persistent-policy: \
357 --long fstab \
358 --long help \
359 --long bzip2 \
360 --long lzma \
361 --long xz \
362 --long lzo \
363 --long lz4 \
364 --long zstd \
365 --long no-compress \
366 --long gzip \
367 --long list-modules \
368 --long show-modules \
369 --long keep \
370 --long printsize \
371 --long regenerate-all \
372 --long noimageifnotneeded \
373 --long early-microcode \
374 --long no-early-microcode \
375 --long reproducible \
376 --long no-reproducible \
377 --long loginstall: \
378 --long uefi \
379 --long uefi-stub: \
380 --long kernel-image: \
381 --long no-hostonly-i18n \
382 --long hostonly-i18n \
383 --long no-machineid \
384 -- "$@")
385
386 if (( $? != 0 )); then
387 usage
388 exit 1
389 fi
390 }
391
392 verbosity_mod_l=0
393 unset kernel
394 unset outfile
395
396 rearrange_params "$@"
397 eval set -- "$TEMP"
398
399 # parse command line args to check if '--rebuild' option is present
400 unset append_args_l
401 unset rebuild_file
402 while :
403 do
404 if [ "$1" == "--" ]; then
405 shift; break
406 fi
407 if [ "$1" == "--rebuild" ]; then
408 append_args_l="yes"
409 rebuild_file=$2
410 if [ ! -e $rebuild_file ]; then
411 echo "Image file '$rebuild_file', for rebuild, does not exist!"
412 exit 1
413 fi
414 abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
415 shift; continue
416 fi
417 shift
418 done
419
420 # get output file name and kernel version from command line arguments
421 while (($# > 0)); do
422 case ${1%%=*} in
423 ++include)
424 shift 2;;
425 *)
426 if ! [[ ${outfile+x} ]]; then
427 outfile=$1
428 elif ! [[ ${kernel+x} ]]; then
429 kernel=$1
430 else
431 printf "\nUnknown arguments: %s\n\n" "$*" >&2
432 usage; exit 1;
433 fi
434 ;;
435 esac
436 shift
437 done
438
439 # extract input image file provided with rebuild option to get previous parameters, if any
440 if [[ $append_args_l == "yes" ]]; then
441 unset rebuild_param
442
443 # determine resultant file
444 if ! [[ $outfile ]]; then
445 outfile=$rebuild_file
446 fi
447
448 if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
449 echo "Image '$rebuild_file' has no rebuild information stored"
450 exit 1
451 fi
452
453 # prepend previous parameters to current command line args
454 if [[ $rebuild_param ]]; then
455 TEMP="$rebuild_param $TEMP"
456 eval set -- "$TEMP"
457 rearrange_params "$@"
458 fi
459
460 # clean the temporarily used scratch-pad directory
461 rm -rf $scratch_dir
462 fi
463
464 unset PARMS_TO_STORE
465 PARMS_TO_STORE=""
466
467 eval set -- "$TEMP"
468
469 while :; do
470 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
471 PARMS_TO_STORE+=" $1";
472 fi
473 case $1 in
474 --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
475 -a|--add) add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
476 --force-add) force_add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
477 --add-drivers) add_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
478 --force-drivers) force_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
479 --omit-drivers) omit_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
480 -m|--modules) dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
481 -o|--omit) omit_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
482 -d|--drivers) drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
483 --filesystems) filesystems_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
484 -I|--install) install_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
485 --install-optional) install_optional_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
486 --fwdir) fw_dir_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
487 --libdirs) libdirs_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
488 --fscks) fscks_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
489 --add-fstab) add_fstab_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
490 --mount) fstab_lines+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
491 --add-device|--device) add_device_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
492 --kernel-cmdline) kernel_cmdline_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
493 --nofscks) nofscks_l="yes";;
494 --ro-mnt) ro_mnt_l="yes";;
495 -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
496 -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
497 --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
498 --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
499 -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
500 --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
501 --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
502 --loginstall) loginstall_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
503 --rebuild) if [ $rebuild_file == $outfile ]; then
504 force=yes
505 fi
506 shift
507 ;;
508 -f|--force) force=yes;;
509 --kernel-only) kernel_only="yes"; no_kernel="no";;
510 --no-kernel) kernel_only="no"; no_kernel="yes";;
511 --print-cmdline)
512 print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
513 --early-microcode)
514 early_microcode_l="yes";;
515 --no-early-microcode)
516 early_microcode_l="no";;
517 --strip) do_strip_l="yes";;
518 --nostrip) do_strip_l="no";;
519 --prelink) do_prelink_l="yes";;
520 --noprelink) do_prelink_l="no";;
521 --hardlink) do_hardlink_l="yes";;
522 --nohardlink) do_hardlink_l="no";;
523 --noprefix) prefix_l="/";;
524 --mdadmconf) mdadmconf_l="yes";;
525 --nomdadmconf) mdadmconf_l="no";;
526 --lvmconf) lvmconf_l="yes";;
527 --nolvmconf) lvmconf_l="no";;
528 --debug) debug="yes";;
529 --profile) profile="yes";;
530 --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
531 --logfile) logfile_l="$2"; shift;;
532 -v|--verbose) ((verbosity_mod_l++));;
533 -q|--quiet) ((verbosity_mod_l--));;
534 -l|--local)
535 allowlocal="yes"
536 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
537 && dracutbasedir="$(readlink -f "${0%/*}")"
538 ;;
539 -H|--hostonly|--host-only)
540 hostonly_l="yes" ;;
541 -N|--no-hostonly|--no-host-only)
542 hostonly_l="no" ;;
543 --hostonly-cmdline)
544 hostonly_cmdline_l="yes" ;;
545 --hostonly-i18n)
546 i18n_install_all_l="no" ;;
547 --no-hostonly-i18n)
548 i18n_install_all_l="yes" ;;
549 --no-hostonly-cmdline)
550 hostonly_cmdline_l="no" ;;
551 --no-hostonly-default-device)
552 hostonly_default_device="no" ;;
553 --persistent-policy)
554 persistent_policy_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
555 --fstab) use_fstab_l="yes" ;;
556 -h|--help) long_usage; exit 1 ;;
557 -i|--include) include_src+=("$2"); PARMS_TO_STORE+=" '$2'";
558 shift;;
559 --bzip2) compress_l="bzip2";;
560 --lzma) compress_l="lzma";;
561 --xz) compress_l="xz";;
562 --lzo) compress_l="lzo";;
563 --lz4) compress_l="lz4";;
564 --zstd) compress_l="zstd";;
565 --no-compress) _no_compress_l="cat";;
566 --gzip) compress_l="gzip";;
567 --list-modules) do_list="yes";;
568 -M|--show-modules)
569 show_modules_l="yes"
570 ;;
571 --keep) keep="yes";;
572 --printsize) printsize="yes";;
573 --regenerate-all) regenerate_all="yes";;
574 --noimageifnotneeded) noimageifnotneeded="yes";;
575 --reproducible) reproducible_l="yes";;
576 --no-reproducible) reproducible_l="no";;
577 --uefi) uefi="yes";;
578 --uefi-stub)
579 uefi_stub_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
580 --kernel-image)
581 kernel_image_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
582 --no-machineid)
583 machine_id_l="no";;
584 --) shift; break;;
585
586 *) # should not even reach this point
587 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
588 esac
589 shift
590 done
591
592 # getopt cannot handle multiple arguments, so just handle "-I,--include"
593 # the old fashioned way
594
595 while (($# > 0)); do
596 if [ "${1%%=*}" == "++include" ]; then
597 include_src+=("$2")
598 include_target+=("$3")
599 PARMS_TO_STORE+=" --include '$2' '$3'"
600 shift 2
601 fi
602 shift
603 done
604
605 if [[ $regenerate_all == "yes" ]]; then
606 ret=0
607 if [[ $kernel ]]; then
608 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
609 exit 1
610 fi
611
612 if [[ $outfile ]]; then
613 printf -- "--regenerate-all cannot be called with a image file\n" >&2
614 exit 1
615 fi
616
617 ((len=${#dracut_args[@]}))
618 for ((i=0; i < len; i++)); do
619 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
620 unset dracut_args[$i]
621 done
622
623 cd /lib/modules
624 for i in *; do
625 [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
626 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
627 ((ret+=$?))
628 done
629 exit $ret
630 fi
631
632 if ! [[ $kernel ]]; then
633 kernel=$(uname -r)
634 fi
635
636 export LC_ALL=C
637 export LANG=C
638 unset LC_MESSAGES
639 unset LC_CTYPE
640 unset LD_LIBRARY_PATH
641 unset LD_PRELOAD
642 unset GREP_OPTIONS
643
644 export DRACUT_LOG_LEVEL=warning
645 [[ $debug ]] && {
646 export DRACUT_LOG_LEVEL=debug
647 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
648 set -x
649 }
650
651 [[ $profile ]] && {
652 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
653 set -x
654 debug=yes
655 }
656
657 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
658
659 # if we were not passed a config file, try the default one
660 if [[ ! -f $conffile ]]; then
661 if [[ $allowlocal ]]; then
662 conffile="$dracutbasedir/dracut.conf"
663 else
664 conffile="/etc/dracut.conf"
665 fi
666 fi
667
668 if [[ ! -d $confdir ]]; then
669 if [[ $allowlocal ]]; then
670 confdir="$dracutbasedir/dracut.conf.d"
671 else
672 confdir="/etc/dracut.conf.d"
673 fi
674 fi
675
676 # source our config file
677 [[ -f $conffile ]] && . "$conffile"
678
679 # source our config dir
680 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
681 [[ -e $f ]] && . "$f"
682 done
683
684 DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
685
686 for i in $DRACUT_PATH; do
687 rl=$i
688 if [ -L "$i" ]; then
689 rl=$(readlink -f $i)
690 fi
691 if [[ "$NPATH" != *:$rl* ]] ; then
692 NPATH+=":$rl"
693 fi
694 done
695 export PATH="${NPATH#:}"
696 unset NPATH
697
698 # these options add to the stuff in the config file
699 (( ${#add_dracutmodules_l[@]} )) && add_dracutmodules+=" ${add_dracutmodules_l[@]} "
700 (( ${#force_add_dracutmodules_l[@]} )) && force_add_dracutmodules+=" ${force_add_dracutmodules_l[@]} "
701 (( ${#fscks_l[@]} )) && fscks+=" ${fscks_l[@]} "
702 (( ${#add_fstab_l[@]} )) && add_fstab+=" ${add_fstab_l[@]} "
703 (( ${#fstab_lines_l[@]} )) && fstab_lines+=( "${fstab_lines_l[@]}" )
704 (( ${#install_items_l[@]} )) && install_items+=" ${install_items_l[@]} "
705 (( ${#install_optional_items_l[@]} )) && install_optional_items+=" ${install_optional_items_l[@]} "
706
707 # these options override the stuff in the config file
708 (( ${#dracutmodules_l[@]} )) && dracutmodules="${dracutmodules_l[@]}"
709 (( ${#omit_dracutmodules_l[@]} )) && omit_dracutmodules="${omit_dracutmodules_l[@]}"
710 (( ${#filesystems_l[@]} )) && filesystems="${filesystems_l[@]}"
711 (( ${#fw_dir_l[@]} )) && fw_dir="${fw_dir_l[@]}"
712 (( ${#libdirs_l[@]} ))&& libdirs="${libdirs_l[@]}"
713
714 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
715 [[ ! $stdloglvl ]] && stdloglvl=4
716 stdloglvl=$((stdloglvl + verbosity_mod_l))
717 ((stdloglvl > 6)) && stdloglvl=6
718 ((stdloglvl < 0)) && stdloglvl=0
719
720 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
721 [[ $do_strip_l ]] && do_strip=$do_strip_l
722 [[ $do_strip ]] || do_strip=yes
723 [[ $do_prelink_l ]] && do_prelink=$do_prelink_l
724 [[ $do_prelink ]] || do_prelink=yes
725 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
726 [[ $do_hardlink ]] || do_hardlink=yes
727 [[ $prefix_l ]] && prefix=$prefix_l
728 [[ $prefix = "/" ]] && unset prefix
729 [[ $hostonly_l ]] && hostonly=$hostonly_l
730 [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
731 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes"
732 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
733 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
734 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
735 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
736 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
737 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
738 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
739 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
740 [[ $tmpdir ]] || tmpdir=/var/tmp
741 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
742 [[ $compress_l ]] && compress=$compress_l
743 [[ $show_modules_l ]] && show_modules=$show_modules_l
744 [[ $nofscks_l ]] && nofscks="yes"
745 [[ $ro_mnt_l ]] && ro_mnt="yes"
746 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
747 [[ $early_microcode ]] || early_microcode=no
748 [[ $logfile_l ]] && logfile="$logfile_l"
749 [[ $reproducible_l ]] && reproducible="$reproducible_l"
750 [[ $loginstall_l ]] && loginstall="$loginstall_l"
751 [[ $uefi_stub_l ]] && uefi_stub="$uefi_stub_l"
752 [[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
753 [[ $machine_id_l ]] && machine_id="$machine_id_l"
754
755 if ! [[ $outfile ]]; then
756 if [[ $machine_id != "no" ]]; then
757 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
758 fi
759
760 if [[ $uefi == "yes" ]]; then
761 BUILD_ID=$(cat /etc/os-release /usr/lib/os-release \
762 | while read -r line || [[ $line ]]; do \
763 [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
764 done)
765 if [[ -d /efi ]] && mountpoint -q /efi; then
766 efidir=/efi
767 else
768 efidir=/boot/EFI
769 if [[ -d /boot/efi/EFI ]] && mountpoint -q /boot/efi; then
770 efidir=/boot/efi/EFI
771 fi
772 fi
773 mkdir -p "$efidir/Linux"
774 outfile="$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
775 else
776 if [[ -e "/boot/vmlinuz-$kernel" ]]; then
777 outfile="/boot/initramfs-$kernel.img"
778 elif [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
779 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
780 else
781 outfile="/boot/initramfs-$kernel.img"
782 fi
783 fi
784 fi
785
786 # eliminate IFS hackery when messing with fw_dir
787 export DRACUT_FIRMWARE_PATH=${fw_dir// /:}
788 fw_dir=${fw_dir//:/ }
789
790 # check for logfile and try to create one if it doesn't exist
791 if [[ -n "$logfile" ]];then
792 if [[ ! -f "$logfile" ]];then
793 touch "$logfile"
794 if [ ! $? -eq 0 ] ;then
795 printf "%s\n" "dracut: touch $logfile failed." >&2
796 fi
797 fi
798 fi
799
800 # handle compression options.
801 if [[ $_no_compress_l = "cat" ]]; then
802 compress="cat"
803 fi
804
805 if ! [[ $compress ]]; then
806 # check all known compressors, if none specified
807 for i in pigz gzip lz4 lzop zstd lzma xz lbzip2 bzip2 cat; do
808 command -v "$i" &>/dev/null || continue
809 compress="$i"
810 break
811 done
812 if [[ $compress = cat ]]; then
813 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
814 fi
815 fi
816
817 # choose the right arguments for the compressor
818 case $compress in
819 bzip2|lbzip2)
820 if [[ "$compress" = lbzip2 ]] || command -v lbzip2 &>/dev/null; then
821 compress="lbzip2 -9"
822 else
823 compress="bzip2 -9"
824 fi
825 ;;
826 lzma)
827 compress="lzma -9 -T0"
828 ;;
829 xz)
830 compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
831 ;;
832 gzip|pigz)
833 if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
834 compress="pigz -9 -n -T -R"
835 elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
836 compress="gzip -n -9 --rsyncable"
837 else
838 compress="gzip -n -9"
839 fi
840 ;;
841 lzo|lzop)
842 compress="lzop -9"
843 ;;
844 lz4)
845 compress="lz4 -l -9"
846 ;;
847 zstd)
848 compress="zstd -15 -q -T0"
849 ;;
850 esac
851
852 [[ $hostonly = yes ]] && hostonly="-h"
853 [[ $hostonly != "-h" ]] && unset hostonly
854
855 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
856
857 readonly TMPDIR="$(realpath -e "$tmpdir")"
858 [ -d "$TMPDIR" ] || {
859 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
860 exit 1
861 }
862 readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
863 [ -d "$DRACUT_TMPDIR" ] || {
864 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
865 exit 1
866 }
867
868 # clean up after ourselves no matter how we die.
869 trap '
870 ret=$?;
871 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
872 exit $ret;
873 ' EXIT
874
875 # clean up after ourselves no matter how we die.
876 trap 'exit 1;' SIGINT
877
878 readonly initdir="${DRACUT_TMPDIR}/initramfs"
879 mkdir "$initdir"
880
881 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
882 readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio"
883 mkdir "$early_cpio_dir"
884 fi
885
886 export DRACUT_RESOLVE_LAZY="1"
887
888 if [[ $print_cmdline ]]; then
889 stdloglvl=0
890 sysloglvl=0
891 fileloglvl=0
892 kmsgloglvl=0
893 fi
894
895 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
896 . $dracutbasedir/dracut-version.sh
897 fi
898
899 if [[ -f $dracutbasedir/dracut-init.sh ]]; then
900 . $dracutbasedir/dracut-init.sh
901 else
902 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
903 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
904 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
905 exit 1
906 fi
907
908 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
909 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
910 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
911 exit 1
912 fi
913
914 if ! [[ $print_cmdline ]]; then
915 inst /bin/sh
916 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
917 unset DRACUT_RESOLVE_LAZY
918 export DRACUT_RESOLVE_DEPS=1
919 fi
920 rm -fr -- ${initdir}/*
921 fi
922
923 dracutfunctions=$dracutbasedir/dracut-functions.sh
924 export dracutfunctions
925
926 (( ${#drivers_l[@]} )) && drivers="${drivers_l[@]}"
927 drivers=${drivers/-/_}
928
929 (( ${#add_drivers_l[@]} )) && add_drivers+=" ${add_drivers_l[@]} "
930 add_drivers=${add_drivers/-/_}
931
932 (( ${#force_drivers_l[@]} )) && force_drivers+=" ${force_drivers_l[@]} "
933 force_drivers=${force_drivers/-/_}
934
935 (( ${#omit_drivers_l[@]} )) && omit_drivers+=" ${omit_drivers_l[@]} "
936 omit_drivers=${omit_drivers/-/_}
937
938 (( ${#kernel_cmdline_l[@]} )) && kernel_cmdline+=" ${kernel_cmdline_l[@]} "
939
940 omit_drivers_corrected=""
941 for d in $omit_drivers; do
942 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
943 [[ " $drivers $force_drivers " == *\ $d\ * ]] && continue
944 omit_drivers_corrected+="$d|"
945 done
946 omit_drivers="${omit_drivers_corrected%|}"
947 unset omit_drivers_corrected
948
949 # prepare args for logging
950 for ((i=0; i < ${#dracut_args[@]}; i++)); do
951 [[ "${dracut_args[$i]}" == *\ * ]] && \
952 dracut_args[$i]="\"${dracut_args[$i]}\""
953 #" keep vim happy
954 done
955
956 dinfo "Executing: $dracut_cmd ${dracut_args[@]}"
957
958 [[ $do_list = yes ]] && {
959 for mod in $dracutbasedir/modules.d/*; do
960 [[ -d $mod ]] || continue;
961 [[ -e $mod/install || -e $mod/installkernel || \
962 -e $mod/module-setup.sh ]] || continue
963 printf "%s\n" "${mod##*/??}"
964 done
965 exit 0
966 }
967
968 # This is kinda legacy -- eventually it should go away.
969 case $dracutmodules in
970 ""|auto) dracutmodules="all" ;;
971 esac
972
973 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
974
975 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
976 if ! [[ -f $srcmods/modules.dep ]]; then
977 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
978 dfatal "$srcmods/modules.dep is missing. Did you run depmod?"
979 exit 1
980 else
981 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
982 fi
983 elif ! ( command -v gzip &>/dev/null && command -v xz &>/dev/null); then
984 read _mod < $srcmods/modules.dep
985 _mod=${_mod%%:*}
986 if [[ -f $srcmods/"$_mod" ]]; then
987 # Check, if kernel modules are compressed, and if we can uncompress them
988 case "$_mod" in
989 *.ko.gz) kcompress=gzip;;
990 *.ko.xz) kcompress=xz;;
991 esac
992 if [[ $kcompress ]]; then
993 if ! command -v "$kcompress" &>/dev/null; then
994 dfatal "Kernel modules are compressed with $kcompress, but $kcompress is not available."
995 exit 1
996 fi
997 fi
998 fi
999 fi
1000 fi
1001
1002 if [[ ! $print_cmdline ]]; then
1003 if [[ -f $outfile && ! $force ]]; then
1004 dfatal "Will not override existing initramfs ($outfile) without --force"
1005 exit 1
1006 fi
1007
1008 outdir=${outfile%/*}
1009 [[ $outdir ]] || outdir="/"
1010
1011 if [[ ! -d "$outdir" ]]; then
1012 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1013 exit 1
1014 elif [[ ! -w "$outdir" ]]; then
1015 dfatal "No permission to write to $outdir."
1016 exit 1
1017 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1018 dfatal "No permission to write $outfile."
1019 exit 1
1020 fi
1021
1022 if [[ $loginstall ]]; then
1023 if ! mkdir -p "$loginstall"; then
1024 dfatal "Could not create directory to log installed files to '$loginstall'."
1025 exit 1
1026 fi
1027 loginstall=$(readlink -f "$loginstall")
1028 fi
1029
1030 if [[ $uefi = yes ]]; then
1031 if ! command -v objcopy &>/dev/null; then
1032 dfatal "Need 'objcopy' to create a UEFI executable"
1033 exit 1
1034 fi
1035 unset EFI_MACHINE_TYPE_NAME
1036 case $(arch) in
1037 x86_64)
1038 EFI_MACHINE_TYPE_NAME=x64;;
1039 ia32)
1040 EFI_MACHINE_TYPE_NAME=ia32;;
1041 *)
1042 dfatal "Architecture '$(arch)' not supported to create a UEFI executable"
1043 exit 1
1044 ;;
1045 esac
1046
1047 if ! [[ -s $uefi_stub ]]; then
1048 for uefi_stub in \
1049 "${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1050 "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1051 [[ -s $uefi_stub ]] || continue
1052 break
1053 done
1054 fi
1055 if ! [[ -s $uefi_stub ]]; then
1056 dfatal "Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1057 exit 1
1058 fi
1059
1060 if ! [[ $kernel_image ]]; then
1061 for kernel_image in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
1062 [[ -s "$kernel_image" ]] || continue
1063 break
1064 done
1065 fi
1066 if ! [[ -s $kernel_image ]]; then
1067 dfatal "Can't find a kernel image '$kernel_image' to create a UEFI executable"
1068 exit 1
1069 fi
1070 fi
1071 fi
1072
1073 if [[ $acpi_override = yes ]] && ! ( check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE ); then
1074 dwarn "Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1075 unset acpi_override
1076 fi
1077
1078 if [[ $early_microcode = yes ]]; then
1079 if [[ $hostonly ]]; then
1080 [[ $(get_cpu_vendor) == "AMD" ]] \
1081 && ! check_kernel_config CONFIG_MICROCODE_AMD \
1082 && unset early_microcode
1083 [[ $(get_cpu_vendor) == "Intel" ]] \
1084 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1085 && unset early_microcode
1086 else
1087 ! check_kernel_config CONFIG_MICROCODE_AMD \
1088 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1089 && unset early_microcode
1090 fi
1091 [[ $early_microcode != yes ]] \
1092 && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1093 fi
1094
1095 # Need to be able to have non-root users read stuff (rpcbind etc)
1096 chmod 755 "$initdir"
1097
1098 if [[ $hostonly ]]; then
1099 for i in /sys /proc /run /dev; do
1100 if ! findmnt --target "$i" &>/dev/null; then
1101 dwarning "Turning off host-only mode: '$i' is not mounted!"
1102 unset hostonly
1103 fi
1104 done
1105 fi
1106
1107 declare -A host_fs_types
1108
1109 for line in "${fstab_lines[@]}"; do
1110 set -- $line
1111 dev="$1"
1112 #dev mp fs fsopts
1113 case "$dev" in
1114 UUID=*)
1115 dev=$(blkid -l -t UUID=${dev#UUID=} -o device)
1116 ;;
1117 LABEL=*)
1118 dev=$(blkid -l -t LABEL=${dev#LABEL=} -o device)
1119 ;;
1120 PARTUUID=*)
1121 dev=$(blkid -l -t PARTUUID=${dev#PARTUUID=} -o device)
1122 ;;
1123 PARTLABEL=*)
1124 dev=$(blkid -l -t PARTLABEL=${dev#PARTLABEL=} -o device)
1125 ;;
1126 esac
1127 [ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue
1128 if [[ "$3" == btrfs ]]; then
1129 for i in $(btrfs_devs "$2"); do
1130 push_host_devs "$i"
1131 done
1132 fi
1133 push_host_devs "$dev"
1134 host_fs_types["$dev"]="$3"
1135 done
1136
1137 for f in $add_fstab; do
1138 [[ -e $f ]] || continue
1139 while read dev rest || [ -n "$dev" ]; do
1140 push_host_devs "$dev"
1141 done < "$f"
1142 done
1143
1144 for dev in $add_device; do
1145 push_host_devs "$dev"
1146 done
1147
1148 if (( ${#add_device_l[@]} )); then
1149 add_device+=" ${add_device_l[@]} "
1150 push_host_devs "${add_device_l[@]}"
1151 fi
1152
1153 if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
1154 # in hostonly mode, determine all devices, which have to be accessed
1155 # and examine them for filesystem types
1156
1157 for mp in \
1158 "/" \
1159 "/etc" \
1160 "/bin" \
1161 "/sbin" \
1162 "/lib" \
1163 "/lib64" \
1164 "/usr" \
1165 "/usr/bin" \
1166 "/usr/sbin" \
1167 "/usr/lib" \
1168 "/usr/lib64" \
1169 "/boot" \
1170 "/boot/efi" \
1171 ;
1172 do
1173 mp=$(readlink -f "$mp")
1174 mountpoint "$mp" >/dev/null 2>&1 || continue
1175 _dev=$(find_block_device "$mp")
1176 _bdev=$(readlink -f "/dev/block/$_dev")
1177 [[ -b $_bdev ]] && _dev=$_bdev
1178 [[ "$mp" == "/" ]] && root_devs+=("$_dev")
1179 push_host_devs "$_dev"
1180 if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
1181 for i in $(btrfs_devs "$mp"); do
1182 [[ "$mp" == "/" ]] && root_devs+=("$i")
1183 push_host_devs "$i"
1184 done
1185 fi
1186 done
1187
1188 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
1189 while read dev type rest || [ -n "$dev" ]; do
1190 [[ -b $dev ]] || continue
1191 [[ "$type" == "partition" ]] || continue
1192
1193 while read _d _m _t _o _r || [ -n "$_d" ]; do
1194 [[ "$_d" == \#* ]] && continue
1195 [[ $_d ]] || continue
1196 [[ $_t != "swap" ]] && continue
1197 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1198 [[ "$_o" == *noauto* ]] && continue
1199 _d=$(expand_persistent_dev "$_d")
1200 [[ "$_d" -ef "$dev" ]] || continue
1201
1202 if [[ -f /etc/crypttab ]]; then
1203 while read _mapper _a _p _o || [ -n "$_mapper" ]; do
1204 [[ $_mapper = \#* ]] && continue
1205 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
1206 [[ "$_o" ]] || _o="$_p"
1207 # skip entries with password files
1208 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1209 # skip mkswap swap
1210 [[ $_o == *swap* ]] && continue 2
1211 done < /etc/crypttab
1212 fi
1213
1214 _dev="$(readlink -f "$dev")"
1215 push_host_devs "$_dev"
1216 swap_devs+=("$_dev")
1217 break
1218 done < /etc/fstab
1219 done < /proc/swaps
1220 fi
1221
1222 # collect all "x-initrd.mount" entries from /etc/fstab
1223 if [[ -f /etc/fstab ]]; then
1224 while read _d _m _t _o _r || [ -n "$_d" ]; do
1225 [[ "$_d" == \#* ]] && continue
1226 [[ $_d ]] || continue
1227 [[ "$_o" != *x-initrd.mount* ]] && continue
1228 _dev=$(expand_persistent_dev "$_d")
1229 _dev="$(readlink -f "$_dev")"
1230 [[ -b $_dev ]] || continue
1231
1232 push_host_devs "$_dev"
1233 if [[ "$_t" == btrfs ]]; then
1234 for i in $(find_btrfs_devs "$_m"); do
1235 push_host_devs "$i"
1236 done
1237 fi
1238 done < /etc/fstab
1239 fi
1240 fi
1241
1242 unset m
1243 unset rest
1244
1245 _get_fs_type() {
1246 [[ $1 ]] || return
1247 if [[ -b /dev/block/$1 ]]; then
1248 ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
1249 return 1
1250 fi
1251 if [[ -b $1 ]]; then
1252 ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
1253 return 1
1254 fi
1255 if fstype=$(find_dev_fstype "$1"); then
1256 host_fs_types["$1"]="$fstype"
1257 return 1
1258 fi
1259 return 1
1260 }
1261
1262 for dev in "${host_devs[@]}"; do
1263 _get_fs_type "$dev"
1264 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1265 done
1266
1267 for dev in "${!host_fs_types[@]}"; do
1268 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
1269 rootopts=$(find_dev_fsopts "$dev")
1270 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1271 journaldev=$(fs_get_option $rootopts "jdev")
1272 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1273 journaldev=$(fs_get_option $rootopts "logdev")
1274 fi
1275 if [[ $journaldev ]]; then
1276 dev="$(readlink -f "$dev")"
1277 push_host_devs "$dev"
1278 _get_fs_type "$dev"
1279 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1280 fi
1281 done
1282
1283 [[ -d $udevdir ]] \
1284 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1285 if ! [[ -d "$udevdir" ]]; then
1286 [[ ! -h /lib ]] && [[ -d /lib/udev ]] && udevdir=/lib/udev
1287 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
1288 fi
1289
1290 [[ -d $systemdutildir ]] \
1291 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
1292
1293 if ! [[ -d "$systemdutildir" ]]; then
1294 [[ ! -h /lib ]] && [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
1295 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
1296 fi
1297
1298 [[ -d $systemdsystemunitdir ]] \
1299 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
1300
1301 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
1302
1303 [[ -d $systemdsystemconfdir ]] \
1304 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
1305
1306 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
1307
1308 [[ -d $tmpfilesdir ]] \
1309 || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null)
1310
1311 if ! [[ -d "$tmpfilesdir" ]]; then
1312 [[ -d /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d
1313 [[ -d /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d
1314 fi
1315
1316 export initdir dracutbasedir \
1317 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1318 mods_to_load \
1319 fw_dir drivers_dir debug no_kernel kernel_only \
1320 omit_drivers mdadmconf lvmconf root_devs \
1321 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1322 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1323 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1324 DRACUT_VERSION udevdir prefix filesystems drivers \
1325 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1326 hostonly_cmdline loginstall \
1327 tmpfilesdir
1328
1329 mods_to_load=""
1330 # check all our modules to see if they should be sourced.
1331 # This builds a list of modules that we will install next.
1332 for_each_module_dir check_module
1333 for_each_module_dir check_mount
1334
1335 dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
1336
1337 do_print_cmdline()
1338 {
1339 local -A _mods_to_print
1340 for i in $modules_loaded $mods_to_load; do
1341 _mods_to_print[$i]=1
1342 done
1343
1344 # source our modules.
1345 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1346 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1347 [[ ${_mods_to_print[$_d_mod]} ]] || continue
1348 module_cmdline "$_d_mod"
1349 done
1350 unset moddir
1351 }
1352
1353 if [[ $print_cmdline ]]; then
1354 do_print_cmdline
1355 printf "\n"
1356 exit 0
1357 fi
1358
1359 # Create some directory structure first
1360 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1361
1362 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1363 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1364
1365 if [[ $prefix ]]; then
1366 for d in bin etc lib sbin tmp usr var $libdirs; do
1367 [[ "$d" == */* ]] && continue
1368 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1369 done
1370 fi
1371
1372 if [[ $kernel_only != yes ]]; then
1373 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var var/tmp $libdirs; do
1374 [[ -e "${initdir}${prefix}/$d" ]] && continue
1375 if [ -L "/$d" ]; then
1376 inst_symlink "/$d" "${prefix}/$d"
1377 else
1378 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1379 fi
1380 done
1381
1382 for d in dev proc sys sysroot root run; do
1383 if [ -L "/$d" ]; then
1384 inst_symlink "/$d"
1385 else
1386 mkdir -m 0755 -p "$initdir/$d"
1387 fi
1388 done
1389
1390 ln -sfn ../run "$initdir/var/run"
1391 ln -sfn ../run/lock "$initdir/var/lock"
1392 else
1393 for d in lib "$libdir"; do
1394 [[ -e "${initdir}${prefix}/$d" ]] && continue
1395 if [ -h "/$d" ]; then
1396 inst "/$d" "${prefix}/$d"
1397 else
1398 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1399 fi
1400 done
1401 fi
1402
1403 if [[ $kernel_only != yes ]]; then
1404 mkdir -p "${initdir}/etc/cmdline.d"
1405 for _d in $hookdirs; do
1406 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1407 done
1408 if [[ "$EUID" = "0" ]]; then
1409 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1410 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1411 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1412 [ -c ${initdir}/dev/random ] || mknod ${initdir}/dev/random c 1 8
1413 [ -c ${initdir}/dev/urandom ] || mknod ${initdir}/dev/urandom c 1 9
1414 fi
1415 fi
1416
1417 _isize=0 #initramfs size
1418 modules_loaded=" "
1419 # source our modules.
1420 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1421 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1422 [[ "$mods_to_load" == *\ $_d_mod\ * ]] || continue
1423 if [[ $show_modules = yes ]]; then
1424 printf "%s\n" "$_d_mod"
1425 else
1426 dinfo "*** Including module: $_d_mod ***"
1427 fi
1428 if [[ $kernel_only == yes ]]; then
1429 module_installkernel "$_d_mod" || {
1430 dfatal "installkernel failed in module $_d_mod"
1431 exit 1
1432 }
1433 else
1434 module_install "$_d_mod"
1435 if [[ $no_kernel != yes ]]; then
1436 module_installkernel "$_d_mod" || {
1437 dfatal "installkernel failed in module $_d_mod"
1438 exit 1
1439 }
1440 fi
1441 fi
1442 mods_to_load=${mods_to_load// $_d_mod /}
1443 modules_loaded+="$_d_mod "
1444
1445 #print the module install size
1446 if [ -n "$printsize" ]; then
1447 _isize_new=$(du -sk ${initdir}|cut -f1)
1448 _isize_delta=$((_isize_new - _isize))
1449 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1450 _isize=$_isize_new
1451 fi
1452 done
1453 unset moddir
1454
1455 for i in $modules_loaded; do
1456 mkdir -p $initdir/lib/dracut
1457 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1458 done
1459
1460 dinfo "*** Including modules done ***"
1461
1462 ## final stuff that has to happen
1463 if [[ $no_kernel != yes ]]; then
1464
1465 if [[ $drivers ]]; then
1466 hostonly='' instmods $drivers
1467 fi
1468
1469 if [[ $add_drivers ]]; then
1470 hostonly='' instmods -c $add_drivers
1471 fi
1472 if [[ $force_drivers ]]; then
1473 hostonly='' instmods -c $force_drivers
1474 rm -f $initdir/etc/cmdline.d/20-force_driver.conf
1475 for mod in $force_drivers; do
1476 echo "rd.driver.pre=$mod" >>$initdir/etc/cmdline.d/20-force_drivers.conf
1477 done
1478 fi
1479 if [[ $filesystems ]]; then
1480 hostonly='' instmods -c $filesystems
1481 fi
1482
1483 dinfo "*** Installing kernel module dependencies ***"
1484 dracut_kernel_post
1485 dinfo "*** Installing kernel module dependencies done ***"
1486
1487 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1488 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1489 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1490 for i in ${initdir}/etc/cmdline.d/*.conf; do
1491 # We need no initramfs image and do not generate one.
1492 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1493 done
1494 fi
1495 fi
1496 fi
1497
1498 if [[ $kernel_only != yes ]]; then
1499 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1500 (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]}
1501
1502 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1503
1504 for line in "${fstab_lines[@]}"; do
1505 line=($line)
1506
1507 if [ -z "${line[1]}" ]; then
1508 # Determine device and mount options from current system
1509 mountpoint -q "${line[0]}" || derror "${line[0]} is not a mount point!"
1510 line=($(findmnt --raw -n --target "${line[0]}" --output=source,target,fstype,options))
1511 dinfo "Line for ${line[1]}: ${line[@]}"
1512 else
1513 # Use default options
1514 [ -z "${line[3]}" ] && line[3]="defaults"
1515 fi
1516
1517 # Default options for freq and passno
1518 [ -z "${line[4]}" ] && line[4]="0"
1519 [ -z "${line[5]}" ] && line[5]="2"
1520
1521 strstr "${line[2]}" "nfs" && line[5]="0"
1522 echo "${line[@]}" >> "${initdir}/etc/fstab"
1523 done
1524
1525 for f in $add_fstab; do
1526 cat "$f" >> "${initdir}/etc/fstab"
1527 done
1528
1529 if [[ $systemdutildir ]]; then
1530 if [ -d ${initdir}/$systemdutildir ]; then
1531 mkdir -p ${initdir}/etc/conf.d
1532 {
1533 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1534 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1535 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1536 } > ${initdir}/etc/conf.d/systemd.conf
1537 fi
1538 fi
1539
1540 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1541 dinfo "*** Resolving executable dependencies ***"
1542 find "$initdir" -type f -perm /0111 -not -path '*.ko' -print0 \
1543 | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-f} --
1544 dinfo "*** Resolving executable dependencies done***"
1545 fi
1546
1547 # Now we are done with lazy resolving, always install dependencies
1548 unset DRACUT_RESOLVE_LAZY
1549 export DRACUT_RESOLVE_DEPS=1
1550
1551 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1552 for _dir in $libdirs; do
1553 for _f in "$_dir/libpthread.so"*; do
1554 [[ -e "$_f" ]] || continue
1555 inst_libdir_file "libgcc_s.so*"
1556 break 2
1557 done
1558 done
1559 fi
1560
1561 for ((i=0; i < ${#include_src[@]}; i++)); do
1562 src="${include_src[$i]}"
1563 target="${include_target[$i]}"
1564 if [[ $src && $target ]]; then
1565 if [[ -f $src ]]; then
1566 inst $src $target
1567 else
1568 ddebug "Including directory: $src"
1569 destdir="${initdir}/${target}"
1570 mkdir -p "$destdir"
1571 # check for preexisting symlinks, so we can cope with the
1572 # symlinks to $prefix
1573 # Objectname is a file or a directory
1574 for objectname in "$src"/*; do
1575 [[ -e "$objectname" || -h "$objectname" ]] || continue
1576 if [[ -d "$objectname" ]]; then
1577 # objectname is a directory, let's compute the final directory name
1578 object_destdir=${destdir}/${objectname#$src/}
1579 if ! [[ -e "$object_destdir" ]]; then
1580 mkdir -m 0755 -p "$object_destdir"
1581 chmod --reference="$objectname" "$object_destdir"
1582 fi
1583 $DRACUT_CP -t "$object_destdir" "$objectname"/*
1584 else
1585 $DRACUT_CP -t "$destdir" "$objectname"
1586 fi
1587 done
1588 fi
1589 fi
1590 done
1591
1592 if [[ $kernel_only != yes ]]; then
1593 # make sure that library links are correct and up to date
1594 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1595 [[ -f $f ]] && inst_simple "$f"
1596 done
1597 if ! ldconfig -r "$initdir"; then
1598 if [[ $EUID = 0 ]]; then
1599 derror "ldconfig exited ungracefully"
1600 else
1601 derror "ldconfig might need uid=0 (root) for chroot()"
1602 fi
1603 fi
1604 fi
1605
1606 PRELINK_BIN="$(command -v prelink)"
1607 if [[ $EUID = 0 ]] && [[ $PRELINK_BIN ]]; then
1608 if [[ $DRACUT_FIPS_MODE ]]; then
1609 dinfo "*** Installing prelink files ***"
1610 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1611 elif [[ $do_prelink == yes ]]; then
1612 dinfo "*** Pre-linking files ***"
1613 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1614 chroot "$initdir" "$PRELINK_BIN" -a
1615 rm -f -- "$initdir/$PRELINK_BIN"
1616 rm -fr -- "$initdir"/etc/prelink.*
1617 dinfo "*** Pre-linking files done ***"
1618 fi
1619 fi
1620
1621 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1622 dinfo "*** Hardlinking files ***"
1623 hardlink "$initdir" 2>&1
1624 dinfo "*** Hardlinking files done ***"
1625 fi
1626
1627 # strip binaries
1628 if [[ $do_strip = yes ]] ; then
1629 # Prefer strip from elfutils for package size
1630 declare strip_cmd=$(command -v eu-strip)
1631 test -z "$strip_cmd" && strip_cmd="strip"
1632
1633 for p in $strip_cmd xargs find; do
1634 if ! type -P $p >/dev/null; then
1635 dinfo "Could not find '$p'. Not stripping the initramfs."
1636 do_strip=no
1637 fi
1638 done
1639 fi
1640
1641 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1642 dinfo "*** Stripping files ***"
1643 find "$initdir" -type f \
1644 -executable -not -path '*/lib/modules/*.ko' -print0 \
1645 | xargs -r -0 $strip_cmd -g 2>/dev/null
1646
1647 # strip kernel modules, but do not touch signed modules
1648 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1649 | while read -r -d $'\0' f || [ -n "$f" ]; do
1650 SIG=$(tail -c 28 "$f" | tr -d '\000')
1651 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1652 done | xargs -r -0 $strip_cmd -g
1653
1654 dinfo "*** Stripping files done ***"
1655 fi
1656 if [[ $early_microcode = yes ]]; then
1657 dinfo "*** Generating early-microcode cpio image ***"
1658 ucode_dir=(amd-ucode intel-ucode)
1659 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1660 _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
1661 _dest_idx="0 1"
1662 mkdir -p $_dest_dir
1663 if [[ $hostonly ]]; then
1664 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1665 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1666 fi
1667 for idx in $_dest_idx; do
1668 _fw=${ucode_dir[$idx]}
1669 for _fwdir in $fw_dir; do
1670 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1671 _src="*"
1672 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1673 if [[ $hostonly ]]; then
1674 _src=$(get_ucode_file)
1675 [[ $_src ]] || break
1676 [[ -r $_fwdir/$_fw/$_src ]] || break
1677 fi
1678
1679 for i in $_fwdir/$_fw/$_src; do
1680 [ -e "$i" ] && break
1681 break 2
1682 done
1683 for i in $_fwdir/$_fw/$_src; do
1684 [[ -e "$i" ]] || continue
1685 # skip gpg files
1686 str_ends "$i" ".asc" && continue
1687 cat "$i" >> $_dest_dir/${ucode_dest[$idx]}
1688 done
1689 create_early_cpio="yes"
1690 fi
1691 done
1692 done
1693 fi
1694
1695 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1696 dinfo "*** Packaging ACPI tables to override BIOS provided ones ***"
1697 _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi"
1698 mkdir -p $_dest_dir
1699 for table in $acpi_table_dir/*.aml; do
1700 dinfo " Adding ACPI table: $table"
1701 $DRACUT_CP $table $_dest_dir
1702 create_early_cpio="yes"
1703 done
1704 fi
1705
1706 dinfo "*** Store current command line parameters ***"
1707 if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
1708 dfatal "Could not store the current command line parameters"
1709 exit 1
1710 fi
1711
1712 if [[ $hostonly_cmdline == "yes" ]] ; then
1713 unset _stored_cmdline
1714 if [ -d $initdir/etc/cmdline.d ];then
1715 dinfo "Stored kernel commandline:"
1716 for conf in $initdir/etc/cmdline.d/*.conf ; do
1717 [ -e "$conf" ] || continue
1718 dinfo "$(< $conf)"
1719 _stored_cmdline=1
1720 done
1721 fi
1722 if ! [[ $_stored_cmdline ]]; then
1723 dinfo "No dracut internal kernel commandline stored in the initramfs"
1724 fi
1725 fi
1726
1727 dinfo "*** Creating image file '$outfile' ***"
1728
1729 if [[ $uefi = yes ]]; then
1730 readonly uefi_outdir="$DRACUT_TMPDIR/uefi"
1731 mkdir "$uefi_outdir"
1732 fi
1733
1734 if [[ $DRACUT_REPRODUCIBLE ]]; then
1735 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1736 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1737
1738 if [[ "$(cpio --help)" == *--reproducible* ]]; then
1739 CPIO_REPRODUCIBLE=1
1740 else
1741 dinfo "cpio does not support '--reproducible'. Resulting image will not be reproducible."
1742 fi
1743 fi
1744
1745 [[ "$EUID" != 0 ]] && cpio_owner_root="-R 0:0"
1746
1747 if [[ $create_early_cpio = yes ]]; then
1748 echo 1 > "$early_cpio_dir/d/early_cpio"
1749
1750 if [[ $DRACUT_REPRODUCIBLE ]]; then
1751 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1752 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1753 fi
1754
1755 # The microcode blob is _before_ the initramfs blob, not after
1756 if ! (
1757 umask 077; cd "$early_cpio_dir/d"
1758 find . -print0 | sort -z \
1759 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
1760 ); then
1761 dfatal "dracut: creation of $outfile failed"
1762 exit 1
1763 fi
1764 fi
1765
1766 if ! (
1767 umask 077; cd "$initdir"
1768 find . -print0 | sort -z \
1769 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet \
1770 | $compress >> "${DRACUT_TMPDIR}/initramfs.img"
1771 ); then
1772 dfatal "dracut: creation of $outfile failed"
1773 exit 1
1774 fi
1775
1776 if (( maxloglvl >= 5 )) && (( verbosity_mod_l >= 0 )); then
1777 if [[ $allowlocal ]]; then
1778 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img"| ddebug
1779 else
1780 lsinitrd "${DRACUT_TMPDIR}/initramfs.img"| ddebug
1781 fi
1782 fi
1783
1784 umask 077
1785
1786 if [[ $uefi = yes ]]; then
1787 if [[ $kernel_cmdline ]]; then
1788 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
1789 elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc/cmdline.d ];then
1790 for conf in $initdir/etc/cmdline.d/*.conf ; do
1791 [ -e "$conf" ] || continue
1792 printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
1793 done
1794 else
1795 do_print_cmdline > "$uefi_outdir/cmdline.txt"
1796 fi
1797 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
1798
1799 dinfo "Using UEFI kernel cmdline:"
1800 dinfo $(< "$uefi_outdir/cmdline.txt")
1801
1802 [[ -s /usr/lib/os-release ]] && uefi_osrelease="/usr/lib/os-release"
1803 [[ -s /etc/os-release ]] && uefi_osrelease="/etc/os-release"
1804
1805 if objcopy \
1806 ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
1807 --add-section .cmdline="${uefi_outdir}/cmdline.txt" --change-section-vma .cmdline=0x30000 \
1808 --add-section .linux="$kernel_image" --change-section-vma .linux=0x40000 \
1809 --add-section .initrd="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd=0x3000000 \
1810 "$uefi_stub" "${uefi_outdir}/linux.efi" \
1811 && cp --reflink=auto "${uefi_outdir}/linux.efi" "$outfile"; then
1812 dinfo "*** Creating UEFI image file '$outfile' done ***"
1813 else
1814 rm -f -- "$outfile"
1815 dfatal "*** Creating UEFI image file '$outfile' failed ***"
1816 exit 1
1817 fi
1818 else
1819 if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
1820 dinfo "*** Creating initramfs image file '$outfile' done ***"
1821 else
1822 rm -f -- "$outfile"
1823 dfatal "dracut: creation of $outfile failed"
1824 exit 1
1825 fi
1826 fi
1827
1828 command -v restorecon &>/dev/null && restorecon -- "$outfile"
1829
1830 if ! sync "$outfile" 2> /dev/null; then
1831 dinfo "dracut: sync operartion on newly created initramfs $outfile failed"
1832 exit 1
1833 fi
1834
1835 exit 0