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
8 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
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.
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.
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/>.
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
35 readonly dracut_cmd
="$(readlink -f $0)"
40 [[ $dracutbasedir ]] || dracutbasedir
=$dracutsysrootdir/usr
/lib
/dracut
41 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
42 .
$dracutbasedir/dracut-version.sh
45 # 80x25 linebreak here ^
47 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
49 Version: $DRACUT_VERSION
51 Creates initial ramdisk images for preloading modules
53 -h, --help Display all options
55 If a [LIST] has multiple arguments, then you have to put these in quotes.
59 # dracut --add-drivers "module1 module2" ...
65 [[ $dracutbasedir ]] || dracutbasedir
=$dracutsysrootdir/usr
/lib
/dracut
66 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
67 .
$dracutbasedir/dracut-version.sh
70 # 80x25 linebreak here ^
72 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
74 Version: $DRACUT_VERSION
76 Creates initial ramdisk images for preloading modules
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
101 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
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
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
143 -r, --sysroot [DIR] Specify sysroot directory to collect files from.
144 -l, --local Local mode. Use modules from the current working
145 directory instead of the system-wide installed in
146 /usr/lib/dracut/modules.d.
147 Useful when running dracut from a git checkout.
148 -H, --hostonly Host-Only mode: Install only what is needed for
149 booting the local host instead of a generic host.
150 -N, --no-hostonly Disables Host-Only mode
151 --hostonly-mode <mode>
152 Specify the hostonly mode to use. <mode> could be
153 one of "sloppy" or "strict". "sloppy" mode is used
155 In "sloppy" hostonly mode, extra drivers and modules
156 will be installed, so minor hardware change won't make
157 the image unbootable (eg. changed keyboard), and the
158 image is still portable among similar hosts.
159 With "strict" mode enabled, anything not necessary
160 for booting the local host in its current state will
161 not be included, and modules may do some extra job
162 to save more space. Minor change of hardware or
163 environment could make the image unbootable.
164 DO NOT use "strict" mode unless you know what you
166 --hostonly-cmdline Store kernel command line arguments needed
168 --no-hostonly-cmdline Do not store kernel command line arguments needed
170 --no-hostonly-default-device
171 Do not generate implicit host devices like root,
172 swap, fstab, etc. Use "--mount" or "--add-device"
173 to explicitly add devices as needed.
174 --hostonly-i18n Install only needed keyboard and font files according
175 to the host configuration (default).
176 --no-hostonly-i18n Install all keyboard and font files available.
177 --persistent-policy [POLICY]
178 Use [POLICY] to address disks and partitions.
179 POLICY can be any directory name found in /dev/disk.
180 E.g. "by-uuid", "by-label"
181 --fstab Use /etc/fstab to determine the root device.
182 --add-fstab [FILE] Add file to the initramfs fstab
183 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
184 Mount device [DEV] on mountpoint [MP] with filesystem
185 [FSTYPE] and options [FSOPTS] in the initramfs
186 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
187 determined by looking at the current mounts.
188 --add-device "[DEV]" Bring up [DEV] in initramfs
189 -i, --include [SOURCE] [TARGET]
190 Include the files in the SOURCE directory into the
191 Target directory in the final initramfs.
192 If SOURCE is a file, it will be installed to TARGET
193 in the final initramfs.
194 -I, --install [LIST] Install the space separated list of files into the
196 --install-optional [LIST] Install the space separated list of files into the
197 initramfs, if they exist.
198 --gzip Compress the generated initramfs using gzip.
199 This will be done by default, unless another
200 compression option or --no-compress is passed.
201 --bzip2 Compress the generated initramfs using bzip2.
202 Make sure your kernel has bzip2 decompression support
203 compiled in, otherwise you will not be able to boot.
204 --lzma Compress the generated initramfs using lzma.
205 Make sure your kernel has lzma support compiled in,
206 otherwise you will not be able to boot.
207 --xz Compress the generated initramfs using xz.
208 Make sure that your kernel has xz support compiled
209 in, otherwise you will not be able to boot.
210 --lzo Compress the generated initramfs using lzop.
211 Make sure that your kernel has lzo support compiled
212 in, otherwise you will not be able to boot.
213 --lz4 Compress the generated initramfs using lz4.
214 Make sure that your kernel has lz4 support compiled
215 in, otherwise you will not be able to boot.
216 --zstd Compress the generated initramfs using Zstandard.
217 Make sure that your kernel has zstd support compiled
218 in, otherwise you will not be able to boot.
219 --compress [COMPRESSION] Compress the generated initramfs with the
220 passed compression program. Make sure your kernel
221 knows how to decompress the generated initramfs,
222 otherwise you will not be able to boot.
223 --no-compress Do not compress the generated initramfs. This will
224 override any other compression options.
225 --list-modules List all available dracut modules.
226 -M, --show-modules Print included module's name to standard output during
228 --keep Keep the temporary initramfs for debugging purposes
229 --printsize Print out the module install size
230 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
231 --logfile [FILE] Logfile to use (overrides configuration setting)
232 --reproducible Create reproducible images
233 --no-reproducible Do not create reproducible images
234 --loginstall [DIR] Log all files installed from the host to [DIR]
235 --uefi Create an UEFI executable with the kernel cmdline and
237 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
238 --kernel-image [FILE] location of the kernel image
240 If [LIST] has multiple arguments, then you have to put these in quotes.
244 # dracut --add-drivers "module1 module2" ...
249 # Fills up host_devs stack variable and makes sure there are no duplicates
253 [[ " ${host_devs[@]} " == *" $_dev "* ]] && return
254 host_devs
+=( "$_dev" )
258 # Little helper function for reading args from the commandline.
259 # it automatically handles -a b and -a=b variants, and returns 1 if
260 # we need to shift $3.
265 local rematch
='^[^=]*=(.*)$'
266 if [[ $2 =~
$rematch ]]; then
267 read "$1" <<< "${BASH_REMATCH[1]}"
270 # There is no way to shift our callers args, so
271 # return 1 to indicate they should do it instead.
278 local suffix
=$1; shift
283 for i
in "$d/"*"$suffix"; do
284 if [[ -e "$i" ]]; then
285 printf "%s\n" "${i##*/}"
291 for f
in "${files[@]}"; do
293 if [[ -e "$d/$f" ]]; then
294 printf "%s\n" "$d/$f"
304 # Workaround -i, --include taking 2 arguments
307 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
308 newat
+=("++include") # Replace --include by ++include
313 set -- "${newat[@]}" # Set new $@
315 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
316 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
320 --long add-drivers
: \
321 --long force-drivers
: \
322 --long omit-drivers
: \
326 --long filesystems
: \
328 --long install-optional
: \
349 --long print-cmdline \
350 --long kernel-cmdline
: \
370 --long no-host-only \
371 --long hostonly-mode
: \
372 --long hostonly-cmdline \
373 --long no-hostonly-cmdline \
374 --long no-hostonly-default-device \
375 --long persistent-policy
: \
386 --long list-modules \
387 --long show-modules \
390 --long regenerate-all \
391 --long noimageifnotneeded \
392 --long early-microcode \
393 --long no-early-microcode \
394 --long reproducible \
395 --long no-reproducible \
399 --long kernel-image
: \
400 --long no-hostonly-i18n \
401 --long hostonly-i18n \
402 --long no-machineid \
405 if (( $?
!= 0 )); then
415 rearrange_params
"$@"
418 # parse command line args to check if '--rebuild' option is present
423 if [ "$1" == "--" ]; then
426 if [ "$1" == "--rebuild" ]; then
429 if [ ! -e $rebuild_file ]; then
430 echo "Image file '$rebuild_file', for rebuild, does not exist!"
433 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
439 # get output file name and kernel version from command line arguments
445 if ! [[ ${outfile+x} ]]; then
447 elif ! [[ ${kernel+x} ]]; then
450 printf "\nUnknown arguments: %s\n\n" "$*" >&2
458 # extract input image file provided with rebuild option to get previous parameters, if any
459 if [[ $append_args_l == "yes" ]]; then
462 # determine resultant file
463 if ! [[ $outfile ]]; then
464 outfile
=$rebuild_file
467 if ! rebuild_param
=$
(lsinitrd
$rebuild_file '*lib/dracut/build-parameter.txt'); then
468 echo "Image '$rebuild_file' has no rebuild information stored"
472 # prepend previous parameters to current command line args
473 if [[ $rebuild_param ]]; then
474 TEMP
="$rebuild_param $TEMP"
476 rearrange_params
"$@"
486 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
487 PARMS_TO_STORE
+=" $1";
490 --kver) kernel
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
491 -a|
--add) add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
492 --force-add) force_add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
493 --add-drivers) add_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
494 --force-drivers) force_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
495 --omit-drivers) omit_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
496 -m|
--modules) dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
497 -o|
--omit) omit_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
498 -d|
--drivers) drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
499 --filesystems) filesystems_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
500 -I|
--install) install_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
501 --install-optional) install_optional_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
502 --fwdir) fw_dir_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
503 --libdirs) libdirs_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
504 --fscks) fscks_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
505 --add-fstab) add_fstab_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
506 --mount) fstab_lines
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
507 --add-device|
--device) add_device_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
508 --kernel-cmdline) kernel_cmdline_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
509 --nofscks) nofscks_l
="yes";;
510 --ro-mnt) ro_mnt_l
="yes";;
511 -k|
--kmoddir) drivers_dir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
512 -c|
--conf) conffile
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
513 --confdir) confdir
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
514 --tmpdir) tmpdir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
515 -L|
--stdlog) stdloglvl_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
516 --compress) compress_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
517 --prefix) prefix_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
518 --loginstall) loginstall_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
519 --rebuild) if [ $rebuild_file == $outfile ]; then
524 -f|
--force) force
=yes;;
525 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
526 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
528 print_cmdline
="yes"; hostonly_l
="yes"; kernel_only
="yes"; no_kernel
="yes";;
530 early_microcode_l
="yes";;
531 --no-early-microcode)
532 early_microcode_l
="no";;
533 --strip) do_strip_l
="yes";;
534 --nostrip) do_strip_l
="no";;
535 --hardlink) do_hardlink_l
="yes";;
536 --nohardlink) do_hardlink_l
="no";;
537 --noprefix) prefix_l
="/";;
538 --mdadmconf) mdadmconf_l
="yes";;
539 --nomdadmconf) mdadmconf_l
="no";;
540 --lvmconf) lvmconf_l
="yes";;
541 --nolvmconf) lvmconf_l
="no";;
542 --debug) debug
="yes";;
543 --profile) profile
="yes";;
544 --sshkey) sshkey
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
545 --logfile) logfile_l
="$2"; shift;;
546 -v|
--verbose) ((verbosity_mod_l
++));;
547 -q|
--quiet) ((verbosity_mod_l--
));;
550 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
551 && dracutbasedir
="$(readlink -f "${0%/*}")"
553 -H|
--hostonly|
--host-only)
555 -N|
--no-hostonly|
--no-host-only)
558 hostonly_mode_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
560 hostonly_cmdline_l
="yes" ;;
562 i18n_install_all_l
="no" ;;
564 i18n_install_all_l
="yes" ;;
565 --no-hostonly-cmdline)
566 hostonly_cmdline_l
="no" ;;
567 --no-hostonly-default-device)
568 hostonly_default_device
="no" ;;
570 persistent_policy_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
571 --fstab) use_fstab_l
="yes" ;;
572 -h|
--help) long_usage
; exit 1 ;;
573 -i|
--include) include_src
+=("$2"); PARMS_TO_STORE
+=" '$2'";
575 --bzip2) compress_l
="bzip2";;
576 --lzma) compress_l
="lzma";;
577 --xz) compress_l
="xz";;
578 --lzo) compress_l
="lzo";;
579 --lz4) compress_l
="lz4";;
580 --zstd) compress_l
="zstd";;
581 --no-compress) _no_compress_l
="cat";;
582 --gzip) compress_l
="gzip";;
583 --list-modules) do_list
="yes";;
588 --printsize) printsize
="yes";;
589 --regenerate-all) regenerate_all
="yes";;
590 --noimageifnotneeded) noimageifnotneeded
="yes";;
591 --reproducible) reproducible_l
="yes";;
592 --no-reproducible) reproducible_l
="no";;
595 uefi_stub_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
597 kernel_image_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
602 *) # should not even reach this point
603 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
608 # getopt cannot handle multiple arguments, so just handle "-I,--include"
609 # the old fashioned way
612 if [ "${1%%=*}" == "++include" ]; then
614 include_target
+=("$3")
615 PARMS_TO_STORE
+=" --include '$2' '$3'"
621 if [[ $regenerate_all == "yes" ]]; then
623 if [[ $kernel ]]; then
624 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
628 if [[ $outfile ]]; then
629 printf -- "--regenerate-all cannot be called with a image file\n" >&2
633 ((len
=${#dracut_args[@]}))
634 for ((i
=0; i
< len
; i
++)); do
635 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
636 unset dracut_args
[$i]
639 cd $dracutsysrootdir/lib
/modules
641 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
642 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
648 if ! [[ $kernel ]]; then
656 unset LD_LIBRARY_PATH
660 export DRACUT_LOG_LEVEL
=warning
662 export DRACUT_LOG_LEVEL
=debug
663 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
668 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
673 [[ $dracutbasedir ]] || dracutbasedir
=$dracutsysrootdir/usr
/lib
/dracut
675 # if we were not passed a config file, try the default one
676 if [[ ! -f $conffile ]]; then
677 if [[ $allowlocal ]]; then
678 conffile
="$dracutbasedir/dracut.conf"
680 conffile
="$dracutsysrootdir/etc/dracut.conf"
684 if [[ ! -d $confdir ]]; then
685 if [[ $allowlocal ]]; then
686 confdir
="$dracutbasedir/dracut.conf.d"
688 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
692 # source our config file
693 [[ -f $conffile ]] && .
"$conffile"
695 # source our config dir
696 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
697 [[ -e $f ]] && .
"$f"
700 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
702 for i
in $DRACUT_PATH; do
704 if [ -L "$dracutsysrootdir$i" ]; then
705 rl
=$
(readlink
-f $dracutsysrootdir$i)
707 if [[ "$NPATH" != *:$rl* ]] ; then
711 export PATH
="${NPATH#:}"
714 # these options add to the stuff in the config file
715 (( ${#add_dracutmodules_l[@]} )) && add_dracutmodules
+=" ${add_dracutmodules_l[@]} "
716 (( ${#force_add_dracutmodules_l[@]} )) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[@]} "
717 (( ${#fscks_l[@]} )) && fscks
+=" ${fscks_l[@]} "
718 (( ${#add_fstab_l[@]} )) && add_fstab
+=" ${add_fstab_l[@]} "
719 (( ${#fstab_lines_l[@]} )) && fstab_lines
+=( "${fstab_lines_l[@]}" )
720 (( ${#install_items_l[@]} )) && install_items
+=" ${install_items_l[@]} "
721 (( ${#install_optional_items_l[@]} )) && install_optional_items
+=" ${install_optional_items_l[@]} "
723 # these options override the stuff in the config file
724 (( ${#dracutmodules_l[@]} )) && dracutmodules
="${dracutmodules_l[@]}"
725 (( ${#omit_dracutmodules_l[@]} )) && omit_dracutmodules
="${omit_dracutmodules_l[@]}"
726 (( ${#filesystems_l[@]} )) && filesystems
="${filesystems_l[@]}"
727 (( ${#fw_dir_l[@]} )) && fw_dir
="${fw_dir_l[@]}"
728 (( ${#libdirs_l[@]} ))&& libdirs
="${libdirs_l[@]}"
730 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
731 [[ ! $stdloglvl ]] && stdloglvl
=4
732 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
733 ((stdloglvl
> 6)) && stdloglvl
=6
734 ((stdloglvl
< 0)) && stdloglvl
=0
736 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
737 [[ $do_strip_l ]] && do_strip
=$do_strip_l
738 [[ $do_strip ]] || do_strip
=yes
739 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
740 [[ $do_hardlink ]] || do_hardlink
=yes
741 [[ $prefix_l ]] && prefix
=$prefix_l
742 [[ $prefix = "/" ]] && unset prefix
743 [[ $hostonly_l ]] && hostonly
=$hostonly_l
744 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
745 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
746 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
747 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
748 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
749 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
750 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
751 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
752 [[ $dracutbasedir ]] || dracutbasedir
=$dracutsysrootdir/usr
/lib
/dracut
753 [[ $fw_dir ]] || fw_dir
="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
754 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
755 [[ $tmpdir ]] || tmpdir
=$dracutsysrootdir/var
/tmp
756 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
757 [[ $compress_l ]] && compress=$compress_l
758 [[ $show_modules_l ]] && show_modules
=$show_modules_l
759 [[ $nofscks_l ]] && nofscks
="yes"
760 [[ $ro_mnt_l ]] && ro_mnt
="yes"
761 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
762 [[ $early_microcode ]] || early_microcode
=yes
763 [[ $logfile_l ]] && logfile
="$logfile_l"
764 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
765 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
766 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
767 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
768 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
770 if ! [[ $outfile ]]; then
771 if [[ $machine_id != "no" ]]; then
772 [[ -f $dracutsysrootdir/etc
/machine-id
]] && read MACHINE_ID
< $dracutsysrootdir/etc
/machine-id
775 if [[ $uefi == "yes" ]]; then
776 if [[ -n "$uefi_secureboot_key" && -z "$uefi_secureboot_cert" ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
777 dfatal
"Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set."
781 if [[ -n "$uefi_secureboot_key" && -n "$uefi_secureboot_cert" ]] && !command -v sbsign
&>/dev
/null
; then
782 dfatal
"Need 'sbsign' to create a signed UEFI executable"
786 BUILD_ID
=$
(cat $dracutsysrootdir/etc
/os-release
$dracutsysrootdir/usr
/lib
/os-release \
787 |
while read -r line ||
[[ $line ]]; do \
788 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
790 if [[ -z $dracutsysrootdir ]]; then
791 if [[ -d /efi
]] && mountpoint
-q /efi
; then
795 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
801 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
805 mkdir
-p "$dracutsysrootdir$efidir/Linux"
806 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
808 if [[ -e "$dracutsysrootdir/boot/vmlinuz-$kernel" ]]; then
809 outfile
="/boot/initramfs-$kernel.img"
810 elif [[ $MACHINE_ID ]] && ( [[ -d $dracutsysrootdir/boot
/${MACHINE_ID} ]] ||
[[ -L $dracutsysrootdir/boot
/${MACHINE_ID} ]] ); then
811 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
813 outfile
="$dracutsysrootdir/boot/initramfs-$kernel.img"
818 # eliminate IFS hackery when messing with fw_dir
819 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
820 fw_dir
=${fw_dir//:/ }
822 # check for logfile and try to create one if it doesn't exist
823 if [[ -n "$logfile" ]];then
824 if [[ ! -f "$logfile" ]];then
826 if [ ! $?
-eq 0 ] ;then
827 printf "%s\n" "dracut: touch $logfile failed." >&2
832 # handle compression options.
833 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
834 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
835 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
836 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
837 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
838 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
839 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
840 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
841 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
842 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
844 if [[ $_no_compress_l = "$DRACUT_COMPRESS_CAT" ]]; then
845 compress="$DRACUT_COMPRESS_CAT"
848 if ! [[ $compress ]]; then
849 # check all known compressors, if none specified
850 for i
in $DRACUT_COMPRESS_PIGZ $DRACUT_COMPRESS_GZIP $DRACUT_COMPRESS_LZ4 $DRACUT_COMPRESS_LZOP $
$DRACUT_COMPRESS_ZSTD $DRACUT_COMPRESS_LZMA $DRACUT_COMPRESS_XZ $DRACUT_COMPRESS_LBZIP2 $OMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
851 command -v "$i" &>/dev
/null ||
continue
855 if [[ $compress = cat ]]; then
856 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
860 # choose the right arguments for the compressor
863 if [[ "$compress" = lbzip2
]] ||
command -v $DRACUT_COMPRESS_LBZIP2 &>/dev
/null
; then
864 compress="$DRACUT_COMPRESS_LBZIP2 -9"
866 compress="$DRACUT_COMPRESS_BZIP2 -9"
870 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
873 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
876 if [[ "$compress" = pigz
]] ||
command -v $DRACUT_COMPRESS_PIGZ &>/dev
/null
; then
877 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
878 elif command -v gzip &>/dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
879 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
881 compress="$DRACUT_COMPRESS_GZIP -n -9"
885 compress="$DRACUT_COMPRESS_LZOP -9"
888 compress="$DRACUT_COMPRESS_LZ4 -l -9"
891 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
895 [[ $hostonly = yes ]] && hostonly
="-h"
896 [[ $hostonly != "-h" ]] && unset hostonly
898 case $hostonly_mode in
900 [[ $hostonly ]] && hostonly_mode
="sloppy" ;;
902 if [[ ! $hostonly ]]; then
907 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
911 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
913 readonly TMPDIR
="$(realpath -e "$tmpdir")"
914 [ -d "$TMPDIR" ] ||
{
915 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
918 readonly DRACUT_TMPDIR
="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
919 [ -d "$DRACUT_TMPDIR" ] ||
{
920 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
924 # clean up after ourselves no matter how we die.
927 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
931 # clean up after ourselves no matter how we die.
932 trap 'exit 1;' SIGINT
934 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
937 if [[ $early_microcode = yes ]] ||
( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
938 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
939 mkdir
"$early_cpio_dir"
942 [[ -n "$dracutsysrootdir" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
944 if [[ $print_cmdline ]]; then
951 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
952 .
$dracutbasedir/dracut-version.sh
955 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
956 .
$dracutbasedir/dracut-init.sh
958 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
959 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
960 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
964 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
965 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
966 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
970 if ! [[ $print_cmdline ]]; then
972 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &>/dev
/null
; then
973 unset DRACUT_RESOLVE_LAZY
974 export DRACUT_RESOLVE_DEPS
=1
976 rm -fr -- ${initdir}/*
979 dracutfunctions
=$dracutbasedir/dracut-functions.sh
980 export dracutfunctions
982 (( ${#drivers_l[@]} )) && drivers
="${drivers_l[@]}"
983 drivers
=${drivers/-/_}
985 (( ${#add_drivers_l[@]} )) && add_drivers
+=" ${add_drivers_l[@]} "
986 add_drivers
=${add_drivers/-/_}
988 (( ${#force_drivers_l[@]} )) && force_drivers
+=" ${force_drivers_l[@]} "
989 force_drivers
=${force_drivers/-/_}
991 (( ${#omit_drivers_l[@]} )) && omit_drivers
+=" ${omit_drivers_l[@]} "
992 omit_drivers
=${omit_drivers/-/_}
994 (( ${#kernel_cmdline_l[@]} )) && kernel_cmdline
+=" ${kernel_cmdline_l[@]} "
996 omit_drivers_corrected
=""
997 for d
in $omit_drivers; do
998 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
999 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1000 omit_drivers_corrected
+="$d|"
1002 omit_drivers
="${omit_drivers_corrected%|}"
1003 unset omit_drivers_corrected
1005 # prepare args for logging
1006 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
1007 [[ "${dracut_args[$i]}" == *\
* ]] && \
1008 dracut_args
[$i]="\"${dracut_args[$i]}\""
1012 dinfo
"Executing: $dracut_cmd ${dracut_args[@]}"
1014 [[ $do_list = yes ]] && {
1015 for mod
in $dracutbasedir/modules.d
/*; do
1016 [[ -d $mod ]] ||
continue;
1017 [[ -e $mod/install ||
-e $mod/installkernel || \
1018 -e $mod/module-setup.sh
]] ||
continue
1019 printf "%s\n" "${mod##*/??}"
1024 # This is kinda legacy -- eventually it should go away.
1025 case $dracutmodules in
1026 ""|auto
) dracutmodules
="all" ;;
1029 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1032 [[ -d $systemdutildir ]] \
1033 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
1035 if ! [[ -d "$systemdutildir" ]]; then
1036 [[ -e /lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1037 [[ -e /usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1041 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1042 if ! [[ -f $srcmods/modules.dep
]]; then
1043 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1044 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1047 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1049 elif ! ( command -v gzip &>/dev
/null
&& command -v xz
&>/dev
/null
); then
1050 read _mod
< $srcmods/modules.dep
1052 if [[ -f $srcmods/"$_mod" ]]; then
1053 # Check, if kernel modules are compressed, and if we can uncompress them
1055 *.ko.gz
) kcompress
=gzip;;
1056 *.ko.xz
) kcompress
=xz
;;
1058 if [[ $kcompress ]]; then
1059 if ! command -v "$kcompress" &>/dev
/null
; then
1060 dfatal
"Kernel modules are compressed with $kcompress, but $kcompress is not available."
1068 if [[ ! $print_cmdline ]]; then
1069 if [[ -f $outfile && ! $force ]]; then
1070 dfatal
"Will not override existing initramfs ($outfile) without --force"
1074 outdir
=${outfile%/*}
1075 [[ $outdir ]] || outdir
="/"
1077 if [[ ! -d "$outdir" ]]; then
1078 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1080 elif [[ ! -w "$outdir" ]]; then
1081 dfatal
"No permission to write to $outdir."
1083 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1084 dfatal
"No permission to write $outfile."
1088 if [[ $loginstall ]]; then
1089 if ! mkdir
-p "$loginstall"; then
1090 dfatal
"Could not create directory to log installed files to '$loginstall'."
1093 loginstall
=$
(readlink
-f "$loginstall")
1096 if [[ $uefi = yes ]]; then
1097 if ! command -v objcopy
&>/dev
/null
; then
1098 dfatal
"Need 'objcopy' to create a UEFI executable"
1101 unset EFI_MACHINE_TYPE_NAME
1104 EFI_MACHINE_TYPE_NAME
=x64
;;
1106 EFI_MACHINE_TYPE_NAME
=ia32
;;
1108 dfatal
"Architecture '$(uname -m)' not supported to create a UEFI executable"
1113 if ! [[ -s $uefi_stub ]]; then
1115 $dracutsysrootdir"${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1116 "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1117 [[ -s $uefi_stub ]] ||
continue
1121 if ! [[ -s $uefi_stub ]]; then
1122 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1126 if ! [[ $kernel_image ]]; then
1127 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1128 [[ -s "$kernel_image" ]] ||
continue
1132 if ! [[ -s $kernel_image ]]; then
1133 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1139 if [[ $acpi_override = yes ]] && ! ( check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1140 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1144 if [[ $early_microcode = yes ]]; then
1145 if [[ $hostonly ]]; then
1146 [[ $
(get_cpu_vendor
) == "AMD" ]] \
1147 && ! check_kernel_config CONFIG_MICROCODE_AMD \
1148 && unset early_microcode
1149 [[ $
(get_cpu_vendor
) == "Intel" ]] \
1150 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1151 && unset early_microcode
1153 ! check_kernel_config CONFIG_MICROCODE_AMD \
1154 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1155 && unset early_microcode
1157 [[ $early_microcode != yes ]] \
1158 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1161 # Need to be able to have non-root users read stuff (rpcbind etc)
1162 chmod 755 "$initdir"
1164 if [[ $hostonly ]]; then
1165 for i
in /sys
/proc
/run
/dev
; do
1166 if ! findmnt
--target "$i" &>/dev
/null
; then
1167 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1173 declare -A host_fs_types
1175 for line
in "${fstab_lines[@]}"; do
1181 dev
=$
(blkid
-l -t UUID
=${dev#UUID=} -o device
)
1184 dev
=$
(blkid
-l -t LABEL
=${dev#LABEL=} -o device
)
1187 dev
=$
(blkid
-l -t PARTUUID
=${dev#PARTUUID=} -o device
)
1190 dev
=$
(blkid
-l -t PARTLABEL
=${dev#PARTLABEL=} -o device
)
1193 [ -z "$dev" ] && dwarn
"Bad fstab entry $@" && continue
1194 if [[ "$3" == btrfs
]]; then
1195 for i
in $
(btrfs_devs
"$2"); do
1199 push_host_devs
"$dev"
1200 host_fs_types
["$dev"]="$3"
1203 for f
in $add_fstab; do
1204 [[ -e $f ]] ||
continue
1205 while read dev rest ||
[ -n "$dev" ]; do
1206 push_host_devs
"$dev"
1210 for dev
in $add_device; do
1211 push_host_devs
"$dev"
1214 if (( ${#add_device_l[@]} )); then
1215 add_device
+=" ${add_device_l[@]} "
1216 push_host_devs
"${add_device_l[@]}"
1219 if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
1220 # in hostonly mode, determine all devices, which have to be accessed
1221 # and examine them for filesystem types
1240 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1241 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
1242 _dev
=$
(find_block_device
"$mp")
1243 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1244 [[ -b $_bdev ]] && _dev
=$_bdev
1245 [[ "$mp" == "/" ]] && root_devs
+=("$_dev")
1246 push_host_devs
"$_dev"
1247 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1248 for i
in $
(btrfs_devs
"$mp"); do
1249 [[ "$mp" == "/" ]] && root_devs
+=("$i")
1255 # TODO - with sysroot, /proc/swaps is not relevant
1256 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1257 while read dev
type rest ||
[ -n "$dev" ]; do
1258 [[ -b $dev ]] ||
continue
1259 [[ "$type" == "partition" ]] ||
continue
1261 while read _d _m _t _o _r ||
[ -n "$_d" ]; do
1262 [[ "$_d" == \
#* ]] && continue
1263 [[ $_d ]] ||
continue
1264 [[ $_t != "swap" ]] && continue
1265 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1266 [[ "$_o" == *noauto
* ]] && continue
1267 _d
=$
(expand_persistent_dev
"$_d")
1268 [[ "$_d" -ef "$dev" ]] ||
continue
1270 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1271 while read _mapper _a _p _o ||
[ -n "$_mapper" ]; do
1272 [[ $_mapper = \
#* ]] && continue
1273 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1274 [[ "$_o" ]] || _o
="$_p"
1275 # skip entries with password files
1276 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1278 [[ $_o == *swap
* ]] && continue 2
1279 done < $dracutsysrootdir/etc
/crypttab
1282 _dev
="$(readlink -f "$dev")"
1283 push_host_devs
"$_dev"
1284 swap_devs
+=("$_dev")
1286 done < $dracutsysrootdir/etc
/fstab
1290 # collect all "x-initrd.mount" entries from /etc/fstab
1291 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1292 while read _d _m _t _o _r ||
[ -n "$_d" ]; do
1293 [[ "$_d" == \
#* ]] && continue
1294 [[ $_d ]] ||
continue
1295 [[ "$_o" != *x-initrd.mount
* ]] && continue
1296 _dev
=$
(expand_persistent_dev
"$_d")
1297 _dev
="$(readlink -f "$_dev")"
1298 [[ -b $_dev ]] ||
continue
1300 push_host_devs
"$_dev"
1301 if [[ "$_t" == btrfs
]]; then
1302 for i
in $
(btrfs_devs
"$_m"); do
1306 done < $dracutsysrootdir/etc
/fstab
1315 if [[ -b /dev
/block
/$1 ]]; then
1316 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1319 if [[ -b $1 ]]; then
1320 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1323 if fstype
=$
(find_dev_fstype
"$1"); then
1324 host_fs_types
["$1"]="$fstype"
1330 for dev
in "${host_devs[@]}"; do
1332 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1335 for dev
in "${!host_fs_types[@]}"; do
1336 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
1337 rootopts
=$
(find_dev_fsopts
"$dev")
1338 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1339 journaldev
=$
(fs_get_option
$rootopts "jdev")
1340 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1341 journaldev
=$
(fs_get_option
$rootopts "logdev")
1343 if [[ $journaldev ]]; then
1344 dev
="$(readlink -f "$dev")"
1345 push_host_devs
"$dev"
1347 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1351 [[ -d $dracutsysrootdir$udevdir ]] \
1352 || udevdir
="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1353 if ! [[ -d "$dracutsysrootdir$udevdir" ]]; then
1354 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1355 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1358 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1359 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
1361 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1363 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1364 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2>/dev
/null
)
1366 [[ -d "$dracutsysrootdir$systemdsystemconfdir" ]] || systemdsystemconfdir
=/etc
/systemd
/system
1368 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1369 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2>/dev
/null
)
1371 if ! [[ -d "$dracutsysrootdir$tmpfilesdir" ]]; then
1372 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1373 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1376 export initdir dracutbasedir \
1377 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1379 fw_dir drivers_dir debug no_kernel kernel_only \
1380 omit_drivers mdadmconf lvmconf root_devs \
1381 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1382 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1383 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1384 DRACUT_VERSION udevdir prefix filesystems drivers \
1385 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1386 hostonly_cmdline loginstall \
1390 # check all our modules to see if they should be sourced.
1391 # This builds a list of modules that we will install next.
1392 for_each_module_dir check_module
1393 for_each_module_dir check_mount
1395 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1399 local -A _mods_to_print
1400 for i
in $modules_loaded $mods_to_load; do
1401 _mods_to_print
[$i]=1
1404 # source our modules.
1405 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1406 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1407 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1408 module_cmdline
"$_d_mod" "$moddir"
1413 if [[ $print_cmdline ]]; then
1419 # Create some directory structure first
1420 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1422 [[ -h $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1423 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1425 if [[ $prefix ]]; then
1426 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1427 [[ "$d" == */* ]] && continue
1428 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1432 if [[ $kernel_only != yes ]]; then
1433 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var var
/tmp
$libdirs; do
1434 [[ -e "${initdir}${prefix}/$d" ]] && continue
1435 if [ -L "/$d" ]; then
1436 inst_symlink
"/$d" "${prefix}/$d"
1438 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1442 for d
in dev proc sys sysroot root run
; do
1443 if [ -L "/$d" ]; then
1446 mkdir
-m 0755 -p "$initdir/$d"
1450 ln -sfn ..
/run
"$initdir/var/run"
1451 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1453 for d
in lib
"$libdir"; do
1454 [[ -e "${initdir}${prefix}/$d" ]] && continue
1455 if [ -h "/$d" ]; then
1456 inst
"/$d" "${prefix}/$d"
1458 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1463 if [[ $kernel_only != yes ]]; then
1464 mkdir
-p "${initdir}/etc/cmdline.d"
1465 for _d
in $hookdirs; do
1466 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
1468 if [[ "$EUID" = "0" ]]; then
1469 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
1470 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
1471 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
1472 [ -c ${initdir}/dev
/random
] || mknod
${initdir}/dev
/random c
1 8
1473 [ -c ${initdir}/dev
/urandom
] || mknod
${initdir}/dev
/urandom c
1 9
1477 _isize
=0 #initramfs size
1479 # source our modules.
1480 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1481 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1482 [[ "$mods_to_load" == *\
$_d_mod\
* ]] ||
continue
1483 if [[ $show_modules = yes ]]; then
1484 printf "%s\n" "$_d_mod"
1486 dinfo
"*** Including module: $_d_mod ***"
1488 if [[ $kernel_only == yes ]]; then
1489 module_installkernel
"$_d_mod" "$moddir" ||
{
1490 dfatal
"installkernel failed in module $_d_mod"
1494 module_install
"$_d_mod" "$moddir"
1495 if [[ $no_kernel != yes ]]; then
1496 module_installkernel
"$_d_mod" "$moddir" ||
{
1497 dfatal
"installkernel failed in module $_d_mod"
1502 mods_to_load
=${mods_to_load// $_d_mod /}
1503 modules_loaded
+="$_d_mod "
1505 #print the module install size
1506 if [ -n "$printsize" ]; then
1507 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
1508 _isize_delta
=$
((_isize_new
- _isize
))
1509 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1515 for i
in $modules_loaded; do
1516 mkdir
-p $initdir/lib
/dracut
1517 printf "%s\n" "$i" >> $initdir/lib
/dracut
/modules.txt
1520 dinfo
"*** Including modules done ***"
1522 ## final stuff that has to happen
1523 if [[ $no_kernel != yes ]]; then
1524 if [[ $hostonly_mode = "strict" ]]; then
1525 cp "$DRACUT_KERNEL_MODALIASES" $initdir/lib
/dracut
/hostonly-kernel-modules.txt
1528 if [[ $drivers ]]; then
1529 hostonly
='' instmods
$drivers
1532 if [[ -n "${add_drivers// }" ]]; then
1533 hostonly
='' instmods
-c $add_drivers
1535 if [[ $force_drivers ]]; then
1536 hostonly
='' instmods
-c $force_drivers
1537 rm -f $initdir/etc
/cmdline.d
/20-force_driver.conf
1538 for mod
in $force_drivers; do
1539 echo "rd.driver.pre=$mod" >>$initdir/etc
/cmdline.d
/20-force_drivers.conf
1542 if [[ $filesystems ]]; then
1543 hostonly
='' instmods
-c $filesystems
1546 dinfo
"*** Installing kernel module dependencies ***"
1548 dinfo
"*** Installing kernel module dependencies done ***"
1550 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1551 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1552 [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1553 for i
in ${initdir}/etc
/cmdline.d
/*.conf
; do
1554 # We need no initramfs image and do not generate one.
1555 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1561 if [[ $kernel_only != yes ]]; then
1562 (( ${#install_items[@]} > 0 )) && inst_multiple
${install_items[@]}
1563 (( ${#install_optional_items[@]} > 0 )) && inst_multiple
-o ${install_optional_items[@]}
1565 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1567 for line
in "${fstab_lines[@]}"; do
1570 if [ -z "${line[1]}" ]; then
1571 # Determine device and mount options from current system
1572 mountpoint
-q "${line[0]}" || derror
"${line[0]} is not a mount point!"
1573 line
=($
(findmnt
--raw -n --target "${line[0]}" --output=source,target
,fstype
,options
))
1574 dinfo
"Line for ${line[1]}: ${line[@]}"
1576 # Use default options
1577 [ -z "${line[3]}" ] && line
[3]="defaults"
1580 # Default options for freq and passno
1581 [ -z "${line[4]}" ] && line
[4]="0"
1582 [ -z "${line[5]}" ] && line
[5]="2"
1584 strstr
"${line[2]}" "nfs" && line
[5]="0"
1585 echo "${line[@]}" >> "${initdir}/etc/fstab"
1588 for f
in $add_fstab; do
1589 cat "$f" >> "${initdir}/etc/fstab"
1592 if [[ $dracutsysrootdir$systemdutildir ]]; then
1593 if [ -d ${initdir}/$systemdutildir ]; then
1594 mkdir
-p ${initdir}/etc
/conf.d
1596 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1597 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1598 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1599 } > ${initdir}/etc
/conf.d
/systemd.conf
1603 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1604 dinfo
"*** Resolving executable dependencies ***"
1605 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
1606 |
xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
1607 dinfo
"*** Resolving executable dependencies done ***"
1610 # Now we are done with lazy resolving, always install dependencies
1611 unset DRACUT_RESOLVE_LAZY
1612 export DRACUT_RESOLVE_DEPS
=1
1614 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1615 for _dir
in $libdirs; do
1616 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
1617 [[ -e "$_f" ]] ||
continue
1618 inst_libdir_file
"libgcc_s.so*"
1624 for ((i
=0; i
< ${#include_src[@]}; i
++)); do
1625 src
="${include_src[$i]}"
1626 target
="${include_target[$i]}"
1627 if [[ $src && $target ]]; then
1628 if [[ -f $src ]]; then
1630 elif [[ -d $src ]]; then
1631 ddebug
"Including directory: $src"
1632 destdir
="${initdir}/${target}"
1634 # check for preexisting symlinks, so we can cope with the
1635 # symlinks to $prefix
1636 # Objectname is a file or a directory
1637 for objectname
in "$src"/*; do
1638 [[ -e "$objectname" ||
-h "$objectname" ]] ||
continue
1639 if [[ -d "$objectname" ]]; then
1640 # objectname is a directory, let's compute the final directory name
1641 object_destdir
=${destdir}/${objectname#$src/}
1642 if ! [[ -e "$object_destdir" ]]; then
1643 mkdir
-m 0755 -p "$object_destdir"
1644 chmod --reference="$objectname" "$object_destdir"
1646 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
1648 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
1651 elif [[ -e $src ]]; then
1652 derror
"$src is neither a directory nor a regular file"
1654 derror
"$src doesn't exist"
1659 if [[ $kernel_only != yes ]]; then
1660 # make sure that library links are correct and up to date
1661 for f
in $dracutsysrootdir/etc
/ld.so.conf
$dracutsysrootdir/etc
/ld.so.conf.d
/*; do
1662 [[ -f $f ]] && inst_simple
"${f#$dracutsysrootdir}"
1664 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc
/ld.so.conf
; then
1665 if [[ $EUID = 0 ]]; then
1666 derror
"ldconfig exited ungracefully"
1668 derror
"ldconfig might need uid=0 (root) for chroot()"
1673 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1674 dinfo
"*** Hardlinking files ***"
1675 hardlink
"$initdir" 2>&1
1676 dinfo
"*** Hardlinking files done ***"
1680 if [[ $do_strip = yes ]] ; then
1681 # Prefer strip from elfutils for package size
1682 declare strip_cmd
=$
(command -v eu-strip
)
1683 test -z "$strip_cmd" && strip_cmd
="strip"
1685 for p
in $strip_cmd xargs find; do
1686 if ! type -P $p >/dev
/null
; then
1687 dinfo
"Could not find '$p'. Not stripping the initramfs."
1693 # cleanup empty ldconfig_paths directories
1694 for d
in $
(ldconfig_paths
); do
1695 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" >/dev
/null
2>&1
1698 if [[ $early_microcode = yes ]]; then
1699 dinfo
"*** Generating early-microcode cpio image ***"
1700 ucode_dir
=(amd-ucode intel-ucode
)
1701 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
1702 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
1705 if [[ $hostonly ]]; then
1706 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
1707 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
1709 for idx
in $_dest_idx; do
1710 _fw
=${ucode_dir[$idx]}
1711 for _fwdir
in $fw_dir; do
1712 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1714 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
1715 if [[ $hostonly ]]; then
1716 _src
=$
(get_ucode_file
)
1717 [[ $_src ]] ||
break
1718 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
1719 [[ -r $_fwdir/$_fw/$_src ]] ||
break
1722 for i
in $_fwdir/$_fw/$_src; do
1723 [ -e "$i" ] && break
1726 for i
in $_fwdir/$_fw/$_src; do
1727 [[ -e "$i" ]] ||
continue
1729 str_ends
"$i" ".asc" && continue
1730 cat "$i" >> $_dest_dir/${ucode_dest[$idx]}
1732 create_early_cpio
="yes"
1738 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1739 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
1740 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
1742 for table
in $acpi_table_dir/*.aml
; do
1743 dinfo
" Adding ACPI table: $table"
1744 $DRACUT_CP $table $_dest_dir
1745 create_early_cpio
="yes"
1749 dinfo
"*** Store current command line parameters ***"
1750 if ! ( echo $PARMS_TO_STORE > $initdir/lib
/dracut
/build-parameter.txt
); then
1751 dfatal
"Could not store the current command line parameters"
1755 if [[ $hostonly_cmdline == "yes" ]] ; then
1756 unset _stored_cmdline
1757 if [ -d $initdir/etc
/cmdline.d
];then
1758 dinfo
"Stored kernel commandline:"
1759 for conf
in $initdir/etc
/cmdline.d
/*.conf
; do
1760 [ -e "$conf" ] ||
continue
1765 if ! [[ $_stored_cmdline ]]; then
1766 dinfo
"No dracut internal kernel commandline stored in the initramfs"
1770 if dracut_module_included
"squash"; then
1771 dinfo
"*** Install squash loader ***"
1772 if ! check_kernel_config CONFIG_SQUASHFS
; then
1773 dfatal
"CONFIG_SQUASHFS have to be enabled for dracut squash module to work"
1776 if ! check_kernel_config CONFIG_OVERLAY_FS
; then
1777 dfatal
"CONFIG_OVERLAY_FS have to be enabled for dracut squash module to work"
1780 if ! check_kernel_config CONFIG_DEVTMPFS
; then
1781 dfatal
"CONFIG_DEVTMPFS have to be enabled for dracut squash module to work"
1785 readonly squash_dir
="$initdir/squash/root"
1786 readonly squash_img
=$initdir/squash
/root.img
1788 # Currently only move "usr" "etc" to squashdir
1789 readonly squash_candidate
=( "usr" "etc" )
1791 mkdir
-m 0755 -p $squash_dir
1792 for folder
in "${squash_candidate[@]}"; do
1793 mv $initdir/$folder $squash_dir/$folder
1796 # Move some files out side of the squash image, including:
1797 # - Files required to boot and mount the squashfs image
1798 # - Files need to be accessible without mounting the squash image
1799 required_in_root
() {
1801 local _sqsh_file
=$squash_dir/$file
1802 local _init_file
=$initdir/$file
1804 if [[ -e $_init_file ]]; then
1808 if [[ ! -e $_sqsh_file ]] && [[ ! -L $_sqsh_file ]]; then
1809 derror
"$file is required to boot a squashed initramfs but it's not installed!"
1813 if [[ ! -d $
(dirname $_init_file) ]]; then
1814 required_in_root $
(dirname $file)
1817 if [[ -L $_sqsh_file ]]; then
1818 cp --preserve=all
-P $_sqsh_file $_init_file
1819 _sqsh_file
=$
(realpath
$_sqsh_file 2>/dev
/null
)
1820 if [[ -e $_sqsh_file ]] && [[ "$_sqsh_file" == "$squash_dir"* ]]; then
1822 required_in_root
${_sqsh_file#$squash_dir/}
1825 if [[ -e $squash_dir$_sqsh_file ]]; then
1827 required_in_root
${_sqsh_file#/}
1830 required_in_root
${module_spec#$squash_dir/}
1832 if [[ -d $_sqsh_file ]]; then
1835 mv $_sqsh_file $_init_file
1840 required_in_root etc
/initrd-release
1842 for module_spec
in $squash_dir/usr
/lib
/modules
/*/modules.
*;
1844 required_in_root
${module_spec#$squash_dir/}
1847 for dracut_spec
in $squash_dir/usr
/lib
/dracut
/*;
1849 required_in_root
${dracut_spec#$squash_dir/}
1852 mv $initdir/init
$initdir/init.stock
1853 ln -s squash
/init.sh
$initdir/init
1855 # Reinstall required files for the squash image setup script.
1856 # We have moved them inside the squashed image, but they need to be
1857 # accessible before mounting the image.
1858 inst_multiple
"echo" "sh" "mount" "modprobe" "mkdir"
1859 hostonly
="" instmods
"loop" "squashfs" "overlay"
1861 # Only keep systemctl outsite if we need switch root
1862 if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
1866 for folder
in "${squash_candidate[@]}"; do
1867 # Remove duplicated files in squashfs image, save some more space
1868 [[ ! -d $initdir/$folder/ ]] && continue
1869 for file in $
(find $initdir/$folder/ -not -type d
);
1871 if [[ -e $squash_dir${file#$initdir} ]]; then
1872 mv $squash_dir${file#$initdir} $file
1878 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1879 dinfo
"*** Stripping files ***"
1880 find "$initdir" -type f \
1881 -executable -not -path '*/lib/modules/*.ko' -print0 \
1882 |
xargs -r -0 $strip_cmd -g -p 2>/dev
/null
1884 # strip kernel modules, but do not touch signed modules
1885 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
1886 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
1887 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
1888 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
1889 done |
xargs -r -0 $strip_cmd -g -p
1890 dinfo
"*** Stripping files done ***"
1893 if dracut_module_included
"squash"; then
1894 dinfo
"*** Squashing the files inside the initramfs ***"
1895 mksquashfs
$squash_dir $squash_img -no-xattrs -no-exports -noappend -always-use-fragments -comp xz
-Xdict-size 100% -no-progress 1> /dev
/null
1897 if [[ $?
!= 0 ]]; then
1898 dfatal
"dracut: Failed making squash image"
1903 dinfo
"*** Squashing the files inside the initramfs done ***"
1906 dinfo
"*** Creating image file '$outfile' ***"
1908 if [[ $uefi = yes ]]; then
1909 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
1910 mkdir
"$uefi_outdir"
1913 if [[ $DRACUT_REPRODUCIBLE ]]; then
1914 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1915 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1917 if [[ "$(cpio --help)" == *--reproducible* ]]; then
1920 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
1924 [[ "$EUID" != 0 ]] && cpio_owner_root
="-R 0:0"
1926 if [[ $create_early_cpio = yes ]]; then
1927 echo 1 > "$early_cpio_dir/d/early_cpio"
1929 if [[ $DRACUT_REPRODUCIBLE ]]; then
1930 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1931 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1934 # The microcode blob is _before_ the initramfs blob, not after
1936 umask 077; cd "$early_cpio_dir/d"
1937 find .
-print0 |
sort -z \
1938 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
1940 dfatal
"dracut: creation of $outfile failed"
1946 umask 077; cd "$initdir"
1947 find .
-print0 |
sort -z \
1948 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet \
1949 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
1951 dfatal
"dracut: creation of $outfile failed"
1955 if (( maxloglvl
>= 5 )) && (( verbosity_mod_l
>= 0 )); then
1956 if [[ $allowlocal ]]; then
1957 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img"| ddebug
1959 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img"| ddebug
1965 if [[ $uefi = yes ]]; then
1966 if [[ $kernel_cmdline ]]; then
1967 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
1968 elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc
/cmdline.d
];then
1969 for conf
in $initdir/etc
/cmdline.d
/*.conf
; do
1970 [ -e "$conf" ] ||
continue
1971 printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
1974 do_print_cmdline
> "$uefi_outdir/cmdline.txt"
1976 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
1978 dinfo
"Using UEFI kernel cmdline:"
1979 dinfo $
(tr -d '\000' < "$uefi_outdir/cmdline.txt")
1981 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
1982 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
1985 ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
1986 --add-section .cmdline
="${uefi_outdir}/cmdline.txt" --change-section-vma .cmdline
=0x30000 \
1987 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x40000 \
1988 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
=0x3000000 \
1989 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
1990 if [[ -n "${uefi_secureboot_key}" && -n "${uefi_secureboot_cert}" ]]; then \
1992 --key "${uefi_secureboot_key}" \
1993 --cert "${uefi_secureboot_cert}" \
1994 --output "$outfile" "${uefi_outdir}/linux.efi"; then
1995 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
1997 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2001 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2002 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2007 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2011 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2012 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2015 dfatal
"dracut: creation of $outfile failed"
2020 command -v restorecon
&>/dev
/null
&& restorecon
-- "$outfile"
2022 # We sync/fsfreeze only if we're operating on a live booted system.
2023 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2024 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2025 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2026 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2027 if test -d $dracutsysrootdir/run
/systemd
/system
; then
2028 if ! sync
"$outfile" 2> /dev
/null
; then
2029 dinfo
"dracut: sync operation on newly created initramfs $outfile failed"
2033 # use fsfreeze only if we're not writing to /
2034 if [[ "$(stat -c %m -- "$outfile")" != "/" && "$(stat -f -c %T -- "$outfile")" != "msdos" ]]; then
2035 if ! $
(fsfreeze
-f $
(dirname "$outfile") 2>/dev
/null
&& fsfreeze
-u $
(dirname "$outfile") 2>/dev
/null
); then
2036 dinfo
"dracut: warning: could not fsfreeze $(dirname "$outfile")"