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