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 readonly dracut_cmd
=$
(readlink
-f "$0")
38 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
39 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
40 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
41 # shellcheck source=./dracut-version.sh
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 # shellcheck source=./dracut-version.sh
68 .
"$dracutbasedir"/dracut-version.sh
71 # 80x25 linebreak here ^
73 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
75 Version: $DRACUT_VERSION
77 Creates initial ramdisk images for preloading modules
79 --kver [VERSION] Set kernel version to [VERSION].
80 -f, --force Overwrite existing initramfs file.
81 -a, --add [LIST] Add a space-separated list of dracut modules.
82 --rebuild Append arguments to those of existing image and rebuild
83 -m, --modules [LIST] Specify a space-separated list of dracut modules to
84 call when building the initramfs. Modules are located
85 in /usr/lib/dracut/modules.d.
86 -o, --omit [LIST] Omit a space-separated list of dracut modules.
87 --force-add [LIST] Force to add a space-separated list of dracut modules
88 to the default set of modules, when -H is specified.
89 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
90 exclusively include in the initramfs.
91 --add-drivers [LIST] Specify a space-separated list of kernel
92 modules to add to the initramfs.
93 --force-drivers [LIST] Specify a space-separated list of kernel
94 modules to add to the initramfs and make sure they
95 are tried to be loaded via modprobe same as passing
96 rd.driver.pre=DRIVER kernel parameter.
97 --omit-drivers [LIST] Specify a space-separated list of kernel
98 modules not to add to the initramfs.
99 --filesystems [LIST] Specify a space-separated list of kernel filesystem
100 modules to exclusively include in the generic
102 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
104 --fwdir [DIR] Specify additional directories, where to look for
105 firmwares, separated by :
106 --kernel-only Only install kernel drivers and firmware files
107 --no-kernel Do not install kernel drivers and firmware files
108 --print-cmdline Print the kernel command line for the given disk layout
109 --early-microcode Combine early microcode with ramdisk
110 --no-early-microcode Do not combine early microcode with ramdisk
111 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
112 --strip Strip binaries in the initramfs
113 --nostrip Do not strip binaries in the initramfs
114 --hardlink Hardlink files in the initramfs
115 --nohardlink Do not hardlink files in the initramfs
116 --prefix [DIR] Prefix initramfs files with [DIR]
117 --noprefix Do not prefix initramfs files
118 --mdadmconf Include local /etc/mdadm.conf
119 --nomdadmconf Do not include local /etc/mdadm.conf
120 --lvmconf Include local /etc/lvm/lvm.conf
121 --nolvmconf Do not include local /etc/lvm/lvm.conf
122 --fscks [LIST] Add a space-separated list of fsck helpers.
123 --nofscks Inhibit installation of any fsck helpers.
124 --ro-mnt Mount / and /usr read-only by default.
125 -h, --help This message
126 --debug Output debug information of the build process
127 --profile Output profile information of the build process
128 -L, --stdlog [0-6] Specify logging level (to standard error)
129 0 - suppress any messages
130 1 - only fatal errors
134 5 - debug info (here starts lots of output)
135 6 - trace info (and even more)
136 -v, --verbose Increase verbosity level
137 -q, --quiet Decrease verbosity level
138 -c, --conf [FILE] Specify configuration file to use.
139 Default: /etc/dracut.conf
140 --confdir [DIR] Specify configuration directory to use *.conf files
141 from. Default: /etc/dracut.conf.d
142 --tmpdir [DIR] Temporary directory to be used instead of default
144 -r, --sysroot [DIR] Specify sysroot directory to collect files from.
145 -l, --local Local mode. Use modules from the current working
146 directory instead of the system-wide installed in
147 /usr/lib/dracut/modules.d.
148 Useful when running dracut from a git checkout.
149 -H, --hostonly Host-Only mode: Install only what is needed for
150 booting the local host instead of a generic host.
151 -N, --no-hostonly Disables Host-Only mode
152 --hostonly-mode <mode>
153 Specify the hostonly mode to use. <mode> could be
154 one of "sloppy" or "strict". "sloppy" mode is used
156 In "sloppy" hostonly mode, extra drivers and modules
157 will be installed, so minor hardware change won't make
158 the image unbootable (eg. changed keyboard), and the
159 image is still portable among similar hosts.
160 With "strict" mode enabled, anything not necessary
161 for booting the local host in its current state will
162 not be included, and modules may do some extra job
163 to save more space. Minor change of hardware or
164 environment could make the image unbootable.
165 DO NOT use "strict" mode unless you know what you
167 --hostonly-cmdline Store kernel command line arguments needed
169 --no-hostonly-cmdline Do not store kernel command line arguments needed
171 --no-hostonly-default-device
172 Do not generate implicit host devices like root,
173 swap, fstab, etc. Use "--mount" or "--add-device"
174 to explicitly add devices as needed.
175 --hostonly-i18n Install only needed keyboard and font files according
176 to the host configuration (default).
177 --no-hostonly-i18n Install all keyboard and font files available.
178 --hostonly-nics [LIST]
179 Only enable listed NICs in the initramfs.
180 --persistent-policy [POLICY]
181 Use [POLICY] to address disks and partitions.
182 POLICY can be any directory name found in /dev/disk.
183 E.g. "by-uuid", "by-label"
184 --fstab Use /etc/fstab to determine the root device.
185 --add-fstab [FILE] Add file to the initramfs fstab
186 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
187 Mount device [DEV] on mountpoint [MP] with filesystem
188 [FSTYPE] and options [FSOPTS] in the initramfs
189 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
190 determined by looking at the current mounts.
191 --add-device "[DEV]" Bring up [DEV] in initramfs
192 -i, --include [SOURCE] [TARGET]
193 Include the files in the SOURCE directory into the
194 Target directory in the final initramfs.
195 If SOURCE is a file, it will be installed to TARGET
196 in the final initramfs.
197 -I, --install [LIST] Install the space separated list of files into the
199 --install-optional [LIST] Install the space separated list of files into the
200 initramfs, if they exist.
201 --gzip Compress the generated initramfs using gzip.
202 This will be done by default, unless another
203 compression option or --no-compress is passed.
204 --bzip2 Compress the generated initramfs using bzip2.
205 Make sure your kernel has bzip2 decompression support
206 compiled in, otherwise you will not be able to boot.
207 --lzma Compress the generated initramfs using lzma.
208 Make sure your kernel has lzma support compiled in,
209 otherwise you will not be able to boot.
210 --xz Compress the generated initramfs using xz.
211 Make sure that your kernel has xz support compiled
212 in, otherwise you will not be able to boot.
213 --lzo Compress the generated initramfs using lzop.
214 Make sure that your kernel has lzo support compiled
215 in, otherwise you will not be able to boot.
216 --lz4 Compress the generated initramfs using lz4.
217 Make sure that your kernel has lz4 support compiled
218 in, otherwise you will not be able to boot.
219 --zstd Compress the generated initramfs using Zstandard.
220 Make sure that your kernel has zstd support compiled
221 in, otherwise you will not be able to boot.
222 --compress [COMPRESSION] Compress the generated initramfs with the
223 passed compression program. Make sure your kernel
224 knows how to decompress the generated initramfs,
225 otherwise you will not be able to boot.
226 --no-compress Do not compress the generated initramfs. This will
227 override any other compression options.
228 --list-modules List all available dracut modules.
229 -M, --show-modules Print included module's name to standard output during
231 --keep Keep the temporary initramfs for debugging purposes
232 --printsize Print out the module install size
233 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
234 --logfile [FILE] Logfile to use (overrides configuration setting)
235 --reproducible Create reproducible images
236 --no-reproducible Do not create reproducible images
237 --loginstall [DIR] Log all files installed from the host to [DIR]
238 --uefi Create an UEFI executable with the kernel cmdline and
240 --no-uefi Disables UEFI mode
241 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
242 --uefi-splash-image [FILE]
243 Use [FILE] as a splash image when creating an UEFI
245 --kernel-image [FILE] location of the kernel image
246 --regenerate-all Regenerate all initramfs images at the default location
247 for the kernel versions found on the system
248 --version Display version
250 If [LIST] has multiple arguments, then you have to put these in quotes.
254 # dracut --add-drivers "module1 module2" ...
260 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
261 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
262 # shellcheck source=./dracut-version.sh
263 .
"$dracutbasedir"/dracut-version.sh
265 echo "dracut $DRACUT_VERSION"
268 # Fills up host_devs stack variable and makes sure there are no duplicates
272 [[ " ${host_devs[*]} " == *" $_dev "* ]] && return
277 # Little helper function for reading args from the commandline.
278 # it automatically handles -a b and -a=b variants, and returns 1 if
279 # we need to shift $3.
284 local rematch
='^[^=]*=(.*)$'
285 if [[ $2 =~
$rematch ]]; then
286 read -r "$1" <<< "${BASH_REMATCH[1]}"
288 read -r "$1" <<< "$3"
289 # There is no way to shift our callers args, so
290 # return 1 to indicate they should do it instead.
296 if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
297 printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
298 printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
309 for i
in "$d/"*"$suffix"; do
311 printf "%s\n" "${i##*/}"
317 for f
in "${files[@]}"; do
319 if [[ -e "$d/$f" ]]; then
320 printf "%s\n" "$d/$f"
329 # Workaround -i, --include taking 2 arguments
332 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
333 newat
+=("++include") # Replace --include by ++include
338 set -- "${newat[@]}" # Set new $@
341 unset POSIXLY_CORRECT
343 -o "a:m:o:d:I:k:c:r:L:fvqlHhMN" \
347 --long add-drivers
: \
348 --long force-drivers
: \
349 --long omit-drivers
: \
353 --long filesystems
: \
355 --long install-optional
: \
377 --long print-cmdline \
378 --long kernel-cmdline
: \
398 --long no-host-only \
399 --long hostonly-mode
: \
400 --long hostonly-cmdline \
401 --long no-hostonly-cmdline \
402 --long no-hostonly-default-device \
403 --long persistent-policy
: \
414 --long list-modules \
415 --long show-modules \
418 --long regenerate-all \
419 --long noimageifnotneeded \
420 --long early-microcode \
421 --long no-early-microcode \
422 --long reproducible \
423 --long no-reproducible \
428 --long uefi-splash-image
: \
429 --long kernel-image
: \
430 --long no-hostonly-i18n \
431 --long hostonly-i18n \
432 --long hostonly-nics
: \
433 --long no-machineid \
438 # shellcheck disable=SC2181
449 rearrange_params
"$@"
452 # parse command line args to check if '--rebuild' option is present
456 if [ "$1" == "--" ]; then
460 if [ "$1" == "--rebuild" ]; then
463 if [ ! -e "$rebuild_file" ]; then
464 echo "Image file '$rebuild_file', for rebuild, does not exist!"
467 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
474 # get output file name and kernel version from command line arguments
481 if ! [[ ${outfile+x} ]]; then
483 elif ! [[ ${kernel+x} ]]; then
486 printf "\nUnknown arguments: %s\n\n" "$*" >&2
495 # extract input image file provided with rebuild option to get previous parameters, if any
496 if [[ $append_args_l == "yes" ]]; then
499 # determine resultant file
500 if ! [[ $outfile ]]; then
501 outfile
=$rebuild_file
504 if ! rebuild_param
=$
(lsinitrd
"$rebuild_file" '*lib/dracut/build-parameter.txt'); then
505 echo "Image '$rebuild_file' has no rebuild information stored"
509 # prepend previous parameters to current command line args
510 if [[ $rebuild_param ]]; then
511 TEMP
="$rebuild_param $TEMP"
513 rearrange_params
"$@"
523 if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
524 PARMS_TO_STORE
+=" $1"
529 PARMS_TO_STORE
+=" '$2'"
533 add_dracutmodules_l
+=("$2")
534 PARMS_TO_STORE
+=" '$2'"
538 force_add_dracutmodules_l
+=("$2")
539 PARMS_TO_STORE
+=" '$2'"
543 add_drivers_l
+=("$2")
544 PARMS_TO_STORE
+=" '$2'"
548 force_drivers_l
+=("$2")
549 PARMS_TO_STORE
+=" '$2'"
553 omit_drivers_l
+=("$2")
554 PARMS_TO_STORE
+=" '$2'"
558 dracutmodules_l
+=("$2")
559 PARMS_TO_STORE
+=" '$2'"
563 omit_dracutmodules_l
+=("$2")
564 PARMS_TO_STORE
+=" '$2'"
569 PARMS_TO_STORE
+=" '$2'"
573 filesystems_l
+=("$2")
574 PARMS_TO_STORE
+=" '$2'"
578 install_items_l
+=("$2")
579 PARMS_TO_STORE
+=" '$2'"
583 install_optional_items_l
+=("$2")
584 PARMS_TO_STORE
+=" '$2'"
589 PARMS_TO_STORE
+=" '$2'"
594 PARMS_TO_STORE
+=" '$2'"
599 PARMS_TO_STORE
+=" '$2'"
604 PARMS_TO_STORE
+=" '$2'"
609 PARMS_TO_STORE
+=" '$2'"
612 --add-device |
--device)
614 PARMS_TO_STORE
+=" '$2'"
618 kernel_cmdline_l
+=("$2")
619 PARMS_TO_STORE
+=" '$2'"
622 --nofscks) nofscks_l
="yes" ;;
623 --ro-mnt) ro_mnt_l
="yes" ;;
626 PARMS_TO_STORE
+=" '$2'"
631 PARMS_TO_STORE
+=" '$2'"
636 PARMS_TO_STORE
+=" '$2'"
641 PARMS_TO_STORE
+=" '$2'"
646 PARMS_TO_STORE
+=" '$2'"
651 PARMS_TO_STORE
+=" '$2'"
656 PARMS_TO_STORE
+=" '$2'"
661 PARMS_TO_STORE
+=" '$2'"
666 PARMS_TO_STORE
+=" '$2'"
670 if [[ $rebuild_file == "$outfile" ]]; then
675 -f |
--force) force
=yes ;;
691 early_microcode_l
="yes"
693 --no-early-microcode)
694 early_microcode_l
="no"
696 --strip) do_strip_l
="yes" ;;
697 --nostrip) do_strip_l
="no" ;;
698 --hardlink) do_hardlink_l
="yes" ;;
699 --nohardlink) do_hardlink_l
="no" ;;
700 --noprefix) prefix_l
="/" ;;
701 --mdadmconf) mdadmconf_l
="yes" ;;
702 --nomdadmconf) mdadmconf_l
="no" ;;
703 --lvmconf) lvmconf_l
="yes" ;;
704 --nolvmconf) lvmconf_l
="no" ;;
705 --debug) debug
="yes" ;;
706 --profile) profile
="yes" ;;
709 PARMS_TO_STORE
+=" '$2'"
716 -v |
--verbose) ((verbosity_mod_l
++)) ;;
717 -q |
--quiet) ((verbosity_mod_l--
)) ;;
720 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
721 && dracutbasedir
="$(readlink -f "${0%/*}")"
723 -H |
--hostonly |
--host-only)
726 -N |
--no-hostonly |
--no-host-only)
731 PARMS_TO_STORE
+=" '$2'"
735 hostonly_cmdline_l
="yes"
738 i18n_install_all_l
="no"
741 hostonly_nics_l
+=("$2")
742 PARMS_TO_STORE
+=" '$2'"
746 i18n_install_all_l
="yes"
748 --no-hostonly-cmdline)
749 hostonly_cmdline_l
="no"
751 --no-hostonly-default-device)
752 hostonly_default_device
="no"
755 persistent_policy_l
="$2"
756 PARMS_TO_STORE
+=" '$2'"
759 --fstab) use_fstab_l
="yes" ;;
764 --bzip2) compress_l
="bzip2" ;;
765 --lzma) compress_l
="lzma" ;;
766 --xz) compress_l
="xz" ;;
767 --lzo) compress_l
="lzo" ;;
768 --lz4) compress_l
="lz4" ;;
769 --zstd) compress_l
="zstd" ;;
770 --no-compress) _no_compress_l
="cat" ;;
771 --gzip) compress_l
="gzip" ;;
772 --list-modules) do_list
="yes" ;;
776 --keep) keep
="yes" ;;
777 --printsize) printsize
="yes" ;;
778 --regenerate-all) regenerate_all
="yes" ;;
779 --noimageifnotneeded) noimageifnotneeded
="yes" ;;
780 --reproducible) reproducible_l
="yes" ;;
781 --no-reproducible) reproducible_l
="no" ;;
782 --uefi) uefi_l
="yes" ;;
783 --no-uefi) uefi_l
="no" ;;
786 PARMS_TO_STORE
+=" '$2'"
790 uefi_splash_image_l
="$2"
791 PARMS_TO_STORE
+=" '$2'"
796 PARMS_TO_STORE
+=" '$2'"
811 *) # should not even reach this point
812 printf "\n!Unknown option: '%s'\n\n" "$1" >&2
820 # getopt cannot handle multiple arguments, so just handle "-I,--include"
821 # the old fashioned way
824 if [ "${1%%=*}" == "++include" ]; then
826 include_target
+=("$3")
827 PARMS_TO_STORE
+=" --include '$2' '$3'"
833 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
835 if [[ $regenerate_all == "yes" ]]; then
837 if [[ $kernel ]]; then
838 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
842 if [[ $outfile ]]; then
843 printf -- "--regenerate-all cannot be called with a image file\n" >&2
847 ((len
= ${#dracut_args[@]}))
848 for ((i
= 0; i
< len
; i
++)); do
849 [[ ${dracut_args[$i]} == "--regenerate-all" ]] \
850 && unset dracut_args
["$i"]
853 cd "$dracutsysrootdir"/lib
/modules ||
exit 1
855 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
856 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
862 if ! [[ $kernel ]]; then
870 unset LD_LIBRARY_PATH
874 export DRACUT_LOG_LEVEL
=warning
876 export DRACUT_LOG_LEVEL
=debug
877 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
882 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '
887 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
889 # if we were not passed a config file, try the default one
890 if [[ ! -f $conffile ]]; then
891 if [[ $allowlocal ]]; then
892 conffile
="$dracutbasedir/dracut.conf"
894 conffile
="$dracutsysrootdir/etc/dracut.conf"
898 if [[ ! -d $confdir ]]; then
899 if [[ $allowlocal ]]; then
900 confdir
="$dracutbasedir/dracut.conf.d"
902 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
906 # source our config file
907 if [[ -f $conffile ]]; then
908 check_conf_file
"$conffile"
909 # shellcheck disable=SC1090
913 # source our config dir
914 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
916 # shellcheck disable=SC1090
917 [[ -e $f ]] && .
"$f"
920 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
922 for i
in $DRACUT_PATH; do
924 if [ -L "$dracutsysrootdir$i" ]; then
925 rl
=$
(readlink
-f "$dracutsysrootdir$i")
927 rl
="${rl#$dracutsysrootdir}"
928 if [[ $NPATH != *:$rl* ]]; then
932 [[ -z $dracutsysrootdir ]] && export PATH
="${NPATH#:}"
935 export SYSTEMCTL
=${SYSTEMCTL:-systemctl}
937 # these options add to the stuff in the config file
938 ((${#add_dracutmodules_l[@]})) && add_dracutmodules
+=" ${add_dracutmodules_l[*]} "
939 ((${#omit_dracutmodules_l[@]})) && omit_dracutmodules
+=" ${omit_dracutmodules_l[*]} "
940 ((${#force_add_dracutmodules_l[@]})) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[*]} "
941 ((${#fscks_l[@]})) && fscks
+=" ${fscks_l[*]} "
942 ((${#add_fstab_l[@]})) && add_fstab
+=" ${add_fstab_l[*]} "
943 ((${#install_items_l[@]})) && install_items
+=" ${install_items_l[*]} "
944 ((${#install_optional_items_l[@]})) && install_optional_items
+=" ${install_optional_items_l[*]} "
945 ((${#hostonly_nics_l[@]})) && hostonly_nics
+=" ${hostonly_nics_l[*]} "
947 # these options override the stuff in the config file
948 ((${#dracutmodules_l[@]})) && dracutmodules
="${dracutmodules_l[*]}"
949 ((${#filesystems_l[@]})) && filesystems
="${filesystems_l[*]}"
950 ((${#fw_dir_l[@]})) && fw_dir
="${fw_dir_l[*]}"
951 ((${#libdirs_l[@]})) && libdirs
="${libdirs_l[*]}"
953 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
954 [[ ! $stdloglvl ]] && stdloglvl
=4
955 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
956 ((stdloglvl
> 6)) && stdloglvl
=6
957 ((stdloglvl
< 0)) && stdloglvl
=0
959 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
960 [[ $do_strip_l ]] && do_strip
=$do_strip_l
961 [[ $do_strip ]] || do_strip
=yes
962 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
963 [[ $do_hardlink ]] || do_hardlink
=yes
964 [[ $prefix_l ]] && prefix
=$prefix_l
965 [[ $prefix == "/" ]] && unset prefix
966 [[ $hostonly_l ]] && hostonly
=$hostonly_l
967 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
968 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
969 [[ $hostonly == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
970 # shellcheck disable=SC2034
971 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
972 # shellcheck disable=SC2034
973 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
974 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
975 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
976 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
977 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
978 [[ $fw_dir ]] || fw_dir
="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
979 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
980 [[ $tmpdir ]] || tmpdir
="$TMPDIR"
981 [[ $tmpdir ]] || tmpdir
="$dracutsysrootdir"/var
/tmp
982 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
983 [[ $compress_l ]] && compress=$compress_l
984 [[ $show_modules_l ]] && show_modules
=$show_modules_l
985 [[ $nofscks_l ]] && nofscks
="yes"
986 [[ $ro_mnt_l ]] && ro_mnt
="yes"
987 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
988 [[ $early_microcode ]] || early_microcode
=yes
989 [[ $early_microcode_image_dir ]] || early_microcode_image_dir
=('/boot')
990 [[ $early_microcode_image_name ]] \
991 || early_microcode_image_name
=('intel-uc.img' 'intel-ucode.img' 'amd-uc.img' 'amd-ucode.img' 'early_ucode.cpio' 'microcode.cpio')
992 [[ $logfile_l ]] && logfile
="$logfile_l"
993 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
994 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
995 [[ $uefi_l ]] && uefi
=$uefi_l
996 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
997 [[ $uefi_splash_image_l ]] && uefi_splash_image
="$uefi_splash_image_l"
998 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
999 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
1001 if ! [[ $outfile ]]; then
1002 if [[ $machine_id != "no" ]]; then
1003 [[ -f "$dracutsysrootdir"/etc
/machine-id
]] && read -r MACHINE_ID
< "$dracutsysrootdir"/etc
/machine-id
1006 if [[ $uefi == "yes" ]]; then
1007 # shellcheck disable=SC2154
1008 if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
1009 dfatal
"Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set."
1013 if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign
&> /dev
/null
; then
1014 dfatal
"Need 'sbsign' to create a signed UEFI executable"
1018 BUILD_ID
=$
(cat "$dracutsysrootdir"/etc
/os-release
"$dracutsysrootdir"/usr
/lib
/os-release \
1019 |
while read -r line ||
[[ $line ]]; do
1020 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break
1022 if [[ -z $dracutsysrootdir ]]; then
1023 if [[ -d /efi
]] && mountpoint
-q /efi
; then
1027 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1028 efidir
=/boot
/efi
/EFI
1033 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1034 efidir
=/boot
/efi
/EFI
1037 mkdir
-p "$dracutsysrootdir$efidir/Linux"
1038 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
1040 if [[ -e $dracutsysrootdir/boot
/vmlinuz-
$kernel ]]; then
1041 outfile
="/boot/initramfs-$kernel.img"
1042 elif [[ $MACHINE_ID ]] && { [[ -d $dracutsysrootdir/boot
/${MACHINE_ID} ]] || [[ -L $dracutsysrootdir/boot/${MACHINE_ID} ]]; }; then
1043 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
1045 outfile
="$dracutsysrootdir/boot/initramfs-$kernel.img"
1050 # eliminate IFS hackery when messing with fw_dir
1051 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
1052 fw_dir
=${fw_dir//:/ }
1054 # check for logfile and try to create one if it doesn't exist
1055 if [[ -n $logfile ]]; then
1056 if [[ ! -f $logfile ]]; then
1057 if touch "$logfile"; then
1058 printf "%s\n" "dracut: touch $logfile failed." >&2
1063 # handle compression options.
1064 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
1065 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
1066 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
1067 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
1068 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
1069 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
1070 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
1071 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
1072 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
1073 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
1075 if [[ $_no_compress_l == "$DRACUT_COMPRESS_CAT" ]]; then
1076 compress="$DRACUT_COMPRESS_CAT"
1079 [[ $hostonly == yes ]] && hostonly
="-h"
1080 [[ $hostonly != "-h" ]] && unset hostonly
1082 case $hostonly_mode in
1084 [[ $hostonly ]] && hostonly_mode
="sloppy"
1087 if [[ ! $hostonly ]]; then
1092 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
1097 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
1099 case "${drivers_dir}" in
1100 '' |
*lib
/modules
/${kernel} |
*lib
/modules
/${kernel}/) ;;
1102 [[ "$DRACUT_KMODDIR_OVERRIDE" ]] ||
{
1103 printf "%s\n" 'dracut: -k/--kmoddir path must contain "lib/modules" as a parent of your kernel module directory,'
1104 printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
1105 printf "%s\n" "dracut: was given: ${drivers_dir}"
1106 printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
1107 printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
1108 printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
1114 readonly TMPDIR
="$(realpath -e "$tmpdir")"
1115 [ -d "$TMPDIR" ] ||
{
1116 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
1120 if findmnt
--raw -n --target "$tmpdir" --output=options |
grep -q noexec
; then
1121 [[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
1125 readonly DRACUT_TMPDIR
="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
1126 [ -d "$DRACUT_TMPDIR" ] ||
{
1127 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
1131 # clean up after ourselves no matter how we die.
1134 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
1135 if [[ ${FSFROZEN} ]]; then
1136 fsfreeze -u "${FSFROZEN}"
1141 # clean up after ourselves no matter how we die.
1142 trap 'exit 1;' SIGINT
1144 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
1147 # shellcheck disable=SC2154
1148 if [[ $early_microcode == yes ]] ||
{ [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
1149 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
1150 mkdir
"$early_cpio_dir"
1153 [[ "$dracutsysrootdir" ]] ||
[[ "$noexec" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
1155 if [[ $print_cmdline ]]; then
1162 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
1163 # shellcheck source=./dracut-version.sh
1164 .
"$dracutbasedir"/dracut-version.sh
1167 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
1168 # shellcheck source=./dracut-init.sh
1169 .
"$dracutbasedir"/dracut-init.sh
1171 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1172 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1173 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1177 # shellcheck disable=SC2154
1178 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1179 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
1180 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
1184 if ! [[ $print_cmdline ]]; then
1185 inst
"$DRACUT_TESTBIN"
1186 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &> /dev
/null
; then
1187 unset DRACUT_RESOLVE_LAZY
1188 export DRACUT_RESOLVE_DEPS
=1
1190 rm -fr -- "${initdir:?}"/*
1193 dracutfunctions
=$dracutbasedir/dracut-functions.sh
1194 export dracutfunctions
1196 ((${#drivers_l[@]})) && drivers
="${drivers_l[*]}"
1197 drivers
=${drivers/-/_}
1199 ((${#add_drivers_l[@]})) && add_drivers
+=" ${add_drivers_l[*]} "
1200 add_drivers
=${add_drivers/-/_}
1202 ((${#force_drivers_l[@]})) && force_drivers
+=" ${force_drivers_l[*]} "
1203 force_drivers
=${force_drivers/-/_}
1205 ((${#omit_drivers_l[@]})) && omit_drivers
+=" ${omit_drivers_l[*]} "
1206 omit_drivers
=${omit_drivers/-/_}
1208 ((${#kernel_cmdline_l[@]})) && kernel_cmdline
+=" ${kernel_cmdline_l[*]} "
1210 omit_drivers_corrected
=""
1211 for d
in $omit_drivers; do
1212 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
1213 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1214 omit_drivers_corrected
+="$d|"
1216 omit_drivers
="${omit_drivers_corrected%|}"
1217 unset omit_drivers_corrected
1219 # prepare args for logging
1220 for ((i
= 0; i
< ${#dracut_args[@]}; i
++)); do
1221 [[ ${dracut_args[$i]} == *\
* ]] \
1222 && dracut_args
[$i]="\"${dracut_args[$i]}\""
1226 dinfo
"Executing: $dracut_cmd ${dracut_args[*]}"
1228 [[ $do_list == yes ]] && {
1229 for mod
in "$dracutbasedir"/modules.d
/*; do
1230 [[ -d $mod ]] ||
continue
1231 [[ -e $mod/install ||
-e $mod/installkernel ||
-e \
1232 $mod/module-setup.sh
]] ||
continue
1233 printf "%s\n" "${mod##*/??}"
1238 # This is kinda legacy -- eventually it should go away.
1239 case $dracutmodules in
1240 "" | auto
) dracutmodules
="all" ;;
1243 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1245 [[ -d $dracutsysrootdir$systemdutildir ]] \
1246 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2> /dev
/null
)
1248 if ! [[ -d $dracutsysrootdir$systemdutildir ]]; then
1249 [[ -e $dracutsysrootdir/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1250 [[ -e $dracutsysrootdir/usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1253 [[ -d $dracutsysrootdir$systemdutilconfdir ]] \
1254 || systemdutilconfdir
=$
(pkg-config systemd
--variable=systemdutilconfdir
2> /dev
/null
)
1256 [[ -d $dracutsysrootdir$systemdutilconfdir ]] || systemdutilconfdir
=/etc
/systemd
1258 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1259 if ! [[ -f $srcmods/modules.dep
]]; then
1260 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1261 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1264 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1266 elif ! (command -v gzip &> /dev
/null
&& command -v xz
&> /dev
/null
); then
1267 read -r _mod
< "$srcmods"/modules.dep
1269 if [[ -f $srcmods/"$_mod" ]]; then
1270 # Check, if kernel modules are compressed, and if we can uncompress them
1272 *.ko.gz
) kcompress
=gzip ;;
1273 *.ko.xz
) kcompress
=xz
;;
1275 if [[ $kcompress ]]; then
1276 if ! command -v "$kcompress" &> /dev
/null
; then
1277 dfatal
"Kernel modules are compressed with $kcompress, but $kcompress is not available."
1285 if [[ ! $print_cmdline ]]; then
1286 if [[ -f $outfile && ! $force ]]; then
1287 dfatal
"Will not override existing initramfs ($outfile) without --force"
1291 outdir
=${outfile%/*}
1292 [[ $outdir ]] || outdir
="/"
1294 if [[ ! -d $outdir ]]; then
1295 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1297 elif [[ ! -w $outdir ]]; then
1298 dfatal
"No permission to write to $outdir."
1300 elif [[ -f $outfile && ! -w $outfile ]]; then
1301 dfatal
"No permission to write $outfile."
1305 if [[ $loginstall ]]; then
1306 if ! mkdir
-p "$loginstall"; then
1307 dfatal
"Could not create directory to log installed files to '$loginstall'."
1310 loginstall
=$
(readlink
-f "$loginstall")
1313 if [[ $uefi == yes ]]; then
1314 if ! command -v objcopy
&> /dev
/null
; then
1315 dfatal
"Need 'objcopy' to create a UEFI executable"
1318 unset EFI_MACHINE_TYPE_NAME
1321 EFI_MACHINE_TYPE_NAME
=x64
1324 EFI_MACHINE_TYPE_NAME
=ia32
1327 dfatal
"Architecture '$(uname -m)' not supported to create a UEFI executable"
1332 if ! [[ -s $uefi_stub ]]; then
1334 "$dracutsysrootdir${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1335 "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1336 [[ -s $uefi_stub ]] ||
continue
1340 if ! [[ -s $uefi_stub ]]; then
1341 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1345 if ! [[ $kernel_image ]]; then
1346 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1347 [[ -s $kernel_image ]] ||
continue
1351 if ! [[ -s $kernel_image ]]; then
1352 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1358 if [[ $acpi_override == yes ]] && ! (check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1359 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1363 if [[ $early_microcode == yes ]]; then
1364 if [[ $hostonly ]]; then
1365 if [[ $
(get_cpu_vendor
) == "AMD" ]]; then
1366 check_kernel_config CONFIG_MICROCODE_AMD ||
unset early_microcode
1367 elif [[ $
(get_cpu_vendor
) == "Intel" ]]; then
1368 check_kernel_config CONFIG_MICROCODE_INTEL ||
unset early_microcode
1370 unset early_microcode
1373 ! check_kernel_config CONFIG_MICROCODE_AMD \
1374 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1375 && unset early_microcode
1377 # Do not complain on non-x86 architectures as it makes no sense
1380 [[ $early_microcode != yes ]] \
1381 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1387 # Need to be able to have non-root users read stuff (rpcbind etc)
1388 chmod 755 "$initdir"
1390 if [[ $hostonly ]]; then
1391 for i
in /sys
/proc
/run
/dev
; do
1392 if ! findmnt
--target "$i" &> /dev
/null
; then
1393 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1399 declare -A host_fs_types
1401 for line
in "${fstab_lines[@]}"; do
1402 # shellcheck disable=SC2086
1408 dev
=$
(blkid
-l -t "UUID=${dev#UUID=}" -o device
)
1411 dev
=$
(blkid
-l -t "LABEL=${dev#LABEL=}" -o device
)
1414 dev
=$
(blkid
-l -t "PARTUUID=${dev#PARTUUID=}" -o device
)
1417 dev
=$
(blkid
-l -t "PARTLABEL=${dev#PARTLABEL=}" -o device
)
1420 [ -z "$dev" ] && dwarn
"Bad fstab entry $*" && continue
1421 if [[ $3 == btrfs
]]; then
1422 for i
in $
(btrfs_devs
"$2"); do
1426 push_host_devs
"$dev"
1427 host_fs_types
["$dev"]="$3"
1430 for f
in $add_fstab; do
1431 [[ -e $f ]] ||
continue
1432 while read -r dev rest ||
[ -n "$dev" ]; do
1433 push_host_devs
"$dev"
1437 for dev
in $add_device; do
1438 push_host_devs
"$dev"
1441 if ((${#add_device_l[@]})); then
1442 add_device
+=" ${add_device_l[*]} "
1443 push_host_devs
"${add_device_l[@]}"
1446 if [[ $hostonly ]] && [[ $hostonly_default_device != "no" ]]; then
1447 # in hostonly mode, determine all devices, which have to be accessed
1448 # and examine them for filesystem types
1465 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1466 mountpoint
"$mp" > /dev
/null
2>&1 ||
continue
1467 _dev
=$
(find_block_device
"$mp")
1468 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1469 [[ -b $_bdev ]] && _dev
=$_bdev
1470 [[ $mp == "/" ]] && root_devs
+=("$_dev")
1471 push_host_devs
"$_dev"
1472 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1473 for i
in $
(btrfs_devs
"$mp"); do
1474 [[ $mp == "/" ]] && root_devs
+=("$i")
1480 # TODO - with sysroot, /proc/swaps is not relevant
1481 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1482 while read -r dev
type rest ||
[ -n "$dev" ]; do
1483 [[ -b $dev ]] ||
continue
1484 [[ $type == "partition" ]] ||
continue
1486 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1487 [[ $_d == \
#* ]] && continue
1488 [[ $_d ]] ||
continue
1489 [[ $_t != "swap" ]] && continue
1490 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1491 [[ $_o == *noauto
* ]] && continue
1492 _d
=$
(expand_persistent_dev
"$_d")
1493 [[ $_d -ef $dev ]] ||
continue
1495 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1496 while read -r _mapper _ _p _o ||
[ -n "$_mapper" ]; do
1497 [[ $_mapper == \
#* ]] && continue
1498 [[ $_d -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1499 [[ "$_o" ]] || _o
="$_p"
1500 # skip entries with password files
1501 [[ $_p == /* ]] && [[ -f $_p ]] && continue 2
1503 [[ $_o == *swap
* ]] && continue 2
1504 done < "$dracutsysrootdir"/etc
/crypttab
1507 _dev
="$(readlink -f "$dev")"
1508 push_host_devs
"$_dev"
1509 swap_devs
+=("$_dev")
1511 done < "$dracutsysrootdir"/etc
/fstab
1515 # collect all "x-initrd.mount" entries from /etc/fstab
1516 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1517 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1518 [[ $_d == \
#* ]] && continue
1519 [[ $_d ]] ||
continue
1520 [[ $_o != *x-initrd.mount
* ]] && continue
1521 _dev
=$
(expand_persistent_dev
"$_d")
1522 _dev
="$(readlink -f "$_dev")"
1523 [[ -b $_dev ]] ||
continue
1525 push_host_devs
"$_dev"
1526 if [[ $_t == btrfs
]]; then
1527 for i
in $
(btrfs_devs
"$_m"); do
1531 done < "$dracutsysrootdir"/etc
/fstab
1540 if [[ -b /dev
/block
/$1 ]]; then
1541 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1544 if [[ -b $1 ]]; then
1545 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1548 if fstype
=$
(find_dev_fstype
"$1"); then
1549 host_fs_types
["$1"]="$fstype"
1555 for dev
in "${host_devs[@]}"; do
1557 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1560 for dev
in "${!host_fs_types[@]}"; do
1561 [[ ${host_fs_types[$dev]} == "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} == "xfs" ]] ||
continue
1562 rootopts
=$
(find_dev_fsopts
"$dev")
1563 if [[ ${host_fs_types[$dev]} == "reiserfs" ]]; then
1564 journaldev
=$
(fs_get_option
"$rootopts" "jdev")
1565 elif [[ ${host_fs_types[$dev]} == "xfs" ]]; then
1566 journaldev
=$
(fs_get_option
"$rootopts" "logdev")
1568 if [[ $journaldev ]]; then
1569 dev
="$(readlink -f "$dev")"
1570 push_host_devs
"$dev"
1572 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1576 [[ -d $dracutsysrootdir$dbus ]] \
1577 || dbus
=$
(pkg-config dbus
--variable=dbus
2> /dev
/null
)
1579 [[ -d $dracutsysrootdir$dbus ]] || dbus
=/usr
/share
/dbus-1
1581 [[ -d $dracutsysrootdir$dbusconfdir ]] \
1582 || dbusconfdir
=$
(pkg-config dbus
--variable=dbusconfdir
2> /dev
/null
)
1584 [[ -d $dracutsysrootdir$dbusconfdir ]] || dbusconfdir
=/etc
/dbus-1
1586 [[ -d $dracutsysrootdir$dbusinterfaces ]] \
1587 || dbusinterfaces
=$
(pkg-config dbus
--variable=dbusinterfaces
2> /dev
/null
)
1589 [[ -d $dracutsysrootdir$dbusinterfaces ]] || dbusinterfaces
=${dbus}/interfaces
1591 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] \
1592 || dbusinterfacesconfdir
=$
(pkg-config dbus
--variable=dbusinterfacesconfdir
2> /dev
/null
)
1594 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] || dbusinterfacesconfdir
=${dbusconfdir}/interfaces
1596 [[ -d $dracutsysrootdir$dbusservices ]] \
1597 || dbusservices
=$
(pkg-config dbus
--variable=dbusservices
2> /dev
/null
)
1599 [[ -d $dracutsysrootdir$dbusservices ]] || dbusservices
=${dbus}/services
1601 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] \
1602 || dbusservicesconfdir
=$
(pkg-config dbus
--variable=dbusservicesconfdir
2> /dev
/null
)
1604 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] || dbusservicesconfdir
=${dbusconfdir}/services
1606 [[ -d $dracutsysrootdir$dbussession ]] \
1607 || dbussession
=$
(pkg-config dbus
--variable=dbussession
2> /dev
/null
)
1609 [[ -d $dracutsysrootdir$dbussession ]] || dbussession
=${dbus}/session.d
1611 [[ -d $dracutsysrootdir$dbussessionconfdir ]] \
1612 || dbussessionconfdir
=$
(pkg-config dbus
--variable=dbussessionconfdir
2> /dev
/null
)
1614 [[ -d $dracutsysrootdir$dbussessionconfdir ]] || dbussessionconfdir
=${dbusconfdir}/session.d
1616 [[ -d $dracutsysrootdir$dbussystem ]] \
1617 || dbussystem
=$
(pkg-config dbus
--variable=dbussystem
2> /dev
/null
)
1619 [[ -d $dracutsysrootdir$dbussystem ]] || dbussystem
=${dbus}/system.d
1621 [[ -d $dracutsysrootdir$dbussystemconfdir ]] \
1622 || dbussystemconfdir
=$
(pkg-config dbus
--variable=dbussystemconfdir
2> /dev
/null
)
1624 [[ -d $dracutsysrootdir$dbussystemconfdir ]] || dbussystemconfdir
=${dbusconfdir}/system.d
1626 [[ -d $dracutsysrootdir$dbussystemservices ]] \
1627 || dbussystemservices
=$
(pkg-config dbus
--variable=dbussystemservices
2> /dev
/null
)
1629 [[ -d $dracutsysrootdir$dbussystemservices ]] || dbussystemservices
=${dbus}/system-services
1631 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] \
1632 || dbussystemservicesconfdir
=$
(pkg-config dbus
--variable=dbussystemservicesconfdir
2> /dev
/null
)
1634 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] || dbussystemservicesconfdir
=${dbusconfdir}/system-services
1636 [[ -d $dracutsysrootdir$udevdir ]] \
1637 || udevdir
="$(pkg-config udev --variable=udevdir 2> /dev/null)"
1638 if ! [[ -d $dracutsysrootdir$udevdir ]]; then
1639 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1640 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1643 [[ -d $dracutsysrootdir$sysctld ]] \
1644 || sysctld
=$
(pkg-config systemd
--variable=sysctld
2> /dev
/null
)
1646 [[ -d $dracutsysrootdir$sysctld ]] || sysctld
=/usr
/lib
/sysctl.d
1648 [[ -d $dracutsysrootdir$sysctlconfdir ]] \
1649 || sysctlconfdir
=$
(pkg-config systemd
--variable=sysctlconfdir
2> /dev
/null
)
1651 [[ -d $dracutsysrootdir$sysctlconfdir ]] || sysctlconfdir
=/etc
/sysctl.d
1653 [[ -d $dracutsysrootdir$environment ]] \
1654 || environment
=$
(pkg-config systemd
--variable=environment
2> /dev
/null
)
1656 [[ -d $dracutsysrootdir$environment ]] || environment
=/usr
/lib
/environment.d
1658 [[ -d $dracutsysrootdir$environmentconfdir ]] \
1659 || environmentconfdir
=$
(pkg-config systemd
--variable=environmentconfdir
2> /dev
/null
)
1661 [[ -d $dracutsysrootdir$environmentconfdir ]] || environmentconfdir
=/etc
/environment.d
1663 [[ -d $dracutsysrootdir$systemdcatalog ]] \
1664 || systemdcatalog
=$
(pkg-config systemd
--variable=systemdcatalog
2> /dev
/null
)
1666 [[ -d $dracutsysrootdir$systemdcatalog ]] || systemdcatalog
=${systemdutildir}/catalog
1668 [[ -d $dracutsysrootdir$modulesload ]] \
1669 || modulesload
=$
(pkg-config systemd
--variable=modulesload
2> /dev
/null
)
1671 [[ -d $dracutsysrootdir$modulesload ]] || modulesload
=/usr
/lib
/modules-load.d
1673 [[ -d $dracutsysrootdir$modulesloadconfdir ]] \
1674 || modulesloadconfdir
=$
(pkg-config systemd
--variable=modulesloadconfdir
2> /dev
/null
)
1676 [[ -d $dracutsysrootdir$modulesloadconfdir ]] || modulesloadconfdir
=/etc
/modules-load.d
1678 [[ -d $dracutsysrootdir$systemdnetwork ]] \
1679 || systemdnetwork
=$
(pkg-config systemd
--variable=systemdnetwork
2> /dev
/null
)
1681 [[ -d $dracutsysrootdir$systemdnetwork ]] || systemdnetwork
=${systemdutildir}/network
1683 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] \
1684 || systemdnetworkconfdir
=$
(pkg-config systemd
--variable=systemdnetworkconfdir
2> /dev
/null
)
1686 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] || systemdnetworkconfdir
=${systemdsystemconfdir}/network
1688 [[ -d $dracutsysrootdir$systemdntpunits ]] \
1689 || systemdntpunits
=$
(pkg-config systemd
--variable=systemdntpunits
2> /dev
/null
)
1691 [[ -d $dracutsysrootdir$systemdntpunits ]] || systemdntpunits
=${systemdutildir}/ntp-units.d
1693 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] \
1694 || systemdntpunitsconfdir
=$
(pkg-config systemd
--variable=systemdntpunitsconfdir
2> /dev
/null
)
1696 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] || systemdntpunitsconfdir
=${systemdsystemconfdir}/ntp-units.d
1698 [[ -d $dracutsysrootdir$systemdportable ]] \
1699 || systemdportable
=$
(pkg-config systemd
--variable=systemdportable
2> /dev
/null
)
1701 [[ -d $dracutsysrootdir$systemdportable ]] || systemdportable
=${systemdutildir}/portable
1703 [[ -d $dracutsysrootdir$systemdportableconfdir ]] \
1704 || systemdportableconfdir
=$
(pkg-config systemd
--variable=systemdportableconfdir
2> /dev
/null
)
1706 [[ -d "$dracutsysrootdir$systemdportableconfdir" ]] || systemdportableconfdir
=${systemdsystemconfdir}/portable
1708 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1709 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2> /dev
/null
)
1711 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1713 [[ -d $dracutsysrootdir$systemduser ]] \
1714 || systemduser
=$
(pkg-config systemd
--variable=systemduser
2> /dev
/null
)
1716 [[ -d $dracutsysrootdir$systemduser ]] || systemduser
=${systemdutildir}/user
1718 [[ -d $dracutsysrootdir$systemduserconfdir ]] \
1719 || systemduserconfdir
=$
(pkg-config systemd
--variable=systemduserconfdir
2> /dev
/null
)
1721 [[ -d $dracutsysrootdir$systemduserconfdir ]] || systemduserconfdir
=${systemdsystemconfdir}/user
1723 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1724 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2> /dev
/null
)
1726 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] || systemdsystemconfdir
=/etc
/systemd
/system
1728 [[ -d $dracutsysrootdir$sysusers ]] \
1729 || sysusers
=$
(pkg-config systemd
--variable=sysusers
2> /dev
/null
)
1731 [[ -d $dracutsysrootdir$sysusers ]] || sysusers
=/usr
/lib
/sysusers.d
1733 [[ -d $dracutsysrootdir$sysusersconfdir ]] \
1734 || sysusersconfdir
=$
(pkg-config systemd
--variable=sysusersconfdir
2> /dev
/null
)
1736 [[ -d $dracutsysrootdir$sysusersconfdir ]] || sysusersconfdir
=/etc
/sysusers.d
1738 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1739 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2> /dev
/null
)
1741 if ! [[ -d $dracutsysrootdir$tmpfilesdir ]]; then
1742 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1743 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1746 export initdir dracutbasedir \
1747 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1749 fw_dir drivers_dir debug no_kernel kernel_only \
1750 omit_drivers mdadmconf lvmconf root_devs \
1751 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1752 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1753 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1754 DRACUT_VERSION udevdir prefix filesystems drivers \
1755 dbus dbusconfdir dbusinterfaces dbusinterfacesconfdir \
1756 dbusservices dbusservicesconfdir dbussession dbussessionconfdir \
1757 dbussystem dbussystemconfdir dbussystemservices dbussystemservicesconfdir \
1758 environment environmentconfdir modulesload modulesloadconfdir sysctl \
1759 sysctlconfdir sysusers sysusersconfdir systemdutildir systemdutilconfdir \
1760 systemdcatalog systemdntpunits systemdntpunitsconfdir systemdsystemunitdir \
1761 systemdsystemconfdir hostonly_cmdline loginstall \
1765 # check all our modules to see if they should be sourced.
1766 # This builds a list of modules that we will install next.
1767 for_each_module_dir check_module
1768 for_each_module_dir check_mount
1770 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1772 do_print_cmdline
() {
1773 local -A _mods_to_print
1774 for i
in $modules_loaded $mods_to_load; do
1775 _mods_to_print
[$i]=1
1778 # source our modules.
1779 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1780 _d_mod
=${moddir##*/}
1781 _d_mod
=${_d_mod#[0-9][0-9]}
1782 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1783 module_cmdline
"$_d_mod" "$moddir"
1788 if [[ $print_cmdline ]]; then
1794 # Create some directory structure first
1795 # shellcheck disable=SC2174
1796 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1798 # shellcheck disable=SC2174
1799 [[ -L $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1800 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1802 if [[ $prefix ]]; then
1803 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1804 [[ $d == */* ]] && continue
1805 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1809 if [[ $kernel_only != yes ]]; then
1810 for d
in usr usr
/bin usr
/sbin bin etc lib sbin tmp var var
/tmp
$libdirs; do
1811 [[ -e "${initdir}${prefix}/$d" ]] && continue
1812 if [ -L "/$d" ]; then
1813 inst_symlink
"/$d" "${prefix}/$d"
1815 # shellcheck disable=SC2174
1816 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1820 for d
in dev proc sys sysroot root run
; do
1821 if [ -L "/$d" ]; then
1824 # shellcheck disable=SC2174
1825 mkdir
-m 0755 -p "$initdir/$d"
1829 ln -sfn ..
/run
"$initdir/var/run"
1830 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1832 for d
in lib
"$libdirs"; do
1833 [[ -e "${initdir}${prefix}/$d" ]] && continue
1834 if [ -h "/$d" ]; then
1835 inst
"/$d" "${prefix}/$d"
1837 # shellcheck disable=SC2174
1838 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1843 if [[ $kernel_only != yes ]]; then
1844 mkdir
-p "${initdir}/etc/cmdline.d"
1845 # shellcheck disable=SC2174
1846 mkdir
-m 0755 -p "${initdir}"/lib "${initdir}"/lib/dracut "${initdir}"/lib
/dracut
/hooks
1847 # shellcheck disable=SC2154
1848 for _d
in $hookdirs; do
1849 # shellcheck disable=SC2174
1850 mkdir
-m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
1852 if [[ $EUID == "0" ]]; then
1853 [[ -c ${initdir}/dev
/null
]] || mknod
"${initdir}"/dev
/null c
1 3
1854 [[ -c ${initdir}/dev
/kmsg
]] || mknod
"${initdir}"/dev
/kmsg c
1 11
1855 [[ -c ${initdir}/dev
/console
]] || mknod
"${initdir}"/dev
/console c
5 1
1856 [[ -c ${initdir}/dev
/random
]] || mknod
"${initdir}"/dev
/random c
1 8
1857 [[ -c ${initdir}/dev
/urandom
]] || mknod
"${initdir}"/dev
/urandom c
1 9
1861 _isize
=0 #initramfs size
1863 # source our modules.
1864 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1865 _d_mod
=${moddir##*/}
1866 _d_mod
=${_d_mod#[0-9][0-9]}
1867 [[ $mods_to_load == *\
$_d_mod\
* ]] ||
continue
1868 if [[ $show_modules == yes ]]; then
1869 printf "%s\n" "$_d_mod"
1871 dinfo
"*** Including module: $_d_mod ***"
1873 if [[ $kernel_only == yes ]]; then
1874 module_installkernel
"$_d_mod" "$moddir" ||
{
1875 dfatal
"installkernel failed in module $_d_mod"
1879 module_install
"$_d_mod" "$moddir"
1880 if [[ $no_kernel != yes ]]; then
1881 module_installkernel
"$_d_mod" "$moddir" ||
{
1882 dfatal
"installkernel failed in module $_d_mod"
1887 mods_to_load
=${mods_to_load// $_d_mod /}
1888 modules_loaded
+="$_d_mod "
1890 #print the module install size
1891 if [ -n "$printsize" ]; then
1892 _isize_new
=$
(du
-sk "${initdir}" |
{
1896 _isize_delta
=$
((_isize_new
- _isize
))
1897 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1903 for i
in $modules_loaded; do
1904 mkdir
-p "$initdir"/lib
/dracut
1905 printf "%s\n" "$i" >> "$initdir"/lib
/dracut
/modules.txt
1908 dinfo
"*** Including modules done ***"
1910 ## final stuff that has to happen
1911 if [[ $no_kernel != yes ]]; then
1912 if [[ $hostonly_mode == "strict" ]]; then
1913 cp "$DRACUT_KERNEL_MODALIASES" "$initdir"/lib
/dracut
/hostonly-kernel-modules.txt
1916 if [[ $drivers ]]; then
1917 # shellcheck disable=SC2086
1918 hostonly
='' instmods
$drivers
1921 if [[ -n ${add_drivers// /} ]]; then
1922 # shellcheck disable=SC2086
1923 hostonly
='' instmods
-c $add_drivers
1925 if [[ $force_drivers ]]; then
1926 # shellcheck disable=SC2086
1927 hostonly
='' instmods
-c $force_drivers
1928 rm -f "$initdir"/etc
/cmdline.d
/20-force_driver.conf
1929 for mod
in $force_drivers; do
1930 echo "rd.driver.pre=$mod" >> "$initdir"/etc
/cmdline.d
/20-force_drivers.conf
1933 if [[ $filesystems ]]; then
1934 # shellcheck disable=SC2086
1935 hostonly
='' instmods
-c $filesystems
1938 dinfo
"*** Installing kernel module dependencies ***"
1940 dinfo
"*** Installing kernel module dependencies done ***"
1942 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1943 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] \
1944 && [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1945 for i
in "${initdir}"/etc
/cmdline.d
/*.conf
; do
1946 # We need no initramfs image and do not generate one.
1947 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1953 if [[ $kernel_only != yes ]]; then
1954 # FIXME: handle legacy item split
1955 # shellcheck disable=SC2068
1956 ((${#install_items[@]} > 0)) && inst_multiple
${install_items[@]}
1957 # shellcheck disable=SC2068
1958 ((${#install_optional_items[@]} > 0)) && inst_multiple
-o ${install_optional_items[@]}
1960 if [[ $kernel_cmdline ]] && [[ $uefi != yes ]]; then
1961 printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1964 for line
in "${fstab_lines[@]}"; do
1965 read -r -a fstab_field
<<< "$line"
1966 if [ -z "${fstab_field[1]}" ]; then
1967 # Determine device and mount options from current system
1968 mountpoint
-q "${fstab_field[0]}" || derror
"${fstab_field[0]} is not a mount point!"
1969 read -r -a fstab_field
< <(findmnt
--raw -n --target "${fstab_field[0]}" --output=source,target
,fstype
,options
)
1970 dinfo
"Line for ${fstab_field[1]}: ${fstab_field[*]}"
1972 # Use default options
1973 [ -z "${fstab_field[3]}" ] && fstab_field
[3]="defaults"
1976 # Default options for freq and passno
1977 [ -z "${fstab_field[4]}" ] && fstab_field
[4]="0"
1978 [ -z "${fstab_field[5]}" ] && fstab_field
[5]="2"
1980 strstr
"${fstab_field[2]}" "nfs" && fstab_field
[5]="0"
1981 echo "${fstab_field[@]}" >> "${initdir}/etc/fstab"
1984 for f
in $add_fstab; do
1985 cat "$f" >> "${initdir}/etc/fstab"
1988 if [[ $dracutsysrootdir$systemdutildir ]]; then
1989 if [[ -d ${initdir}/$systemdutildir ]]; then
1990 mkdir
-p "${initdir}"/etc
/conf.d
1992 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1993 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1994 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1995 } > "${initdir}"/etc
/conf.d
/systemd.conf
1999 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
2000 dinfo
"*** Resolving executable dependencies ***"
2001 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
2002 |
xargs -r -0 "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
2003 dinfo
"*** Resolving executable dependencies done ***"
2006 # Now we are done with lazy resolving, always install dependencies
2007 unset DRACUT_RESOLVE_LAZY
2008 export DRACUT_RESOLVE_DEPS
=1
2011 for ((i
= 0; i
< ${#include_src[@]}; i
++)); do
2012 src
="${include_src[$i]}"
2013 target
="${include_target[$i]}"
2014 if [[ $src && $target ]]; then
2015 if [[ -f $src ]]; then
2016 inst
"$src" "$target"
2017 elif [[ -d $src ]]; then
2018 ddebug
"Including directory: $src"
2019 destdir
="${initdir}/${target}"
2021 # check for preexisting symlinks, so we can cope with the
2022 # symlinks to $prefix
2023 # Objectname is a file or a directory
2024 for objectname
in "$src"/*; do
2025 [[ -e $objectname ||
-L $objectname ]] ||
continue
2026 if [[ -d $objectname ]]; then
2027 # objectname is a directory, let's compute the final directory name
2028 object_destdir
=${destdir}/${objectname#$src/}
2029 if ! [[ -e $object_destdir ]]; then
2030 # shellcheck disable=SC2174
2031 mkdir
-m 0755 -p "$object_destdir"
2032 chmod --reference="$objectname" "$object_destdir"
2034 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
2036 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
2039 elif [[ -e $src ]]; then
2040 derror
"$src is neither a directory nor a regular file"
2042 derror
"$src doesn't exist"
2047 if [[ $do_hardlink == yes ]] && command -v hardlink
> /dev
/null
; then
2048 dinfo
"*** Hardlinking files ***"
2049 hardlink
"$initdir" 2>&1
2050 dinfo
"*** Hardlinking files done ***"
2054 if [[ $do_strip == yes ]]; then
2055 # Prefer strip from elfutils for package size
2057 strip_cmd
=$
(command -v eu-strip
)
2058 [ -z "$strip_cmd" ] && strip_cmd
="strip"
2060 for p
in $strip_cmd xargs find; do
2061 if ! type -P $p > /dev
/null
; then
2062 dinfo
"Could not find '$p'. Not stripping the initramfs."
2068 # cleanup empty ldconfig_paths directories
2069 for d
in $
(ldconfig_paths
); do
2070 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" > /dev
/null
2>&1
2073 if [[ $early_microcode == yes ]]; then
2074 dinfo
"*** Generating early-microcode cpio image ***"
2075 ucode_dir
=(amd-ucode intel-ucode
)
2076 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
2077 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
2079 mkdir
-p "$_dest_dir"
2080 if [[ $hostonly ]]; then
2081 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
2082 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
2084 for idx
in $_dest_idx; do
2085 _fw
=${ucode_dir[$idx]}
2086 for _fwdir
in $fw_dir; do
2087 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
2089 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
2090 if [[ $hostonly ]]; then
2091 _src
=$
(get_ucode_file
)
2092 [[ $_src ]] ||
break
2093 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
2094 [[ -r $_fwdir/$_fw/$_src ]] ||
break
2097 for i
in $_fwdir/$_fw/$_src; do
2098 [ -e "$i" ] && break
2101 for i
in $_fwdir/$_fw/$_src; do
2102 [[ -e $i ]] ||
continue
2104 str_ends
"$i" ".asc" && continue
2105 cat "$i" >> "$_dest_dir/${ucode_dest[$idx]}"
2107 create_early_cpio
="yes"
2110 if [[ ! -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2111 if cd "$early_cpio_dir/d"; then
2112 for _ucodedir
in "${early_microcode_image_dir[@]}"; do
2113 for _ucodename
in "${early_microcode_image_name[@]}"; do
2114 [[ -e "$_ucodedir/$_ucodename" ]] \
2115 && cpio --extract --file "$_ucodedir/$_ucodename" --quiet \
2116 "kernel/x86/microcode/${ucode_dest[$idx]}"
2117 if [[ -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2118 dinfo
"*** Using microcode found in '$_ucodedir/$_ucodename' ***"
2119 create_early_cpio
="yes"
2129 if [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; then
2130 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
2131 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
2132 mkdir
-p "$_dest_dir"
2133 for table
in "$acpi_table_dir"/*.aml
; do
2134 dinfo
" Adding ACPI table: $table"
2135 $DRACUT_CP "$table" "$_dest_dir"
2136 create_early_cpio
="yes"
2140 dinfo
"*** Store current command line parameters ***"
2141 if ! (echo "$PARMS_TO_STORE" > "$initdir"/lib
/dracut
/build-parameter.txt
); then
2142 dfatal
"Could not store the current command line parameters"
2146 if [[ $hostonly_cmdline == "yes" ]]; then
2147 unset _stored_cmdline
2148 if [[ -d $initdir/etc
/cmdline.d
]]; then
2149 dinfo
"Stored kernel commandline:"
2150 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2151 [ -e "$conf" ] ||
continue
2152 dinfo
"$(< "$conf")"
2156 if ! [[ $_stored_cmdline ]]; then
2157 dinfo
"No dracut internal kernel commandline stored in the initramfs"
2161 if [[ $kernel_only != yes ]]; then
2162 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
2163 for _dir
in $libdirs; do
2164 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
2165 [[ -e $_f ]] ||
continue
2166 inst_libdir_file
"libgcc_s.so*"
2171 # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
2172 if [[ $DRACUT_FIPS_MODE ]]; then
2173 for _dir
in $libdirs; do
2174 for _f
in "$dracutsysrootdir$_dir/libcrypto.so"*; do
2175 [[ -e $_f ]] ||
continue
2176 inst_libdir_file
-o "libssl.so*"
2183 if [[ $kernel_only != yes ]]; then
2184 # make sure that library links are correct and up to date
2185 for f
in "$dracutsysrootdir"/etc
/ld.so.conf
"$dracutsysrootdir"/etc
/ld.so.conf.d
/*; do
2186 [[ -f $f ]] && inst_simple
"${f#$dracutsysrootdir}"
2188 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc
/ld.so.conf
; then
2189 if [[ $EUID == 0 ]]; then
2190 derror
"ldconfig exited ungracefully"
2192 derror
"ldconfig might need uid=0 (root) for chroot()"
2197 if dracut_module_included
"squash"; then
2198 readonly squash_dir
="$initdir/squash/root"
2199 readonly squash_img
="$initdir/squash-root.img"
2200 mkdir
-p "$squash_dir"
2201 dinfo
"*** Install squash loader ***"
2202 DRACUT_SQUASH_POST_INST
=1 module_install
"squash"
2205 if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2206 dinfo
"*** Stripping files ***"
2207 find "$initdir" -type f \
2208 -executable -not -path '*/lib/modules/*.ko' -print0 \
2209 |
xargs -r -0 $strip_cmd -g -p 2> /dev
/null
2211 # strip kernel modules, but do not touch signed modules
2212 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
2213 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
2214 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
2215 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
2216 done |
xargs -r -0 $strip_cmd -g -p
2217 dinfo
"*** Stripping files done ***"
2220 if dracut_module_included
"squash"; then
2221 dinfo
"*** Squashing the files inside the initramfs ***"
2222 declare squash_compress_arg
2223 # shellcheck disable=SC2086
2224 if [[ $compress ]]; then
2225 if ! mksquashfs
/dev
/null
"$DRACUT_TMPDIR"/.squash-test.img
-no-progress -comp $compress &> /dev
/null
; then
2226 dwarn
"mksquashfs doesn't support compressor '$compress', failing back to default compressor."
2228 squash_compress_arg
="$compress"
2232 # shellcheck disable=SC2086
2233 if ! mksquashfs
"$squash_dir" "$squash_img" \
2234 -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
2235 -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev
/null
; then
2236 dfatal
"dracut: Failed making squash image"
2240 rm -rf "$squash_dir"
2241 dinfo
"*** Squashing the files inside the initramfs done ***"
2243 # Skip initramfs compress
2247 dinfo
"*** Creating image file '$outfile' ***"
2249 if [[ $uefi == yes ]]; then
2250 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
2251 mkdir
-p "$uefi_outdir"
2254 if [[ $DRACUT_REPRODUCIBLE ]]; then
2255 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2256 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2258 if [[ "$(cpio --help)" == *--reproducible* ]]; then
2261 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
2265 [[ $EUID != 0 ]] && cpio_owner
="0:0"
2267 if [[ $create_early_cpio == yes ]]; then
2268 echo 1 > "$early_cpio_dir/d/early_cpio"
2270 if [[ $DRACUT_REPRODUCIBLE ]]; then
2271 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2272 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2275 # The microcode blob is _before_ the initramfs blob, not after
2278 cd "$early_cpio_dir/d"
2279 find .
-print0 |
sort -z \
2280 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
2281 ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
2283 dfatal
"dracut: creation of $outfile failed"
2288 if ! [[ $compress ]]; then
2289 # check all known compressors, if none specified
2290 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
2291 command -v "$i" &> /dev
/null ||
continue
2295 if [[ $compress == cat ]]; then
2296 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
2300 # choose the right arguments for the compressor
2303 if [[ $compress == lbzip2
]] ||
command -v "$DRACUT_COMPRESS_LBZIP2" &> /dev
/null
; then
2304 compress="$DRACUT_COMPRESS_LBZIP2 -9"
2306 compress="$DRACUT_COMPRESS_BZIP2 -9"
2310 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
2313 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
2316 if [[ $compress == pigz
]] ||
command -v "$DRACUT_COMPRESS_PIGZ" &> /dev
/null
; then
2317 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
2318 elif command -v gzip &> /dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
2319 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
2321 compress="$DRACUT_COMPRESS_GZIP -n -9"
2325 compress="$DRACUT_COMPRESS_LZOP -9"
2328 compress="$DRACUT_COMPRESS_LZ4 -l -9"
2331 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
2338 find .
-print0 |
sort -z \
2339 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet \
2340 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
2342 dfatal
"dracut: creation of $outfile failed"
2346 # shellcheck disable=SC2154
2347 if ((maxloglvl
>= 5)) && ((verbosity_mod_l
>= 0)); then
2348 if [[ $allowlocal ]]; then
2349 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
2351 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img" | ddebug
2357 if [[ $uefi == yes ]]; then
2358 if [[ $kernel_cmdline ]]; then
2359 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
2360 elif [[ $hostonly_cmdline == yes ]] && [ -d "$initdir/etc/cmdline.d" ]; then
2361 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2362 [ -e "$conf" ] ||
continue
2363 printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
2367 if [[ $kernel_cmdline ]] ||
[[ $hostonly_cmdline == yes && -d "$initdir/etc/cmdline.d" ]]; then
2368 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
2369 dinfo
"Using UEFI kernel cmdline:"
2370 dinfo
"$(tr -d '\000' < "$uefi_outdir/cmdline.txt
")"
2371 uefi_cmdline
="${uefi_outdir}/cmdline.txt"
2376 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
2377 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
2378 if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then
2379 uefi_splash_image
="${dracutsysrootdir}${uefi_splash_image}"
2381 unset uefi_splash_image
2385 ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \
2386 ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \
2387 ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \
2388 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x2000000 \
2389 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
=0x3000000 \
2390 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
2391 if [[ -n ${uefi_secureboot_key} && -n ${uefi_secureboot_cert} ]]; then
2393 --key "${uefi_secureboot_key}" \
2394 --cert "${uefi_secureboot_cert}" \
2395 --output "$outfile" "${uefi_outdir}/linux.efi"; then
2396 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
2398 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2402 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2403 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2408 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2412 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2413 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2416 dfatal
"dracut: creation of $outfile failed"
2421 command -v restorecon
&> /dev
/null
&& restorecon
-- "$outfile"
2424 btrfs filesystem show
"$1" |
sed -n '1s/^.*uuid: //p'
2427 freeze_ok_for_btrfs
() {
2428 local mnt uuid1 uuid2
2429 # If the output file is on btrfs, we need to make sure that it's
2430 # not on a subvolume of the same file system as the root FS.
2431 # Otherwise, fsfreeze() might freeze the entire system.
2432 # This is most conveniently checked by comparing the FS uuid.
2434 [[ "$(stat -f -c %T -- "/")" == "btrfs" ]] ||
return 0
2435 mnt
=$
(stat
-c %m
-- "$1")
2436 uuid1
=$
(btrfs_uuid
"$mnt")
2437 uuid2
=$
(btrfs_uuid
"/")
2438 [[ $uuid1 && $uuid2 && $uuid1 != "$uuid2" ]]
2441 freeze_ok_for_fstype
() {
2445 [[ "$(stat -c %m -- "$outfile")" == "/" ]] && return 1
2446 fstype
=$
(stat
-f -c %T
-- "$outfile")
2452 freeze_ok_for_btrfs
"$outfile"
2460 # We sync/fsfreeze only if we're operating on a live booted system.
2461 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2462 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2463 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2464 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2465 if [[ -d $dracutsysrootdir/run
/systemd
/system
]]; then
2466 if ! sync
"$outfile" 2> /dev
/null
; then
2467 dinfo
"dracut: sync operation on newly created initramfs $outfile failed"
2471 # use fsfreeze only if we're not writing to /
2472 if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype
"$outfile"; then
2473 FSFROZEN
="$(dirname "$outfile")"
2474 if ! (fsfreeze
-f "${FSFROZEN}" 2> /dev
/null
&& fsfreeze
-u "${FSFROZEN}" 2> /dev
/null
); then
2475 dinfo
"dracut: warning: could not fsfreeze $(dirname "$outfile")"