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