]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
Remove obsolete prelinking functionality
[thirdparty/dracut.git] / dracut.sh
1 #!/bin/bash -p
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 unset BASH_ENV
27
28 # Verify bash version, current minimum is 4
29 if (( BASH_VERSINFO[0] < 4 )); then
30 printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
31 exit 1
32 fi
33
34 dracut_args=( "$@" )
35 readonly dracut_cmd="$(readlink -f $0)"
36
37 set -o pipefail
38
39 usage() {
40 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
41 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
42 . $dracutbasedir/dracut-version.sh
43 fi
44
45 # 80x25 linebreak here ^
46 cat << EOF
47 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
48
49 Version: $DRACUT_VERSION
50
51 Creates initial ramdisk images for preloading modules
52
53 -h, --help Display all options
54
55 If a [LIST] has multiple arguments, then you have to put these in quotes.
56
57 For example:
58
59 # dracut --add-drivers "module1 module2" ...
60
61 EOF
62 }
63
64 long_usage() {
65 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
66 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
67 . $dracutbasedir/dracut-version.sh
68 fi
69
70 # 80x25 linebreak here ^
71 cat << EOF
72 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
73
74 Version: $DRACUT_VERSION
75
76 Creates initial ramdisk images for preloading modules
77
78 --kver [VERSION] Set kernel version to [VERSION].
79 -f, --force Overwrite existing initramfs file.
80 -a, --add [LIST] Add a space-separated list of dracut modules.
81 --rebuild Append arguments to those of existing image and rebuild
82 -m, --modules [LIST] Specify a space-separated list of dracut modules to
83 call when building the initramfs. Modules are located
84 in /usr/lib/dracut/modules.d.
85 -o, --omit [LIST] Omit a space-separated list of dracut modules.
86 --force-add [LIST] Force to add a space-separated list of dracut modules
87 to the default set of modules, when -H is specified.
88 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
89 exclusively include in the initramfs.
90 --add-drivers [LIST] Specify a space-separated list of kernel
91 modules to add to the initramfs.
92 --force-drivers [LIST] Specify a space-separated list of kernel
93 modules to add to the initramfs and make sure they
94 are tried to be loaded via modprobe same as passing
95 rd.driver.pre=DRIVER kernel parameter.
96 --omit-drivers [LIST] Specify a space-separated list of kernel
97 modules not to add to the initramfs.
98 --filesystems [LIST] Specify a space-separated list of kernel filesystem
99 modules to exclusively include in the generic
100 initramfs.
101 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
102 modules
103 --fwdir [DIR] Specify additional directories, where to look for
104 firmwares, separated by :
105 --kernel-only Only install kernel drivers and firmware files
106 --no-kernel Do not install kernel drivers and firmware files
107 --print-cmdline Print the kernel command line for the given disk layout
108 --early-microcode Combine early microcode with ramdisk
109 --no-early-microcode Do not combine early microcode with ramdisk
110 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
111 --strip Strip binaries in the initramfs
112 --nostrip Do not strip 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 newat=()
290 for i in "$@"; do
291 if [[ $i == "-i" ]] || [[ $i == "--include" ]]; then
292 newat+=("++include") # Replace --include by ++include
293 else
294 newat+=("$i")
295 fi
296 done
297 set -- "${newat[@]}" # Set new $@
298
299 TEMP=$(unset POSIXLY_CORRECT; getopt \
300 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
301 --long kver: \
302 --long add: \
303 --long force-add: \
304 --long add-drivers: \
305 --long force-drivers: \
306 --long omit-drivers: \
307 --long modules: \
308 --long omit: \
309 --long drivers: \
310 --long filesystems: \
311 --long install: \
312 --long install-optional: \
313 --long fwdir: \
314 --long libdirs: \
315 --long fscks: \
316 --long add-fstab: \
317 --long mount: \
318 --long device: \
319 --long add-device: \
320 --long nofscks \
321 --long ro-mnt \
322 --long kmoddir: \
323 --long conf: \
324 --long confdir: \
325 --long tmpdir: \
326 --long stdlog: \
327 --long compress: \
328 --long prefix: \
329 --long rebuild: \
330 --long force \
331 --long kernel-only \
332 --long no-kernel \
333 --long print-cmdline \
334 --long kernel-cmdline: \
335 --long strip \
336 --long nostrip \
337 --long hardlink \
338 --long nohardlink \
339 --long noprefix \
340 --long mdadmconf \
341 --long nomdadmconf \
342 --long lvmconf \
343 --long nolvmconf \
344 --long debug \
345 --long profile \
346 --long sshkey: \
347 --long logfile: \
348 --long verbose \
349 --long quiet \
350 --long local \
351 --long hostonly \
352 --long host-only \
353 --long no-hostonly \
354 --long no-host-only \
355 --long hostonly-cmdline \
356 --long no-hostonly-cmdline \
357 --long no-hostonly-default-device \
358 --long persistent-policy: \
359 --long fstab \
360 --long help \
361 --long bzip2 \
362 --long lzma \
363 --long xz \
364 --long lzo \
365 --long lz4 \
366 --long zstd \
367 --long no-compress \
368 --long gzip \
369 --long list-modules \
370 --long show-modules \
371 --long keep \
372 --long printsize \
373 --long regenerate-all \
374 --long noimageifnotneeded \
375 --long early-microcode \
376 --long no-early-microcode \
377 --long reproducible \
378 --long no-reproducible \
379 --long loginstall: \
380 --long uefi \
381 --long uefi-stub: \
382 --long kernel-image: \
383 --long no-hostonly-i18n \
384 --long hostonly-i18n \
385 --long no-machineid \
386 -- "$@")
387
388 if (( $? != 0 )); then
389 usage
390 exit 1
391 fi
392 }
393
394 verbosity_mod_l=0
395 unset kernel
396 unset outfile
397
398 rearrange_params "$@"
399 eval set -- "$TEMP"
400
401 # parse command line args to check if '--rebuild' option is present
402 unset append_args_l
403 unset rebuild_file
404 while :
405 do
406 if [ "$1" == "--" ]; then
407 shift; break
408 fi
409 if [ "$1" == "--rebuild" ]; then
410 append_args_l="yes"
411 rebuild_file=$2
412 if [ ! -e $rebuild_file ]; then
413 echo "Image file '$rebuild_file', for rebuild, does not exist!"
414 exit 1
415 fi
416 abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
417 shift; continue
418 fi
419 shift
420 done
421
422 # get output file name and kernel version from command line arguments
423 while (($# > 0)); do
424 case ${1%%=*} in
425 ++include)
426 shift 2;;
427 *)
428 if ! [[ ${outfile+x} ]]; then
429 outfile=$1
430 elif ! [[ ${kernel+x} ]]; then
431 kernel=$1
432 else
433 printf "\nUnknown arguments: %s\n\n" "$*" >&2
434 usage; exit 1;
435 fi
436 ;;
437 esac
438 shift
439 done
440
441 # extract input image file provided with rebuild option to get previous parameters, if any
442 if [[ $append_args_l == "yes" ]]; then
443 unset rebuild_param
444
445 # determine resultant file
446 if ! [[ $outfile ]]; then
447 outfile=$rebuild_file
448 fi
449
450 if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
451 echo "Image '$rebuild_file' has no rebuild information stored"
452 exit 1
453 fi
454
455 # prepend previous parameters to current command line args
456 if [[ $rebuild_param ]]; then
457 TEMP="$rebuild_param $TEMP"
458 eval set -- "$TEMP"
459 rearrange_params "$@"
460 fi
461
462 # clean the temporarily used scratch-pad directory
463 rm -rf $scratch_dir
464 fi
465
466 unset PARMS_TO_STORE
467 PARMS_TO_STORE=""
468
469 eval set -- "$TEMP"
470
471 while :; do
472 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
473 PARMS_TO_STORE+=" $1";
474 fi
475 case $1 in
476 --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
477 -a|--add) add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
478 --force-add) force_add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
479 --add-drivers) add_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
480 --force-drivers) force_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
481 --omit-drivers) omit_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
482 -m|--modules) dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
483 -o|--omit) omit_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
484 -d|--drivers) drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
485 --filesystems) filesystems_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
486 -I|--install) install_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
487 --install-optional) install_optional_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
488 --fwdir) fw_dir_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
489 --libdirs) libdirs_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
490 --fscks) fscks_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
491 --add-fstab) add_fstab_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
492 --mount) fstab_lines+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
493 --add-device|--device) add_device_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
494 --kernel-cmdline) kernel_cmdline_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
495 --nofscks) nofscks_l="yes";;
496 --ro-mnt) ro_mnt_l="yes";;
497 -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
498 -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
499 --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
500 --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
501 -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
502 --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
503 --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
504 --loginstall) loginstall_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
505 --rebuild) if [ $rebuild_file == $outfile ]; then
506 force=yes
507 fi
508 shift
509 ;;
510 -f|--force) force=yes;;
511 --kernel-only) kernel_only="yes"; no_kernel="no";;
512 --no-kernel) kernel_only="no"; no_kernel="yes";;
513 --print-cmdline)
514 print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
515 --early-microcode)
516 early_microcode_l="yes";;
517 --no-early-microcode)
518 early_microcode_l="no";;
519 --strip) do_strip_l="yes";;
520 --nostrip) do_strip_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_hardlink_l ]] && do_hardlink=$do_hardlink_l
724 [[ $do_hardlink ]] || do_hardlink=yes
725 [[ $prefix_l ]] && prefix=$prefix_l
726 [[ $prefix = "/" ]] && unset prefix
727 [[ $hostonly_l ]] && hostonly=$hostonly_l
728 [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
729 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes"
730 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
731 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
732 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
733 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
734 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
735 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
736 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
737 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
738 [[ $tmpdir ]] || tmpdir=/var/tmp
739 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
740 [[ $compress_l ]] && compress=$compress_l
741 [[ $show_modules_l ]] && show_modules=$show_modules_l
742 [[ $nofscks_l ]] && nofscks="yes"
743 [[ $ro_mnt_l ]] && ro_mnt="yes"
744 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
745 [[ $early_microcode ]] || early_microcode=yes
746 [[ $logfile_l ]] && logfile="$logfile_l"
747 [[ $reproducible_l ]] && reproducible="$reproducible_l"
748 [[ $loginstall_l ]] && loginstall="$loginstall_l"
749 [[ $uefi_stub_l ]] && uefi_stub="$uefi_stub_l"
750 [[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
751 [[ $machine_id_l ]] && machine_id="$machine_id_l"
752
753 if ! [[ $outfile ]]; then
754 if [[ $machine_id != "no" ]]; then
755 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
756 fi
757
758 if [[ $uefi == "yes" ]]; then
759 BUILD_ID=$(cat /etc/os-release /usr/lib/os-release \
760 | while read -r line || [[ $line ]]; do \
761 [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
762 done)
763 if [[ -d /efi ]] && mountpoint -q /efi; then
764 efidir=/efi
765 else
766 efidir=/boot/EFI
767 if [[ -d /boot/efi/EFI ]] && mountpoint -q /boot/efi; then
768 efidir=/boot/efi/EFI
769 fi
770 fi
771 mkdir -p "$efidir/Linux"
772 outfile="$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
773 else
774 if [[ -e "/boot/vmlinuz-$kernel" ]]; then
775 outfile="/boot/initramfs-$kernel.img"
776 elif [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
777 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
778 else
779 outfile="/boot/initramfs-$kernel.img"
780 fi
781 fi
782 fi
783
784 # eliminate IFS hackery when messing with fw_dir
785 export DRACUT_FIRMWARE_PATH=${fw_dir// /:}
786 fw_dir=${fw_dir//:/ }
787
788 # check for logfile and try to create one if it doesn't exist
789 if [[ -n "$logfile" ]];then
790 if [[ ! -f "$logfile" ]];then
791 touch "$logfile"
792 if [ ! $? -eq 0 ] ;then
793 printf "%s\n" "dracut: touch $logfile failed." >&2
794 fi
795 fi
796 fi
797
798 # handle compression options.
799 if [[ $_no_compress_l = "cat" ]]; then
800 compress="cat"
801 fi
802
803 if ! [[ $compress ]]; then
804 # check all known compressors, if none specified
805 for i in pigz gzip lz4 lzop zstd lzma xz lbzip2 bzip2 cat; do
806 command -v "$i" &>/dev/null || continue
807 compress="$i"
808 break
809 done
810 if [[ $compress = cat ]]; then
811 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
812 fi
813 fi
814
815 # choose the right arguments for the compressor
816 case $compress in
817 bzip2|lbzip2)
818 if [[ "$compress" = lbzip2 ]] || command -v lbzip2 &>/dev/null; then
819 compress="lbzip2 -9"
820 else
821 compress="bzip2 -9"
822 fi
823 ;;
824 lzma)
825 compress="lzma -9 -T0"
826 ;;
827 xz)
828 compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
829 ;;
830 gzip|pigz)
831 if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
832 compress="pigz -9 -n -T -R"
833 elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
834 compress="gzip -n -9 --rsyncable"
835 else
836 compress="gzip -n -9"
837 fi
838 ;;
839 lzo|lzop)
840 compress="lzop -9"
841 ;;
842 lz4)
843 compress="lz4 -l -9"
844 ;;
845 zstd)
846 compress="zstd -15 -q -T0"
847 ;;
848 esac
849
850 [[ $hostonly = yes ]] && hostonly="-h"
851 [[ $hostonly != "-h" ]] && unset hostonly
852
853 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
854
855 readonly TMPDIR="$(realpath -e "$tmpdir")"
856 [ -d "$TMPDIR" ] || {
857 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
858 exit 1
859 }
860 readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
861 [ -d "$DRACUT_TMPDIR" ] || {
862 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
863 exit 1
864 }
865
866 # clean up after ourselves no matter how we die.
867 trap '
868 ret=$?;
869 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
870 exit $ret;
871 ' EXIT
872
873 # clean up after ourselves no matter how we die.
874 trap 'exit 1;' SIGINT
875
876 readonly initdir="${DRACUT_TMPDIR}/initramfs"
877 mkdir "$initdir"
878
879 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
880 readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio"
881 mkdir "$early_cpio_dir"
882 fi
883
884 export DRACUT_RESOLVE_LAZY="1"
885
886 if [[ $print_cmdline ]]; then
887 stdloglvl=0
888 sysloglvl=0
889 fileloglvl=0
890 kmsgloglvl=0
891 fi
892
893 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
894 . $dracutbasedir/dracut-version.sh
895 fi
896
897 if [[ -f $dracutbasedir/dracut-init.sh ]]; then
898 . $dracutbasedir/dracut-init.sh
899 else
900 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
901 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
902 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
903 exit 1
904 fi
905
906 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
907 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
908 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
909 exit 1
910 fi
911
912 if ! [[ $print_cmdline ]]; then
913 inst /bin/sh
914 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
915 unset DRACUT_RESOLVE_LAZY
916 export DRACUT_RESOLVE_DEPS=1
917 fi
918 rm -fr -- ${initdir}/*
919 fi
920
921 dracutfunctions=$dracutbasedir/dracut-functions.sh
922 export dracutfunctions
923
924 (( ${#drivers_l[@]} )) && drivers="${drivers_l[@]}"
925 drivers=${drivers/-/_}
926
927 (( ${#add_drivers_l[@]} )) && add_drivers+=" ${add_drivers_l[@]} "
928 add_drivers=${add_drivers/-/_}
929
930 (( ${#force_drivers_l[@]} )) && force_drivers+=" ${force_drivers_l[@]} "
931 force_drivers=${force_drivers/-/_}
932
933 (( ${#omit_drivers_l[@]} )) && omit_drivers+=" ${omit_drivers_l[@]} "
934 omit_drivers=${omit_drivers/-/_}
935
936 (( ${#kernel_cmdline_l[@]} )) && kernel_cmdline+=" ${kernel_cmdline_l[@]} "
937
938 omit_drivers_corrected=""
939 for d in $omit_drivers; do
940 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
941 [[ " $drivers $force_drivers " == *\ $d\ * ]] && continue
942 omit_drivers_corrected+="$d|"
943 done
944 omit_drivers="${omit_drivers_corrected%|}"
945 unset omit_drivers_corrected
946
947 # prepare args for logging
948 for ((i=0; i < ${#dracut_args[@]}; i++)); do
949 [[ "${dracut_args[$i]}" == *\ * ]] && \
950 dracut_args[$i]="\"${dracut_args[$i]}\""
951 #" keep vim happy
952 done
953
954 dinfo "Executing: $dracut_cmd ${dracut_args[@]}"
955
956 [[ $do_list = yes ]] && {
957 for mod in $dracutbasedir/modules.d/*; do
958 [[ -d $mod ]] || continue;
959 [[ -e $mod/install || -e $mod/installkernel || \
960 -e $mod/module-setup.sh ]] || continue
961 printf "%s\n" "${mod##*/??}"
962 done
963 exit 0
964 }
965
966 # This is kinda legacy -- eventually it should go away.
967 case $dracutmodules in
968 ""|auto) dracutmodules="all" ;;
969 esac
970
971 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
972
973 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
974 if ! [[ -f $srcmods/modules.dep ]]; then
975 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
976 dfatal "$srcmods/modules.dep is missing. Did you run depmod?"
977 exit 1
978 else
979 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
980 fi
981 elif ! ( command -v gzip &>/dev/null && command -v xz &>/dev/null); then
982 read _mod < $srcmods/modules.dep
983 _mod=${_mod%%:*}
984 if [[ -f $srcmods/"$_mod" ]]; then
985 # Check, if kernel modules are compressed, and if we can uncompress them
986 case "$_mod" in
987 *.ko.gz) kcompress=gzip;;
988 *.ko.xz) kcompress=xz;;
989 esac
990 if [[ $kcompress ]]; then
991 if ! command -v "$kcompress" &>/dev/null; then
992 dfatal "Kernel modules are compressed with $kcompress, but $kcompress is not available."
993 exit 1
994 fi
995 fi
996 fi
997 fi
998 fi
999
1000 if [[ ! $print_cmdline ]]; then
1001 if [[ -f $outfile && ! $force ]]; then
1002 dfatal "Will not override existing initramfs ($outfile) without --force"
1003 exit 1
1004 fi
1005
1006 outdir=${outfile%/*}
1007 [[ $outdir ]] || outdir="/"
1008
1009 if [[ ! -d "$outdir" ]]; then
1010 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1011 exit 1
1012 elif [[ ! -w "$outdir" ]]; then
1013 dfatal "No permission to write to $outdir."
1014 exit 1
1015 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1016 dfatal "No permission to write $outfile."
1017 exit 1
1018 fi
1019
1020 if [[ $loginstall ]]; then
1021 if ! mkdir -p "$loginstall"; then
1022 dfatal "Could not create directory to log installed files to '$loginstall'."
1023 exit 1
1024 fi
1025 loginstall=$(readlink -f "$loginstall")
1026 fi
1027
1028 if [[ $uefi = yes ]]; then
1029 if ! command -v objcopy &>/dev/null; then
1030 dfatal "Need 'objcopy' to create a UEFI executable"
1031 exit 1
1032 fi
1033 unset EFI_MACHINE_TYPE_NAME
1034 case $(arch) in
1035 x86_64)
1036 EFI_MACHINE_TYPE_NAME=x64;;
1037 ia32)
1038 EFI_MACHINE_TYPE_NAME=ia32;;
1039 *)
1040 dfatal "Architecture '$(arch)' not supported to create a UEFI executable"
1041 exit 1
1042 ;;
1043 esac
1044
1045 if ! [[ -s $uefi_stub ]]; then
1046 for uefi_stub in \
1047 "${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1048 "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1049 [[ -s $uefi_stub ]] || continue
1050 break
1051 done
1052 fi
1053 if ! [[ -s $uefi_stub ]]; then
1054 dfatal "Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1055 exit 1
1056 fi
1057
1058 if ! [[ $kernel_image ]]; then
1059 for kernel_image in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
1060 [[ -s "$kernel_image" ]] || continue
1061 break
1062 done
1063 fi
1064 if ! [[ -s $kernel_image ]]; then
1065 dfatal "Can't find a kernel image '$kernel_image' to create a UEFI executable"
1066 exit 1
1067 fi
1068 fi
1069 fi
1070
1071 if [[ $acpi_override = yes ]] && ! ( check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE ); then
1072 dwarn "Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1073 unset acpi_override
1074 fi
1075
1076 if [[ $early_microcode = yes ]]; then
1077 if [[ $hostonly ]]; then
1078 [[ $(get_cpu_vendor) == "AMD" ]] \
1079 && ! check_kernel_config CONFIG_MICROCODE_AMD \
1080 && unset early_microcode
1081 [[ $(get_cpu_vendor) == "Intel" ]] \
1082 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1083 && unset early_microcode
1084 else
1085 ! check_kernel_config CONFIG_MICROCODE_AMD \
1086 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1087 && unset early_microcode
1088 fi
1089 [[ $early_microcode != yes ]] \
1090 && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1091 fi
1092
1093 # Need to be able to have non-root users read stuff (rpcbind etc)
1094 chmod 755 "$initdir"
1095
1096 if [[ $hostonly ]]; then
1097 for i in /sys /proc /run /dev; do
1098 if ! findmnt --target "$i" &>/dev/null; then
1099 dwarning "Turning off host-only mode: '$i' is not mounted!"
1100 unset hostonly
1101 fi
1102 done
1103 fi
1104
1105 declare -A host_fs_types
1106
1107 for line in "${fstab_lines[@]}"; do
1108 set -- $line
1109 dev="$1"
1110 #dev mp fs fsopts
1111 case "$dev" in
1112 UUID=*)
1113 dev=$(blkid -l -t UUID=${dev#UUID=} -o device)
1114 ;;
1115 LABEL=*)
1116 dev=$(blkid -l -t LABEL=${dev#LABEL=} -o device)
1117 ;;
1118 PARTUUID=*)
1119 dev=$(blkid -l -t PARTUUID=${dev#PARTUUID=} -o device)
1120 ;;
1121 PARTLABEL=*)
1122 dev=$(blkid -l -t PARTLABEL=${dev#PARTLABEL=} -o device)
1123 ;;
1124 esac
1125 [ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue
1126 if [[ "$3" == btrfs ]]; then
1127 for i in $(btrfs_devs "$2"); do
1128 push_host_devs "$i"
1129 done
1130 fi
1131 push_host_devs "$dev"
1132 host_fs_types["$dev"]="$3"
1133 done
1134
1135 for f in $add_fstab; do
1136 [[ -e $f ]] || continue
1137 while read dev rest || [ -n "$dev" ]; do
1138 push_host_devs "$dev"
1139 done < "$f"
1140 done
1141
1142 for dev in $add_device; do
1143 push_host_devs "$dev"
1144 done
1145
1146 if (( ${#add_device_l[@]} )); then
1147 add_device+=" ${add_device_l[@]} "
1148 push_host_devs "${add_device_l[@]}"
1149 fi
1150
1151 if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
1152 # in hostonly mode, determine all devices, which have to be accessed
1153 # and examine them for filesystem types
1154
1155 for mp in \
1156 "/" \
1157 "/etc" \
1158 "/bin" \
1159 "/sbin" \
1160 "/lib" \
1161 "/lib64" \
1162 "/usr" \
1163 "/usr/bin" \
1164 "/usr/sbin" \
1165 "/usr/lib" \
1166 "/usr/lib64" \
1167 "/boot" \
1168 "/boot/efi" \
1169 "/boot/zipl" \
1170 ;
1171 do
1172 mp=$(readlink -f "$mp")
1173 mountpoint "$mp" >/dev/null 2>&1 || continue
1174 _dev=$(find_block_device "$mp")
1175 _bdev=$(readlink -f "/dev/block/$_dev")
1176 [[ -b $_bdev ]] && _dev=$_bdev
1177 [[ "$mp" == "/" ]] && root_devs+=("$_dev")
1178 push_host_devs "$_dev"
1179 if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
1180 for i in $(btrfs_devs "$mp"); do
1181 [[ "$mp" == "/" ]] && root_devs+=("$i")
1182 push_host_devs "$i"
1183 done
1184 fi
1185 done
1186
1187 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
1188 while read dev type rest || [ -n "$dev" ]; do
1189 [[ -b $dev ]] || continue
1190 [[ "$type" == "partition" ]] || continue
1191
1192 while read _d _m _t _o _r || [ -n "$_d" ]; do
1193 [[ "$_d" == \#* ]] && continue
1194 [[ $_d ]] || continue
1195 [[ $_t != "swap" ]] && continue
1196 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1197 [[ "$_o" == *noauto* ]] && continue
1198 _d=$(expand_persistent_dev "$_d")
1199 [[ "$_d" -ef "$dev" ]] || continue
1200
1201 if [[ -f /etc/crypttab ]]; then
1202 while read _mapper _a _p _o || [ -n "$_mapper" ]; do
1203 [[ $_mapper = \#* ]] && continue
1204 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
1205 [[ "$_o" ]] || _o="$_p"
1206 # skip entries with password files
1207 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1208 # skip mkswap swap
1209 [[ $_o == *swap* ]] && continue 2
1210 done < /etc/crypttab
1211 fi
1212
1213 _dev="$(readlink -f "$dev")"
1214 push_host_devs "$_dev"
1215 swap_devs+=("$_dev")
1216 break
1217 done < /etc/fstab
1218 done < /proc/swaps
1219 fi
1220
1221 # collect all "x-initrd.mount" entries from /etc/fstab
1222 if [[ -f /etc/fstab ]]; then
1223 while read _d _m _t _o _r || [ -n "$_d" ]; do
1224 [[ "$_d" == \#* ]] && continue
1225 [[ $_d ]] || continue
1226 [[ "$_o" != *x-initrd.mount* ]] && continue
1227 _dev=$(expand_persistent_dev "$_d")
1228 _dev="$(readlink -f "$_dev")"
1229 [[ -b $_dev ]] || continue
1230
1231 push_host_devs "$_dev"
1232 if [[ "$_t" == btrfs ]]; then
1233 for i in $(btrfs_devs "$_m"); do
1234 push_host_devs "$i"
1235 done
1236 fi
1237 done < /etc/fstab
1238 fi
1239 fi
1240
1241 unset m
1242 unset rest
1243
1244 _get_fs_type() {
1245 [[ $1 ]] || return
1246 if [[ -b /dev/block/$1 ]]; then
1247 ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
1248 return 1
1249 fi
1250 if [[ -b $1 ]]; then
1251 ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
1252 return 1
1253 fi
1254 if fstype=$(find_dev_fstype "$1"); then
1255 host_fs_types["$1"]="$fstype"
1256 return 1
1257 fi
1258 return 1
1259 }
1260
1261 for dev in "${host_devs[@]}"; do
1262 _get_fs_type "$dev"
1263 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1264 done
1265
1266 for dev in "${!host_fs_types[@]}"; do
1267 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
1268 rootopts=$(find_dev_fsopts "$dev")
1269 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1270 journaldev=$(fs_get_option $rootopts "jdev")
1271 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1272 journaldev=$(fs_get_option $rootopts "logdev")
1273 fi
1274 if [[ $journaldev ]]; then
1275 dev="$(readlink -f "$dev")"
1276 push_host_devs "$dev"
1277 _get_fs_type "$dev"
1278 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1279 fi
1280 done
1281
1282 [[ -d $udevdir ]] \
1283 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1284 if ! [[ -d "$udevdir" ]]; then
1285 [[ ! -h /lib ]] && [[ -d /lib/udev ]] && udevdir=/lib/udev
1286 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
1287 fi
1288
1289 [[ -d $systemdutildir ]] \
1290 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
1291
1292 if ! [[ -d "$systemdutildir" ]]; then
1293 [[ ! -h /lib ]] && [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
1294 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
1295 fi
1296
1297 [[ -d $systemdsystemunitdir ]] \
1298 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
1299
1300 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
1301
1302 [[ -d $systemdsystemconfdir ]] \
1303 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
1304
1305 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
1306
1307 [[ -d $tmpfilesdir ]] \
1308 || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null)
1309
1310 if ! [[ -d "$tmpfilesdir" ]]; then
1311 [[ -d /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d
1312 [[ -d /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d
1313 fi
1314
1315 export initdir dracutbasedir \
1316 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1317 mods_to_load \
1318 fw_dir drivers_dir debug no_kernel kernel_only \
1319 omit_drivers mdadmconf lvmconf root_devs \
1320 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1321 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1322 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1323 DRACUT_VERSION udevdir prefix filesystems drivers \
1324 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1325 hostonly_cmdline loginstall \
1326 tmpfilesdir
1327
1328 mods_to_load=""
1329 # check all our modules to see if they should be sourced.
1330 # This builds a list of modules that we will install next.
1331 for_each_module_dir check_module
1332 for_each_module_dir check_mount
1333
1334 dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
1335
1336 do_print_cmdline()
1337 {
1338 local -A _mods_to_print
1339 for i in $modules_loaded $mods_to_load; do
1340 _mods_to_print[$i]=1
1341 done
1342
1343 # source our modules.
1344 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1345 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1346 [[ ${_mods_to_print[$_d_mod]} ]] || continue
1347 module_cmdline "$_d_mod"
1348 done
1349 unset moddir
1350 }
1351
1352 if [[ $print_cmdline ]]; then
1353 do_print_cmdline
1354 printf "\n"
1355 exit 0
1356 fi
1357
1358 # Create some directory structure first
1359 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1360
1361 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1362 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1363
1364 if [[ $prefix ]]; then
1365 for d in bin etc lib sbin tmp usr var $libdirs; do
1366 [[ "$d" == */* ]] && continue
1367 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1368 done
1369 fi
1370
1371 if [[ $kernel_only != yes ]]; then
1372 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var var/tmp $libdirs; do
1373 [[ -e "${initdir}${prefix}/$d" ]] && continue
1374 if [ -L "/$d" ]; then
1375 inst_symlink "/$d" "${prefix}/$d"
1376 else
1377 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1378 fi
1379 done
1380
1381 for d in dev proc sys sysroot root run; do
1382 if [ -L "/$d" ]; then
1383 inst_symlink "/$d"
1384 else
1385 mkdir -m 0755 -p "$initdir/$d"
1386 fi
1387 done
1388
1389 ln -sfn ../run "$initdir/var/run"
1390 ln -sfn ../run/lock "$initdir/var/lock"
1391 else
1392 for d in lib "$libdir"; do
1393 [[ -e "${initdir}${prefix}/$d" ]] && continue
1394 if [ -h "/$d" ]; then
1395 inst "/$d" "${prefix}/$d"
1396 else
1397 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1398 fi
1399 done
1400 fi
1401
1402 if [[ $kernel_only != yes ]]; then
1403 mkdir -p "${initdir}/etc/cmdline.d"
1404 for _d in $hookdirs; do
1405 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1406 done
1407 if [[ "$EUID" = "0" ]]; then
1408 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1409 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1410 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1411 [ -c ${initdir}/dev/random ] || mknod ${initdir}/dev/random c 1 8
1412 [ -c ${initdir}/dev/urandom ] || mknod ${initdir}/dev/urandom c 1 9
1413 fi
1414 fi
1415
1416 _isize=0 #initramfs size
1417 modules_loaded=" "
1418 # source our modules.
1419 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1420 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1421 [[ "$mods_to_load" == *\ $_d_mod\ * ]] || continue
1422 if [[ $show_modules = yes ]]; then
1423 printf "%s\n" "$_d_mod"
1424 else
1425 dinfo "*** Including module: $_d_mod ***"
1426 fi
1427 if [[ $kernel_only == yes ]]; then
1428 module_installkernel "$_d_mod" || {
1429 dfatal "installkernel failed in module $_d_mod"
1430 exit 1
1431 }
1432 else
1433 module_install "$_d_mod"
1434 if [[ $no_kernel != yes ]]; then
1435 module_installkernel "$_d_mod" || {
1436 dfatal "installkernel failed in module $_d_mod"
1437 exit 1
1438 }
1439 fi
1440 fi
1441 mods_to_load=${mods_to_load// $_d_mod /}
1442 modules_loaded+="$_d_mod "
1443
1444 #print the module install size
1445 if [ -n "$printsize" ]; then
1446 _isize_new=$(du -sk ${initdir}|cut -f1)
1447 _isize_delta=$((_isize_new - _isize))
1448 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1449 _isize=$_isize_new
1450 fi
1451 done
1452 unset moddir
1453
1454 for i in $modules_loaded; do
1455 mkdir -p $initdir/lib/dracut
1456 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1457 done
1458
1459 dinfo "*** Including modules done ***"
1460
1461 ## final stuff that has to happen
1462 if [[ $no_kernel != yes ]]; then
1463
1464 if [[ $drivers ]]; then
1465 hostonly='' instmods $drivers
1466 fi
1467
1468 if [[ -n "${add_drivers// }" ]]; then
1469 hostonly='' instmods -c $add_drivers
1470 fi
1471 if [[ $force_drivers ]]; then
1472 hostonly='' instmods -c $force_drivers
1473 rm -f $initdir/etc/cmdline.d/20-force_driver.conf
1474 for mod in $force_drivers; do
1475 echo "rd.driver.pre=$mod" >>$initdir/etc/cmdline.d/20-force_drivers.conf
1476 done
1477 fi
1478 if [[ $filesystems ]]; then
1479 hostonly='' instmods -c $filesystems
1480 fi
1481
1482 dinfo "*** Installing kernel module dependencies ***"
1483 dracut_kernel_post
1484 dinfo "*** Installing kernel module dependencies done ***"
1485
1486 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1487 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1488 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1489 for i in ${initdir}/etc/cmdline.d/*.conf; do
1490 # We need no initramfs image and do not generate one.
1491 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1492 done
1493 fi
1494 fi
1495 fi
1496
1497 if [[ $kernel_only != yes ]]; then
1498 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1499 (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]}
1500
1501 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1502
1503 for line in "${fstab_lines[@]}"; do
1504 line=($line)
1505
1506 if [ -z "${line[1]}" ]; then
1507 # Determine device and mount options from current system
1508 mountpoint -q "${line[0]}" || derror "${line[0]} is not a mount point!"
1509 line=($(findmnt --raw -n --target "${line[0]}" --output=source,target,fstype,options))
1510 dinfo "Line for ${line[1]}: ${line[@]}"
1511 else
1512 # Use default options
1513 [ -z "${line[3]}" ] && line[3]="defaults"
1514 fi
1515
1516 # Default options for freq and passno
1517 [ -z "${line[4]}" ] && line[4]="0"
1518 [ -z "${line[5]}" ] && line[5]="2"
1519
1520 strstr "${line[2]}" "nfs" && line[5]="0"
1521 echo "${line[@]}" >> "${initdir}/etc/fstab"
1522 done
1523
1524 for f in $add_fstab; do
1525 cat "$f" >> "${initdir}/etc/fstab"
1526 done
1527
1528 if [[ $systemdutildir ]]; then
1529 if [ -d ${initdir}/$systemdutildir ]; then
1530 mkdir -p ${initdir}/etc/conf.d
1531 {
1532 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1533 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1534 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1535 } > ${initdir}/etc/conf.d/systemd.conf
1536 fi
1537 fi
1538
1539 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1540 dinfo "*** Resolving executable dependencies ***"
1541 find "$initdir" -type f -perm /0111 -not -path '*.ko' -print0 \
1542 | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-f} --
1543 dinfo "*** Resolving executable dependencies done***"
1544 fi
1545
1546 # Now we are done with lazy resolving, always install dependencies
1547 unset DRACUT_RESOLVE_LAZY
1548 export DRACUT_RESOLVE_DEPS=1
1549
1550 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1551 for _dir in $libdirs; do
1552 for _f in "$_dir/libpthread.so"*; do
1553 [[ -e "$_f" ]] || continue
1554 inst_libdir_file "libgcc_s.so*"
1555 break 2
1556 done
1557 done
1558 fi
1559
1560 for ((i=0; i < ${#include_src[@]}; i++)); do
1561 src="${include_src[$i]}"
1562 target="${include_target[$i]}"
1563 if [[ $src && $target ]]; then
1564 if [[ -f $src ]]; then
1565 inst $src $target
1566 else
1567 ddebug "Including directory: $src"
1568 destdir="${initdir}/${target}"
1569 mkdir -p "$destdir"
1570 # check for preexisting symlinks, so we can cope with the
1571 # symlinks to $prefix
1572 # Objectname is a file or a directory
1573 for objectname in "$src"/*; do
1574 [[ -e "$objectname" || -h "$objectname" ]] || continue
1575 if [[ -d "$objectname" ]]; then
1576 # objectname is a directory, let's compute the final directory name
1577 object_destdir=${destdir}/${objectname#$src/}
1578 if ! [[ -e "$object_destdir" ]]; then
1579 mkdir -m 0755 -p "$object_destdir"
1580 chmod --reference="$objectname" "$object_destdir"
1581 fi
1582 $DRACUT_CP -t "$object_destdir" "$objectname"/*
1583 else
1584 $DRACUT_CP -t "$destdir" "$objectname"
1585 fi
1586 done
1587 fi
1588 fi
1589 done
1590
1591 if [[ $kernel_only != yes ]]; then
1592 # make sure that library links are correct and up to date
1593 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1594 [[ -f $f ]] && inst_simple "$f"
1595 done
1596 if ! ldconfig -r "$initdir"; then
1597 if [[ $EUID = 0 ]]; then
1598 derror "ldconfig exited ungracefully"
1599 else
1600 derror "ldconfig might need uid=0 (root) for chroot()"
1601 fi
1602 fi
1603 fi
1604
1605 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1606 dinfo "*** Hardlinking files ***"
1607 hardlink "$initdir" 2>&1
1608 dinfo "*** Hardlinking files done ***"
1609 fi
1610
1611 # strip binaries
1612 if [[ $do_strip = yes ]] ; then
1613 # Prefer strip from elfutils for package size
1614 declare strip_cmd=$(command -v eu-strip)
1615 test -z "$strip_cmd" && strip_cmd="strip"
1616
1617 for p in $strip_cmd xargs find; do
1618 if ! type -P $p >/dev/null; then
1619 dinfo "Could not find '$p'. Not stripping the initramfs."
1620 do_strip=no
1621 fi
1622 done
1623 fi
1624
1625 # cleanup empty ldconfig_paths directories
1626 for d in $(ldconfig_paths); do
1627 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" >/dev/null 2>&1
1628 done
1629
1630 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1631 dinfo "*** Stripping files ***"
1632 find "$initdir" -type f \
1633 -executable -not -path '*/lib/modules/*.ko' -print0 \
1634 | xargs -r -0 $strip_cmd -g 2>/dev/null
1635
1636 # strip kernel modules, but do not touch signed modules
1637 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1638 | while read -r -d $'\0' f || [ -n "$f" ]; do
1639 SIG=$(tail -c 28 "$f" | tr -d '\000')
1640 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1641 done | xargs -r -0 $strip_cmd -g
1642
1643 dinfo "*** Stripping files done ***"
1644 fi
1645 if [[ $early_microcode = yes ]]; then
1646 dinfo "*** Generating early-microcode cpio image ***"
1647 ucode_dir=(amd-ucode intel-ucode)
1648 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1649 _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
1650 _dest_idx="0 1"
1651 mkdir -p $_dest_dir
1652 if [[ $hostonly ]]; then
1653 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1654 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1655 fi
1656 for idx in $_dest_idx; do
1657 _fw=${ucode_dir[$idx]}
1658 for _fwdir in $fw_dir; do
1659 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1660 _src="*"
1661 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1662 if [[ $hostonly ]]; then
1663 _src=$(get_ucode_file)
1664 [[ $_src ]] || break
1665 [[ -r $_fwdir/$_fw/$_src ]] || break
1666 fi
1667
1668 for i in $_fwdir/$_fw/$_src; do
1669 [ -e "$i" ] && break
1670 break 2
1671 done
1672 for i in $_fwdir/$_fw/$_src; do
1673 [[ -e "$i" ]] || continue
1674 # skip gpg files
1675 str_ends "$i" ".asc" && continue
1676 cat "$i" >> $_dest_dir/${ucode_dest[$idx]}
1677 done
1678 create_early_cpio="yes"
1679 fi
1680 done
1681 done
1682 fi
1683
1684 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1685 dinfo "*** Packaging ACPI tables to override BIOS provided ones ***"
1686 _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi"
1687 mkdir -p $_dest_dir
1688 for table in $acpi_table_dir/*.aml; do
1689 dinfo " Adding ACPI table: $table"
1690 $DRACUT_CP $table $_dest_dir
1691 create_early_cpio="yes"
1692 done
1693 fi
1694
1695 dinfo "*** Store current command line parameters ***"
1696 if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
1697 dfatal "Could not store the current command line parameters"
1698 exit 1
1699 fi
1700
1701 if [[ $hostonly_cmdline == "yes" ]] ; then
1702 unset _stored_cmdline
1703 if [ -d $initdir/etc/cmdline.d ];then
1704 dinfo "Stored kernel commandline:"
1705 for conf in $initdir/etc/cmdline.d/*.conf ; do
1706 [ -e "$conf" ] || continue
1707 dinfo "$(< $conf)"
1708 _stored_cmdline=1
1709 done
1710 fi
1711 if ! [[ $_stored_cmdline ]]; then
1712 dinfo "No dracut internal kernel commandline stored in the initramfs"
1713 fi
1714 fi
1715
1716 dinfo "*** Creating image file '$outfile' ***"
1717
1718 if [[ $uefi = yes ]]; then
1719 readonly uefi_outdir="$DRACUT_TMPDIR/uefi"
1720 mkdir "$uefi_outdir"
1721 fi
1722
1723 if [[ $DRACUT_REPRODUCIBLE ]]; then
1724 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1725 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1726
1727 if [[ "$(cpio --help)" == *--reproducible* ]]; then
1728 CPIO_REPRODUCIBLE=1
1729 else
1730 dinfo "cpio does not support '--reproducible'. Resulting image will not be reproducible."
1731 fi
1732 fi
1733
1734 [[ "$EUID" != 0 ]] && cpio_owner_root="-R 0:0"
1735
1736 if [[ $create_early_cpio = yes ]]; then
1737 echo 1 > "$early_cpio_dir/d/early_cpio"
1738
1739 if [[ $DRACUT_REPRODUCIBLE ]]; then
1740 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1741 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1742 fi
1743
1744 # The microcode blob is _before_ the initramfs blob, not after
1745 if ! (
1746 umask 077; cd "$early_cpio_dir/d"
1747 find . -print0 | sort -z \
1748 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
1749 ); then
1750 dfatal "dracut: creation of $outfile failed"
1751 exit 1
1752 fi
1753 fi
1754
1755 if ! (
1756 umask 077; cd "$initdir"
1757 find . -print0 | sort -z \
1758 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet \
1759 | $compress >> "${DRACUT_TMPDIR}/initramfs.img"
1760 ); then
1761 dfatal "dracut: creation of $outfile failed"
1762 exit 1
1763 fi
1764
1765 if (( maxloglvl >= 5 )) && (( verbosity_mod_l >= 0 )); then
1766 if [[ $allowlocal ]]; then
1767 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img"| ddebug
1768 else
1769 lsinitrd "${DRACUT_TMPDIR}/initramfs.img"| ddebug
1770 fi
1771 fi
1772
1773 umask 077
1774
1775 if [[ $uefi = yes ]]; then
1776 if [[ $kernel_cmdline ]]; then
1777 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
1778 elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc/cmdline.d ];then
1779 for conf in $initdir/etc/cmdline.d/*.conf ; do
1780 [ -e "$conf" ] || continue
1781 printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
1782 done
1783 else
1784 do_print_cmdline > "$uefi_outdir/cmdline.txt"
1785 fi
1786 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
1787
1788 dinfo "Using UEFI kernel cmdline:"
1789 dinfo $(< "$uefi_outdir/cmdline.txt")
1790
1791 [[ -s /usr/lib/os-release ]] && uefi_osrelease="/usr/lib/os-release"
1792 [[ -s /etc/os-release ]] && uefi_osrelease="/etc/os-release"
1793
1794 if objcopy \
1795 ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
1796 --add-section .cmdline="${uefi_outdir}/cmdline.txt" --change-section-vma .cmdline=0x30000 \
1797 --add-section .linux="$kernel_image" --change-section-vma .linux=0x40000 \
1798 --add-section .initrd="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd=0x3000000 \
1799 "$uefi_stub" "${uefi_outdir}/linux.efi" \
1800 && cp --reflink=auto "${uefi_outdir}/linux.efi" "$outfile"; then
1801 dinfo "*** Creating UEFI image file '$outfile' done ***"
1802 else
1803 rm -f -- "$outfile"
1804 dfatal "*** Creating UEFI image file '$outfile' failed ***"
1805 exit 1
1806 fi
1807 else
1808 if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
1809 dinfo "*** Creating initramfs image file '$outfile' done ***"
1810 else
1811 rm -f -- "$outfile"
1812 dfatal "dracut: creation of $outfile failed"
1813 exit 1
1814 fi
1815 fi
1816
1817 command -v restorecon &>/dev/null && restorecon -- "$outfile"
1818
1819 # We sync/fsfreeze only if we're operating on a live booted system.
1820 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
1821 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
1822 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
1823 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
1824 if test -d /run/systemd/system; then
1825 if ! sync "$outfile" 2> /dev/null; then
1826 dinfo "dracut: sync operation on newly created initramfs $outfile failed"
1827 exit 1
1828 fi
1829
1830 # use fsfreeze only if we're not writing to /
1831 if [[ "$(stat -c %m -- "$outfile")" != "/" && "$(stat -f -c %T -- "$outfile")" != "msdos" ]]; then
1832 if ! $(fsfreeze -f $(dirname "$outfile") 2>/dev/null && fsfreeze -u $(dirname "$outfile") 2>/dev/null); then
1833 dinfo "dracut: warning: could not fsfreeze $(dirname "$outfile")"
1834 fi
1835 fi
1836 fi
1837
1838 exit 0