3 # Generator script for a dracut initramfs
5 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # Verify bash version, current minimum is 4
27 if ((BASH_VERSINFO
[0] < 4)); then
28 printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
33 # shellcheck disable=SC2155
34 readonly dracut_cmd
=$
(readlink
-f "$0")
39 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
40 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
41 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
42 # shellcheck source=./dracut-version.sh
43 .
"$dracutbasedir"/dracut-version.sh
46 # 80x25 linebreak here ^
48 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
50 Version: $DRACUT_VERSION
52 Creates initial ramdisk images for preloading modules
54 -h, --help Display all options
56 If a [LIST] has multiple arguments, then you have to put these in quotes.
60 # dracut --add-drivers "module1 module2" ...
66 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
67 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
68 # shellcheck source=./dracut-version.sh
69 .
"$dracutbasedir"/dracut-version.sh
72 # 80x25 linebreak here ^
74 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
76 Version: $DRACUT_VERSION
78 Creates initial ramdisk images for preloading modules
80 --kver [VERSION] Set kernel version to [VERSION].
81 -f, --force Overwrite existing initramfs file.
82 [OUTPUT_FILE] --rebuild
83 Append the current arguments to those with which the
84 input initramfs image was built. This option helps in
85 incrementally building the initramfs for testing.
86 If optional [OUTPUT_FILE] is not provided, the input
87 initramfs provided to rebuild will be used as output
89 -a, --add [LIST] Add a space-separated list of dracut modules.
90 --force-add [LIST] Force to add a space-separated list of dracut modules
91 to the default set of modules, when -H is specified.
92 -o, --omit [LIST] Omit a space-separated list of dracut modules.
93 -m, --modules [LIST] Specify a space-separated list of dracut modules to
94 call when building the initramfs. Modules are located
95 in /usr/lib/dracut/modules.d.
96 This option forces dracut to only include the specified
98 In most cases the --add option is what you want to use.
99 --add-drivers [LIST] Specify a space-separated list of kernel
100 modules to add to the initramfs.
101 --force-drivers [LIST]
102 Specify a space-separated list of kernel
103 modules to add to the initramfs and make sure they
104 are tried to be loaded via modprobe same as passing
105 rd.driver.pre=DRIVER kernel parameter.
106 --omit-drivers [LIST] Specify a space-separated list of kernel
107 modules not to add to the initramfs.
108 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
109 exclusively include in the initramfs.
110 --filesystems [LIST] Specify a space-separated list of kernel filesystem
111 modules to exclusively include in the generic
113 -k, --kmoddir [DIR] Specify the directory where to look for kernel
115 --fwdir [DIR] Specify additional colon-separated list of directories
116 where to look for firmware files.
117 --libdirs [LIST] Specify a space-separated list of directories
118 where to look for libraries.
119 --kernel-only Only install kernel drivers and firmware files.
120 --no-kernel Do not install kernel drivers and firmware files.
121 --print-cmdline Print the kernel command line for the given disk layout.
122 --early-microcode Combine early microcode with ramdisk.
123 --no-early-microcode Do not combine early microcode with ramdisk.
124 --kernel-cmdline [PARAMETERS]
125 Specify default kernel command line parameters.
126 --strip Strip binaries in the initramfs.
127 --aggressive-strip Strip more than just debug symbol and sections,
128 for a smaller initramfs build. The --strip option must
130 --nostrip Do not strip binaries in the initramfs.
131 --hardlink Hardlink files in the initramfs.
132 --nohardlink Do not hardlink files in the initramfs.
133 --prefix [DIR] Prefix initramfs files with [DIR].
134 --noprefix Do not prefix initramfs files.
135 --mdadmconf Include local /etc/mdadm.conf file.
136 --nomdadmconf Do not include local /etc/mdadm.conf file.
137 --lvmconf Include local /etc/lvm/lvm.conf file.
138 --nolvmconf Do not include local /etc/lvm/lvm.conf file.
139 --fscks [LIST] Add a space-separated list of fsck helpers.
140 --nofscks Inhibit installation of any fsck helpers.
141 --ro-mnt Mount / and /usr read-only by default.
142 -h, --help This message.
143 --debug Output debug information of the build process.
144 --profile Output profile information of the build process.
145 -L, --stdlog [0-6] Specify logging level (to standard error)
146 0 - suppress any messages
147 1 - only fatal errors
151 5 - debug info (here starts lots of output)
152 6 - trace info (and even more)
153 -v, --verbose Increase verbosity level.
154 -q, --quiet Decrease verbosity level.
155 -c, --conf [FILE] Specify configuration file to use.
156 Default: /etc/dracut.conf
157 --confdir [DIR] Specify configuration directory to use *.conf files
158 from. Default: /etc/dracut.conf.d
159 --tmpdir [DIR] Temporary directory to be used instead of default
161 -r, --sysroot [DIR] Specify sysroot directory to collect files from.
162 -l, --local Local mode. Use modules from the current working
163 directory instead of the system-wide installed in
164 /usr/lib/dracut/modules.d.
165 Useful when running dracut from a git checkout.
166 -H, --hostonly Host-only mode: Install only what is needed for
167 booting the local host instead of a generic host.
168 -N, --no-hostonly Disables host-only mode.
169 --hostonly-mode [MODE]
170 Specify the host-only mode to use. [MODE] could be
171 one of "sloppy" or "strict". "sloppy" mode is used
173 In "sloppy" host-only mode, extra drivers and modules
174 will be installed, so minor hardware change won't make
175 the image unbootable (e.g. changed keyboard), and the
176 image is still portable among similar hosts.
177 With "strict" mode enabled, anything not necessary
178 for booting the local host in its current state will
179 not be included, and modules may do some extra job
180 to save more space. Minor change of hardware or
181 environment could make the image unbootable.
182 DO NOT use "strict" mode unless you know what you
184 --hostonly-cmdline Store kernel command line arguments needed
186 --no-hostonly-cmdline Do not store kernel command line arguments needed
188 --no-hostonly-default-device
189 Do not generate implicit host devices like root,
190 swap, fstab, etc. Use "--mount" or "--add-device"
191 to explicitly add devices as needed.
192 --hostonly-i18n Install only needed keyboard and font files according
193 to the host configuration (default).
194 --no-hostonly-i18n Install all keyboard and font files available.
195 --hostonly-nics [LIST]
196 Only enable listed NICs in the initramfs. The list can
197 be empty, so other modules can install only the
198 necessary network drivers.
199 --persistent-policy [POLICY]
200 Use [POLICY] to address disks and partitions.
201 POLICY can be any directory name found in /dev/disk.
202 E.g. "by-uuid", "by-label"
203 --fstab Use /etc/fstab to determine the root device.
204 --add-fstab [FILE] Add file to the initramfs fstab.
205 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
206 Mount device [DEV] on mountpoint [MP] with filesystem
207 [FSTYPE] and options [FSOPTS] in the initramfs.
208 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
209 determined by looking at the current mounts.
210 --add-device "[DEV]" Bring up [DEV] in initramfs.
211 -i, --include [SOURCE] [TARGET]
212 Include the files in the SOURCE directory into the
213 Target directory in the final initramfs.
214 If SOURCE is a file, it will be installed to TARGET
215 in the final initramfs.
216 -I, --install [LIST] Install the space separated list of files into the
218 --install-optional [LIST]
219 Install the space separated list of files into the
220 initramfs, if they exist.
221 --gzip Compress the generated initramfs using gzip.
222 This will be done by default, unless another
223 compression option or --no-compress is passed.
224 --bzip2 Compress the generated initramfs using bzip2.
225 Make sure your kernel has bzip2 decompression support
226 compiled in, otherwise you will not be able to boot.
227 --lzma Compress the generated initramfs using lzma.
228 Make sure your kernel has lzma support compiled in,
229 otherwise you will not be able to boot.
230 --xz Compress the generated initramfs using xz.
231 Make sure that your kernel has xz support compiled
232 in, otherwise you will not be able to boot.
233 --lzo Compress the generated initramfs using lzop.
234 Make sure that your kernel has lzo support compiled
235 in, otherwise you will not be able to boot.
236 --lz4 Compress the generated initramfs using lz4.
237 Make sure that your kernel has lz4 support compiled
238 in, otherwise you will not be able to boot.
239 --zstd Compress the generated initramfs using Zstandard.
240 Make sure that your kernel has zstd support compiled
241 in, otherwise you will not be able to boot.
242 --compress [COMPRESSION]
243 Compress the generated initramfs with the
244 passed compression program. Make sure your kernel
245 knows how to decompress the generated initramfs,
246 otherwise you will not be able to boot.
247 --no-compress Do not compress the generated initramfs. This will
248 override any other compression options.
249 --squash-compressor [COMPRESSION]
250 Specify the compressor and compressor specific options
251 used by mksquashfs if squash module is called when
252 building the initramfs.
253 --enhanced-cpio Attempt to reflink cpio file data using dracut-cpio.
254 --list-modules List all available dracut modules.
255 -M, --show-modules Print included module's name to standard output during
257 --keep Keep the temporary initramfs for debugging purposes.
258 --printsize Print out the module install size.
259 --sshkey [SSHKEY] Add SSH key to initramfs (use with ssh-client module).
260 --logfile [FILE] Logfile to use (overrides configuration setting).
261 --reproducible Create reproducible images.
262 --no-reproducible Do not create reproducible images.
263 --loginstall [DIR] Log all files installed from the host to [DIR].
264 --uefi Create an UEFI executable with the kernel cmdline and
266 --no-uefi Disables UEFI mode.
267 --no-machineid Affects the default output filename of the UEFI
268 executable, discarding the <MACHINE_ID> part.
269 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable.
270 --uefi-splash-image [FILE]
271 Use [FILE] as a splash image when creating an UEFI
272 executable. Requires bitmap (.bmp) image format.
273 --kernel-image [FILE] Location of the kernel image.
274 --regenerate-all Regenerate all initramfs images at the default location
275 for the kernel versions found on the system.
276 -p, --parallel Use parallel processing if possible (currently only
277 supported --regenerate-all)
278 images simultaneously.
279 --version Display version.
281 If [LIST] has multiple arguments, then you have to put these in quotes.
285 # dracut --add-drivers "module1 module2" ...
291 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
292 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
293 # shellcheck source=./dracut-version.sh
294 .
"$dracutbasedir"/dracut-version.sh
296 echo "dracut $DRACUT_VERSION"
299 # Fills up host_devs stack variable and makes sure there are no duplicates
303 [[ " ${host_devs[*]} " == *" $_dev "* ]] && return
308 # Little helper function for reading args from the commandline.
309 # it automatically handles -a b and -a=b variants, and returns 1 if
310 # we need to shift $3.
315 local rematch
='^[^=]*=(.*)$'
316 if [[ $2 =~
$rematch ]]; then
317 read -r "$1" <<< "${BASH_REMATCH[1]}"
319 read -r "$1" <<< "$3"
320 # There is no way to shift our callers args, so
321 # return 1 to indicate they should do it instead.
327 if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
328 printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
329 printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
340 for i
in "$d/"*"$suffix"; do
342 printf "%s\n" "${i##*/}"
348 for f
in "${files[@]}"; do
350 if [[ -e "$d/$f" ]]; then
351 printf "%s\n" "$d/$f"
360 # Workaround -i, --include taking 2 arguments
363 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
364 newat
+=("++include") # Replace --include by ++include
369 set -- "${newat[@]}" # Set new $@
372 unset POSIXLY_CORRECT
374 -o "a:m:o:d:I:k:c:r:L:fvqlHhMNp" \
378 --long add-drivers
: \
379 --long force-drivers
: \
380 --long omit-drivers
: \
384 --long filesystems
: \
386 --long install-optional
: \
403 --long squash-compressor
: \
409 --long print-cmdline \
410 --long kernel-cmdline
: \
412 --long aggressive-strip \
431 --long no-host-only \
432 --long hostonly-mode
: \
433 --long hostonly-cmdline \
434 --long no-hostonly-cmdline \
435 --long no-hostonly-default-device \
436 --long persistent-policy
: \
447 --long enhanced-cpio \
448 --long list-modules \
449 --long show-modules \
452 --long regenerate-all \
454 --long noimageifnotneeded \
455 --long early-microcode \
456 --long no-early-microcode \
457 --long reproducible \
458 --long no-reproducible \
463 --long uefi-splash-image
: \
464 --long kernel-image
: \
465 --long no-hostonly-i18n \
466 --long hostonly-i18n \
467 --long hostonly-nics
: \
468 --long no-machineid \
473 # shellcheck disable=SC2181
484 rearrange_params
"$@"
487 # parse command line args to check if '--rebuild' option is present
491 if [ "$1" == "--" ]; then
495 if [ "$1" == "--rebuild" ]; then
498 if [ ! -e "$rebuild_file" ]; then
499 echo "Image file '$rebuild_file', for rebuild, does not exist!"
502 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
509 # get output file name and kernel version from command line arguments
516 if ! [[ ${outfile+x} ]]; then
518 elif ! [[ ${kernel+x} ]]; then
521 printf "\nUnknown arguments: %s\n\n" "$*" >&2
530 # extract input image file provided with rebuild option to get previous parameters, if any
531 if [[ $append_args_l == "yes" ]]; then
534 # determine resultant file
535 if ! [[ $outfile ]]; then
536 outfile
=$rebuild_file
539 if ! rebuild_param
=$
(lsinitrd
"$rebuild_file" '*lib/dracut/build-parameter.txt'); then
540 echo "Image '$rebuild_file' has no rebuild information stored"
544 # prepend previous parameters to current command line args
545 if [[ $rebuild_param ]]; then
546 TEMP
="$rebuild_param $TEMP"
548 rearrange_params
"$@"
558 if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
559 PARMS_TO_STORE
+=" $1"
564 PARMS_TO_STORE
+=" '$2'"
568 add_dracutmodules_l
+=("$2")
569 PARMS_TO_STORE
+=" '$2'"
573 force_add_dracutmodules_l
+=("$2")
574 PARMS_TO_STORE
+=" '$2'"
578 add_drivers_l
+=("$2")
579 PARMS_TO_STORE
+=" '$2'"
583 force_drivers_l
+=("$2")
584 PARMS_TO_STORE
+=" '$2'"
588 omit_drivers_l
+=("$2")
589 PARMS_TO_STORE
+=" '$2'"
593 dracutmodules_l
+=("$2")
594 PARMS_TO_STORE
+=" '$2'"
598 omit_dracutmodules_l
+=("$2")
599 PARMS_TO_STORE
+=" '$2'"
604 PARMS_TO_STORE
+=" '$2'"
608 filesystems_l
+=("$2")
609 PARMS_TO_STORE
+=" '$2'"
613 install_items_l
+=("$2")
614 PARMS_TO_STORE
+=" '$2'"
618 install_optional_items_l
+=("$2")
619 PARMS_TO_STORE
+=" '$2'"
624 PARMS_TO_STORE
+=" '$2'"
629 PARMS_TO_STORE
+=" '$2'"
634 PARMS_TO_STORE
+=" '$2'"
639 PARMS_TO_STORE
+=" '$2'"
644 PARMS_TO_STORE
+=" '$2'"
647 --add-device |
--device)
649 PARMS_TO_STORE
+=" '$2'"
653 kernel_cmdline_l
+=("$2")
654 PARMS_TO_STORE
+=" '$2'"
657 --nofscks) nofscks_l
="yes" ;;
658 --ro-mnt) ro_mnt_l
="yes" ;;
661 PARMS_TO_STORE
+=" '$2'"
666 PARMS_TO_STORE
+=" '$2'"
671 PARMS_TO_STORE
+=" '$2'"
676 PARMS_TO_STORE
+=" '$2'"
681 PARMS_TO_STORE
+=" '$2'"
686 PARMS_TO_STORE
+=" '$2'"
691 PARMS_TO_STORE
+=" '$2'"
695 squash_compress_l
="$2"
696 PARMS_TO_STORE
+=" '$2'"
701 PARMS_TO_STORE
+=" '$2'"
706 PARMS_TO_STORE
+=" '$2'"
710 if [[ $rebuild_file == "$outfile" ]]; then
715 -f |
--force) force
=yes ;;
731 early_microcode_l
="yes"
733 --no-early-microcode)
734 early_microcode_l
="no"
736 --strip) do_strip_l
="yes" ;;
737 --aggressive-strip) aggressive_strip_l
="yes" ;;
738 --nostrip) do_strip_l
="no" ;;
739 --hardlink) do_hardlink_l
="yes" ;;
740 --nohardlink) do_hardlink_l
="no" ;;
741 --noprefix) prefix_l
="/" ;;
742 --mdadmconf) mdadmconf_l
="yes" ;;
743 --nomdadmconf) mdadmconf_l
="no" ;;
744 --lvmconf) lvmconf_l
="yes" ;;
745 --nolvmconf) lvmconf_l
="no" ;;
746 --debug) debug
="yes" ;;
747 --profile) profile
="yes" ;;
750 PARMS_TO_STORE
+=" '$2'"
757 -v |
--verbose) ((verbosity_mod_l
++)) ;;
758 -q |
--quiet) ((verbosity_mod_l--
)) ;;
761 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
762 && dracutbasedir
="$(readlink -f "${0%/*}")"
764 -H |
--hostonly |
--host-only)
767 -N |
--no-hostonly |
--no-host-only)
772 PARMS_TO_STORE
+=" '$2'"
776 hostonly_cmdline_l
="yes"
779 i18n_install_all_l
="no"
782 hostonly_nics_l
+=("$2")
783 PARMS_TO_STORE
+=" '$2'"
787 i18n_install_all_l
="yes"
789 --no-hostonly-cmdline)
790 hostonly_cmdline_l
="no"
792 --no-hostonly-default-device)
793 hostonly_default_device
="no"
796 persistent_policy_l
="$2"
797 PARMS_TO_STORE
+=" '$2'"
800 --fstab) use_fstab_l
="yes" ;;
805 --bzip2) compress_l
="bzip2" ;;
806 --lzma) compress_l
="lzma" ;;
807 --xz) compress_l
="xz" ;;
808 --lzo) compress_l
="lzop" ;;
809 --lz4) compress_l
="lz4" ;;
810 --zstd) compress_l
="zstd" ;;
811 --no-compress) _no_compress_l
="cat" ;;
812 --gzip) compress_l
="gzip" ;;
813 --enhanced-cpio) enhanced_cpio_l
="yes" ;;
814 --list-modules) do_list
="yes" ;;
818 --keep) keep
="yes" ;;
819 --printsize) printsize
="yes" ;;
820 --regenerate-all) regenerate_all_l
="yes" ;;
821 -p |
--parallel) parallel_l
="yes" ;;
822 --noimageifnotneeded) noimageifnotneeded
="yes" ;;
823 --reproducible) reproducible_l
="yes" ;;
824 --no-reproducible) reproducible_l
="no" ;;
825 --uefi) uefi_l
="yes" ;;
826 --no-uefi) uefi_l
="no" ;;
829 PARMS_TO_STORE
+=" '$2'"
833 uefi_splash_image_l
="$2"
834 PARMS_TO_STORE
+=" '$2'"
839 PARMS_TO_STORE
+=" '$2'"
854 *) # should not even reach this point
855 printf "\n!Unknown option: '%s'\n\n" "$1" >&2
863 # getopt cannot handle multiple arguments, so just handle "-I,--include"
864 # the old fashioned way
867 if [ "${1%%=*}" == "++include" ]; then
869 include_target
+=("$3")
870 PARMS_TO_STORE
+=" --include '$2' '$3'"
876 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
882 unset LD_LIBRARY_PATH
886 export DRACUT_LOG_LEVEL
=warning
888 export DRACUT_LOG_LEVEL
=debug
889 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
894 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '
899 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
901 # if we were not passed a config file, try the default one
902 if [[ -z $conffile ]]; then
903 if [[ $allowlocal ]]; then
904 conffile
="$dracutbasedir/dracut.conf"
906 conffile
="$dracutsysrootdir/etc/dracut.conf"
908 elif [[ ! -e $conffile ]]; then
909 printf "%s\n" "dracut: Configuration file '$conffile' not found." >&2
913 if [[ -z $confdir ]]; then
914 if [[ $allowlocal ]]; then
915 confdir
="$dracutbasedir/dracut.conf.d"
917 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
919 elif [[ ! -d $confdir ]]; then
920 printf "%s\n" "dracut: Configuration directory '$confdir' not found." >&2
924 # source our config file
925 if [[ -f $conffile ]]; then
926 check_conf_file
"$conffile"
927 # shellcheck disable=SC1090
931 # source our config dir
932 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
934 # shellcheck disable=SC1090
935 [[ -e $f ]] && .
"$f"
938 # regenerate_all shouldn't be set in conf files
939 regenerate_all
=$regenerate_all_l
940 if [[ $parallel_l == "yes" ]]; then
944 if [[ $regenerate_all == "yes" ]]; then
946 if [[ $kernel ]]; then
947 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
951 if [[ $outfile ]]; then
952 printf -- "--regenerate-all cannot be called with a image file\n" >&2
956 ((len
= ${#dracut_args[@]}))
957 for ((i
= 0; i
< len
; i
++)); do
958 case ${dracut_args[$i]} in
959 --regenerate-all |
--parallel)
960 unset dracut_args
["$i"]
965 cd "$dracutsysrootdir"/lib
/modules ||
exit 1
966 if [[ $parallel != "yes" ]]; then
968 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
969 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
974 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
975 "$dracut_cmd" --kver="$i" "${dracut_args[@]}" &
980 if [[ $wst == 127 ]]; then
990 if ! [[ $kernel ]]; then
994 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
996 for i
in $DRACUT_PATH; do
998 if [ -L "$dracutsysrootdir$i" ]; then
999 rl
=$
(readlink
-f "$dracutsysrootdir$i")
1001 rl
="${rl#$dracutsysrootdir}"
1002 if [[ $NPATH != *:$rl* ]]; then
1006 [[ -z $dracutsysrootdir ]] && export PATH
="${NPATH#:}"
1009 export SYSTEMCTL
=${SYSTEMCTL:-systemctl}
1011 # these options add to the stuff in the config file
1012 ((${#add_dracutmodules_l[@]})) && add_dracutmodules
+=" ${add_dracutmodules_l[*]} "
1013 ((${#omit_dracutmodules_l[@]})) && omit_dracutmodules
+=" ${omit_dracutmodules_l[*]} "
1014 ((${#force_add_dracutmodules_l[@]})) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[*]} "
1015 ((${#fscks_l[@]})) && fscks
+=" ${fscks_l[*]} "
1016 ((${#add_fstab_l[@]})) && add_fstab
+=" ${add_fstab_l[*]} "
1017 ((${#install_items_l[@]})) && install_items
+=" ${install_items_l[*]} "
1018 ((${#install_optional_items_l[@]})) && install_optional_items
+=" ${install_optional_items_l[*]} "
1019 ((${#hostonly_nics_l[@]})) && hostonly_nics
+=" ${hostonly_nics_l[*]} "
1021 # these options override the stuff in the config file
1022 ((${#dracutmodules_l[@]})) && dracutmodules
="${dracutmodules_l[*]}"
1023 ((${#filesystems_l[@]})) && filesystems
="${filesystems_l[*]}"
1024 ((${#fw_dir_l[@]})) && fw_dir
="${fw_dir_l[*]}"
1025 ((${#libdirs_l[@]})) && libdirs
="${libdirs_l[*]}"
1027 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
1028 [[ ! $stdloglvl ]] && stdloglvl
=4
1029 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
1030 ((stdloglvl
> 6)) && stdloglvl
=6
1031 ((stdloglvl
< 0)) && stdloglvl
=0
1033 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
1034 drivers_dir
="${drivers_dir%%+(/)}"
1035 [[ $do_strip_l ]] && do_strip
=$do_strip_l
1036 [[ $do_strip ]] || do_strip
=yes
1037 [[ $aggressive_strip_l ]] && aggressive_strip
=$aggressive_strip_l
1038 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
1039 [[ $do_hardlink ]] || do_hardlink
=yes
1040 [[ $prefix_l ]] && prefix
=$prefix_l
1041 [[ $prefix == "/" ]] && unset prefix
1042 [[ $hostonly_l ]] && hostonly
=$hostonly_l
1043 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
1044 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
1045 [[ $hostonly == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
1046 # shellcheck disable=SC2034
1047 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
1048 # shellcheck disable=SC2034
1049 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
1050 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
1051 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
1052 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
1053 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
1055 fw_path_para
=$
(< /sys
/module
/firmware_class
/parameters
/path
)
1056 fw_dir
="${fw_path_para:+$dracutsysrootdir$fw_path_para:}$dracutsysrootdir/lib/firmware/updates/$kernel:$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware/$kernel:$dracutsysrootdir/lib/firmware"
1058 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
1059 [[ $tmpdir ]] || tmpdir
="$TMPDIR"
1060 [[ $tmpdir ]] || tmpdir
="$dracutsysrootdir"/var
/tmp
1061 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
1062 [[ $compress_l ]] && compress=$compress_l
1063 [[ $squash_compress_l ]] && squash_compress
=$squash_compress_l
1064 [[ $enhanced_cpio_l ]] && enhanced_cpio
=$enhanced_cpio_l
1065 [[ $show_modules_l ]] && show_modules
=$show_modules_l
1066 [[ $nofscks_l ]] && nofscks
="yes"
1067 [[ $ro_mnt_l ]] && ro_mnt
="yes"
1068 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
1069 [[ $early_microcode ]] || early_microcode
=yes
1070 [[ $early_microcode_image_dir ]] || early_microcode_image_dir
=('/boot')
1071 [[ $early_microcode_image_name ]] \
1072 || early_microcode_image_name
=('intel-uc.img' 'intel-ucode.img' 'amd-uc.img' 'amd-ucode.img' 'early_ucode.cpio' 'microcode.cpio')
1073 [[ $logfile_l ]] && logfile
="$logfile_l"
1074 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
1075 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
1076 [[ $uefi_l ]] && uefi
=$uefi_l
1077 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
1078 [[ $uefi_splash_image_l ]] && uefi_splash_image
="$uefi_splash_image_l"
1079 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
1080 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
1082 if ! [[ $outfile ]]; then
1083 if [[ $machine_id != "no" ]]; then
1084 if [[ -d "$dracutsysrootdir"/efi
/Default
]] \
1085 ||
[[ -d "$dracutsysrootdir"/boot
/Default
]] \
1086 ||
[[ -d "$dracutsysrootdir"/boot
/efi
/Default
]]; then
1087 MACHINE_ID
="Default"
1088 elif [[ -f "$dracutsysrootdir"/etc
/machine-id
]]; then
1089 read -r MACHINE_ID
< "$dracutsysrootdir"/etc
/machine-id
1091 MACHINE_ID
="Default"
1095 if [[ $uefi == "yes" ]]; then
1096 # shellcheck disable=SC2154
1097 if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
1098 printf "%s\n" "dracut: Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set." >&2
1102 if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign
&> /dev
/null
; then
1103 printf "%s\n" "dracut: Need 'sbsign' to create a signed UEFI executable." >&2
1107 BUILD_ID
=$
(cat "$dracutsysrootdir"/etc
/os-release
"$dracutsysrootdir"/usr
/lib
/os-release \
1108 |
while read -r line ||
[[ $line ]]; do
1109 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break
1111 if [[ -z $dracutsysrootdir ]]; then
1112 if [[ -d /efi
]] && mountpoint
-q /efi
; then
1116 if [[ -d /boot
/efi
/EFI
]]; then
1117 efidir
=/boot
/efi
/EFI
1122 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1123 efidir
=/boot
/efi
/EFI
1126 mkdir
-p "$dracutsysrootdir$efidir/Linux"
1127 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
1129 if [[ -d "$dracutsysrootdir"/efi
/loader
/entries ||
-L "$dracutsysrootdir"/efi
/loader
/entries
]] \
1130 && [[ $MACHINE_ID ]] \
1131 && [[ -d "$dracutsysrootdir"/efi
/${MACHINE_ID} ||
-L "$dracutsysrootdir"/efi
/${MACHINE_ID} ]]; then
1132 outfile
="$dracutsysrootdir/efi/${MACHINE_ID}/${kernel}/initrd"
1133 elif [[ -d "$dracutsysrootdir"/boot
/loader
/entries ||
-L "$dracutsysrootdir"/boot
/loader
/entries
]] \
1134 && [[ $MACHINE_ID ]] \
1135 && [[ -d "$dracutsysrootdir"/boot
/${MACHINE_ID} ||
-L "$dracutsysrootdir"/boot
/${MACHINE_ID} ]]; then
1136 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/${kernel}/initrd"
1137 elif [[ -d "$dracutsysrootdir"/boot
/efi
/loader
/entries ||
-L "$dracutsysrootdir"/boot
/efi
/loader
/entries
]] \
1138 && [[ $MACHINE_ID ]] \
1139 && [[ -d "$dracutsysrootdir"/boot
/efi
/${MACHINE_ID} ||
-L "$dracutsysrootdir"/boot
/efi
/${MACHINE_ID} ]]; then
1140 outfile
="$dracutsysrootdir/boot/efi/${MACHINE_ID}/${kernel}/initrd"
1141 elif [[ -f "$dracutsysrootdir"/lib
/modules
/${kernel}/initrd
]]; then
1142 outfile
="$dracutsysrootdir/lib/modules/${kernel}/initrd"
1143 elif [[ -e $dracutsysrootdir/boot
/vmlinuz-
${kernel} ]]; then
1144 outfile
="$dracutsysrootdir/boot/initramfs-${kernel}.img"
1145 elif [[ -z $dracutsysrootdir ]] \
1146 && [[ $MACHINE_ID ]] \
1147 && mountpoint
-q /efi
; then
1148 outfile
="/efi/${MACHINE_ID}/${kernel}/initrd"
1149 elif [[ -z $dracutsysrootdir ]] \
1150 && [[ $MACHINE_ID ]] \
1151 && mountpoint
-q /boot
/efi
; then
1152 outfile
="/boot/efi/${MACHINE_ID}/${kernel}/initrd"
1154 outfile
="$dracutsysrootdir/boot/initramfs-${kernel}.img"
1159 # eliminate IFS hackery when messing with fw_dir
1160 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
1161 fw_dir
=${fw_dir//:/ }
1163 # check for logfile and try to create one if it doesn't exist
1164 if [[ -n $logfile ]]; then
1165 if [[ ! -f $logfile ]]; then
1166 if touch "$logfile"; then
1167 printf "%s\n" "dracut: touch $logfile failed." >&2
1172 # handle compression options.
1173 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
1174 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
1175 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
1176 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
1177 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
1178 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
1179 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
1180 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
1181 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
1182 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
1184 if [[ $_no_compress_l == "$DRACUT_COMPRESS_CAT" ]]; then
1185 compress="$DRACUT_COMPRESS_CAT"
1188 [[ $hostonly == yes ]] && hostonly
="-h"
1189 [[ $hostonly != "-h" ]] && unset hostonly
1191 case $hostonly_mode in
1193 [[ $hostonly ]] && hostonly_mode
="sloppy"
1196 if [[ ! $hostonly ]]; then
1201 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
1206 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
1208 if [[ -z $DRACUT_KMODDIR_OVERRIDE && -n $drivers_dir ]]; then
1209 drivers_basename
="${drivers_dir##*/}"
1210 if [[ -n $drivers_basename && $drivers_basename != "$kernel" ]]; then
1211 printf "%s\n" "dracut: The provided directory where to look for kernel modules ($drivers_basename)" >&2
1212 printf "%s\n" "dracut: does not match the kernel version set for the initramfs ($kernel)." >&2
1213 printf "%s\n" "dracut: Set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1216 drivers_dirname
="${drivers_dir%/*}/"
1217 if [[ ! $drivers_dirname =~ .
*/lib
/modules
/$
]]; then
1218 printf "%s\n" "dracut: drivers_dir path ${drivers_dir_l:+"set via -k/--kmoddir "}must contain \"/lib/modules/\" as a parent of your kernel module directory," >&2
1219 printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs." >&2
1220 printf "%s\n" "dracut: was given: ${drivers_dir}" >&2
1221 printf "%s\n" "dracut: expected: ${drivers_dirname}lib/modules/${kernel}" >&2
1222 printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location," >&2
1223 printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check." >&2
1228 # shellcheck disable=SC2155
1229 readonly TMPDIR
="$(realpath -e "$tmpdir")"
1230 [ -d "$TMPDIR" ] ||
{
1231 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
1235 if findmnt
--raw -n --target "$tmpdir" --output=options |
grep -q noexec
; then
1236 [[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
1240 # shellcheck disable=SC2155
1241 readonly DRACUT_TMPDIR
="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
1242 [ -d "$DRACUT_TMPDIR" ] ||
{
1243 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
1247 # Cache file used to optimize get_maj_min()
1248 declare -x -r get_maj_min_cache_file
="${DRACUT_TMPDIR}/majmin_cache"
1249 : > "$get_maj_min_cache_file"
1251 # clean up after ourselves no matter how we die.
1254 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
1255 if [[ ${FSFROZEN} ]]; then
1256 fsfreeze -u "${FSFROZEN}"
1261 # clean up after ourselves no matter how we die.
1262 trap 'exit 1;' SIGINT
1264 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
1267 # shellcheck disable=SC2154
1268 if [[ $early_microcode == yes ]] ||
{ [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
1269 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
1270 mkdir
"$early_cpio_dir"
1273 [[ "$dracutsysrootdir" ]] ||
[[ "$noexec" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
1275 if [[ $print_cmdline ]]; then
1282 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
1283 # shellcheck source=./dracut-version.sh
1284 .
"$dracutbasedir"/dracut-version.sh
1287 if systemd-detect-virt
-c &> /dev
/null
; then
1288 export DRACUT_NO_MKNOD
=1 DRACUT_NO_XATTR
=1
1289 if [[ $hostonly ]]; then
1290 printf "%s\n" "dracut: WARNING: running in hostonly mode in a container!!"
1294 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
1295 # shellcheck source=./dracut-init.sh
1296 .
"$dracutbasedir"/dracut-init.sh
1298 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1299 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1300 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1304 if [[ $enhanced_cpio == "yes" ]]; then
1305 enhanced_cpio
="$dracutbasedir/dracut-cpio"
1306 if [[ -x $enhanced_cpio ]]; then
1307 # align based on statfs optimal transfer size
1308 cpio_align
=$
(stat
--file-system -c "%s" -- "$initdir")
1310 dinfo
"--enhanced-cpio ignored due to lack of dracut-cpio"
1317 # shellcheck disable=SC2154
1318 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1319 dfatal
"Cannot find module directory $srcmods"
1320 dfatal
"and --no-kernel was not specified"
1324 if ! [[ $print_cmdline ]]; then
1325 inst
"$DRACUT_TESTBIN"
1326 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &> /dev
/null
; then
1327 unset DRACUT_RESOLVE_LAZY
1328 export DRACUT_RESOLVE_DEPS
=1
1330 rm -fr -- "${initdir:?}"/*
1333 dracutfunctions
=$dracutbasedir/dracut-functions.sh
1334 export dracutfunctions
1336 ((${#drivers_l[@]})) && drivers
="${drivers_l[*]}"
1337 drivers
=${drivers/-/_}
1339 ((${#add_drivers_l[@]})) && add_drivers
+=" ${add_drivers_l[*]} "
1340 add_drivers
=${add_drivers/-/_}
1342 ((${#force_drivers_l[@]})) && force_drivers
+=" ${force_drivers_l[*]} "
1343 force_drivers
=${force_drivers/-/_}
1345 ((${#omit_drivers_l[@]})) && omit_drivers
+=" ${omit_drivers_l[*]} "
1346 omit_drivers
=${omit_drivers/-/_}
1348 ((${#kernel_cmdline_l[@]})) && kernel_cmdline
+=" ${kernel_cmdline_l[*]} "
1350 omit_drivers_corrected
=""
1351 for d
in $omit_drivers; do
1352 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
1353 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1354 omit_drivers_corrected
+="^$d$|"
1356 omit_drivers
="${omit_drivers_corrected%|}"
1357 unset omit_drivers_corrected
1359 # prepare args for logging
1360 for ((i
= 0; i
< ${#dracut_args[@]}; i
++)); do
1361 [[ ${dracut_args[$i]} == *\
* ]] \
1362 && dracut_args
[$i]="\"${dracut_args[$i]}\""
1366 dinfo
"Executing: $dracut_cmd ${dracut_args[*]}"
1368 [[ $do_list == yes ]] && {
1369 for mod
in "$dracutbasedir"/modules.d
/*; do
1370 [[ -d $mod ]] ||
continue
1371 [[ -e $mod/install ||
-e $mod/installkernel ||
-e $mod/module-setup.sh
]] ||
continue
1372 printf "%s\n" "${mod##*/??}"
1377 # This is kinda legacy -- eventually it should go away.
1378 case $dracutmodules in
1379 "" | auto
) dracutmodules
="all" ;;
1382 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1384 [[ -d $dracutsysrootdir$systemdutildir ]] \
1385 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2> /dev
/null
)
1387 if ! [[ -d $dracutsysrootdir$systemdutildir ]]; then
1388 [[ -e $dracutsysrootdir/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1389 [[ -e $dracutsysrootdir/usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1392 [[ -d $dracutsysrootdir$systemdutilconfdir ]] \
1393 || systemdutilconfdir
=$
(pkg-config systemd
--variable=systemdutilconfdir
2> /dev
/null
)
1395 [[ -d $dracutsysrootdir$systemdutilconfdir ]] || systemdutilconfdir
=/etc
/systemd
1397 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1398 if ! [[ -f $srcmods/modules.dep
]]; then
1399 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1400 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1403 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1408 if [[ ! $print_cmdline ]]; then
1409 if [[ -f $outfile && ! $force ]]; then
1410 dfatal
"Will not override existing initramfs ($outfile) without --force"
1414 outdir
=${outfile%/*}
1415 [[ $outdir ]] || outdir
="/"
1417 if [[ ! -d $outdir ]]; then
1418 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1420 elif [[ ! -w $outdir ]]; then
1421 dfatal
"No permission to write to $outdir."
1423 elif [[ -f $outfile && ! -w $outfile ]]; then
1424 dfatal
"No permission to write $outfile."
1428 if [[ $loginstall ]]; then
1429 if ! mkdir
-p "$loginstall"; then
1430 dfatal
"Could not create directory to log installed files to '$loginstall'."
1433 loginstall
=$
(readlink
-f "$loginstall")
1436 if [[ $uefi == yes ]]; then
1437 if ! command -v objcopy
&> /dev
/null
; then
1438 dfatal
"Need 'objcopy' to create a UEFI executable"
1441 unset EFI_MACHINE_TYPE_NAME
1442 EFI_SECTION_VMA_INITRD
=0x3000000
1443 case "${DRACUT_ARCH:-$(uname -m)}" in
1445 EFI_MACHINE_TYPE_NAME
=x64
1448 EFI_MACHINE_TYPE_NAME
=ia32
1451 EFI_MACHINE_TYPE_NAME
=aa64
1452 # aarch64 kernels are uncompressed and thus larger, so we need a bigger gap between vma sections
1453 EFI_SECTION_VMA_INITRD
=0x4000000
1456 dfatal
"Architecture '${DRACUT_ARCH:-$(uname -m)}' not supported to create a UEFI executable"
1461 if ! [[ -s $uefi_stub ]]; then
1462 uefi_stub
="$dracutsysrootdir${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"
1465 if ! [[ -s $uefi_stub ]]; then
1466 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1470 if ! [[ $kernel_image ]]; then
1471 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1472 [[ -s $kernel_image ]] ||
continue
1476 if ! [[ -s $kernel_image ]]; then
1477 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1483 if [[ $acpi_override == yes ]] && ! (check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1484 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1488 if [[ $early_microcode == yes ]]; then
1489 if [[ $hostonly ]]; then
1490 if [[ $
(get_cpu_vendor
) == "AMD" ]]; then
1491 check_kernel_config CONFIG_MICROCODE_AMD ||
unset early_microcode
1492 elif [[ $
(get_cpu_vendor
) == "Intel" ]]; then
1493 check_kernel_config CONFIG_MICROCODE_INTEL ||
unset early_microcode
1495 unset early_microcode
1498 ! check_kernel_config CONFIG_MICROCODE_AMD \
1499 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1500 && unset early_microcode
1502 # Do not complain on non-x86 architectures as it makes no sense
1503 case "${DRACUT_ARCH:-$(uname -m)}" in
1505 [[ $early_microcode != yes ]] \
1506 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1512 # Need to be able to have non-root users read stuff (rpcbind etc)
1513 chmod 755 "$initdir"
1515 if [[ $hostonly ]]; then
1516 for i
in /sys
/proc
/run
/dev
; do
1517 if ! findmnt
--target "$i" &> /dev
/null
; then
1518 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1524 declare -A host_fs_types
1526 for line
in "${fstab_lines[@]}"; do
1527 # shellcheck disable=SC2086
1533 dev
=$
(blkid
-l -t "UUID=${dev#UUID=}" -o device
)
1536 dev
=$
(blkid
-l -t "LABEL=${dev#LABEL=}" -o device
)
1539 dev
=$
(blkid
-l -t "PARTUUID=${dev#PARTUUID=}" -o device
)
1542 dev
=$
(blkid
-l -t "PARTLABEL=${dev#PARTLABEL=}" -o device
)
1545 [ -z "$dev" ] && dwarn
"Bad fstab entry $*" && continue
1546 if [[ $3 == btrfs
]]; then
1547 for mp
in $
(findmnt
--source "$1" -o TARGET
-n); do
1548 for i
in $
(btrfs_devs
"$mp"); do
1552 elif [[ $3 == zfs
]]; then
1553 for mp
in $
(zfs_devs
"$1"); do
1554 push_host_devs
"$mp"
1557 push_host_devs
"$dev"
1558 host_fs_types
["$dev"]="$3"
1561 for f
in $add_fstab; do
1562 [[ -e $f ]] ||
continue
1563 while read -r dev rest ||
[ -n "$dev" ]; do
1564 push_host_devs
"$dev"
1568 for dev
in $add_device; do
1569 push_host_devs
"$dev"
1572 if ((${#add_device_l[@]})); then
1573 add_device
+=" ${add_device_l[*]} "
1574 push_host_devs
"${add_device_l[@]}"
1577 if [[ $hostonly ]] && [[ $hostonly_default_device != "no" ]]; then
1578 # in hostonly mode, determine all devices, which have to be accessed
1579 # and examine them for filesystem types
1596 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1597 mountpoint
"$mp" > /dev
/null
2>&1 ||
continue
1598 _dev
=$
(find_block_device
"$mp")
1599 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1600 [[ -b $_bdev ]] && _dev
=$_bdev
1601 [[ $mp == "/" ]] && root_devs
+=("$_dev")
1602 push_host_devs
"$_dev"
1603 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1604 for i
in $
(btrfs_devs
"$mp"); do
1605 [[ $mp == "/" ]] && root_devs
+=("$i")
1608 elif [[ $
(find_mp_fstype
"$mp") == zfs
]]; then
1609 for i
in $
(zfs_devs
"$(findmnt -n -o SOURCE "$mp")"); do
1610 [[ $mp == "/" ]] && root_devs
+=("$i")
1617 # TODO - with sysroot, /proc/swaps is not relevant
1618 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1619 while read -r dev
type rest ||
[ -n "$dev" ]; do
1620 [[ -b $dev ]] ||
continue
1621 [[ $type == "partition" ]] ||
continue
1623 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1624 [[ $_d == \
#* ]] && continue
1625 [[ $_d ]] ||
continue
1626 [[ $_t != "swap" ]] && continue
1627 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1628 [[ $_o == *noauto
* ]] && continue
1629 _d
=$
(expand_persistent_dev
"$_d")
1630 [[ $_d -ef $dev ]] ||
continue
1632 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1633 while read -r _mapper _ _p _o ||
[ -n "$_mapper" ]; do
1634 [[ $_mapper == \
#* ]] && continue
1635 [[ $_d -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1636 [[ "$_o" ]] || _o
="$_p"
1637 # skip entries with password files
1638 [[ $_p == /* ]] && [[ -f $_p ]] && continue 2
1640 [[ $_o == *swap
* ]] && continue 2
1641 done < "$dracutsysrootdir"/etc
/crypttab
1644 _dev
="$(readlink -f "$dev")"
1645 push_host_devs
"$_dev"
1646 swap_devs
+=("$_dev")
1648 done < "$dracutsysrootdir"/etc
/fstab
1652 # collect all "x-initrd.mount" entries from /etc/fstab
1653 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1654 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1655 [[ $_d == \
#* ]] && continue
1656 [[ $_d ]] ||
continue
1657 [[ $_o != *x-initrd.mount
* ]] && continue
1658 _dev
=$
(expand_persistent_dev
"$_d")
1659 _dev
="$(readlink -f "$_dev")"
1660 [[ -b $_dev ]] ||
continue
1662 push_host_devs
"$_dev"
1663 if [[ $_t == btrfs
]]; then
1664 for i
in $
(btrfs_devs
"$_m"); do
1667 elif [[ $_t == zfs
]]; then
1668 for i
in $
(zfs_devs
"$_d"); do
1672 done < "$dracutsysrootdir"/etc
/fstab
1681 if [[ -b /dev
/block
/$1 ]]; then
1682 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1685 if [[ -b $1 ]]; then
1686 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1689 if fstype
=$
(find_dev_fstype
"$1"); then
1690 host_fs_types
["$1"]="$fstype"
1696 for dev
in "${host_devs[@]}"; do
1698 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1701 for dev
in "${!host_fs_types[@]}"; do
1702 [[ ${host_fs_types[$dev]} == "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} == "xfs" ]] ||
continue
1703 rootopts
=$
(find_dev_fsopts
"$dev")
1704 if [[ ${host_fs_types[$dev]} == "reiserfs" ]]; then
1705 journaldev
=$
(fs_get_option
"$rootopts" "jdev")
1706 elif [[ ${host_fs_types[$dev]} == "xfs" ]]; then
1707 journaldev
=$
(fs_get_option
"$rootopts" "logdev")
1709 if [[ $journaldev ]]; then
1710 dev
="$(readlink -f "$dev")"
1711 push_host_devs
"$dev"
1713 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1717 [[ -d $dracutsysrootdir$dbus ]] \
1718 || dbus
=$
(pkg-config dbus
--variable=dbus
2> /dev
/null
)
1720 [[ -d $dracutsysrootdir$dbus ]] || dbus
=/usr
/share
/dbus-1
1722 [[ -d $dracutsysrootdir$dbusconfdir ]] \
1723 || dbusconfdir
=$
(pkg-config dbus
--variable=dbusconfdir
2> /dev
/null
)
1725 [[ -d $dracutsysrootdir$dbusconfdir ]] || dbusconfdir
=/etc
/dbus-1
1727 [[ -d $dracutsysrootdir$dbusinterfaces ]] \
1728 || dbusinterfaces
=$
(pkg-config dbus
--variable=dbusinterfaces
2> /dev
/null
)
1730 [[ -d $dracutsysrootdir$dbusinterfaces ]] || dbusinterfaces
=${dbus}/interfaces
1732 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] \
1733 || dbusinterfacesconfdir
=$
(pkg-config dbus
--variable=dbusinterfacesconfdir
2> /dev
/null
)
1735 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] || dbusinterfacesconfdir
=${dbusconfdir}/interfaces
1737 [[ -d $dracutsysrootdir$dbusservices ]] \
1738 || dbusservices
=$
(pkg-config dbus
--variable=dbusservices
2> /dev
/null
)
1740 [[ -d $dracutsysrootdir$dbusservices ]] || dbusservices
=${dbus}/services
1742 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] \
1743 || dbusservicesconfdir
=$
(pkg-config dbus
--variable=dbusservicesconfdir
2> /dev
/null
)
1745 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] || dbusservicesconfdir
=${dbusconfdir}/services
1747 [[ -d $dracutsysrootdir$dbussession ]] \
1748 || dbussession
=$
(pkg-config dbus
--variable=dbussession
2> /dev
/null
)
1750 [[ -d $dracutsysrootdir$dbussession ]] || dbussession
=${dbus}/session.d
1752 [[ -d $dracutsysrootdir$dbussessionconfdir ]] \
1753 || dbussessionconfdir
=$
(pkg-config dbus
--variable=dbussessionconfdir
2> /dev
/null
)
1755 [[ -d $dracutsysrootdir$dbussessionconfdir ]] || dbussessionconfdir
=${dbusconfdir}/session.d
1757 [[ -d $dracutsysrootdir$dbussystem ]] \
1758 || dbussystem
=$
(pkg-config dbus
--variable=dbussystem
2> /dev
/null
)
1760 [[ -d $dracutsysrootdir$dbussystem ]] || dbussystem
=${dbus}/system.d
1762 [[ -d $dracutsysrootdir$dbussystemconfdir ]] \
1763 || dbussystemconfdir
=$
(pkg-config dbus
--variable=dbussystemconfdir
2> /dev
/null
)
1765 [[ -d $dracutsysrootdir$dbussystemconfdir ]] || dbussystemconfdir
=${dbusconfdir}/system.d
1767 [[ -d $dracutsysrootdir$dbussystemservices ]] \
1768 || dbussystemservices
=$
(pkg-config dbus
--variable=dbussystemservices
2> /dev
/null
)
1770 [[ -d $dracutsysrootdir$dbussystemservices ]] || dbussystemservices
=${dbus}/system-services
1772 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] \
1773 || dbussystemservicesconfdir
=$
(pkg-config dbus
--variable=dbussystemservicesconfdir
2> /dev
/null
)
1775 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] || dbussystemservicesconfdir
=${dbusconfdir}/system-services
1777 [[ -d $dracutsysrootdir$udevdir ]] \
1778 || udevdir
="$(pkg-config udev --variable=udevdir 2> /dev/null)"
1779 if ! [[ -d $dracutsysrootdir$udevdir ]]; then
1780 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1781 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1784 [[ -d $dracutsysrootdir$udevconfdir ]] \
1785 || udevconfdir
=$
(pkg-config udev
--variable=udevconfdir
2> /dev
/null
)
1787 [[ -d $dracutsysrootdir$udevconfdir ]] || udevconfdir
=/etc
/udev
1789 [[ -d $dracutsysrootdir$udevrulesdir ]] \
1790 || udevrulesdir
=$
(pkg-config udev
--variable=udevrulesdir
2> /dev
/null
)
1792 [[ -d $dracutsysrootdir$udevrulesdir ]] || udevrulesdir
=${udevdir}/rules.d
1794 [[ -d $dracutsysrootdir$udevrulesconfdir ]] \
1795 || udevrulesconfdir
=$
(pkg-config udev
--variable=udevrulesconfdir
2> /dev
/null
)
1797 [[ -d $dracutsysrootdir$udevrulesconfdir ]] || udevrulesconfdir
=${udevconfdir}/rules.d
1799 [[ -d $dracutsysrootdir$sysctld ]] \
1800 || sysctld
=$
(pkg-config systemd
--variable=sysctld
2> /dev
/null
)
1802 [[ -d $dracutsysrootdir$sysctld ]] || sysctld
=/usr
/lib
/sysctl.d
1804 [[ -d $dracutsysrootdir$sysctlconfdir ]] \
1805 || sysctlconfdir
=$
(pkg-config systemd
--variable=sysctlconfdir
2> /dev
/null
)
1807 [[ -d $dracutsysrootdir$sysctlconfdir ]] || sysctlconfdir
=/etc
/sysctl.d
1809 [[ -d $dracutsysrootdir$environment ]] \
1810 || environment
=$
(pkg-config systemd
--variable=environment
2> /dev
/null
)
1812 [[ -d $dracutsysrootdir$environment ]] || environment
=/usr
/lib
/environment.d
1814 [[ -d $dracutsysrootdir$environmentconfdir ]] \
1815 || environmentconfdir
=$
(pkg-config systemd
--variable=environmentconfdir
2> /dev
/null
)
1817 [[ -d $dracutsysrootdir$environmentconfdir ]] || environmentconfdir
=/etc
/environment.d
1819 [[ -d $dracutsysrootdir$systemdcatalog ]] \
1820 || systemdcatalog
=$
(pkg-config systemd
--variable=systemdcatalog
2> /dev
/null
)
1822 [[ -d $dracutsysrootdir$systemdcatalog ]] || systemdcatalog
=${systemdutildir}/catalog
1824 [[ -d $dracutsysrootdir$modulesload ]] \
1825 || modulesload
=$
(pkg-config systemd
--variable=modulesload
2> /dev
/null
)
1827 [[ -d $dracutsysrootdir$modulesload ]] || modulesload
=/usr
/lib
/modules-load.d
1829 [[ -d $dracutsysrootdir$modulesloadconfdir ]] \
1830 || modulesloadconfdir
=$
(pkg-config systemd
--variable=modulesloadconfdir
2> /dev
/null
)
1832 [[ -d $dracutsysrootdir$modulesloadconfdir ]] || modulesloadconfdir
=/etc
/modules-load.d
1834 [[ -d $dracutsysrootdir$systemdnetwork ]] \
1835 || systemdnetwork
=$
(pkg-config systemd
--variable=systemdnetwork
2> /dev
/null
)
1837 [[ -d $dracutsysrootdir$systemdnetwork ]] || systemdnetwork
=${systemdutildir}/network
1839 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] \
1840 || systemdnetworkconfdir
=$
(pkg-config systemd
--variable=systemdnetworkconfdir
2> /dev
/null
)
1842 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] || systemdnetworkconfdir
=${systemdutilconfdir}/network
1844 [[ -d $dracutsysrootdir$systemdntpunits ]] \
1845 || systemdntpunits
=$
(pkg-config systemd
--variable=systemdntpunits
2> /dev
/null
)
1847 [[ -d $dracutsysrootdir$systemdntpunits ]] || systemdntpunits
=${systemdutildir}/ntp-units.d
1849 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] \
1850 || systemdntpunitsconfdir
=$
(pkg-config systemd
--variable=systemdntpunitsconfdir
2> /dev
/null
)
1852 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] || systemdntpunitsconfdir
=${systemdutilconfdir}/ntp-units.d
1854 [[ -d $dracutsysrootdir$systemdportable ]] \
1855 || systemdportable
=$
(pkg-config systemd
--variable=systemdportable
2> /dev
/null
)
1857 [[ -d $dracutsysrootdir$systemdportable ]] || systemdportable
=${systemdutildir}/portable
1859 [[ -d $dracutsysrootdir$systemdportableconfdir ]] \
1860 || systemdportableconfdir
=$
(pkg-config systemd
--variable=systemdportableconfdir
2> /dev
/null
)
1862 [[ -d "$dracutsysrootdir$systemdportableconfdir" ]] || systemdportableconfdir
=${systemdutilconfdir}/portable
1864 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1865 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2> /dev
/null
)
1867 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1869 [[ -d $dracutsysrootdir$systemduser ]] \
1870 || systemduser
=$
(pkg-config systemd
--variable=systemduser
2> /dev
/null
)
1872 [[ -d $dracutsysrootdir$systemduser ]] || systemduser
=${systemdutildir}/user
1874 [[ -d $dracutsysrootdir$systemduserconfdir ]] \
1875 || systemduserconfdir
=$
(pkg-config systemd
--variable=systemduserconfdir
2> /dev
/null
)
1877 [[ -d $dracutsysrootdir$systemduserconfdir ]] || systemduserconfdir
=${systemdutilconfdir}/user
1879 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1880 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2> /dev
/null
)
1882 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] || systemdsystemconfdir
=/etc
/systemd
/system
1884 [[ -d $dracutsysrootdir$sysusers ]] \
1885 || sysusers
=$
(pkg-config systemd
--variable=sysusers
2> /dev
/null
)
1887 [[ -d $dracutsysrootdir$sysusers ]] || sysusers
=/usr
/lib
/sysusers.d
1889 [[ -d $dracutsysrootdir$sysusersconfdir ]] \
1890 || sysusersconfdir
=$
(pkg-config systemd
--variable=sysusersconfdir
2> /dev
/null
)
1892 [[ -d $dracutsysrootdir$sysusersconfdir ]] || sysusersconfdir
=/etc
/sysusers.d
1894 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1895 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2> /dev
/null
)
1897 if ! [[ -d $dracutsysrootdir$tmpfilesdir ]]; then
1898 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1899 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1902 [[ -d $dracutsysrootdir$tmpfilesconfdir ]] \
1903 || tmpfilesconfdir
=$
(pkg-config systemd
--variable=tmpfilesconfdir
2> /dev
/null
)
1905 [[ -d $dracutsysrootdir$tmpfilesconfdir ]] || tmpfilesconfdir
=/etc
/tmpfiles.d
1907 [[ -d $dracutsysrootdir$depmodd ]] \
1908 || depmodd
=$
(pkg-config libkmod
--variable=depmodd
2> /dev
/null
)
1910 [[ -d $dracutsysrootdir$depmodd ]] || depmodd
=/usr
/lib
/depmod.d
1912 [[ -d $dracutsysrootdir$depmodconfdir ]] \
1913 || depmodconfdir
=$
(pkg-config libkmod
--variable=depmodconfdir
2> /dev
/null
)
1915 [[ -d $dracutsysrootdir$depmodconfdir ]] || depmodconfdir
=/etc
/depmod.d
1917 export initdir dracutbasedir \
1918 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1920 fw_dir drivers_dir debug no_kernel kernel_only \
1921 omit_drivers mdadmconf lvmconf root_devs \
1922 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1923 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1924 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1925 DRACUT_VERSION udevdir udevconfdir udevrulesdir udevrulesconfdir \
1926 prefix filesystems drivers dbus dbusconfdir dbusinterfaces \
1927 dbusinterfacesconfdir dbusservices dbusservicesconfdir dbussession \
1928 dbussessionconfdir dbussystem dbussystemconfdir dbussystemservices \
1929 dbussystemservicesconfdir environment environmentconfdir modulesload \
1930 modulesloadconfdir sysctld sysctlconfdir sysusers sysusersconfdir \
1931 systemdutildir systemdutilconfdir systemdcatalog systemdnetwork \
1932 systemdnetworkconfdir systemdntpunits systemdntpunitsconfdir \
1933 systemdportable systemdportableconfdir systemdsystemunitdir \
1934 systemdsystemconfdir systemduser systemduserconfdir \
1935 hostonly_cmdline loginstall tmpfilesdir tmpfilesconfdir depmodd \
1939 # check all our modules to see if they should be sourced.
1940 # This builds a list of modules that we will install next.
1941 for_each_module_dir check_module
1942 for_each_module_dir check_mount
1944 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1946 do_print_cmdline
() {
1947 local -A _mods_to_print
1948 for i
in $modules_loaded $mods_to_load; do
1949 _mods_to_print
[$i]=1
1952 # source our modules.
1953 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1954 _d_mod
=${moddir##*/}
1955 _d_mod
=${_d_mod#[0-9][0-9]}
1956 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1957 module_cmdline
"$_d_mod" "$moddir"
1962 if [[ $print_cmdline ]]; then
1968 # Create some directory structure first
1969 # shellcheck disable=SC2174
1970 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1972 # shellcheck disable=SC2174
1973 [[ -L $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1974 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1976 if [[ $prefix ]]; then
1977 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1979 [[ $d == */* ]] && continue
1980 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1984 if [[ $kernel_only != yes ]]; then
1985 for d
in usr usr
/bin usr
/sbin bin etc lib sbin tmp var var
/tmp
$libdirs; do
1987 [[ -e "${initdir}${prefix}/$d" ]] && continue
1988 if [ -L "/$d" ]; then
1989 inst_symlink
"/$d" "${prefix}/$d"
1991 # shellcheck disable=SC2174
1992 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1996 for d
in dev proc sys sysroot root run
; do
1997 if [ -L "/$d" ]; then
2000 # shellcheck disable=SC2174
2001 mkdir
-m 0755 -p "$initdir/$d"
2005 ln -sfn ..
/run
"$initdir/var/run"
2006 ln -sfn ..
/run
/lock
"$initdir/var/lock"
2008 for d
in lib
"$libdirs"; do
2009 [[ -e "${initdir}${prefix}/$d" ]] && continue
2010 if [ -h "/$d" ]; then
2011 inst
"/$d" "${prefix}/$d"
2013 # shellcheck disable=SC2174
2014 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
2019 mkdir
-p "${initdir}"/lib
/dracut
2021 if [[ $kernel_only != yes ]]; then
2022 mkdir
-p "${initdir}/etc/cmdline.d"
2023 mkdir
-m 0755 "${initdir}"/lib
/dracut
/hooks
2024 # shellcheck disable=SC2154
2025 for _d
in $hookdirs; do
2026 # shellcheck disable=SC2174
2027 mkdir
-m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
2029 if [[ $EUID == "0" ]] && ! [[ $DRACUT_NO_MKNOD ]]; then
2030 [[ -c ${initdir}/dev
/null
]] || mknod
"${initdir}"/dev
/null c
1 3
2031 [[ -c ${initdir}/dev
/kmsg
]] || mknod
"${initdir}"/dev
/kmsg c
1 11
2032 [[ -c ${initdir}/dev
/console
]] || mknod
"${initdir}"/dev
/console c
5 1
2033 [[ -c ${initdir}/dev
/random
]] || mknod
"${initdir}"/dev
/random c
1 8
2034 [[ -c ${initdir}/dev
/urandom
]] || mknod
"${initdir}"/dev
/urandom c
1 9
2038 _isize
=0 #initramfs size
2040 # source our modules.
2041 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
2042 _d_mod
=${moddir##*/}
2043 _d_mod
=${_d_mod#[0-9][0-9]}
2044 [[ $mods_to_load == *\
$_d_mod\
* ]] ||
continue
2045 if [[ $show_modules == yes ]]; then
2046 printf "%s\n" "$_d_mod"
2048 dinfo
"*** Including module: $_d_mod ***"
2050 if [[ $kernel_only == yes ]]; then
2051 module_installkernel
"$_d_mod" "$moddir" ||
{
2052 dfatal
"installkernel failed in module $_d_mod"
2056 module_install
"$_d_mod" "$moddir"
2057 if [[ $no_kernel != yes ]]; then
2058 module_installkernel
"$_d_mod" "$moddir" ||
{
2059 dfatal
"installkernel failed in module $_d_mod"
2064 mods_to_load
=${mods_to_load// $_d_mod /}
2065 modules_loaded
+="$_d_mod "
2067 #print the module install size
2068 if [ -n "$printsize" ]; then
2069 _isize_new
=$
(du
-sk "${initdir}" |
{
2073 _isize_delta
=$
((_isize_new
- _isize
))
2074 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
2080 for i
in $modules_loaded; do
2081 printf "%s\n" "$i" >> "$initdir"/lib
/dracut
/modules.txt
2084 dinfo
"*** Including modules done ***"
2086 ## final stuff that has to happen
2087 if [[ $no_kernel != yes ]]; then
2088 if [[ $hostonly_mode == "strict" ]]; then
2089 cp "$DRACUT_KERNEL_MODALIASES" "$initdir"/lib
/dracut
/hostonly-kernel-modules.txt
2092 if [[ $drivers ]]; then
2093 # shellcheck disable=SC2086
2094 hostonly
='' instmods
$drivers
2097 if [[ -n ${add_drivers// /} ]]; then
2098 # shellcheck disable=SC2086
2099 hostonly
='' instmods
-c $add_drivers
2101 if [[ $force_drivers ]]; then
2102 # shellcheck disable=SC2086
2103 hostonly
='' instmods
-c $force_drivers
2104 rm -f "$initdir"/etc
/cmdline.d
/20-force_driver.conf
2105 for mod
in $force_drivers; do
2106 echo "rd.driver.pre=$mod" >> "$initdir"/etc
/cmdline.d
/20-force_drivers.conf
2109 if [[ $filesystems ]]; then
2110 # shellcheck disable=SC2086
2111 hostonly
='' instmods
-c $filesystems
2114 dinfo
"*** Installing kernel module dependencies ***"
2116 dinfo
"*** Installing kernel module dependencies done ***"
2118 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
2119 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] \
2120 && [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
2121 for i
in "${initdir}"/etc
/cmdline.d
/*.conf
; do
2122 # We need no initramfs image and do not generate one.
2123 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
2129 if [[ $kernel_only != yes ]]; then
2130 # FIXME: handle legacy item split
2131 # shellcheck disable=SC2068
2132 ((${#install_items[@]} > 0)) && inst_multiple
${install_items[@]}
2133 # shellcheck disable=SC2068
2134 ((${#install_optional_items[@]} > 0)) && inst_multiple
-o ${install_optional_items[@]}
2136 if [[ $kernel_cmdline ]] && [[ $uefi != yes ]]; then
2137 printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
2140 for line
in "${fstab_lines[@]}"; do
2141 read -r -a fstab_field
<<< "$line"
2142 if [ -z "${fstab_field[1]}" ]; then
2143 # Determine device and mount options from current system
2144 mountpoint
-q "${fstab_field[0]}" || derror
"${fstab_field[0]} is not a mount point!"
2145 read -r -a fstab_field
< <(findmnt
--raw -n --target "${fstab_field[0]}" --output=source,target
,fstype
,options
)
2146 dinfo
"Line for ${fstab_field[1]}: ${fstab_field[*]}"
2148 # Use default options
2149 [ -z "${fstab_field[3]}" ] && fstab_field
[3]="defaults"
2152 # Default options for freq and passno
2153 [ -z "${fstab_field[4]}" ] && fstab_field
[4]="0"
2154 [ -z "${fstab_field[5]}" ] && fstab_field
[5]="2"
2156 strstr
"${fstab_field[2]}" "nfs" && fstab_field
[5]="0"
2157 echo "${fstab_field[@]}" >> "${initdir}/etc/fstab"
2160 for f
in $add_fstab; do
2161 cat "$f" >> "${initdir}/etc/fstab"
2164 if [[ $dracutsysrootdir$systemdutildir ]]; then
2165 if [[ -d ${initdir}/$systemdutildir ]]; then
2166 mkdir
-p "${initdir}"/etc
/conf.d
2168 printf "%s\n" "systemdutildir=\"$systemdutildir\""
2169 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
2170 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
2171 } > "${initdir}"/etc
/conf.d
/systemd.conf
2175 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
2176 dinfo
"*** Resolving executable dependencies ***"
2177 # shellcheck disable=SC2086
2178 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
2179 |
xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
2180 dinfo
"*** Resolving executable dependencies done ***"
2183 # Now we are done with lazy resolving, always install dependencies
2184 unset DRACUT_RESOLVE_LAZY
2185 export DRACUT_RESOLVE_DEPS
=1
2188 for ((i
= 0; i
< ${#include_src[@]}; i
++)); do
2189 src
="${include_src[$i]}"
2190 target
="${include_target[$i]}"
2191 if [[ $src && $target ]]; then
2192 if [[ -f $src ]]; then
2193 inst
"$src" "$target"
2194 elif [[ -d $src ]]; then
2195 ddebug
"Including directory: $src"
2196 destdir
="${initdir}/${target}"
2198 # check for preexisting symlinks, so we can cope with the
2199 # symlinks to $prefix
2200 # Objectname is a file or a directory
2201 reset_dotglob
="$(shopt -p dotglob)"
2203 for objectname
in "$src"/*; do
2204 [[ -e $objectname ||
-L $objectname ]] ||
continue
2205 if [[ -d $objectname ]] && [[ ! -L $objectname ]]; then
2206 # objectname is a directory, let's compute the final directory name
2207 object_destdir
=${destdir}/${objectname#$src/}
2208 if ! [[ -e $object_destdir ]]; then
2209 # shellcheck disable=SC2174
2210 mkdir
-m 0755 -p "$object_destdir"
2211 chmod --reference="$objectname" "$object_destdir"
2213 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/.
2215 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
2218 eval "$reset_dotglob"
2219 elif [[ -e $src ]]; then
2220 derror
"$src is neither a directory nor a regular file"
2222 derror
"$src doesn't exist"
2227 if [[ $do_hardlink == yes ]] && command -v hardlink
> /dev
/null
; then
2228 dinfo
"*** Hardlinking files ***"
2229 hardlink
"$initdir" 2>&1 | dinfo
2230 dinfo
"*** Hardlinking files done ***"
2234 if [[ $do_strip == yes ]]; then
2235 # Prefer strip from elfutils for package size
2237 strip_cmd
=$
(command -v eu-strip
)
2238 [ -z "$strip_cmd" ] && strip_cmd
="strip"
2240 for p
in $strip_cmd xargs find; do
2241 if ! type -P $p > /dev
/null
; then
2242 dinfo
"Could not find '$p'. Not stripping the initramfs."
2247 if [[ $aggressive_strip == yes ]]; then
2248 # `eu-strip` and `strip` both strips all unneeded parts by default
2255 # cleanup empty ldconfig_paths directories
2256 for d
in $
(ldconfig_paths
); do
2257 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" > /dev
/null
2>&1
2260 if [[ $early_microcode == yes ]]; then
2261 dinfo
"*** Generating early-microcode cpio image ***"
2262 ucode_dir
=(amd-ucode intel-ucode
)
2263 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
2264 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
2266 mkdir
-p "$_dest_dir"
2267 if [[ $hostonly ]]; then
2268 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
2269 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
2271 for idx
in $_dest_idx; do
2272 _fw
=${ucode_dir[$idx]}
2273 for _fwdir
in $fw_dir; do
2274 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
2276 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
2277 if [[ $hostonly ]]; then
2278 _src
=$
(get_ucode_file
)
2279 [[ $_src ]] ||
break
2280 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
2281 [[ -r $_fwdir/$_fw/$_src ]] ||
break
2284 for i
in $_fwdir/$_fw/$_src; do
2285 [ -e "$i" ] && break
2288 for i
in $_fwdir/$_fw/$_src; do
2289 [[ -e $i ]] ||
continue
2291 str_ends
"$i" ".asc" && continue
2292 cat "$i" >> "$_dest_dir/${ucode_dest[$idx]}"
2294 create_early_cpio
="yes"
2297 if [[ ! -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2298 if cd "$early_cpio_dir/d"; then
2299 for _ucodedir
in "${early_microcode_image_dir[@]}"; do
2300 for _ucodename
in "${early_microcode_image_name[@]}"; do
2301 [[ -e "$_ucodedir/$_ucodename" ]] \
2302 && cpio --extract --file "$_ucodedir/$_ucodename" --quiet \
2303 "kernel/x86/microcode/${ucode_dest[$idx]}"
2304 if [[ -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2305 dinfo
"*** Using microcode found in '$_ucodedir/$_ucodename' ***"
2306 create_early_cpio
="yes"
2316 if [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; then
2317 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
2318 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
2319 mkdir
-p "$_dest_dir"
2320 for table
in "$acpi_table_dir"/*.aml
; do
2321 dinfo
" Adding ACPI table: $table"
2322 $DRACUT_CP "$table" "$_dest_dir"
2323 create_early_cpio
="yes"
2327 dinfo
"*** Store current command line parameters ***"
2328 if ! (echo "$PARMS_TO_STORE" > "$initdir"/lib
/dracut
/build-parameter.txt
); then
2329 dfatal
"Could not store the current command line parameters"
2333 if [[ $hostonly_cmdline == "yes" ]]; then
2334 unset _stored_cmdline
2335 if [[ -d $initdir/etc
/cmdline.d
]]; then
2336 dinfo
"Stored kernel commandline:"
2337 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2338 [ -e "$conf" ] ||
continue
2339 dinfo
"$(< "$conf")"
2343 if ! [[ $_stored_cmdline ]]; then
2344 dinfo
"No dracut internal kernel commandline stored in the initramfs"
2348 if [[ $kernel_only != yes ]]; then
2349 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
2350 for _dir
in $libdirs; do
2351 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
2352 [[ -e $_f ]] ||
continue
2353 inst_libdir_file
"libgcc_s.so*"
2358 # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
2359 if [[ $DRACUT_FIPS_MODE ]]; then
2360 for _dir
in $libdirs; do
2361 for _f
in "$dracutsysrootdir$_dir/libcrypto.so"*; do
2362 [[ -e $_f ]] ||
continue
2363 inst_libdir_file
-o "libssl.so*"
2370 if [[ $kernel_only != yes ]]; then
2371 # make sure that library links are correct and up to date
2375 if dracut_module_included
"squash"; then
2376 readonly squash_dir
="$initdir/squash/root"
2377 readonly squash_img
="$initdir/squash-root.img"
2378 mkdir
-p "$squash_dir"
2379 dinfo
"*** Install squash loader ***"
2380 DRACUT_SQUASH_POST_INST
=1 module_install
"squash"
2383 if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2384 # stripping files negates (dedup) benefits of using reflink
2385 [[ -n $enhanced_cpio ]] && ddebug
"strip is enabled alongside cpio reflink"
2386 dinfo
"*** Stripping files ***"
2387 find "$initdir" -type f \
2388 -executable -not -path '*/lib/modules/*.ko' -print0 \
2389 |
xargs -r -0 $strip_cmd "${strip_args[@]}" 2> /dev
/null
2391 # strip kernel modules, but do not touch signed modules
2392 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
2393 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
2394 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
2395 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
2396 done |
xargs -r -0 $strip_cmd "${strip_args[@]}"
2397 dinfo
"*** Stripping files done ***"
2400 if dracut_module_included
"squash"; then
2401 dinfo
"*** Squashing the files inside the initramfs ***"
2402 declare squash_compress_arg
2403 # shellcheck disable=SC2086
2404 if [[ $squash_compress ]]; then
2405 if ! mksquashfs
/dev
/null
"$DRACUT_TMPDIR"/.squash-test.img
-no-progress -comp $squash_compress &> /dev
/null
; then
2406 dwarn
"mksquashfs doesn't support compressor '$squash_compress', failing back to default compressor."
2408 squash_compress_arg
="$squash_compress"
2412 # shellcheck disable=SC2086
2413 if ! mksquashfs
"$squash_dir" "$squash_img" \
2414 -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
2415 -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev
/null
; then
2416 dfatal
"Failed making squash image"
2420 rm -rf "$squash_dir"
2421 dinfo
"*** Squashing the files inside the initramfs done ***"
2423 # Skip initramfs compress
2427 dinfo
"*** Creating image file '$outfile' ***"
2429 if [[ $uefi == yes ]]; then
2430 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
2431 mkdir
-p "$uefi_outdir"
2434 if [[ $DRACUT_REPRODUCIBLE ]]; then
2435 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2436 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2438 if [[ "$(cpio --help)" == *--reproducible* ]]; then
2441 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
2445 [[ $EUID != 0 ]] && cpio_owner
="0:0"
2447 if [[ $create_early_cpio == yes ]]; then
2448 echo 1 > "$early_cpio_dir/d/early_cpio"
2450 if [[ $DRACUT_REPRODUCIBLE ]]; then
2451 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2452 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2455 # The microcode blob is _before_ the initramfs blob, not after
2456 if [[ -n $enhanced_cpio ]]; then
2459 cd "$early_cpio_dir/d"
2460 find .
-print0 |
sort -z \
2461 |
$enhanced_cpio --null ${cpio_owner:+--owner "$cpio_owner"} \
2462 --mtime 0 --data-align "$cpio_align" --truncate-existing \
2463 "${DRACUT_TMPDIR}/initramfs.img"
2465 dfatal
"dracut-cpio: creation of $outfile failed"
2471 cd "$early_cpio_dir/d"
2472 find .
-print0 |
sort -z \
2473 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
2474 ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
2476 dfatal
"Creation of $outfile failed"
2482 if check_kernel_config CONFIG_RD_ZSTD
; then
2483 DRACUT_KERNEL_RD_ZSTD
=yes
2485 DRACUT_KERNEL_RD_ZSTD
=
2488 if [[ $compress == $DRACUT_COMPRESS_ZSTD* && ! $DRACUT_KERNEL_RD_ZSTD ]]; then
2489 dwarn
"Kernel has no zstd support compiled in."
2493 if [[ $compress && $compress != cat ]]; then
2494 if ! command -v "${compress%% *}" &> /dev
/null
; then
2495 derror
"Cannot execute compression command '$compress', falling back to default"
2500 if ! [[ $compress ]]; then
2501 # check all known compressors, if none specified
2502 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 $DRACUT_COMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
2503 [[ $i != "$DRACUT_COMPRESS_ZSTD" ||
$DRACUT_KERNEL_RD_ZSTD ]] ||
continue
2504 command -v "$i" &> /dev
/null ||
continue
2508 if [[ $compress == cat ]]; then
2509 dwarn
"No compression tool available. Initramfs image is going to be big."
2511 dinfo
"Using auto-determined compression method '$compress'"
2515 # choose the right arguments for the compressor
2518 if [[ $compress == lbzip2
]] ||
command -v "$DRACUT_COMPRESS_LBZIP2" &> /dev
/null
; then
2519 compress="$DRACUT_COMPRESS_LBZIP2 -9"
2521 compress="$DRACUT_COMPRESS_BZIP2 -9"
2525 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
2528 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
2531 if [[ $compress == pigz
]] ||
command -v "$DRACUT_COMPRESS_PIGZ" &> /dev
/null
; then
2532 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
2533 elif command -v gzip &> /dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
2534 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
2536 compress="$DRACUT_COMPRESS_GZIP -n -9"
2540 compress="$DRACUT_COMPRESS_LZOP -9"
2543 compress="$DRACUT_COMPRESS_LZ4 -l -9"
2546 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
2550 if [[ -n $enhanced_cpio ]]; then
2551 if [[ $compress == "cat" ]]; then
2552 # dracut-cpio appends by default, so any ucode remains
2553 cpio_outfile
="${DRACUT_TMPDIR}/initramfs.img"
2555 ddebug
"$compress compression enabled alongside cpio reflink"
2556 # dracut-cpio doesn't output to stdout, so stage for compression
2557 cpio_outfile
="${DRACUT_TMPDIR}/initramfs.img.uncompressed"
2563 find .
-print0 |
sort -z \
2564 |
$enhanced_cpio --null ${cpio_owner:+--owner "$cpio_owner"} \
2565 --mtime 0 --data-align "$cpio_align" "$cpio_outfile" ||
exit 1
2566 [[ $compress == "cat" ]] && exit 0
2567 $compress < "$cpio_outfile" >> "${DRACUT_TMPDIR}/initramfs.img" \
2568 && rm "$cpio_outfile"
2570 dfatal
"dracut-cpio: creation of $outfile failed"
2578 find .
-print0 |
sort -z \
2579 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet \
2580 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
2582 dfatal
"Creation of $outfile failed"
2587 # shellcheck disable=SC2154
2588 if ((maxloglvl
>= 5)) && ((verbosity_mod_l
>= 0)); then
2589 if [[ $allowlocal ]]; then
2590 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
2592 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img" | ddebug
2598 if [[ $uefi == yes ]]; then
2599 if [[ $kernel_cmdline ]]; then
2600 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
2601 elif [[ $hostonly_cmdline == yes ]]; then
2602 if [ -d "$initdir/etc/cmdline.d" ]; then
2603 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2604 [ -e "$conf" ] ||
continue
2605 printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
2607 elif [ -e "/proc/cmdline" ]; then
2608 printf "%s " "$(< "/proc
/cmdline
")" > "$uefi_outdir/cmdline.txt"
2612 if [[ $kernel_cmdline ]] ||
[[ $hostonly_cmdline == yes && -e "${uefi_outdir}/cmdline.txt" ]]; then
2613 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
2614 dinfo
"Using UEFI kernel cmdline:"
2615 dinfo
"$(tr -d '\000' < "$uefi_outdir/cmdline.txt
")"
2616 uefi_cmdline
="${uefi_outdir}/cmdline.txt"
2621 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
2622 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
2623 if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then
2624 uefi_splash_image
="${dracutsysrootdir}${uefi_splash_image}"
2626 unset uefi_splash_image
2630 ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \
2631 ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \
2632 ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \
2633 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x2000000 \
2634 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
="${EFI_SECTION_VMA_INITRD}" \
2635 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
2636 if [[ -n ${uefi_secureboot_key} && -n ${uefi_secureboot_cert} ]]; then
2638 ${uefi_secureboot_engine:+--engine "$uefi_secureboot_engine"} \
2639 --key "${uefi_secureboot_key}" \
2640 --cert "${uefi_secureboot_cert}" \
2641 --output "$outfile" "${uefi_outdir}/linux.efi"; then
2642 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
2644 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2648 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2649 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2654 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2658 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2659 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2662 dfatal
"Creation of $outfile failed"
2668 btrfs filesystem show
"$1" |
sed -n '1s/^.*uuid: //p'
2671 freeze_ok_for_btrfs
() {
2672 local mnt uuid1 uuid2
2673 # If the output file is on btrfs, we need to make sure that it's
2674 # not on a subvolume of the same file system as the root FS.
2675 # Otherwise, fsfreeze() might freeze the entire system.
2676 # This is most conveniently checked by comparing the FS uuid.
2678 [[ "$(stat -f -c %T -- "/")" == "btrfs" ]] ||
return 0
2679 mnt
=$
(stat
-c %m
-- "$1")
2680 uuid1
=$
(btrfs_uuid
"$mnt")
2681 uuid2
=$
(btrfs_uuid
"/")
2682 [[ $uuid1 && $uuid2 && $uuid1 != "$uuid2" ]]
2685 freeze_ok_for_fstype
() {
2689 [[ "$(stat -c %m -- "$outfile")" == "/" ]] && return 1
2690 fstype
=$
(stat
-f -c %T
-- "$outfile")
2699 freeze_ok_for_btrfs
"$outfile"
2707 # We sync/fsfreeze only if we're operating on a live booted system.
2708 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2709 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2710 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2711 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2712 if [[ -d $dracutsysrootdir/run
/systemd
/system
]]; then
2713 if ! sync
"$outfile" 2> /dev
/null
; then
2714 dinfo
"sync operation on newly created initramfs $outfile failed"
2718 # use fsfreeze only if we're not writing to /
2719 if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype
"$outfile"; then
2720 FSFROZEN
="$(dirname "$outfile")"
2721 if ! (fsfreeze
-f "${FSFROZEN}" 2> /dev
/null
&& fsfreeze
-u "${FSFROZEN}" 2> /dev
/null
); then
2722 dwarn
"Could not fsfreeze $(dirname "$outfile")"