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