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 -a, --add [LIST] Add a space-separated list of dracut modules.
83 --rebuild Append arguments to those of existing image and rebuild
84 -m, --modules [LIST] Specify a space-separated list of dracut modules to
85 call when building the initramfs. Modules are located
86 in /usr/lib/dracut/modules.d.
87 -o, --omit [LIST] Omit a space-separated list of dracut modules.
88 --force-add [LIST] Force to add a space-separated list of dracut modules
89 to the default set of modules, when -H is specified.
90 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
91 exclusively include in the initramfs.
92 --add-drivers [LIST] Specify a space-separated list of kernel
93 modules to add to the initramfs.
94 --force-drivers [LIST] Specify a space-separated list of kernel
95 modules to add to the initramfs and make sure they
96 are tried to be loaded via modprobe same as passing
97 rd.driver.pre=DRIVER kernel parameter.
98 --omit-drivers [LIST] Specify a space-separated list of kernel
99 modules not to add to the initramfs.
100 --filesystems [LIST] Specify a space-separated list of kernel filesystem
101 modules to exclusively include in the generic
103 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
105 --fwdir [DIR] Specify additional directories, where to look for
106 firmwares, separated by :
107 --kernel-only Only install kernel drivers and firmware files
108 --no-kernel Do not install kernel drivers and firmware files
109 --print-cmdline Print the kernel command line for the given disk layout
110 --early-microcode Combine early microcode with ramdisk
111 --no-early-microcode Do not combine early microcode with ramdisk
112 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
113 --strip Strip binaries in the initramfs
114 --nostrip Do not strip binaries in the initramfs
115 --hardlink Hardlink files in the initramfs
116 --nohardlink Do not hardlink files in the initramfs
117 --prefix [DIR] Prefix initramfs files with [DIR]
118 --noprefix Do not prefix initramfs files
119 --mdadmconf Include local /etc/mdadm.conf
120 --nomdadmconf Do not include local /etc/mdadm.conf
121 --lvmconf Include local /etc/lvm/lvm.conf
122 --nolvmconf Do not include local /etc/lvm/lvm.conf
123 --fscks [LIST] Add a space-separated list of fsck helpers.
124 --nofscks Inhibit installation of any fsck helpers.
125 --ro-mnt Mount / and /usr read-only by default.
126 -h, --help This message
127 --debug Output debug information of the build process
128 --profile Output profile information of the build process
129 -L, --stdlog [0-6] Specify logging level (to standard error)
130 0 - suppress any messages
131 1 - only fatal errors
135 5 - debug info (here starts lots of output)
136 6 - trace info (and even more)
137 -v, --verbose Increase verbosity level
138 -q, --quiet Decrease verbosity level
139 -c, --conf [FILE] Specify configuration file to use.
140 Default: /etc/dracut.conf
141 --confdir [DIR] Specify configuration directory to use *.conf files
142 from. Default: /etc/dracut.conf.d
143 --tmpdir [DIR] Temporary directory to be used instead of default
145 -r, --sysroot [DIR] Specify sysroot directory to collect files from.
146 -l, --local Local mode. Use modules from the current working
147 directory instead of the system-wide installed in
148 /usr/lib/dracut/modules.d.
149 Useful when running dracut from a git checkout.
150 -H, --hostonly Host-Only mode: Install only what is needed for
151 booting the local host instead of a generic host.
152 -N, --no-hostonly Disables Host-Only mode
153 --hostonly-mode <mode>
154 Specify the hostonly mode to use. <mode> could be
155 one of "sloppy" or "strict". "sloppy" mode is used
157 In "sloppy" hostonly mode, extra drivers and modules
158 will be installed, so minor hardware change won't make
159 the image unbootable (eg. changed keyboard), and the
160 image is still portable among similar hosts.
161 With "strict" mode enabled, anything not necessary
162 for booting the local host in its current state will
163 not be included, and modules may do some extra job
164 to save more space. Minor change of hardware or
165 environment could make the image unbootable.
166 DO NOT use "strict" mode unless you know what you
168 --hostonly-cmdline Store kernel command line arguments needed
170 --no-hostonly-cmdline Do not store kernel command line arguments needed
172 --no-hostonly-default-device
173 Do not generate implicit host devices like root,
174 swap, fstab, etc. Use "--mount" or "--add-device"
175 to explicitly add devices as needed.
176 --hostonly-i18n Install only needed keyboard and font files according
177 to the host configuration (default).
178 --no-hostonly-i18n Install all keyboard and font files available.
179 --hostonly-nics [LIST]
180 Only enable listed NICs in the initramfs.
181 --persistent-policy [POLICY]
182 Use [POLICY] to address disks and partitions.
183 POLICY can be any directory name found in /dev/disk.
184 E.g. "by-uuid", "by-label"
185 --fstab Use /etc/fstab to determine the root device.
186 --add-fstab [FILE] Add file to the initramfs fstab
187 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
188 Mount device [DEV] on mountpoint [MP] with filesystem
189 [FSTYPE] and options [FSOPTS] in the initramfs
190 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
191 determined by looking at the current mounts.
192 --add-device "[DEV]" Bring up [DEV] in initramfs
193 -i, --include [SOURCE] [TARGET]
194 Include the files in the SOURCE directory into the
195 Target directory in the final initramfs.
196 If SOURCE is a file, it will be installed to TARGET
197 in the final initramfs.
198 -I, --install [LIST] Install the space separated list of files into the
200 --install-optional [LIST] Install the space separated list of files into the
201 initramfs, if they exist.
202 --gzip Compress the generated initramfs using gzip.
203 This will be done by default, unless another
204 compression option or --no-compress is passed.
205 --bzip2 Compress the generated initramfs using bzip2.
206 Make sure your kernel has bzip2 decompression support
207 compiled in, otherwise you will not be able to boot.
208 --lzma Compress the generated initramfs using lzma.
209 Make sure your kernel has lzma support compiled in,
210 otherwise you will not be able to boot.
211 --xz Compress the generated initramfs using xz.
212 Make sure that your kernel has xz support compiled
213 in, otherwise you will not be able to boot.
214 --lzo Compress the generated initramfs using lzop.
215 Make sure that your kernel has lzo support compiled
216 in, otherwise you will not be able to boot.
217 --lz4 Compress the generated initramfs using lz4.
218 Make sure that your kernel has lz4 support compiled
219 in, otherwise you will not be able to boot.
220 --zstd Compress the generated initramfs using Zstandard.
221 Make sure that your kernel has zstd support compiled
222 in, otherwise you will not be able to boot.
223 --compress [COMPRESSION] Compress the generated initramfs with the
224 passed compression program. Make sure your kernel
225 knows how to decompress the generated initramfs,
226 otherwise you will not be able to boot.
227 --no-compress Do not compress the generated initramfs. This will
228 override any other compression options.
229 --list-modules List all available dracut modules.
230 -M, --show-modules Print included module's name to standard output during
232 --keep Keep the temporary initramfs for debugging purposes
233 --printsize Print out the module install size
234 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
235 --logfile [FILE] Logfile to use (overrides configuration setting)
236 --reproducible Create reproducible images
237 --no-reproducible Do not create reproducible images
238 --loginstall [DIR] Log all files installed from the host to [DIR]
239 --uefi Create an UEFI executable with the kernel cmdline and
241 --no-uefi Disables UEFI mode
242 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
243 --uefi-splash-image [FILE]
244 Use [FILE] as a splash image when creating an UEFI
246 --kernel-image [FILE] location of the kernel image
247 --regenerate-all Regenerate all initramfs images at the default location
248 for the kernel versions found on the system
249 --version Display version
251 If [LIST] has multiple arguments, then you have to put these in quotes.
255 # dracut --add-drivers "module1 module2" ...
261 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
262 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
263 # shellcheck source=./dracut-version.sh
264 .
"$dracutbasedir"/dracut-version.sh
266 echo "dracut $DRACUT_VERSION"
269 # Fills up host_devs stack variable and makes sure there are no duplicates
273 [[ " ${host_devs[*]} " == *" $_dev "* ]] && return
278 # Little helper function for reading args from the commandline.
279 # it automatically handles -a b and -a=b variants, and returns 1 if
280 # we need to shift $3.
285 local rematch
='^[^=]*=(.*)$'
286 if [[ $2 =~
$rematch ]]; then
287 read -r "$1" <<< "${BASH_REMATCH[1]}"
289 read -r "$1" <<< "$3"
290 # There is no way to shift our callers args, so
291 # return 1 to indicate they should do it instead.
297 if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
298 printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
299 printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
310 for i
in "$d/"*"$suffix"; do
312 printf "%s\n" "${i##*/}"
318 for f
in "${files[@]}"; do
320 if [[ -e "$d/$f" ]]; then
321 printf "%s\n" "$d/$f"
330 # Workaround -i, --include taking 2 arguments
333 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
334 newat
+=("++include") # Replace --include by ++include
339 set -- "${newat[@]}" # Set new $@
342 unset POSIXLY_CORRECT
344 -o "a:m:o:d:I:k:c:r:L:fvqlHhMN" \
348 --long add-drivers
: \
349 --long force-drivers
: \
350 --long omit-drivers
: \
354 --long filesystems
: \
356 --long install-optional
: \
378 --long print-cmdline \
379 --long kernel-cmdline
: \
399 --long no-host-only \
400 --long hostonly-mode
: \
401 --long hostonly-cmdline \
402 --long no-hostonly-cmdline \
403 --long no-hostonly-default-device \
404 --long persistent-policy
: \
415 --long list-modules \
416 --long show-modules \
419 --long regenerate-all \
420 --long noimageifnotneeded \
421 --long early-microcode \
422 --long no-early-microcode \
423 --long reproducible \
424 --long no-reproducible \
429 --long uefi-splash-image
: \
430 --long kernel-image
: \
431 --long no-hostonly-i18n \
432 --long hostonly-i18n \
433 --long hostonly-nics
: \
434 --long no-machineid \
439 # shellcheck disable=SC2181
450 rearrange_params
"$@"
453 # parse command line args to check if '--rebuild' option is present
457 if [ "$1" == "--" ]; then
461 if [ "$1" == "--rebuild" ]; then
464 if [ ! -e "$rebuild_file" ]; then
465 echo "Image file '$rebuild_file', for rebuild, does not exist!"
468 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
475 # get output file name and kernel version from command line arguments
482 if ! [[ ${outfile+x} ]]; then
484 elif ! [[ ${kernel+x} ]]; then
487 printf "\nUnknown arguments: %s\n\n" "$*" >&2
496 # extract input image file provided with rebuild option to get previous parameters, if any
497 if [[ $append_args_l == "yes" ]]; then
500 # determine resultant file
501 if ! [[ $outfile ]]; then
502 outfile
=$rebuild_file
505 if ! rebuild_param
=$
(lsinitrd
"$rebuild_file" '*lib/dracut/build-parameter.txt'); then
506 echo "Image '$rebuild_file' has no rebuild information stored"
510 # prepend previous parameters to current command line args
511 if [[ $rebuild_param ]]; then
512 TEMP
="$rebuild_param $TEMP"
514 rearrange_params
"$@"
524 if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
525 PARMS_TO_STORE
+=" $1"
530 PARMS_TO_STORE
+=" '$2'"
534 add_dracutmodules_l
+=("$2")
535 PARMS_TO_STORE
+=" '$2'"
539 force_add_dracutmodules_l
+=("$2")
540 PARMS_TO_STORE
+=" '$2'"
544 add_drivers_l
+=("$2")
545 PARMS_TO_STORE
+=" '$2'"
549 force_drivers_l
+=("$2")
550 PARMS_TO_STORE
+=" '$2'"
554 omit_drivers_l
+=("$2")
555 PARMS_TO_STORE
+=" '$2'"
559 dracutmodules_l
+=("$2")
560 PARMS_TO_STORE
+=" '$2'"
564 omit_dracutmodules_l
+=("$2")
565 PARMS_TO_STORE
+=" '$2'"
570 PARMS_TO_STORE
+=" '$2'"
574 filesystems_l
+=("$2")
575 PARMS_TO_STORE
+=" '$2'"
579 install_items_l
+=("$2")
580 PARMS_TO_STORE
+=" '$2'"
584 install_optional_items_l
+=("$2")
585 PARMS_TO_STORE
+=" '$2'"
590 PARMS_TO_STORE
+=" '$2'"
595 PARMS_TO_STORE
+=" '$2'"
600 PARMS_TO_STORE
+=" '$2'"
605 PARMS_TO_STORE
+=" '$2'"
610 PARMS_TO_STORE
+=" '$2'"
613 --add-device |
--device)
615 PARMS_TO_STORE
+=" '$2'"
619 kernel_cmdline_l
+=("$2")
620 PARMS_TO_STORE
+=" '$2'"
623 --nofscks) nofscks_l
="yes" ;;
624 --ro-mnt) ro_mnt_l
="yes" ;;
627 PARMS_TO_STORE
+=" '$2'"
632 PARMS_TO_STORE
+=" '$2'"
637 PARMS_TO_STORE
+=" '$2'"
642 PARMS_TO_STORE
+=" '$2'"
647 PARMS_TO_STORE
+=" '$2'"
652 PARMS_TO_STORE
+=" '$2'"
657 PARMS_TO_STORE
+=" '$2'"
662 PARMS_TO_STORE
+=" '$2'"
667 PARMS_TO_STORE
+=" '$2'"
671 if [[ $rebuild_file == "$outfile" ]]; then
676 -f |
--force) force
=yes ;;
692 early_microcode_l
="yes"
694 --no-early-microcode)
695 early_microcode_l
="no"
697 --strip) do_strip_l
="yes" ;;
698 --nostrip) do_strip_l
="no" ;;
699 --hardlink) do_hardlink_l
="yes" ;;
700 --nohardlink) do_hardlink_l
="no" ;;
701 --noprefix) prefix_l
="/" ;;
702 --mdadmconf) mdadmconf_l
="yes" ;;
703 --nomdadmconf) mdadmconf_l
="no" ;;
704 --lvmconf) lvmconf_l
="yes" ;;
705 --nolvmconf) lvmconf_l
="no" ;;
706 --debug) debug
="yes" ;;
707 --profile) profile
="yes" ;;
710 PARMS_TO_STORE
+=" '$2'"
717 -v |
--verbose) ((verbosity_mod_l
++)) ;;
718 -q |
--quiet) ((verbosity_mod_l--
)) ;;
721 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
722 && dracutbasedir
="$(readlink -f "${0%/*}")"
724 -H |
--hostonly |
--host-only)
727 -N |
--no-hostonly |
--no-host-only)
732 PARMS_TO_STORE
+=" '$2'"
736 hostonly_cmdline_l
="yes"
739 i18n_install_all_l
="no"
742 hostonly_nics_l
+=("$2")
743 PARMS_TO_STORE
+=" '$2'"
747 i18n_install_all_l
="yes"
749 --no-hostonly-cmdline)
750 hostonly_cmdline_l
="no"
752 --no-hostonly-default-device)
753 hostonly_default_device
="no"
756 persistent_policy_l
="$2"
757 PARMS_TO_STORE
+=" '$2'"
760 --fstab) use_fstab_l
="yes" ;;
765 --bzip2) compress_l
="bzip2" ;;
766 --lzma) compress_l
="lzma" ;;
767 --xz) compress_l
="xz" ;;
768 --lzo) compress_l
="lzo" ;;
769 --lz4) compress_l
="lz4" ;;
770 --zstd) compress_l
="zstd" ;;
771 --no-compress) _no_compress_l
="cat" ;;
772 --gzip) compress_l
="gzip" ;;
773 --list-modules) do_list
="yes" ;;
777 --keep) keep
="yes" ;;
778 --printsize) printsize
="yes" ;;
779 --regenerate-all) regenerate_all
="yes" ;;
780 --noimageifnotneeded) noimageifnotneeded
="yes" ;;
781 --reproducible) reproducible_l
="yes" ;;
782 --no-reproducible) reproducible_l
="no" ;;
783 --uefi) uefi_l
="yes" ;;
784 --no-uefi) uefi_l
="no" ;;
787 PARMS_TO_STORE
+=" '$2'"
791 uefi_splash_image_l
="$2"
792 PARMS_TO_STORE
+=" '$2'"
797 PARMS_TO_STORE
+=" '$2'"
812 *) # should not even reach this point
813 printf "\n!Unknown option: '%s'\n\n" "$1" >&2
821 # getopt cannot handle multiple arguments, so just handle "-I,--include"
822 # the old fashioned way
825 if [ "${1%%=*}" == "++include" ]; then
827 include_target
+=("$3")
828 PARMS_TO_STORE
+=" --include '$2' '$3'"
834 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
836 if [[ $regenerate_all == "yes" ]]; then
838 if [[ $kernel ]]; then
839 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
843 if [[ $outfile ]]; then
844 printf -- "--regenerate-all cannot be called with a image file\n" >&2
848 ((len
= ${#dracut_args[@]}))
849 for ((i
= 0; i
< len
; i
++)); do
850 [[ ${dracut_args[$i]} == "--regenerate-all" ]] \
851 && unset dracut_args
["$i"]
854 cd "$dracutsysrootdir"/lib
/modules ||
exit 1
856 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
857 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
863 if ! [[ $kernel ]]; then
871 unset LD_LIBRARY_PATH
875 export DRACUT_LOG_LEVEL
=warning
877 export DRACUT_LOG_LEVEL
=debug
878 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
883 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '
888 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
890 # if we were not passed a config file, try the default one
891 if [[ ! -f $conffile ]]; then
892 if [[ $allowlocal ]]; then
893 conffile
="$dracutbasedir/dracut.conf"
895 conffile
="$dracutsysrootdir/etc/dracut.conf"
899 if [[ ! -d $confdir ]]; then
900 if [[ $allowlocal ]]; then
901 confdir
="$dracutbasedir/dracut.conf.d"
903 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
907 # source our config file
908 if [[ -f $conffile ]]; then
909 check_conf_file
"$conffile"
910 # shellcheck disable=SC1090
914 # source our config dir
915 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
917 # shellcheck disable=SC1090
918 [[ -e $f ]] && .
"$f"
921 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
923 for i
in $DRACUT_PATH; do
925 if [ -L "$dracutsysrootdir$i" ]; then
926 rl
=$
(readlink
-f "$dracutsysrootdir$i")
928 rl
="${rl#$dracutsysrootdir}"
929 if [[ $NPATH != *:$rl* ]]; then
933 [[ -z $dracutsysrootdir ]] && export PATH
="${NPATH#:}"
936 export SYSTEMCTL
=${SYSTEMCTL:-systemctl}
938 # these options add to the stuff in the config file
939 ((${#add_dracutmodules_l[@]})) && add_dracutmodules
+=" ${add_dracutmodules_l[*]} "
940 ((${#omit_dracutmodules_l[@]})) && omit_dracutmodules
+=" ${omit_dracutmodules_l[*]} "
941 ((${#force_add_dracutmodules_l[@]})) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[*]} "
942 ((${#fscks_l[@]})) && fscks
+=" ${fscks_l[*]} "
943 ((${#add_fstab_l[@]})) && add_fstab
+=" ${add_fstab_l[*]} "
944 ((${#install_items_l[@]})) && install_items
+=" ${install_items_l[*]} "
945 ((${#install_optional_items_l[@]})) && install_optional_items
+=" ${install_optional_items_l[*]} "
946 ((${#hostonly_nics_l[@]})) && hostonly_nics
+=" ${hostonly_nics_l[*]} "
948 # these options override the stuff in the config file
949 ((${#dracutmodules_l[@]})) && dracutmodules
="${dracutmodules_l[*]}"
950 ((${#filesystems_l[@]})) && filesystems
="${filesystems_l[*]}"
951 ((${#fw_dir_l[@]})) && fw_dir
="${fw_dir_l[*]}"
952 ((${#libdirs_l[@]})) && libdirs
="${libdirs_l[*]}"
954 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
955 [[ ! $stdloglvl ]] && stdloglvl
=4
956 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
957 ((stdloglvl
> 6)) && stdloglvl
=6
958 ((stdloglvl
< 0)) && stdloglvl
=0
960 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
961 [[ $do_strip_l ]] && do_strip
=$do_strip_l
962 [[ $do_strip ]] || do_strip
=yes
963 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
964 [[ $do_hardlink ]] || do_hardlink
=yes
965 [[ $prefix_l ]] && prefix
=$prefix_l
966 [[ $prefix == "/" ]] && unset prefix
967 [[ $hostonly_l ]] && hostonly
=$hostonly_l
968 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
969 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
970 [[ $hostonly == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
971 # shellcheck disable=SC2034
972 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
973 # shellcheck disable=SC2034
974 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
975 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
976 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
977 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
978 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
979 [[ $fw_dir ]] || fw_dir
="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
980 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
981 [[ $tmpdir ]] || tmpdir
="$TMPDIR"
982 [[ $tmpdir ]] || tmpdir
="$dracutsysrootdir"/var
/tmp
983 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
984 [[ $compress_l ]] && compress=$compress_l
985 [[ $show_modules_l ]] && show_modules
=$show_modules_l
986 [[ $nofscks_l ]] && nofscks
="yes"
987 [[ $ro_mnt_l ]] && ro_mnt
="yes"
988 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
989 [[ $early_microcode ]] || early_microcode
=yes
990 [[ $early_microcode_image_dir ]] || early_microcode_image_dir
=('/boot')
991 [[ $early_microcode_image_name ]] \
992 || early_microcode_image_name
=('intel-uc.img' 'intel-ucode.img' 'amd-uc.img' 'amd-ucode.img' 'early_ucode.cpio' 'microcode.cpio')
993 [[ $logfile_l ]] && logfile
="$logfile_l"
994 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
995 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
996 [[ $uefi_l ]] && uefi
=$uefi_l
997 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
998 [[ $uefi_splash_image_l ]] && uefi_splash_image
="$uefi_splash_image_l"
999 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
1000 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
1002 if ! [[ $outfile ]]; then
1003 if [[ $machine_id != "no" ]]; then
1004 [[ -f "$dracutsysrootdir"/etc
/machine-id
]] && read -r MACHINE_ID
< "$dracutsysrootdir"/etc
/machine-id
1007 if [[ $uefi == "yes" ]]; then
1008 # shellcheck disable=SC2154
1009 if [[ -n $uefi_secureboot_key && -z $uefi_secureboot_cert ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
1010 dfatal
"Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set."
1014 if [[ -n $uefi_secureboot_key && -n $uefi_secureboot_cert ]] && ! command -v sbsign
&> /dev
/null
; then
1015 dfatal
"Need 'sbsign' to create a signed UEFI executable"
1019 BUILD_ID
=$
(cat "$dracutsysrootdir"/etc
/os-release
"$dracutsysrootdir"/usr
/lib
/os-release \
1020 |
while read -r line ||
[[ $line ]]; do
1021 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break
1023 if [[ -z $dracutsysrootdir ]]; then
1024 if [[ -d /efi
]] && mountpoint
-q /efi
; then
1028 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1029 efidir
=/boot
/efi
/EFI
1034 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1035 efidir
=/boot
/efi
/EFI
1038 mkdir
-p "$dracutsysrootdir$efidir/Linux"
1039 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
1041 if [[ -e $dracutsysrootdir/boot
/vmlinuz-
$kernel ]]; then
1042 outfile
="/boot/initramfs-$kernel.img"
1043 elif [[ $MACHINE_ID ]] && { [[ -d $dracutsysrootdir/boot
/${MACHINE_ID} ]] || [[ -L $dracutsysrootdir/boot/${MACHINE_ID} ]]; }; then
1044 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
1046 outfile
="$dracutsysrootdir/boot/initramfs-$kernel.img"
1051 # eliminate IFS hackery when messing with fw_dir
1052 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
1053 fw_dir
=${fw_dir//:/ }
1055 # check for logfile and try to create one if it doesn't exist
1056 if [[ -n $logfile ]]; then
1057 if [[ ! -f $logfile ]]; then
1058 if touch "$logfile"; then
1059 printf "%s\n" "dracut: touch $logfile failed." >&2
1064 # handle compression options.
1065 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
1066 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
1067 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
1068 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
1069 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
1070 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
1071 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
1072 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
1073 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
1074 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
1076 if [[ $_no_compress_l == "$DRACUT_COMPRESS_CAT" ]]; then
1077 compress="$DRACUT_COMPRESS_CAT"
1080 [[ $hostonly == yes ]] && hostonly
="-h"
1081 [[ $hostonly != "-h" ]] && unset hostonly
1083 case $hostonly_mode in
1085 [[ $hostonly ]] && hostonly_mode
="sloppy"
1088 if [[ ! $hostonly ]]; then
1093 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
1098 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
1100 case "${drivers_dir}" in
1101 '' |
*lib
/modules
/${kernel} |
*lib
/modules
/${kernel}/) ;;
1103 [[ "$DRACUT_KMODDIR_OVERRIDE" ]] ||
{
1104 printf "%s\n" 'dracut: -k/--kmoddir path must contain "lib/modules" as a parent of your kernel module directory,'
1105 printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
1106 printf "%s\n" "dracut: was given: ${drivers_dir}"
1107 printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
1108 printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
1109 printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
1115 # shellcheck disable=SC2155
1116 readonly TMPDIR
="$(realpath -e "$tmpdir")"
1117 [ -d "$TMPDIR" ] ||
{
1118 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
1122 if findmnt
--raw -n --target "$tmpdir" --output=options |
grep -q noexec
; then
1123 [[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
1127 # shellcheck disable=SC2155
1128 readonly DRACUT_TMPDIR
="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
1129 [ -d "$DRACUT_TMPDIR" ] ||
{
1130 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
1134 # Cache file used to optimize get_maj_min()
1135 declare -x -r get_maj_min_cache_file
="${DRACUT_TMPDIR}/majmin_cache"
1136 : > "$get_maj_min_cache_file"
1138 # clean up after ourselves no matter how we die.
1141 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
1142 if [[ ${FSFROZEN} ]]; then
1143 fsfreeze -u "${FSFROZEN}"
1148 # clean up after ourselves no matter how we die.
1149 trap 'exit 1;' SIGINT
1151 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
1154 # shellcheck disable=SC2154
1155 if [[ $early_microcode == yes ]] ||
{ [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; }; then
1156 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
1157 mkdir
"$early_cpio_dir"
1160 [[ "$dracutsysrootdir" ]] ||
[[ "$noexec" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
1162 if [[ $print_cmdline ]]; then
1169 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
1170 # shellcheck source=./dracut-version.sh
1171 .
"$dracutbasedir"/dracut-version.sh
1174 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
1175 # shellcheck source=./dracut-init.sh
1176 .
"$dracutbasedir"/dracut-init.sh
1178 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1179 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1180 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1184 # shellcheck disable=SC2154
1185 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1186 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
1187 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
1191 if ! [[ $print_cmdline ]]; then
1192 inst
"$DRACUT_TESTBIN"
1193 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &> /dev
/null
; then
1194 unset DRACUT_RESOLVE_LAZY
1195 export DRACUT_RESOLVE_DEPS
=1
1197 rm -fr -- "${initdir:?}"/*
1200 dracutfunctions
=$dracutbasedir/dracut-functions.sh
1201 export dracutfunctions
1203 ((${#drivers_l[@]})) && drivers
="${drivers_l[*]}"
1204 drivers
=${drivers/-/_}
1206 ((${#add_drivers_l[@]})) && add_drivers
+=" ${add_drivers_l[*]} "
1207 add_drivers
=${add_drivers/-/_}
1209 ((${#force_drivers_l[@]})) && force_drivers
+=" ${force_drivers_l[*]} "
1210 force_drivers
=${force_drivers/-/_}
1212 ((${#omit_drivers_l[@]})) && omit_drivers
+=" ${omit_drivers_l[*]} "
1213 omit_drivers
=${omit_drivers/-/_}
1215 ((${#kernel_cmdline_l[@]})) && kernel_cmdline
+=" ${kernel_cmdline_l[*]} "
1217 omit_drivers_corrected
=""
1218 for d
in $omit_drivers; do
1219 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
1220 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1221 omit_drivers_corrected
+="$d|"
1223 omit_drivers
="${omit_drivers_corrected%|}"
1224 unset omit_drivers_corrected
1226 # prepare args for logging
1227 for ((i
= 0; i
< ${#dracut_args[@]}; i
++)); do
1228 [[ ${dracut_args[$i]} == *\
* ]] \
1229 && dracut_args
[$i]="\"${dracut_args[$i]}\""
1233 dinfo
"Executing: $dracut_cmd ${dracut_args[*]}"
1235 [[ $do_list == yes ]] && {
1236 for mod
in "$dracutbasedir"/modules.d
/*; do
1237 [[ -d $mod ]] ||
continue
1238 [[ -e $mod/install ||
-e $mod/installkernel ||
-e \
1239 $mod/module-setup.sh
]] ||
continue
1240 printf "%s\n" "${mod##*/??}"
1245 # This is kinda legacy -- eventually it should go away.
1246 case $dracutmodules in
1247 "" | auto
) dracutmodules
="all" ;;
1250 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1252 [[ -d $dracutsysrootdir$systemdutildir ]] \
1253 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2> /dev
/null
)
1255 if ! [[ -d $dracutsysrootdir$systemdutildir ]]; then
1256 [[ -e $dracutsysrootdir/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1257 [[ -e $dracutsysrootdir/usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1260 [[ -d $dracutsysrootdir$systemdutilconfdir ]] \
1261 || systemdutilconfdir
=$
(pkg-config systemd
--variable=systemdutilconfdir
2> /dev
/null
)
1263 [[ -d $dracutsysrootdir$systemdutilconfdir ]] || systemdutilconfdir
=/etc
/systemd
1265 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1266 if ! [[ -f $srcmods/modules.dep
]]; then
1267 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1268 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1271 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1273 elif ! (command -v gzip &> /dev
/null
&& command -v xz
&> /dev
/null
); then
1274 read -r _mod
< "$srcmods"/modules.dep
1276 if [[ -f $srcmods/"$_mod" ]]; then
1277 # Check, if kernel modules are compressed, and if we can uncompress them
1279 *.ko.gz
) kcompress
=gzip ;;
1280 *.ko.xz
) kcompress
=xz
;;
1281 *.ko.zst
) kcompress
=zstd
;;
1283 if [[ $kcompress ]]; then
1284 if ! command -v "$kcompress" &> /dev
/null
; then
1285 dfatal
"Kernel modules are compressed with $kcompress, but $kcompress is not available."
1293 if [[ ! $print_cmdline ]]; then
1294 if [[ -f $outfile && ! $force ]]; then
1295 dfatal
"Will not override existing initramfs ($outfile) without --force"
1299 outdir
=${outfile%/*}
1300 [[ $outdir ]] || outdir
="/"
1302 if [[ ! -d $outdir ]]; then
1303 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1305 elif [[ ! -w $outdir ]]; then
1306 dfatal
"No permission to write to $outdir."
1308 elif [[ -f $outfile && ! -w $outfile ]]; then
1309 dfatal
"No permission to write $outfile."
1313 if [[ $loginstall ]]; then
1314 if ! mkdir
-p "$loginstall"; then
1315 dfatal
"Could not create directory to log installed files to '$loginstall'."
1318 loginstall
=$
(readlink
-f "$loginstall")
1321 if [[ $uefi == yes ]]; then
1322 if ! command -v objcopy
&> /dev
/null
; then
1323 dfatal
"Need 'objcopy' to create a UEFI executable"
1326 unset EFI_MACHINE_TYPE_NAME
1329 EFI_MACHINE_TYPE_NAME
=x64
1332 EFI_MACHINE_TYPE_NAME
=ia32
1335 dfatal
"Architecture '$(uname -m)' not supported to create a UEFI executable"
1340 if ! [[ -s $uefi_stub ]]; then
1342 "$dracutsysrootdir${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1343 "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1344 [[ -s $uefi_stub ]] ||
continue
1348 if ! [[ -s $uefi_stub ]]; then
1349 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1353 if ! [[ $kernel_image ]]; then
1354 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1355 [[ -s $kernel_image ]] ||
continue
1359 if ! [[ -s $kernel_image ]]; then
1360 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1366 if [[ $acpi_override == yes ]] && ! (check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1367 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1371 if [[ $early_microcode == yes ]]; then
1372 if [[ $hostonly ]]; then
1373 if [[ $
(get_cpu_vendor
) == "AMD" ]]; then
1374 check_kernel_config CONFIG_MICROCODE_AMD ||
unset early_microcode
1375 elif [[ $
(get_cpu_vendor
) == "Intel" ]]; then
1376 check_kernel_config CONFIG_MICROCODE_INTEL ||
unset early_microcode
1378 unset early_microcode
1381 ! check_kernel_config CONFIG_MICROCODE_AMD \
1382 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1383 && unset early_microcode
1385 # Do not complain on non-x86 architectures as it makes no sense
1388 [[ $early_microcode != yes ]] \
1389 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1395 # Need to be able to have non-root users read stuff (rpcbind etc)
1396 chmod 755 "$initdir"
1398 if [[ $hostonly ]]; then
1399 for i
in /sys
/proc
/run
/dev
; do
1400 if ! findmnt
--target "$i" &> /dev
/null
; then
1401 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1407 declare -A host_fs_types
1409 for line
in "${fstab_lines[@]}"; do
1410 # shellcheck disable=SC2086
1416 dev
=$
(blkid
-l -t "UUID=${dev#UUID=}" -o device
)
1419 dev
=$
(blkid
-l -t "LABEL=${dev#LABEL=}" -o device
)
1422 dev
=$
(blkid
-l -t "PARTUUID=${dev#PARTUUID=}" -o device
)
1425 dev
=$
(blkid
-l -t "PARTLABEL=${dev#PARTLABEL=}" -o device
)
1428 [ -z "$dev" ] && dwarn
"Bad fstab entry $*" && continue
1429 if [[ $3 == btrfs
]]; then
1430 for mp
in $
(findmnt
--source "$1" -o TARGET
-n); do
1431 for i
in $
(btrfs_devs
"$mp"); do
1436 push_host_devs
"$dev"
1437 host_fs_types
["$dev"]="$3"
1440 for f
in $add_fstab; do
1441 [[ -e $f ]] ||
continue
1442 while read -r dev rest ||
[ -n "$dev" ]; do
1443 push_host_devs
"$dev"
1447 for dev
in $add_device; do
1448 push_host_devs
"$dev"
1451 if ((${#add_device_l[@]})); then
1452 add_device
+=" ${add_device_l[*]} "
1453 push_host_devs
"${add_device_l[@]}"
1456 if [[ $hostonly ]] && [[ $hostonly_default_device != "no" ]]; then
1457 # in hostonly mode, determine all devices, which have to be accessed
1458 # and examine them for filesystem types
1475 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1476 mountpoint
"$mp" > /dev
/null
2>&1 ||
continue
1477 _dev
=$
(find_block_device
"$mp")
1478 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1479 [[ -b $_bdev ]] && _dev
=$_bdev
1480 [[ $mp == "/" ]] && root_devs
+=("$_dev")
1481 push_host_devs
"$_dev"
1482 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1483 for i
in $
(btrfs_devs
"$mp"); do
1484 [[ $mp == "/" ]] && root_devs
+=("$i")
1490 # TODO - with sysroot, /proc/swaps is not relevant
1491 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1492 while read -r dev
type rest ||
[ -n "$dev" ]; do
1493 [[ -b $dev ]] ||
continue
1494 [[ $type == "partition" ]] ||
continue
1496 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1497 [[ $_d == \
#* ]] && continue
1498 [[ $_d ]] ||
continue
1499 [[ $_t != "swap" ]] && continue
1500 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1501 [[ $_o == *noauto
* ]] && continue
1502 _d
=$
(expand_persistent_dev
"$_d")
1503 [[ $_d -ef $dev ]] ||
continue
1505 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1506 while read -r _mapper _ _p _o ||
[ -n "$_mapper" ]; do
1507 [[ $_mapper == \
#* ]] && continue
1508 [[ $_d -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1509 [[ "$_o" ]] || _o
="$_p"
1510 # skip entries with password files
1511 [[ $_p == /* ]] && [[ -f $_p ]] && continue 2
1513 [[ $_o == *swap
* ]] && continue 2
1514 done < "$dracutsysrootdir"/etc
/crypttab
1517 _dev
="$(readlink -f "$dev")"
1518 push_host_devs
"$_dev"
1519 swap_devs
+=("$_dev")
1521 done < "$dracutsysrootdir"/etc
/fstab
1525 # collect all "x-initrd.mount" entries from /etc/fstab
1526 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1527 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1528 [[ $_d == \
#* ]] && continue
1529 [[ $_d ]] ||
continue
1530 [[ $_o != *x-initrd.mount
* ]] && continue
1531 _dev
=$
(expand_persistent_dev
"$_d")
1532 _dev
="$(readlink -f "$_dev")"
1533 [[ -b $_dev ]] ||
continue
1535 push_host_devs
"$_dev"
1536 if [[ $_t == btrfs
]]; then
1537 for i
in $
(btrfs_devs
"$_m"); do
1541 done < "$dracutsysrootdir"/etc
/fstab
1550 if [[ -b /dev
/block
/$1 ]]; then
1551 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1554 if [[ -b $1 ]]; then
1555 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1558 if fstype
=$
(find_dev_fstype
"$1"); then
1559 host_fs_types
["$1"]="$fstype"
1565 for dev
in "${host_devs[@]}"; do
1567 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1570 for dev
in "${!host_fs_types[@]}"; do
1571 [[ ${host_fs_types[$dev]} == "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} == "xfs" ]] ||
continue
1572 rootopts
=$
(find_dev_fsopts
"$dev")
1573 if [[ ${host_fs_types[$dev]} == "reiserfs" ]]; then
1574 journaldev
=$
(fs_get_option
"$rootopts" "jdev")
1575 elif [[ ${host_fs_types[$dev]} == "xfs" ]]; then
1576 journaldev
=$
(fs_get_option
"$rootopts" "logdev")
1578 if [[ $journaldev ]]; then
1579 dev
="$(readlink -f "$dev")"
1580 push_host_devs
"$dev"
1582 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1586 [[ -d $dracutsysrootdir$dbus ]] \
1587 || dbus
=$
(pkg-config dbus
--variable=dbus
2> /dev
/null
)
1589 [[ -d $dracutsysrootdir$dbus ]] || dbus
=/usr
/share
/dbus-1
1591 [[ -d $dracutsysrootdir$dbusconfdir ]] \
1592 || dbusconfdir
=$
(pkg-config dbus
--variable=dbusconfdir
2> /dev
/null
)
1594 [[ -d $dracutsysrootdir$dbusconfdir ]] || dbusconfdir
=/etc
/dbus-1
1596 [[ -d $dracutsysrootdir$dbusinterfaces ]] \
1597 || dbusinterfaces
=$
(pkg-config dbus
--variable=dbusinterfaces
2> /dev
/null
)
1599 [[ -d $dracutsysrootdir$dbusinterfaces ]] || dbusinterfaces
=${dbus}/interfaces
1601 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] \
1602 || dbusinterfacesconfdir
=$
(pkg-config dbus
--variable=dbusinterfacesconfdir
2> /dev
/null
)
1604 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] || dbusinterfacesconfdir
=${dbusconfdir}/interfaces
1606 [[ -d $dracutsysrootdir$dbusservices ]] \
1607 || dbusservices
=$
(pkg-config dbus
--variable=dbusservices
2> /dev
/null
)
1609 [[ -d $dracutsysrootdir$dbusservices ]] || dbusservices
=${dbus}/services
1611 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] \
1612 || dbusservicesconfdir
=$
(pkg-config dbus
--variable=dbusservicesconfdir
2> /dev
/null
)
1614 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] || dbusservicesconfdir
=${dbusconfdir}/services
1616 [[ -d $dracutsysrootdir$dbussession ]] \
1617 || dbussession
=$
(pkg-config dbus
--variable=dbussession
2> /dev
/null
)
1619 [[ -d $dracutsysrootdir$dbussession ]] || dbussession
=${dbus}/session.d
1621 [[ -d $dracutsysrootdir$dbussessionconfdir ]] \
1622 || dbussessionconfdir
=$
(pkg-config dbus
--variable=dbussessionconfdir
2> /dev
/null
)
1624 [[ -d $dracutsysrootdir$dbussessionconfdir ]] || dbussessionconfdir
=${dbusconfdir}/session.d
1626 [[ -d $dracutsysrootdir$dbussystem ]] \
1627 || dbussystem
=$
(pkg-config dbus
--variable=dbussystem
2> /dev
/null
)
1629 [[ -d $dracutsysrootdir$dbussystem ]] || dbussystem
=${dbus}/system.d
1631 [[ -d $dracutsysrootdir$dbussystemconfdir ]] \
1632 || dbussystemconfdir
=$
(pkg-config dbus
--variable=dbussystemconfdir
2> /dev
/null
)
1634 [[ -d $dracutsysrootdir$dbussystemconfdir ]] || dbussystemconfdir
=${dbusconfdir}/system.d
1636 [[ -d $dracutsysrootdir$dbussystemservices ]] \
1637 || dbussystemservices
=$
(pkg-config dbus
--variable=dbussystemservices
2> /dev
/null
)
1639 [[ -d $dracutsysrootdir$dbussystemservices ]] || dbussystemservices
=${dbus}/system-services
1641 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] \
1642 || dbussystemservicesconfdir
=$
(pkg-config dbus
--variable=dbussystemservicesconfdir
2> /dev
/null
)
1644 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] || dbussystemservicesconfdir
=${dbusconfdir}/system-services
1646 [[ -d $dracutsysrootdir$udevdir ]] \
1647 || udevdir
="$(pkg-config udev --variable=udevdir 2> /dev/null)"
1648 if ! [[ -d $dracutsysrootdir$udevdir ]]; then
1649 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1650 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1653 [[ -d $dracutsysrootdir$udevconfdir ]] \
1654 || udevconfdir
=$
(pkg-config udev
--variable=udevconfdir
2> /dev
/null
)
1656 [[ -d $dracutsysrootdir$udevconfdir ]] || udevconfdir
=/etc
/udev
1658 [[ -d $dracutsysrootdir$udevrulesdir ]] \
1659 || udevrulesdir
=$
(pkg-config udev
--variable=udevrulesdir
2> /dev
/null
)
1661 [[ -d $dracutsysrootdir$udevrulesdir ]] || udevrulesdir
=${udevdir}/rules.d
1663 [[ -d $dracutsysrootdir$udevrulesconfdir ]] \
1664 || udevrulesconfdir
=$
(pkg-config udev
--variable=udevrulesconfdir
2> /dev
/null
)
1666 [[ -d $dracutsysrootdir$udevrulesconfdir ]] || udevrulesconfdir
=${udevconfdir}/rules.d
1668 [[ -d $dracutsysrootdir$sysctld ]] \
1669 || sysctld
=$
(pkg-config systemd
--variable=sysctld
2> /dev
/null
)
1671 [[ -d $dracutsysrootdir$sysctld ]] || sysctld
=/usr
/lib
/sysctl.d
1673 [[ -d $dracutsysrootdir$sysctlconfdir ]] \
1674 || sysctlconfdir
=$
(pkg-config systemd
--variable=sysctlconfdir
2> /dev
/null
)
1676 [[ -d $dracutsysrootdir$sysctlconfdir ]] || sysctlconfdir
=/etc
/sysctl.d
1678 [[ -d $dracutsysrootdir$environment ]] \
1679 || environment
=$
(pkg-config systemd
--variable=environment
2> /dev
/null
)
1681 [[ -d $dracutsysrootdir$environment ]] || environment
=/usr
/lib
/environment.d
1683 [[ -d $dracutsysrootdir$environmentconfdir ]] \
1684 || environmentconfdir
=$
(pkg-config systemd
--variable=environmentconfdir
2> /dev
/null
)
1686 [[ -d $dracutsysrootdir$environmentconfdir ]] || environmentconfdir
=/etc
/environment.d
1688 [[ -d $dracutsysrootdir$systemdcatalog ]] \
1689 || systemdcatalog
=$
(pkg-config systemd
--variable=systemdcatalog
2> /dev
/null
)
1691 [[ -d $dracutsysrootdir$systemdcatalog ]] || systemdcatalog
=${systemdutildir}/catalog
1693 [[ -d $dracutsysrootdir$modulesload ]] \
1694 || modulesload
=$
(pkg-config systemd
--variable=modulesload
2> /dev
/null
)
1696 [[ -d $dracutsysrootdir$modulesload ]] || modulesload
=/usr
/lib
/modules-load.d
1698 [[ -d $dracutsysrootdir$modulesloadconfdir ]] \
1699 || modulesloadconfdir
=$
(pkg-config systemd
--variable=modulesloadconfdir
2> /dev
/null
)
1701 [[ -d $dracutsysrootdir$modulesloadconfdir ]] || modulesloadconfdir
=/etc
/modules-load.d
1703 [[ -d $dracutsysrootdir$systemdnetwork ]] \
1704 || systemdnetwork
=$
(pkg-config systemd
--variable=systemdnetwork
2> /dev
/null
)
1706 [[ -d $dracutsysrootdir$systemdnetwork ]] || systemdnetwork
=${systemdutildir}/network
1708 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] \
1709 || systemdnetworkconfdir
=$
(pkg-config systemd
--variable=systemdnetworkconfdir
2> /dev
/null
)
1711 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] || systemdnetworkconfdir
=${systemdsystemconfdir}/network
1713 [[ -d $dracutsysrootdir$systemdntpunits ]] \
1714 || systemdntpunits
=$
(pkg-config systemd
--variable=systemdntpunits
2> /dev
/null
)
1716 [[ -d $dracutsysrootdir$systemdntpunits ]] || systemdntpunits
=${systemdutildir}/ntp-units.d
1718 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] \
1719 || systemdntpunitsconfdir
=$
(pkg-config systemd
--variable=systemdntpunitsconfdir
2> /dev
/null
)
1721 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] || systemdntpunitsconfdir
=${systemdsystemconfdir}/ntp-units.d
1723 [[ -d $dracutsysrootdir$systemdportable ]] \
1724 || systemdportable
=$
(pkg-config systemd
--variable=systemdportable
2> /dev
/null
)
1726 [[ -d $dracutsysrootdir$systemdportable ]] || systemdportable
=${systemdutildir}/portable
1728 [[ -d $dracutsysrootdir$systemdportableconfdir ]] \
1729 || systemdportableconfdir
=$
(pkg-config systemd
--variable=systemdportableconfdir
2> /dev
/null
)
1731 [[ -d "$dracutsysrootdir$systemdportableconfdir" ]] || systemdportableconfdir
=${systemdsystemconfdir}/portable
1733 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1734 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2> /dev
/null
)
1736 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1738 [[ -d $dracutsysrootdir$systemduser ]] \
1739 || systemduser
=$
(pkg-config systemd
--variable=systemduser
2> /dev
/null
)
1741 [[ -d $dracutsysrootdir$systemduser ]] || systemduser
=${systemdutildir}/user
1743 [[ -d $dracutsysrootdir$systemduserconfdir ]] \
1744 || systemduserconfdir
=$
(pkg-config systemd
--variable=systemduserconfdir
2> /dev
/null
)
1746 [[ -d $dracutsysrootdir$systemduserconfdir ]] || systemduserconfdir
=${systemdsystemconfdir}/user
1748 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1749 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2> /dev
/null
)
1751 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] || systemdsystemconfdir
=/etc
/systemd
/system
1753 [[ -d $dracutsysrootdir$sysusers ]] \
1754 || sysusers
=$
(pkg-config systemd
--variable=sysusers
2> /dev
/null
)
1756 [[ -d $dracutsysrootdir$sysusers ]] || sysusers
=/usr
/lib
/sysusers.d
1758 [[ -d $dracutsysrootdir$sysusersconfdir ]] \
1759 || sysusersconfdir
=$
(pkg-config systemd
--variable=sysusersconfdir
2> /dev
/null
)
1761 [[ -d $dracutsysrootdir$sysusersconfdir ]] || sysusersconfdir
=/etc
/sysusers.d
1763 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1764 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2> /dev
/null
)
1766 if ! [[ -d $dracutsysrootdir$tmpfilesdir ]]; then
1767 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1768 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1771 [[ -d $dracutsysrootdir$tmpfilesconfdir ]] \
1772 || tmpfilesconfdir
=$
(pkg-config systemd
--variable=tmpfilesconfdir
2> /dev
/null
)
1774 [[ -d $dracutsysrootdir$tmpfilesconfdir ]] || tmpfilesconfdir
=/etc
/tmpfiles.d
1776 [[ -d $dracutsysrootdir$depmodd ]] \
1777 || sysctld
=$
(pkg-config libkmod
--variable=depmodd
2> /dev
/null
)
1779 [[ -d $dracutsysrootdir$depmodd ]] || depmodd
=/usr
/lib
/depmod.d
1781 [[ -d $dracutsysrootdir$depmodconfdir ]] \
1782 || sysctlconfdir
=$
(pkg-config libkmod
--variable=depmodconfdir
2> /dev
/null
)
1784 [[ -d $dracutsysrootdir$depmodconfdir ]] || depmodconfdir
=/etc
/depmod.d
1786 export initdir dracutbasedir \
1787 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1789 fw_dir drivers_dir debug no_kernel kernel_only \
1790 omit_drivers mdadmconf lvmconf root_devs \
1791 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1792 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1793 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1794 DRACUT_VERSION udevdir udevconfdir udevrulesdir udevrulesconfdir \
1795 prefix filesystems drivers dbus dbusconfdir dbusinterfaces \
1796 dbusinterfacesconfdir dbusservices dbusservicesconfdir dbussession \
1797 dbussessionconfdir dbussystem dbussystemconfdir dbussystemservices \
1798 dbussystemservicesconfdir environment environmentconfdir modulesload \
1799 modulesloadconfdir sysctl sysctlconfdir sysusers sysusersconfdir \
1800 systemdutildir systemdutilconfdir systemdcatalog systemdntpunits \
1801 systemdntpunitsconfdir systemdsystemunitdir systemdsystemconfdir \
1802 hostonly_cmdline loginstall tmpfilesdir tmpfilesconfdir depmodd \
1806 # check all our modules to see if they should be sourced.
1807 # This builds a list of modules that we will install next.
1808 for_each_module_dir check_module
1809 for_each_module_dir check_mount
1811 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1813 do_print_cmdline
() {
1814 local -A _mods_to_print
1815 for i
in $modules_loaded $mods_to_load; do
1816 _mods_to_print
[$i]=1
1819 # source our modules.
1820 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1821 _d_mod
=${moddir##*/}
1822 _d_mod
=${_d_mod#[0-9][0-9]}
1823 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1824 module_cmdline
"$_d_mod" "$moddir"
1829 if [[ $print_cmdline ]]; then
1835 # Create some directory structure first
1836 # shellcheck disable=SC2174
1837 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1839 # shellcheck disable=SC2174
1840 [[ -L $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1841 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1843 if [[ $prefix ]]; then
1844 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1845 [[ $d == */* ]] && continue
1846 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1850 if [[ $kernel_only != yes ]]; then
1851 for d
in usr usr
/bin usr
/sbin bin etc lib sbin tmp var var
/tmp
$libdirs; do
1852 [[ -e "${initdir}${prefix}/$d" ]] && continue
1853 if [ -L "/$d" ]; then
1854 inst_symlink
"/$d" "${prefix}/$d"
1856 # shellcheck disable=SC2174
1857 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1861 for d
in dev proc sys sysroot root run
; do
1862 if [ -L "/$d" ]; then
1865 # shellcheck disable=SC2174
1866 mkdir
-m 0755 -p "$initdir/$d"
1870 ln -sfn ..
/run
"$initdir/var/run"
1871 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1873 for d
in lib
"$libdirs"; do
1874 [[ -e "${initdir}${prefix}/$d" ]] && continue
1875 if [ -h "/$d" ]; then
1876 inst
"/$d" "${prefix}/$d"
1878 # shellcheck disable=SC2174
1879 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1884 if [[ $kernel_only != yes ]]; then
1885 mkdir
-p "${initdir}/etc/cmdline.d"
1886 # shellcheck disable=SC2174
1887 mkdir
-m 0755 -p "${initdir}"/lib "${initdir}"/lib/dracut "${initdir}"/lib
/dracut
/hooks
1888 # shellcheck disable=SC2154
1889 for _d
in $hookdirs; do
1890 # shellcheck disable=SC2174
1891 mkdir
-m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
1893 if [[ $EUID == "0" ]]; then
1894 [[ -c ${initdir}/dev
/null
]] || mknod
"${initdir}"/dev
/null c
1 3
1895 [[ -c ${initdir}/dev
/kmsg
]] || mknod
"${initdir}"/dev
/kmsg c
1 11
1896 [[ -c ${initdir}/dev
/console
]] || mknod
"${initdir}"/dev
/console c
5 1
1897 [[ -c ${initdir}/dev
/random
]] || mknod
"${initdir}"/dev
/random c
1 8
1898 [[ -c ${initdir}/dev
/urandom
]] || mknod
"${initdir}"/dev
/urandom c
1 9
1902 _isize
=0 #initramfs size
1904 # source our modules.
1905 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1906 _d_mod
=${moddir##*/}
1907 _d_mod
=${_d_mod#[0-9][0-9]}
1908 [[ $mods_to_load == *\
$_d_mod\
* ]] ||
continue
1909 if [[ $show_modules == yes ]]; then
1910 printf "%s\n" "$_d_mod"
1912 dinfo
"*** Including module: $_d_mod ***"
1914 if [[ $kernel_only == yes ]]; then
1915 module_installkernel
"$_d_mod" "$moddir" ||
{
1916 dfatal
"installkernel failed in module $_d_mod"
1920 module_install
"$_d_mod" "$moddir"
1921 if [[ $no_kernel != yes ]]; then
1922 module_installkernel
"$_d_mod" "$moddir" ||
{
1923 dfatal
"installkernel failed in module $_d_mod"
1928 mods_to_load
=${mods_to_load// $_d_mod /}
1929 modules_loaded
+="$_d_mod "
1931 #print the module install size
1932 if [ -n "$printsize" ]; then
1933 _isize_new
=$
(du
-sk "${initdir}" |
{
1937 _isize_delta
=$
((_isize_new
- _isize
))
1938 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1944 for i
in $modules_loaded; do
1945 mkdir
-p "$initdir"/lib
/dracut
1946 printf "%s\n" "$i" >> "$initdir"/lib
/dracut
/modules.txt
1949 dinfo
"*** Including modules done ***"
1951 ## final stuff that has to happen
1952 if [[ $no_kernel != yes ]]; then
1953 if [[ $hostonly_mode == "strict" ]]; then
1954 cp "$DRACUT_KERNEL_MODALIASES" "$initdir"/lib
/dracut
/hostonly-kernel-modules.txt
1957 if [[ $drivers ]]; then
1958 # shellcheck disable=SC2086
1959 hostonly
='' instmods
$drivers
1962 if [[ -n ${add_drivers// /} ]]; then
1963 # shellcheck disable=SC2086
1964 hostonly
='' instmods
-c $add_drivers
1966 if [[ $force_drivers ]]; then
1967 # shellcheck disable=SC2086
1968 hostonly
='' instmods
-c $force_drivers
1969 rm -f "$initdir"/etc
/cmdline.d
/20-force_driver.conf
1970 for mod
in $force_drivers; do
1971 echo "rd.driver.pre=$mod" >> "$initdir"/etc
/cmdline.d
/20-force_drivers.conf
1974 if [[ $filesystems ]]; then
1975 # shellcheck disable=SC2086
1976 hostonly
='' instmods
-c $filesystems
1979 dinfo
"*** Installing kernel module dependencies ***"
1981 dinfo
"*** Installing kernel module dependencies done ***"
1983 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1984 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] \
1985 && [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1986 for i
in "${initdir}"/etc
/cmdline.d
/*.conf
; do
1987 # We need no initramfs image and do not generate one.
1988 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1994 if [[ $kernel_only != yes ]]; then
1995 # FIXME: handle legacy item split
1996 # shellcheck disable=SC2068
1997 ((${#install_items[@]} > 0)) && inst_multiple
${install_items[@]}
1998 # shellcheck disable=SC2068
1999 ((${#install_optional_items[@]} > 0)) && inst_multiple
-o ${install_optional_items[@]}
2001 if [[ $kernel_cmdline ]] && [[ $uefi != yes ]]; then
2002 printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
2005 for line
in "${fstab_lines[@]}"; do
2006 read -r -a fstab_field
<<< "$line"
2007 if [ -z "${fstab_field[1]}" ]; then
2008 # Determine device and mount options from current system
2009 mountpoint
-q "${fstab_field[0]}" || derror
"${fstab_field[0]} is not a mount point!"
2010 read -r -a fstab_field
< <(findmnt
--raw -n --target "${fstab_field[0]}" --output=source,target
,fstype
,options
)
2011 dinfo
"Line for ${fstab_field[1]}: ${fstab_field[*]}"
2013 # Use default options
2014 [ -z "${fstab_field[3]}" ] && fstab_field
[3]="defaults"
2017 # Default options for freq and passno
2018 [ -z "${fstab_field[4]}" ] && fstab_field
[4]="0"
2019 [ -z "${fstab_field[5]}" ] && fstab_field
[5]="2"
2021 strstr
"${fstab_field[2]}" "nfs" && fstab_field
[5]="0"
2022 echo "${fstab_field[@]}" >> "${initdir}/etc/fstab"
2025 for f
in $add_fstab; do
2026 cat "$f" >> "${initdir}/etc/fstab"
2029 if [[ $dracutsysrootdir$systemdutildir ]]; then
2030 if [[ -d ${initdir}/$systemdutildir ]]; then
2031 mkdir
-p "${initdir}"/etc
/conf.d
2033 printf "%s\n" "systemdutildir=\"$systemdutildir\""
2034 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
2035 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
2036 } > "${initdir}"/etc
/conf.d
/systemd.conf
2040 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
2041 dinfo
"*** Resolving executable dependencies ***"
2042 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
2043 |
xargs -r -0 "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
2044 dinfo
"*** Resolving executable dependencies done ***"
2047 # Now we are done with lazy resolving, always install dependencies
2048 unset DRACUT_RESOLVE_LAZY
2049 export DRACUT_RESOLVE_DEPS
=1
2052 for ((i
= 0; i
< ${#include_src[@]}; i
++)); do
2053 src
="${include_src[$i]}"
2054 target
="${include_target[$i]}"
2055 if [[ $src && $target ]]; then
2056 if [[ -f $src ]]; then
2057 inst
"$src" "$target"
2058 elif [[ -d $src ]]; then
2059 ddebug
"Including directory: $src"
2060 destdir
="${initdir}/${target}"
2062 # check for preexisting symlinks, so we can cope with the
2063 # symlinks to $prefix
2064 # Objectname is a file or a directory
2065 for objectname
in "$src"/*; do
2066 [[ -e $objectname ||
-L $objectname ]] ||
continue
2067 if [[ -d $objectname ]]; then
2068 # objectname is a directory, let's compute the final directory name
2069 object_destdir
=${destdir}/${objectname#$src/}
2070 if ! [[ -e $object_destdir ]]; then
2071 # shellcheck disable=SC2174
2072 mkdir
-m 0755 -p "$object_destdir"
2073 chmod --reference="$objectname" "$object_destdir"
2075 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
2077 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
2080 elif [[ -e $src ]]; then
2081 derror
"$src is neither a directory nor a regular file"
2083 derror
"$src doesn't exist"
2088 if [[ $do_hardlink == yes ]] && command -v hardlink
> /dev
/null
; then
2089 dinfo
"*** Hardlinking files ***"
2090 hardlink
"$initdir" 2>&1
2091 dinfo
"*** Hardlinking files done ***"
2095 if [[ $do_strip == yes ]]; then
2096 # Prefer strip from elfutils for package size
2098 strip_cmd
=$
(command -v eu-strip
)
2099 [ -z "$strip_cmd" ] && strip_cmd
="strip"
2101 for p
in $strip_cmd xargs find; do
2102 if ! type -P $p > /dev
/null
; then
2103 dinfo
"Could not find '$p'. Not stripping the initramfs."
2109 # cleanup empty ldconfig_paths directories
2110 for d
in $
(ldconfig_paths
); do
2111 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" > /dev
/null
2>&1
2114 if [[ $early_microcode == yes ]]; then
2115 dinfo
"*** Generating early-microcode cpio image ***"
2116 ucode_dir
=(amd-ucode intel-ucode
)
2117 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
2118 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
2120 mkdir
-p "$_dest_dir"
2121 if [[ $hostonly ]]; then
2122 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
2123 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
2125 for idx
in $_dest_idx; do
2126 _fw
=${ucode_dir[$idx]}
2127 for _fwdir
in $fw_dir; do
2128 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
2130 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
2131 if [[ $hostonly ]]; then
2132 _src
=$
(get_ucode_file
)
2133 [[ $_src ]] ||
break
2134 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
2135 [[ -r $_fwdir/$_fw/$_src ]] ||
break
2138 for i
in $_fwdir/$_fw/$_src; do
2139 [ -e "$i" ] && break
2142 for i
in $_fwdir/$_fw/$_src; do
2143 [[ -e $i ]] ||
continue
2145 str_ends
"$i" ".asc" && continue
2146 cat "$i" >> "$_dest_dir/${ucode_dest[$idx]}"
2148 create_early_cpio
="yes"
2151 if [[ ! -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2152 if cd "$early_cpio_dir/d"; then
2153 for _ucodedir
in "${early_microcode_image_dir[@]}"; do
2154 for _ucodename
in "${early_microcode_image_name[@]}"; do
2155 [[ -e "$_ucodedir/$_ucodename" ]] \
2156 && cpio --extract --file "$_ucodedir/$_ucodename" --quiet \
2157 "kernel/x86/microcode/${ucode_dest[$idx]}"
2158 if [[ -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2159 dinfo
"*** Using microcode found in '$_ucodedir/$_ucodename' ***"
2160 create_early_cpio
="yes"
2170 if [[ $acpi_override == yes ]] && [[ -d $acpi_table_dir ]]; then
2171 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
2172 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
2173 mkdir
-p "$_dest_dir"
2174 for table
in "$acpi_table_dir"/*.aml
; do
2175 dinfo
" Adding ACPI table: $table"
2176 $DRACUT_CP "$table" "$_dest_dir"
2177 create_early_cpio
="yes"
2181 dinfo
"*** Store current command line parameters ***"
2182 if ! (echo "$PARMS_TO_STORE" > "$initdir"/lib
/dracut
/build-parameter.txt
); then
2183 dfatal
"Could not store the current command line parameters"
2187 if [[ $hostonly_cmdline == "yes" ]]; then
2188 unset _stored_cmdline
2189 if [[ -d $initdir/etc
/cmdline.d
]]; then
2190 dinfo
"Stored kernel commandline:"
2191 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2192 [ -e "$conf" ] ||
continue
2193 dinfo
"$(< "$conf")"
2197 if ! [[ $_stored_cmdline ]]; then
2198 dinfo
"No dracut internal kernel commandline stored in the initramfs"
2202 if [[ $kernel_only != yes ]]; then
2203 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
2204 for _dir
in $libdirs; do
2205 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
2206 [[ -e $_f ]] ||
continue
2207 inst_libdir_file
"libgcc_s.so*"
2212 # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
2213 if [[ $DRACUT_FIPS_MODE ]]; then
2214 for _dir
in $libdirs; do
2215 for _f
in "$dracutsysrootdir$_dir/libcrypto.so"*; do
2216 [[ -e $_f ]] ||
continue
2217 inst_libdir_file
-o "libssl.so*"
2224 if [[ $kernel_only != yes ]]; then
2225 # make sure that library links are correct and up to date
2226 for f
in "$dracutsysrootdir"/etc
/ld.so.conf
"$dracutsysrootdir"/etc
/ld.so.conf.d
/*; do
2227 [[ -f $f ]] && inst_simple
"${f#$dracutsysrootdir}"
2229 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc
/ld.so.conf
; then
2230 if [[ $EUID == 0 ]]; then
2231 derror
"ldconfig exited ungracefully"
2233 derror
"ldconfig might need uid=0 (root) for chroot()"
2238 if dracut_module_included
"squash"; then
2239 readonly squash_dir
="$initdir/squash/root"
2240 readonly squash_img
="$initdir/squash-root.img"
2241 mkdir
-p "$squash_dir"
2242 dinfo
"*** Install squash loader ***"
2243 DRACUT_SQUASH_POST_INST
=1 module_install
"squash"
2246 if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2247 dinfo
"*** Stripping files ***"
2248 find "$initdir" -type f \
2249 -executable -not -path '*/lib/modules/*.ko' -print0 \
2250 |
xargs -r -0 $strip_cmd -g -p 2> /dev
/null
2252 # strip kernel modules, but do not touch signed modules
2253 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
2254 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
2255 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
2256 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
2257 done |
xargs -r -0 $strip_cmd -g -p
2258 dinfo
"*** Stripping files done ***"
2261 if dracut_module_included
"squash"; then
2262 dinfo
"*** Squashing the files inside the initramfs ***"
2263 declare squash_compress_arg
2264 # shellcheck disable=SC2086
2265 if [[ $compress ]]; then
2266 if ! mksquashfs
/dev
/null
"$DRACUT_TMPDIR"/.squash-test.img
-no-progress -comp $compress &> /dev
/null
; then
2267 dwarn
"mksquashfs doesn't support compressor '$compress', failing back to default compressor."
2269 squash_compress_arg
="$compress"
2273 # shellcheck disable=SC2086
2274 if ! mksquashfs
"$squash_dir" "$squash_img" \
2275 -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
2276 -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev
/null
; then
2277 dfatal
"dracut: Failed making squash image"
2281 rm -rf "$squash_dir"
2282 dinfo
"*** Squashing the files inside the initramfs done ***"
2284 # Skip initramfs compress
2288 dinfo
"*** Creating image file '$outfile' ***"
2290 if [[ $uefi == yes ]]; then
2291 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
2292 mkdir
-p "$uefi_outdir"
2295 if [[ $DRACUT_REPRODUCIBLE ]]; then
2296 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2297 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2299 if [[ "$(cpio --help)" == *--reproducible* ]]; then
2302 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
2306 [[ $EUID != 0 ]] && cpio_owner
="0:0"
2308 if [[ $create_early_cpio == yes ]]; then
2309 echo 1 > "$early_cpio_dir/d/early_cpio"
2311 if [[ $DRACUT_REPRODUCIBLE ]]; then
2312 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2313 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2316 # The microcode blob is _before_ the initramfs blob, not after
2319 cd "$early_cpio_dir/d"
2320 find .
-print0 |
sort -z \
2321 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
2322 ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
2324 dfatal
"dracut: creation of $outfile failed"
2329 if ! [[ $compress ]]; then
2330 # check all known compressors, if none specified
2331 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
2332 command -v "$i" &> /dev
/null ||
continue
2336 if [[ $compress == cat ]]; then
2337 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
2341 # choose the right arguments for the compressor
2344 if [[ $compress == lbzip2
]] ||
command -v "$DRACUT_COMPRESS_LBZIP2" &> /dev
/null
; then
2345 compress="$DRACUT_COMPRESS_LBZIP2 -9"
2347 compress="$DRACUT_COMPRESS_BZIP2 -9"
2351 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
2354 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
2357 if [[ $compress == pigz
]] ||
command -v "$DRACUT_COMPRESS_PIGZ" &> /dev
/null
; then
2358 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
2359 elif command -v gzip &> /dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
2360 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
2362 compress="$DRACUT_COMPRESS_GZIP -n -9"
2366 compress="$DRACUT_COMPRESS_LZOP -9"
2369 compress="$DRACUT_COMPRESS_LZ4 -l -9"
2372 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
2379 find .
-print0 |
sort -z \
2380 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet \
2381 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
2383 dfatal
"dracut: creation of $outfile failed"
2387 # shellcheck disable=SC2154
2388 if ((maxloglvl
>= 5)) && ((verbosity_mod_l
>= 0)); then
2389 if [[ $allowlocal ]]; then
2390 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
2392 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img" | ddebug
2398 if [[ $uefi == yes ]]; then
2399 if [[ $kernel_cmdline ]]; then
2400 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
2401 elif [[ $hostonly_cmdline == yes ]] && [ -d "$initdir/etc/cmdline.d" ]; then
2402 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2403 [ -e "$conf" ] ||
continue
2404 printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
2408 if [[ $kernel_cmdline ]] ||
[[ $hostonly_cmdline == yes && -d "$initdir/etc/cmdline.d" ]]; then
2409 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
2410 dinfo
"Using UEFI kernel cmdline:"
2411 dinfo
"$(tr -d '\000' < "$uefi_outdir/cmdline.txt
")"
2412 uefi_cmdline
="${uefi_outdir}/cmdline.txt"
2417 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
2418 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
2419 if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then
2420 uefi_splash_image
="${dracutsysrootdir}${uefi_splash_image}"
2422 unset uefi_splash_image
2426 ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \
2427 ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \
2428 ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \
2429 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x2000000 \
2430 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
=0x3000000 \
2431 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
2432 if [[ -n ${uefi_secureboot_key} && -n ${uefi_secureboot_cert} ]]; then
2434 --key "${uefi_secureboot_key}" \
2435 --cert "${uefi_secureboot_cert}" \
2436 --output "$outfile" "${uefi_outdir}/linux.efi"; then
2437 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
2439 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2443 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2444 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2449 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2453 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2454 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2457 dfatal
"dracut: creation of $outfile failed"
2462 command -v restorecon
&> /dev
/null
&& restorecon
-- "$outfile"
2465 btrfs filesystem show
"$1" |
sed -n '1s/^.*uuid: //p'
2468 freeze_ok_for_btrfs
() {
2469 local mnt uuid1 uuid2
2470 # If the output file is on btrfs, we need to make sure that it's
2471 # not on a subvolume of the same file system as the root FS.
2472 # Otherwise, fsfreeze() might freeze the entire system.
2473 # This is most conveniently checked by comparing the FS uuid.
2475 [[ "$(stat -f -c %T -- "/")" == "btrfs" ]] ||
return 0
2476 mnt
=$
(stat
-c %m
-- "$1")
2477 uuid1
=$
(btrfs_uuid
"$mnt")
2478 uuid2
=$
(btrfs_uuid
"/")
2479 [[ $uuid1 && $uuid2 && $uuid1 != "$uuid2" ]]
2482 freeze_ok_for_fstype
() {
2486 [[ "$(stat -c %m -- "$outfile")" == "/" ]] && return 1
2487 fstype
=$
(stat
-f -c %T
-- "$outfile")
2493 freeze_ok_for_btrfs
"$outfile"
2501 # We sync/fsfreeze only if we're operating on a live booted system.
2502 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2503 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2504 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2505 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2506 if [[ -d $dracutsysrootdir/run
/systemd
/system
]]; then
2507 if ! sync
"$outfile" 2> /dev
/null
; then
2508 dinfo
"dracut: sync operation on newly created initramfs $outfile failed"
2512 # use fsfreeze only if we're not writing to /
2513 if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype
"$outfile"; then
2514 FSFROZEN
="$(dirname "$outfile")"
2515 if ! (fsfreeze
-f "${FSFROZEN}" 2> /dev
/null
&& fsfreeze
-u "${FSFROZEN}" 2> /dev
/null
); then
2516 dinfo
"dracut: warning: could not fsfreeze $(dirname "$outfile")"