3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
8 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 # Verify bash version, current minimum is 4
30 if ((BASH_VERSINFO
[0] < 4)); then
31 printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
36 readonly dracut_cmd
=$
(readlink
-f "$0")
41 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
42 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
43 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
44 # shellcheck source=./dracut-version.sh
45 .
"$dracutbasedir"/dracut-version.sh
48 # 80x25 linebreak here ^
50 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
52 Version: $DRACUT_VERSION
54 Creates initial ramdisk images for preloading modules
56 -h, --help Display all options
58 If a [LIST] has multiple arguments, then you have to put these in quotes.
62 # dracut --add-drivers "module1 module2" ...
68 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
69 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
70 # shellcheck source=./dracut-version.sh
71 .
"$dracutbasedir"/dracut-version.sh
74 # 80x25 linebreak here ^
76 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
78 Version: $DRACUT_VERSION
80 Creates initial ramdisk images for preloading modules
82 --kver [VERSION] Set kernel version to [VERSION].
83 -f, --force Overwrite existing initramfs file.
84 -a, --add [LIST] Add a space-separated list of dracut modules.
85 --rebuild Append arguments to those of existing image and rebuild
86 -m, --modules [LIST] Specify a space-separated list of dracut modules to
87 call when building the initramfs. Modules are located
88 in /usr/lib/dracut/modules.d.
89 -o, --omit [LIST] Omit a space-separated list of dracut modules.
90 --force-add [LIST] Force to add a space-separated list of dracut modules
91 to the default set of modules, when -H is specified.
92 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
93 exclusively include in the initramfs.
94 --add-drivers [LIST] Specify a space-separated list of kernel
95 modules to add to the initramfs.
96 --force-drivers [LIST] Specify a space-separated list of kernel
97 modules to add to the initramfs and make sure they
98 are tried to be loaded via modprobe same as passing
99 rd.driver.pre=DRIVER kernel parameter.
100 --omit-drivers [LIST] Specify a space-separated list of kernel
101 modules not to add to the initramfs.
102 --filesystems [LIST] Specify a space-separated list of kernel filesystem
103 modules to exclusively include in the generic
105 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
107 --fwdir [DIR] Specify additional directories, where to look for
108 firmwares, separated by :
109 --kernel-only Only install kernel drivers and firmware files
110 --no-kernel Do not install kernel drivers and firmware files
111 --print-cmdline Print the kernel command line for the given disk layout
112 --early-microcode Combine early microcode with ramdisk
113 --no-early-microcode Do not combine early microcode with ramdisk
114 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
115 --strip Strip binaries in the initramfs
116 --nostrip Do not strip binaries in the initramfs
117 --hardlink Hardlink files in the initramfs
118 --nohardlink Do not hardlink files in the initramfs
119 --prefix [DIR] Prefix initramfs files with [DIR]
120 --noprefix Do not prefix initramfs files
121 --mdadmconf Include local /etc/mdadm.conf
122 --nomdadmconf Do not include local /etc/mdadm.conf
123 --lvmconf Include local /etc/lvm/lvm.conf
124 --nolvmconf Do not include local /etc/lvm/lvm.conf
125 --fscks [LIST] Add a space-separated list of fsck helpers.
126 --nofscks Inhibit installation of any fsck helpers.
127 --ro-mnt Mount / and /usr read-only by default.
128 -h, --help This message
129 --debug Output debug information of the build process
130 --profile Output profile information of the build process
131 -L, --stdlog [0-6] Specify logging level (to standard error)
132 0 - suppress any messages
133 1 - only fatal errors
137 5 - debug info (here starts lots of output)
138 6 - trace info (and even more)
139 -v, --verbose Increase verbosity level
140 -q, --quiet Decrease verbosity level
141 -c, --conf [FILE] Specify configuration file to use.
142 Default: /etc/dracut.conf
143 --confdir [DIR] Specify configuration directory to use *.conf files
144 from. Default: /etc/dracut.conf.d
145 --tmpdir [DIR] Temporary directory to be used instead of default
147 -r, --sysroot [DIR] Specify sysroot directory to collect files from.
148 -l, --local Local mode. Use modules from the current working
149 directory instead of the system-wide installed in
150 /usr/lib/dracut/modules.d.
151 Useful when running dracut from a git checkout.
152 -H, --hostonly Host-Only mode: Install only what is needed for
153 booting the local host instead of a generic host.
154 -N, --no-hostonly Disables Host-Only mode
155 --hostonly-mode <mode>
156 Specify the hostonly mode to use. <mode> could be
157 one of "sloppy" or "strict". "sloppy" mode is used
159 In "sloppy" hostonly mode, extra drivers and modules
160 will be installed, so minor hardware change won't make
161 the image unbootable (eg. changed keyboard), and the
162 image is still portable among similar hosts.
163 With "strict" mode enabled, anything not necessary
164 for booting the local host in its current state will
165 not be included, and modules may do some extra job
166 to save more space. Minor change of hardware or
167 environment could make the image unbootable.
168 DO NOT use "strict" mode unless you know what you
170 --hostonly-cmdline Store kernel command line arguments needed
172 --no-hostonly-cmdline Do not store kernel command line arguments needed
174 --no-hostonly-default-device
175 Do not generate implicit host devices like root,
176 swap, fstab, etc. Use "--mount" or "--add-device"
177 to explicitly add devices as needed.
178 --hostonly-i18n Install only needed keyboard and font files according
179 to the host configuration (default).
180 --no-hostonly-i18n Install all keyboard and font files available.
181 --hostonly-nics [LIST]
182 Only enable listed NICs in the initramfs.
183 --persistent-policy [POLICY]
184 Use [POLICY] to address disks and partitions.
185 POLICY can be any directory name found in /dev/disk.
186 E.g. "by-uuid", "by-label"
187 --fstab Use /etc/fstab to determine the root device.
188 --add-fstab [FILE] Add file to the initramfs fstab
189 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
190 Mount device [DEV] on mountpoint [MP] with filesystem
191 [FSTYPE] and options [FSOPTS] in the initramfs
192 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
193 determined by looking at the current mounts.
194 --add-device "[DEV]" Bring up [DEV] in initramfs
195 -i, --include [SOURCE] [TARGET]
196 Include the files in the SOURCE directory into the
197 Target directory in the final initramfs.
198 If SOURCE is a file, it will be installed to TARGET
199 in the final initramfs.
200 -I, --install [LIST] Install the space separated list of files into the
202 --install-optional [LIST] Install the space separated list of files into the
203 initramfs, if they exist.
204 --gzip Compress the generated initramfs using gzip.
205 This will be done by default, unless another
206 compression option or --no-compress is passed.
207 --bzip2 Compress the generated initramfs using bzip2.
208 Make sure your kernel has bzip2 decompression support
209 compiled in, otherwise you will not be able to boot.
210 --lzma Compress the generated initramfs using lzma.
211 Make sure your kernel has lzma support compiled in,
212 otherwise you will not be able to boot.
213 --xz Compress the generated initramfs using xz.
214 Make sure that your kernel has xz support compiled
215 in, otherwise you will not be able to boot.
216 --lzo Compress the generated initramfs using lzop.
217 Make sure that your kernel has lzo support compiled
218 in, otherwise you will not be able to boot.
219 --lz4 Compress the generated initramfs using lz4.
220 Make sure that your kernel has lz4 support compiled
221 in, otherwise you will not be able to boot.
222 --zstd Compress the generated initramfs using Zstandard.
223 Make sure that your kernel has zstd support compiled
224 in, otherwise you will not be able to boot.
225 --compress [COMPRESSION] Compress the generated initramfs with the
226 passed compression program. Make sure your kernel
227 knows how to decompress the generated initramfs,
228 otherwise you will not be able to boot.
229 --no-compress Do not compress the generated initramfs. This will
230 override any other compression options.
231 --list-modules List all available dracut modules.
232 -M, --show-modules Print included module's name to standard output during
234 --keep Keep the temporary initramfs for debugging purposes
235 --printsize Print out the module install size
236 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
237 --logfile [FILE] Logfile to use (overrides configuration setting)
238 --reproducible Create reproducible images
239 --no-reproducible Do not create reproducible images
240 --loginstall [DIR] Log all files installed from the host to [DIR]
241 --uefi Create an UEFI executable with the kernel cmdline and
243 --no-uefi Disables UEFI mode
244 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
245 --uefi-splash-image [FILE]
246 Use [FILE] as a splash image when creating an UEFI
248 --kernel-image [FILE] location of the kernel image
249 --regenerate-all Regenerate all initramfs images at the default location
250 for the kernel versions found on the system
251 --version Display version
253 If [LIST] has multiple arguments, then you have to put these in quotes.
257 # dracut --add-drivers "module1 module2" ...
263 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
264 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
265 # shellcheck source=./dracut-version.sh
266 .
"$dracutbasedir"/dracut-version.sh
268 echo "dracut $DRACUT_VERSION"
271 # Fills up host_devs stack variable and makes sure there are no duplicates
275 [[ " ${host_devs[*]} " == *" $_dev "* ]] && return
280 # Little helper function for reading args from the commandline.
281 # it automatically handles -a b and -a=b variants, and returns 1 if
282 # we need to shift $3.
287 local rematch
='^[^=]*=(.*)$'
288 if [[ $2 =~
$rematch ]]; then
289 read -r "$1" <<< "${BASH_REMATCH[1]}"
291 read -r "$1" <<< "$3"
292 # There is no way to shift our callers args, so
293 # return 1 to indicate they should do it instead.
299 if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
300 printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
301 printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
312 for i
in "$d/"*"$suffix"; do
313 if [[ -e "$i" ]]; then
314 printf "%s\n" "${i##*/}"
320 for f
in "${files[@]}"; do
322 if [[ -e "$d/$f" ]]; then
323 printf "%s\n" "$d/$f"
332 # Workaround -i, --include taking 2 arguments
335 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
336 newat
+=("++include") # Replace --include by ++include
341 set -- "${newat[@]}" # Set new $@
344 unset POSIXLY_CORRECT
346 -o "a:m:o:d:I:k:c:r:L:fvqlHhMN" \
350 --long add-drivers
: \
351 --long force-drivers
: \
352 --long omit-drivers
: \
356 --long filesystems
: \
358 --long install-optional
: \
380 --long print-cmdline \
381 --long kernel-cmdline
: \
401 --long no-host-only \
402 --long hostonly-mode
: \
403 --long hostonly-cmdline \
404 --long no-hostonly-cmdline \
405 --long no-hostonly-default-device \
406 --long persistent-policy
: \
417 --long list-modules \
418 --long show-modules \
421 --long regenerate-all \
422 --long noimageifnotneeded \
423 --long early-microcode \
424 --long no-early-microcode \
425 --long reproducible \
426 --long no-reproducible \
431 --long uefi-splash-image
: \
432 --long kernel-image
: \
433 --long no-hostonly-i18n \
434 --long hostonly-i18n \
435 --long hostonly-nics
: \
436 --long no-machineid \
441 # shellcheck disable=SC2181
452 rearrange_params
"$@"
455 # parse command line args to check if '--rebuild' option is present
459 if [ "$1" == "--" ]; then
463 if [ "$1" == "--rebuild" ]; then
466 if [ ! -e "$rebuild_file" ]; then
467 echo "Image file '$rebuild_file', for rebuild, does not exist!"
470 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
477 # get output file name and kernel version from command line arguments
484 if ! [[ ${outfile+x} ]]; then
486 elif ! [[ ${kernel+x} ]]; then
489 printf "\nUnknown arguments: %s\n\n" "$*" >&2
498 # extract input image file provided with rebuild option to get previous parameters, if any
499 if [[ $append_args_l == "yes" ]]; then
502 # determine resultant file
503 if ! [[ $outfile ]]; then
504 outfile
=$rebuild_file
507 if ! rebuild_param
=$
(lsinitrd
"$rebuild_file" '*lib/dracut/build-parameter.txt'); then
508 echo "Image '$rebuild_file' has no rebuild information stored"
512 # prepend previous parameters to current command line args
513 if [[ $rebuild_param ]]; then
514 TEMP
="$rebuild_param $TEMP"
516 rearrange_params
"$@"
526 if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
527 PARMS_TO_STORE
+=" $1"
532 PARMS_TO_STORE
+=" '$2'"
536 add_dracutmodules_l
+=("$2")
537 PARMS_TO_STORE
+=" '$2'"
541 force_add_dracutmodules_l
+=("$2")
542 PARMS_TO_STORE
+=" '$2'"
546 add_drivers_l
+=("$2")
547 PARMS_TO_STORE
+=" '$2'"
551 force_drivers_l
+=("$2")
552 PARMS_TO_STORE
+=" '$2'"
556 omit_drivers_l
+=("$2")
557 PARMS_TO_STORE
+=" '$2'"
561 dracutmodules_l
+=("$2")
562 PARMS_TO_STORE
+=" '$2'"
566 omit_dracutmodules_l
+=("$2")
567 PARMS_TO_STORE
+=" '$2'"
572 PARMS_TO_STORE
+=" '$2'"
576 filesystems_l
+=("$2")
577 PARMS_TO_STORE
+=" '$2'"
581 install_items_l
+=("$2")
582 PARMS_TO_STORE
+=" '$2'"
586 install_optional_items_l
+=("$2")
587 PARMS_TO_STORE
+=" '$2'"
592 PARMS_TO_STORE
+=" '$2'"
597 PARMS_TO_STORE
+=" '$2'"
602 PARMS_TO_STORE
+=" '$2'"
607 PARMS_TO_STORE
+=" '$2'"
612 PARMS_TO_STORE
+=" '$2'"
615 --add-device |
--device)
617 PARMS_TO_STORE
+=" '$2'"
621 kernel_cmdline_l
+=("$2")
622 PARMS_TO_STORE
+=" '$2'"
625 --nofscks) nofscks_l
="yes" ;;
626 --ro-mnt) ro_mnt_l
="yes" ;;
629 PARMS_TO_STORE
+=" '$2'"
634 PARMS_TO_STORE
+=" '$2'"
639 PARMS_TO_STORE
+=" '$2'"
644 PARMS_TO_STORE
+=" '$2'"
649 PARMS_TO_STORE
+=" '$2'"
654 PARMS_TO_STORE
+=" '$2'"
659 PARMS_TO_STORE
+=" '$2'"
664 PARMS_TO_STORE
+=" '$2'"
669 PARMS_TO_STORE
+=" '$2'"
673 if [[ $rebuild_file == "$outfile" ]]; then
678 -f |
--force) force
=yes ;;
694 early_microcode_l
="yes"
696 --no-early-microcode)
697 early_microcode_l
="no"
699 --strip) do_strip_l
="yes" ;;
700 --nostrip) do_strip_l
="no" ;;
701 --hardlink) do_hardlink_l
="yes" ;;
702 --nohardlink) do_hardlink_l
="no" ;;
703 --noprefix) prefix_l
="/" ;;
704 --mdadmconf) mdadmconf_l
="yes" ;;
705 --nomdadmconf) mdadmconf_l
="no" ;;
706 --lvmconf) lvmconf_l
="yes" ;;
707 --nolvmconf) lvmconf_l
="no" ;;
708 --debug) debug
="yes" ;;
709 --profile) profile
="yes" ;;
712 PARMS_TO_STORE
+=" '$2'"
719 -v |
--verbose) ((verbosity_mod_l
++)) ;;
720 -q |
--quiet) ((verbosity_mod_l--
)) ;;
723 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
724 && dracutbasedir
="$(readlink -f "${0%/*}")"
726 -H |
--hostonly |
--host-only)
729 -N |
--no-hostonly |
--no-host-only)
734 PARMS_TO_STORE
+=" '$2'"
738 hostonly_cmdline_l
="yes"
741 i18n_install_all_l
="no"
744 hostonly_nics_l
+=("$2")
745 PARMS_TO_STORE
+=" '$2'"
749 i18n_install_all_l
="yes"
751 --no-hostonly-cmdline)
752 hostonly_cmdline_l
="no"
754 --no-hostonly-default-device)
755 hostonly_default_device
="no"
758 persistent_policy_l
="$2"
759 PARMS_TO_STORE
+=" '$2'"
762 --fstab) use_fstab_l
="yes" ;;
767 --bzip2) compress_l
="bzip2" ;;
768 --lzma) compress_l
="lzma" ;;
769 --xz) compress_l
="xz" ;;
770 --lzo) compress_l
="lzo" ;;
771 --lz4) compress_l
="lz4" ;;
772 --zstd) compress_l
="zstd" ;;
773 --no-compress) _no_compress_l
="cat" ;;
774 --gzip) compress_l
="gzip" ;;
775 --list-modules) do_list
="yes" ;;
779 --keep) keep
="yes" ;;
780 --printsize) printsize
="yes" ;;
781 --regenerate-all) regenerate_all
="yes" ;;
782 --noimageifnotneeded) noimageifnotneeded
="yes" ;;
783 --reproducible) reproducible_l
="yes" ;;
784 --no-reproducible) reproducible_l
="no" ;;
785 --uefi) uefi_l
="yes" ;;
786 --no-uefi) uefi_l
="no" ;;
789 PARMS_TO_STORE
+=" '$2'"
793 uefi_splash_image_l
="$2"
794 PARMS_TO_STORE
+=" '$2'"
799 PARMS_TO_STORE
+=" '$2'"
814 *) # should not even reach this point
815 printf "\n!Unknown option: '%s'\n\n" "$1" >&2
823 # getopt cannot handle multiple arguments, so just handle "-I,--include"
824 # the old fashioned way
827 if [ "${1%%=*}" == "++include" ]; then
829 include_target
+=("$3")
830 PARMS_TO_STORE
+=" --include '$2' '$3'"
836 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
838 if [[ $regenerate_all == "yes" ]]; then
840 if [[ $kernel ]]; then
841 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
845 if [[ $outfile ]]; then
846 printf -- "--regenerate-all cannot be called with a image file\n" >&2
850 ((len
= ${#dracut_args[@]}))
851 for ((i
= 0; i
< len
; i
++)); do
852 [[ ${dracut_args[$i]} == "--regenerate-all" ]] \
853 && unset "dracut_args[$i]"
856 cd "$dracutsysrootdir"/lib
/modules ||
exit 1
858 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
859 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
865 if ! [[ $kernel ]]; then
873 unset LD_LIBRARY_PATH
877 export DRACUT_LOG_LEVEL
=warning
879 export DRACUT_LOG_LEVEL
=debug
880 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
885 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '
890 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
892 # if we were not passed a config file, try the default one
893 if [[ ! -f $conffile ]]; then
894 if [[ $allowlocal ]]; then
895 conffile
="$dracutbasedir/dracut.conf"
897 conffile
="$dracutsysrootdir/etc/dracut.conf"
901 if [[ ! -d $confdir ]]; then
902 if [[ $allowlocal ]]; then
903 confdir
="$dracutbasedir/dracut.conf.d"
905 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
909 # source our config file
910 if [[ -f $conffile ]]; then
911 check_conf_file
"$conffile"
912 # shellcheck disable=SC1090
916 # source our config dir
917 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
919 # shellcheck disable=SC1090
920 [[ -e $f ]] && .
"$f"
923 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
925 for i
in $DRACUT_PATH; do
927 if [ -L "$dracutsysrootdir$i" ]; then
928 rl
=$
(readlink
-f "$dracutsysrootdir$i")
930 rl
="${rl#$dracutsysrootdir}"
931 if [[ "$NPATH" != *:$rl* ]]; then
935 [[ -z "$dracutsysrootdir" ]] && export PATH
="${NPATH#:}"
938 export SYSTEMCTL
=${SYSTEMCTL:-systemctl}
940 # these options add to the stuff in the config file
941 ((${#add_dracutmodules_l[@]})) && add_dracutmodules
+=" ${add_dracutmodules_l[*]} "
942 ((${#force_add_dracutmodules_l[@]})) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[*]} "
943 ((${#fscks_l[@]})) && fscks
+=" ${fscks_l[*]} "
944 ((${#add_fstab_l[@]})) && add_fstab
+=" ${add_fstab_l[*]} "
945 ((${#install_items_l[@]})) && install_items
+=" ${install_items_l[*]} "
946 ((${#install_optional_items_l[@]})) && install_optional_items
+=" ${install_optional_items_l[*]} "
947 ((${#hostonly_nics_l[@]})) && hostonly_nics
+=" ${hostonly_nics_l[*]} "
949 # these options override the stuff in the config file
950 ((${#dracutmodules_l[@]})) && dracutmodules
="${dracutmodules_l[*]}"
951 ((${#omit_dracutmodules_l[@]})) && omit_dracutmodules
="${omit_dracutmodules_l[*]}"
952 ((${#filesystems_l[@]})) && filesystems
="${filesystems_l[*]}"
953 ((${#fw_dir_l[@]})) && fw_dir
="${fw_dir_l[*]}"
954 ((${#libdirs_l[@]})) && libdirs
="${libdirs_l[*]}"
956 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
957 [[ ! $stdloglvl ]] && stdloglvl
=4
958 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
959 ((stdloglvl
> 6)) && stdloglvl
=6
960 ((stdloglvl
< 0)) && stdloglvl
=0
962 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
963 [[ $do_strip_l ]] && do_strip
=$do_strip_l
964 [[ $do_strip ]] || do_strip
=yes
965 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
966 [[ $do_hardlink ]] || do_hardlink
=yes
967 [[ $prefix_l ]] && prefix
=$prefix_l
968 [[ $prefix = "/" ]] && unset prefix
969 [[ $hostonly_l ]] && hostonly
=$hostonly_l
970 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
971 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
972 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
973 # shellcheck disable=SC2034
974 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
975 # shellcheck disable=SC2034
976 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
977 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
978 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
979 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
980 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
981 [[ $fw_dir ]] || fw_dir
="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
982 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
983 [[ $tmpdir ]] || tmpdir
="$TMPDIR"
984 [[ $tmpdir ]] || tmpdir
="$dracutsysrootdir"/var
/tmp
985 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
986 [[ $compress_l ]] && compress=$compress_l
987 [[ $show_modules_l ]] && show_modules
=$show_modules_l
988 [[ $nofscks_l ]] && nofscks
="yes"
989 [[ $ro_mnt_l ]] && ro_mnt
="yes"
990 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
991 [[ $early_microcode ]] || early_microcode
=yes
992 [[ $early_microcode_image_dir ]] || early_microcode_image_dir
=('/boot')
993 [[ $early_microcode_image_name ]] \
994 || early_microcode_image_name
=('intel-uc.img' 'intel-ucode.img' 'amd-uc.img' 'amd-ucode.img' 'early_ucode.cpio' 'microcode.cpio')
995 [[ $logfile_l ]] && logfile
="$logfile_l"
996 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
997 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
998 [[ $uefi_l ]] && uefi
=$uefi_l
999 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
1000 [[ $uefi_splash_image_l ]] && uefi_splash_image
="$uefi_splash_image_l"
1001 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
1002 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
1004 if ! [[ $outfile ]]; then
1005 if [[ $machine_id != "no" ]]; then
1006 [[ -f "$dracutsysrootdir"/etc
/machine-id
]] && read -r MACHINE_ID
< "$dracutsysrootdir"/etc
/machine-id
1009 if [[ $uefi == "yes" ]]; then
1010 # shellcheck disable=SC2154
1011 if [[ -n "$uefi_secureboot_key" && -z "$uefi_secureboot_cert" ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
1012 dfatal
"Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set."
1016 if [[ -n "$uefi_secureboot_key" && -n "$uefi_secureboot_cert" ]] && ! command -v sbsign
&> /dev
/null
; then
1017 dfatal
"Need 'sbsign' to create a signed UEFI executable"
1021 BUILD_ID
=$
(cat "$dracutsysrootdir"/etc
/os-release
"$dracutsysrootdir"/usr
/lib
/os-release \
1022 |
while read -r line ||
[[ $line ]]; do
1023 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break
1025 if [[ -z $dracutsysrootdir ]]; then
1026 if [[ -d /efi
]] && mountpoint
-q /efi
; then
1030 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1031 efidir
=/boot
/efi
/EFI
1036 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
1037 efidir
=/boot
/efi
/EFI
1040 mkdir
-p "$dracutsysrootdir$efidir/Linux"
1041 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
1043 if [[ -e $dracutsysrootdir/boot
/vmlinuz-
$kernel ]]; then
1044 outfile
="/boot/initramfs-$kernel.img"
1045 elif [[ $MACHINE_ID ]] && { [[ -d $dracutsysrootdir/boot
/${MACHINE_ID} ]] || [[ -L $dracutsysrootdir/boot/${MACHINE_ID} ]]; }; then
1046 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
1048 outfile
="$dracutsysrootdir/boot/initramfs-$kernel.img"
1053 # eliminate IFS hackery when messing with fw_dir
1054 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
1055 fw_dir
=${fw_dir//:/ }
1057 # check for logfile and try to create one if it doesn't exist
1058 if [[ -n "$logfile" ]]; then
1059 if [[ ! -f "$logfile" ]]; then
1060 if touch "$logfile"; then
1061 printf "%s\n" "dracut: touch $logfile failed." >&2
1066 # handle compression options.
1067 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
1068 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
1069 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
1070 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
1071 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
1072 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
1073 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
1074 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
1075 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
1076 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
1078 if [[ $_no_compress_l = "$DRACUT_COMPRESS_CAT" ]]; then
1079 compress="$DRACUT_COMPRESS_CAT"
1082 [[ $hostonly = yes ]] && hostonly
="-h"
1083 [[ $hostonly != "-h" ]] && unset hostonly
1085 case $hostonly_mode in
1087 [[ $hostonly ]] && hostonly_mode
="sloppy"
1090 if [[ ! $hostonly ]]; then
1095 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
1100 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
1102 case "${drivers_dir}" in
1103 '' |
*lib
/modules
/${kernel} |
*lib
/modules
/${kernel}/) ;;
1105 [[ "$DRACUT_KMODDIR_OVERRIDE" ]] ||
{
1106 printf "%s\n" "dracut: -k/--kmoddir path must contain \"lib/modules\" as a parent of your kernel module directory,"
1107 printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
1108 printf "%s\n" "dracut: was given: ${drivers_dir}"
1109 printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
1110 printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
1111 printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
1117 readonly TMPDIR
="$(realpath -e "$tmpdir")"
1118 [ -d "$TMPDIR" ] ||
{
1119 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
1123 if findmnt
--raw -n --target "$tmpdir" --output=options |
grep -q noexec
; then
1124 [[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
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 # clean up after ourselves no matter how we die.
1137 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
1138 if [[ ${FSFROZEN} ]]; then
1139 fsfreeze -u "${FSFROZEN}"
1144 # clean up after ourselves no matter how we die.
1145 trap 'exit 1;' SIGINT
1147 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
1150 # shellcheck disable=SC2154
1151 if [[ $early_microcode = yes ]] ||
{ [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; }; then
1152 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
1153 mkdir
"$early_cpio_dir"
1156 [[ "$dracutsysrootdir" ]] ||
[[ "$noexec" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
1158 if [[ $print_cmdline ]]; then
1165 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
1166 # shellcheck source=./dracut-version.sh
1167 .
"$dracutbasedir"/dracut-version.sh
1170 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
1171 # shellcheck source=./dracut-init.sh
1172 .
"$dracutbasedir"/dracut-init.sh
1174 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1175 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1176 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1180 # shellcheck disable=SC2154
1181 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1182 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
1183 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
1187 if ! [[ $print_cmdline ]]; then
1188 inst
"$DRACUT_TESTBIN"
1189 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &> /dev
/null
; then
1190 unset DRACUT_RESOLVE_LAZY
1191 export DRACUT_RESOLVE_DEPS
=1
1193 rm -fr -- "${initdir:?}"/*
1196 dracutfunctions
=$dracutbasedir/dracut-functions.sh
1197 export dracutfunctions
1199 ((${#drivers_l[@]})) && drivers
="${drivers_l[*]}"
1200 drivers
=${drivers/-/_}
1202 ((${#add_drivers_l[@]})) && add_drivers
+=" ${add_drivers_l[*]} "
1203 add_drivers
=${add_drivers/-/_}
1205 ((${#force_drivers_l[@]})) && force_drivers
+=" ${force_drivers_l[*]} "
1206 force_drivers
=${force_drivers/-/_}
1208 ((${#omit_drivers_l[@]})) && omit_drivers
+=" ${omit_drivers_l[*]} "
1209 omit_drivers
=${omit_drivers/-/_}
1211 ((${#kernel_cmdline_l[@]})) && kernel_cmdline
+=" ${kernel_cmdline_l[*]} "
1213 omit_drivers_corrected
=""
1214 for d
in $omit_drivers; do
1215 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
1216 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1217 omit_drivers_corrected
+="$d|"
1219 omit_drivers
="${omit_drivers_corrected%|}"
1220 unset omit_drivers_corrected
1222 # prepare args for logging
1223 for ((i
= 0; i
< ${#dracut_args[@]}; i
++)); do
1224 [[ "${dracut_args[$i]}" == *\
* ]] \
1225 && dracut_args
[$i]="\"${dracut_args[$i]}\""
1229 dinfo
"Executing: $dracut_cmd ${dracut_args[*]}"
1231 [[ $do_list = yes ]] && {
1232 for mod
in "$dracutbasedir"/modules.d
/*; do
1233 [[ -d $mod ]] ||
continue
1234 [[ -e $mod/install ||
-e $mod/installkernel ||
-e \
1235 $mod/module-setup.sh
]] ||
continue
1236 printf "%s\n" "${mod##*/??}"
1241 # This is kinda legacy -- eventually it should go away.
1242 case $dracutmodules in
1243 "" | auto
) dracutmodules
="all" ;;
1246 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1248 [[ -d $dracutsysrootdir$systemdutildir ]] \
1249 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2> /dev
/null
)
1251 if ! [[ -d $dracutsysrootdir$systemdutildir ]]; then
1252 [[ -e $dracutsysrootdir/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1253 [[ -e $dracutsysrootdir/usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1256 [[ -d $dracutsysrootdir$systemdutilconfdir ]] \
1257 || systemdutilconfdir
=$
(pkg-config systemd
--variable=systemdutilconfdir
2> /dev
/null
)
1259 [[ -d $dracutsysrootdir$systemdutilconfdir ]] || systemdutilconfdir
=/etc
/systemd
1261 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1262 if ! [[ -f $srcmods/modules.dep
]]; then
1263 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1264 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1267 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1269 elif ! (command -v gzip &> /dev
/null
&& command -v xz
&> /dev
/null
); then
1270 read -r _mod
< "$srcmods"/modules.dep
1272 if [[ -f $srcmods/"$_mod" ]]; then
1273 # Check, if kernel modules are compressed, and if we can uncompress them
1275 *.ko.gz
) kcompress
=gzip ;;
1276 *.ko.xz
) kcompress
=xz
;;
1278 if [[ $kcompress ]]; then
1279 if ! command -v "$kcompress" &> /dev
/null
; then
1280 dfatal
"Kernel modules are compressed with $kcompress, but $kcompress is not available."
1288 if [[ ! $print_cmdline ]]; then
1289 if [[ -f $outfile && ! $force ]]; then
1290 dfatal
"Will not override existing initramfs ($outfile) without --force"
1294 outdir
=${outfile%/*}
1295 [[ $outdir ]] || outdir
="/"
1297 if [[ ! -d "$outdir" ]]; then
1298 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1300 elif [[ ! -w "$outdir" ]]; then
1301 dfatal
"No permission to write to $outdir."
1303 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1304 dfatal
"No permission to write $outfile."
1308 if [[ $loginstall ]]; then
1309 if ! mkdir
-p "$loginstall"; then
1310 dfatal
"Could not create directory to log installed files to '$loginstall'."
1313 loginstall
=$
(readlink
-f "$loginstall")
1316 if [[ $uefi = yes ]]; then
1317 if ! command -v objcopy
&> /dev
/null
; then
1318 dfatal
"Need 'objcopy' to create a UEFI executable"
1321 unset EFI_MACHINE_TYPE_NAME
1324 EFI_MACHINE_TYPE_NAME
=x64
1327 EFI_MACHINE_TYPE_NAME
=ia32
1330 dfatal
"Architecture '$(uname -m)' not supported to create a UEFI executable"
1335 if ! [[ -s $uefi_stub ]]; then
1337 "$dracutsysrootdir${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1338 "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1339 [[ -s $uefi_stub ]] ||
continue
1343 if ! [[ -s $uefi_stub ]]; then
1344 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1348 if ! [[ $kernel_image ]]; then
1349 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1350 [[ -s "$kernel_image" ]] ||
continue
1354 if ! [[ -s $kernel_image ]]; then
1355 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1361 if [[ $acpi_override = yes ]] && ! (check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1362 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1366 if [[ $early_microcode = yes ]]; then
1367 if [[ $hostonly ]]; then
1368 if [[ $
(get_cpu_vendor
) == "AMD" ]]; then
1369 check_kernel_config CONFIG_MICROCODE_AMD ||
unset early_microcode
1370 elif [[ $
(get_cpu_vendor
) == "Intel" ]]; then
1371 check_kernel_config CONFIG_MICROCODE_INTEL ||
unset early_microcode
1373 unset early_microcode
1376 ! check_kernel_config CONFIG_MICROCODE_AMD \
1377 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1378 && unset early_microcode
1380 # Do not complain on non-x86 architectures as it makes no sense
1383 [[ $early_microcode != yes ]] \
1384 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1390 # Need to be able to have non-root users read stuff (rpcbind etc)
1391 chmod 755 "$initdir"
1393 if [[ $hostonly ]]; then
1394 for i
in /sys
/proc
/run
/dev
; do
1395 if ! findmnt
--target "$i" &> /dev
/null
; then
1396 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1402 declare -A host_fs_types
1404 for line
in "${fstab_lines[@]}"; do
1405 # shellcheck disable=SC2086
1411 dev
=$
(blkid
-l -t "UUID=${dev#UUID=}" -o device
)
1414 dev
=$
(blkid
-l -t "LABEL=${dev#LABEL=}" -o device
)
1417 dev
=$
(blkid
-l -t "PARTUUID=${dev#PARTUUID=}" -o device
)
1420 dev
=$
(blkid
-l -t "PARTLABEL=${dev#PARTLABEL=}" -o device
)
1423 [ -z "$dev" ] && dwarn
"Bad fstab entry $*" && continue
1424 if [[ "$3" == btrfs
]]; then
1425 for i
in $
(btrfs_devs
"$2"); do
1429 push_host_devs
"$dev"
1430 host_fs_types
["$dev"]="$3"
1433 for f
in $add_fstab; do
1434 [[ -e $f ]] ||
continue
1435 while read -r dev rest ||
[ -n "$dev" ]; do
1436 push_host_devs
"$dev"
1440 for dev
in $add_device; do
1441 push_host_devs
"$dev"
1444 if ((${#add_device_l[@]})); then
1445 add_device
+=" ${add_device_l[*]} "
1446 push_host_devs
"${add_device_l[@]}"
1449 if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
1450 # in hostonly mode, determine all devices, which have to be accessed
1451 # and examine them for filesystem types
1468 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1469 mountpoint
"$mp" > /dev
/null
2>&1 ||
continue
1470 _dev
=$
(find_block_device
"$mp")
1471 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1472 [[ -b $_bdev ]] && _dev
=$_bdev
1473 [[ "$mp" == "/" ]] && root_devs
+=("$_dev")
1474 push_host_devs
"$_dev"
1475 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1476 for i
in $
(btrfs_devs
"$mp"); do
1477 [[ "$mp" == "/" ]] && root_devs
+=("$i")
1483 # TODO - with sysroot, /proc/swaps is not relevant
1484 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1485 while read -r dev
type rest ||
[ -n "$dev" ]; do
1486 [[ -b $dev ]] ||
continue
1487 [[ "$type" == "partition" ]] ||
continue
1489 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1490 [[ "$_d" == \
#* ]] && continue
1491 [[ $_d ]] ||
continue
1492 [[ $_t != "swap" ]] && continue
1493 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1494 [[ "$_o" == *noauto
* ]] && continue
1495 _d
=$
(expand_persistent_dev
"$_d")
1496 [[ "$_d" -ef "$dev" ]] ||
continue
1498 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1499 while read -r _mapper _ _p _o ||
[ -n "$_mapper" ]; do
1500 [[ $_mapper = \
#* ]] && continue
1501 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1502 [[ "$_o" ]] || _o
="$_p"
1503 # skip entries with password files
1504 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1506 [[ $_o == *swap
* ]] && continue 2
1507 done < "$dracutsysrootdir"/etc
/crypttab
1510 _dev
="$(readlink -f "$dev")"
1511 push_host_devs
"$_dev"
1512 swap_devs
+=("$_dev")
1514 done < "$dracutsysrootdir"/etc
/fstab
1518 # collect all "x-initrd.mount" entries from /etc/fstab
1519 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1520 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1521 [[ "$_d" == \
#* ]] && continue
1522 [[ $_d ]] ||
continue
1523 [[ "$_o" != *x-initrd.mount
* ]] && continue
1524 _dev
=$
(expand_persistent_dev
"$_d")
1525 _dev
="$(readlink -f "$_dev")"
1526 [[ -b $_dev ]] ||
continue
1528 push_host_devs
"$_dev"
1529 if [[ "$_t" == btrfs
]]; then
1530 for i
in $
(btrfs_devs
"$_m"); do
1534 done < "$dracutsysrootdir"/etc
/fstab
1543 if [[ -b /dev
/block
/$1 ]]; then
1544 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1547 if [[ -b $1 ]]; then
1548 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1551 if fstype
=$
(find_dev_fstype
"$1"); then
1552 host_fs_types
["$1"]="$fstype"
1558 for dev
in "${host_devs[@]}"; do
1560 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1563 for dev
in "${!host_fs_types[@]}"; do
1564 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
1565 rootopts
=$
(find_dev_fsopts
"$dev")
1566 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1567 journaldev
=$
(fs_get_option
"$rootopts" "jdev")
1568 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1569 journaldev
=$
(fs_get_option
"$rootopts" "logdev")
1571 if [[ $journaldev ]]; then
1572 dev
="$(readlink -f "$dev")"
1573 push_host_devs
"$dev"
1575 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1579 [[ -d $dracutsysrootdir$dbus ]] \
1580 || dbus
=$
(pkg-config dbus
--variable=dbus
2> /dev
/null
)
1582 [[ -d $dracutsysrootdir$dbus ]] || dbus
=/usr
/share
/dbus-1
1584 [[ -d $dracutsysrootdir$dbusconfdir ]] \
1585 || dbusconfdir
=$
(pkg-config dbus
--variable=dbusconfdir
2> /dev
/null
)
1587 [[ -d $dracutsysrootdir$dbusconfdir ]] || dbusconfdir
=/etc
/dbus-1
1589 [[ -d $dracutsysrootdir$dbusinterfaces ]] \
1590 || dbusinterfaces
=$
(pkg-config dbus
--variable=dbusinterfaces
2> /dev
/null
)
1592 [[ -d $dracutsysrootdir$dbusinterfaces ]] || dbusinterfaces
=${dbus}/interfaces
1594 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] \
1595 || dbusinterfacesconfdir
=$
(pkg-config dbus
--variable=dbusinterfacesconfdir
2> /dev
/null
)
1597 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] || dbusinterfacesconfdir
=${dbusconfdir}/interfaces
1599 [[ -d $dracutsysrootdir$dbusservices ]] \
1600 || dbusservices
=$
(pkg-config dbus
--variable=dbusservices
2> /dev
/null
)
1602 [[ -d $dracutsysrootdir$dbusservices ]] || dbusservices
=${dbus}/services
1604 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] \
1605 || dbusservicesconfdir
=$
(pkg-config dbus
--variable=dbusservicesconfdir
2> /dev
/null
)
1607 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] || dbusservicesconfdir
=${dbusconfdir}/services
1609 [[ -d $dracutsysrootdir$dbussession ]] \
1610 || dbussession
=$
(pkg-config dbus
--variable=dbussession
2> /dev
/null
)
1612 [[ -d $dracutsysrootdir$dbussession ]] || dbussession
=${dbus}/session.d
1614 [[ -d $dracutsysrootdir$dbussessionconfdir ]] \
1615 || dbussessionconfdir
=$
(pkg-config dbus
--variable=dbussessionconfdir
2> /dev
/null
)
1617 [[ -d $dracutsysrootdir$dbussessionconfdir ]] || dbussessionconfdir
=${dbusconfdir}/session.d
1619 [[ -d $dracutsysrootdir$dbussystem ]] \
1620 || dbussystem
=$
(pkg-config dbus
--variable=dbussystem
2> /dev
/null
)
1622 [[ -d $dracutsysrootdir$dbussystem ]] || dbussystem
=${dbus}/system.d
1624 [[ -d $dracutsysrootdir$dbussystemconfdir ]] \
1625 || dbussystemconfdir
=$
(pkg-config dbus
--variable=dbussystemconfdir
2> /dev
/null
)
1627 [[ -d $dracutsysrootdir$dbussystemconfdir ]] || dbussystemconfdir
=${dbusconfdir}/system.d
1629 [[ -d $dracutsysrootdir$dbussystemservices ]] \
1630 || dbussystemservices
=$
(pkg-config dbus
--variable=dbussystemservices
2> /dev
/null
)
1632 [[ -d $dracutsysrootdir$dbussystemservices ]] || dbussystemservices
=${dbus}/system-services
1634 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] \
1635 || dbussystemservicesconfdir
=$
(pkg-config dbus
--variable=dbussystemservicesconfdir
2> /dev
/null
)
1637 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] || dbussystemservicesconfdir
=${dbusconfdir}/system-services
1639 [[ -d $dracutsysrootdir$udevdir ]] \
1640 || udevdir
="$(pkg-config udev --variable=udevdir 2> /dev/null)"
1641 if ! [[ -d $dracutsysrootdir$udevdir ]]; then
1642 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1643 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1646 [[ -d $dracutsysrootdir$sysctl ]] \
1647 || sysctl
=$
(pkg-config systemd
--variable=sysctl
2> /dev
/null
)
1649 [[ -d $dracutsysrootdir$sysctl ]] || sysctl
=/usr
/lib
/sysctl.d
1651 [[ -d $dracutsysrootdir$sysctlconfdir ]] \
1652 || sysctlconfdir
=$
(pkg-config systemd
--variable=sysctlconfdir
2> /dev
/null
)
1654 [[ -d $dracutsysrootdir$sysctlconfdir ]] || sysctlconfdir
=/etc
/sysctl.d
1656 [[ -d $dracutsysrootdir$environment ]] \
1657 || environment
=$
(pkg-config systemd
--variable=environment
2> /dev
/null
)
1659 [[ -d $dracutsysrootdir$environment ]] || environment
=/usr
/lib
/environment.d
1661 [[ -d $dracutsysrootdir$environmentconfdir ]] \
1662 || environmentconfdir
=$
(pkg-config systemd
--variable=environmentconfdir
2> /dev
/null
)
1664 [[ -d $dracutsysrootdir$environmentconfdir ]] || environmentconfdir
=/etc
/environment.d
1666 [[ -d $dracutsysrootdir$systemdcatalog ]] \
1667 || systemdcatalog
=$
(pkg-config systemd
--variable=systemdcatalog
2> /dev
/null
)
1669 [[ -d $dracutsysrootdir$systemdcatalog ]] || systemdcatalog
=${systemdutildir}/catalog
1671 [[ -d $dracutsysrootdir$systemdnetwork ]] \
1672 || systemdnetwork
=$
(pkg-config systemd
--variable=systemdnetwork
2> /dev
/null
)
1674 [[ -d $dracutsysrootdir$systemdnetwork ]] || systemdnetwork
=${systemdutildir}/network
1676 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] \
1677 || systemdnetworkconfdir
=$
(pkg-config systemd
--variable=systemdnetworkconfdir
2> /dev
/null
)
1679 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] || systemdnetworkconfdir
=${systemdsystemconfdir}/network
1681 [[ -d $dracutsysrootdir$systemdntpunits ]] \
1682 || systemdntpunits
=$
(pkg-config systemd
--variable=systemdntpunits
2> /dev
/null
)
1684 [[ -d $dracutsysrootdir$systemdntpunits ]] || systemdntpunits
=${systemdutildir}/ntp-units.d
1686 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] \
1687 || systemdntpunitsconfdir
=$
(pkg-config systemd
--variable=systemdntpunitsconfdir
2> /dev
/null
)
1689 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] || systemdntpunitsconfdir
=${systemdsystemconfdir}/ntp-units.d
1691 [[ -d $dracutsysrootdir$systemdportable ]] \
1692 || systemdportable
=$
(pkg-config systemd
--variable=systemdportable
2> /dev
/null
)
1694 [[ -d $dracutsysrootdir$systemdportable ]] || systemdportable
=${systemdutildir}/portable
1696 [[ -d $dracutsysrootdir$systemdportableconfdir ]] \
1697 || systemdportableconfdir
=$
(pkg-config systemd
--variable=systemdportableconfdir
2> /dev
/null
)
1699 [[ -d "$dracutsysrootdir$systemdportableconfdir" ]] || systemdportableconfdir
=${systemdsystemconfdir}/portable
1701 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1702 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2> /dev
/null
)
1704 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1706 [[ -d $dracutsysrootdir$systemduser ]] \
1707 || systemduser
=$
(pkg-config systemd
--variable=systemduser
2> /dev
/null
)
1709 [[ -d $dracutsysrootdir$systemduser ]] || systemduser
=${systemdutildir}/user
1711 [[ -d $dracutsysrootdir$systemduserconfdir ]] \
1712 || systemduserconfdir
=$
(pkg-config systemd
--variable=systemduserconfdir
2> /dev
/null
)
1714 [[ -d $dracutsysrootdir$systemduserconfdir ]] || systemduserconfdir
=${systemdsystemconfdir}/user
1716 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1717 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2> /dev
/null
)
1719 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] || systemdsystemconfdir
=/etc
/systemd
/system
1721 [[ -d $dracutsysrootdir$sysusers ]] \
1722 || sysusers
=$
(pkg-config systemd
--variable=sysusers
2> /dev
/null
)
1724 [[ -d $dracutsysrootdir$sysusers ]] || sysusers
=/usr
/lib
/sysusers.d
1726 [[ -d $dracutsysrootdir$sysusersconfdir ]] \
1727 || sysusersconfdir
=$
(pkg-config systemd
--variable=sysusersconfdir
2> /dev
/null
)
1729 [[ -d $dracutsysrootdir$sysusersconfdir ]] || sysusersconfdir
=/etc
/sysusers.d
1731 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1732 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2> /dev
/null
)
1734 if ! [[ -d $dracutsysrootdir$tmpfilesdir ]]; then
1735 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1736 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1739 export initdir dracutbasedir \
1740 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1742 fw_dir drivers_dir debug no_kernel kernel_only \
1743 omit_drivers mdadmconf lvmconf root_devs \
1744 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1745 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1746 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1747 DRACUT_VERSION udevdir prefix filesystems drivers \
1748 dbus dbusconfdir dbusinterfaces dbusinterfacesconfdir \
1749 dbusservices dbusservicesconfdir dbussession dbussessionconfdir \
1750 dbussystem dbussystemconfdir dbussystemservices dbussystemservicesconfdir \
1751 environment environmentconfdir sysctl sysctlconfdir sysusers sysusersconfdir \
1752 systemdutildir systemdutilconfdir systemdcatalog systemdntpunits \
1753 systemdntpunitsconfdir systemdsystemunitdir systemdsystemconfdir \
1754 hostonly_cmdline loginstall \
1758 # check all our modules to see if they should be sourced.
1759 # This builds a list of modules that we will install next.
1760 for_each_module_dir check_module
1761 for_each_module_dir check_mount
1763 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1765 do_print_cmdline
() {
1766 local -A _mods_to_print
1767 for i
in $modules_loaded $mods_to_load; do
1768 _mods_to_print
[$i]=1
1771 # source our modules.
1772 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1773 _d_mod
=${moddir##*/}
1774 _d_mod
=${_d_mod#[0-9][0-9]}
1775 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1776 module_cmdline
"$_d_mod" "$moddir"
1781 if [[ $print_cmdline ]]; then
1787 # Create some directory structure first
1788 # shellcheck disable=SC2174
1789 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1791 # shellcheck disable=SC2174
1792 [[ -L $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1793 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1795 if [[ $prefix ]]; then
1796 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1797 [[ "$d" == */* ]] && continue
1798 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1802 if [[ $kernel_only != yes ]]; then
1803 for d
in usr usr
/bin usr
/sbin bin etc lib sbin tmp var var
/tmp
$libdirs; do
1804 [[ -e "${initdir}${prefix}/$d" ]] && continue
1805 if [ -L "/$d" ]; then
1806 inst_symlink
"/$d" "${prefix}/$d"
1808 # shellcheck disable=SC2174
1809 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1813 for d
in dev proc sys sysroot root run
; do
1814 if [ -L "/$d" ]; then
1817 # shellcheck disable=SC2174
1818 mkdir
-m 0755 -p "$initdir/$d"
1822 ln -sfn ..
/run
"$initdir/var/run"
1823 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1825 for d
in lib
"$libdirs"; do
1826 [[ -e "${initdir}${prefix}/$d" ]] && continue
1827 if [ -h "/$d" ]; then
1828 inst
"/$d" "${prefix}/$d"
1830 # shellcheck disable=SC2174
1831 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1836 if [[ $kernel_only != yes ]]; then
1837 mkdir
-p "${initdir}/etc/cmdline.d"
1838 # shellcheck disable=SC2174
1839 mkdir
-m 0755 -p "${initdir}"/lib "${initdir}"/lib/dracut "${initdir}"/lib
/dracut
/hooks
1840 # shellcheck disable=SC2154
1841 for _d
in $hookdirs; do
1842 # shellcheck disable=SC2174
1843 mkdir
-m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
1845 if [[ "$EUID" = "0" ]]; then
1846 [[ -c ${initdir}/dev
/null
]] || mknod
"${initdir}"/dev
/null c
1 3
1847 [[ -c ${initdir}/dev
/kmsg
]] || mknod
"${initdir}"/dev
/kmsg c
1 11
1848 [[ -c ${initdir}/dev
/console
]] || mknod
"${initdir}"/dev
/console c
5 1
1849 [[ -c ${initdir}/dev
/random
]] || mknod
"${initdir}"/dev
/random c
1 8
1850 [[ -c ${initdir}/dev
/urandom
]] || mknod
"${initdir}"/dev
/urandom c
1 9
1854 _isize
=0 #initramfs size
1856 # source our modules.
1857 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1858 _d_mod
=${moddir##*/}
1859 _d_mod
=${_d_mod#[0-9][0-9]}
1860 [[ "$mods_to_load" == *\
$_d_mod\
* ]] ||
continue
1861 if [[ $show_modules = yes ]]; then
1862 printf "%s\n" "$_d_mod"
1864 dinfo
"*** Including module: $_d_mod ***"
1866 if [[ $kernel_only == yes ]]; then
1867 module_installkernel
"$_d_mod" "$moddir" ||
{
1868 dfatal
"installkernel failed in module $_d_mod"
1872 module_install
"$_d_mod" "$moddir"
1873 if [[ $no_kernel != yes ]]; then
1874 module_installkernel
"$_d_mod" "$moddir" ||
{
1875 dfatal
"installkernel failed in module $_d_mod"
1880 mods_to_load
=${mods_to_load// $_d_mod /}
1881 modules_loaded
+="$_d_mod "
1883 #print the module install size
1884 if [ -n "$printsize" ]; then
1885 _isize_new
=$
(du
-sk "${initdir}" |
{
1889 _isize_delta
=$
((_isize_new
- _isize
))
1890 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1896 for i
in $modules_loaded; do
1897 mkdir
-p "$initdir"/lib
/dracut
1898 printf "%s\n" "$i" >> "$initdir"/lib
/dracut
/modules.txt
1901 dinfo
"*** Including modules done ***"
1903 ## final stuff that has to happen
1904 if [[ $no_kernel != yes ]]; then
1905 if [[ $hostonly_mode = "strict" ]]; then
1906 cp "$DRACUT_KERNEL_MODALIASES" "$initdir"/lib
/dracut
/hostonly-kernel-modules.txt
1909 if [[ $drivers ]]; then
1910 # shellcheck disable=SC2086
1911 hostonly
='' instmods
$drivers
1914 if [[ -n "${add_drivers// /}" ]]; then
1915 # shellcheck disable=SC2086
1916 hostonly
='' instmods
-c $add_drivers
1918 if [[ $force_drivers ]]; then
1919 # shellcheck disable=SC2086
1920 hostonly
='' instmods
-c $force_drivers
1921 rm -f "$initdir"/etc
/cmdline.d
/20-force_driver.conf
1922 for mod
in $force_drivers; do
1923 echo "rd.driver.pre=$mod" >> "$initdir"/etc
/cmdline.d
/20-force_drivers.conf
1926 if [[ $filesystems ]]; then
1927 # shellcheck disable=SC2086
1928 hostonly
='' instmods
-c $filesystems
1931 dinfo
"*** Installing kernel module dependencies ***"
1933 dinfo
"*** Installing kernel module dependencies done ***"
1935 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1936 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] \
1937 && [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1938 for i
in "${initdir}"/etc
/cmdline.d
/*.conf
; do
1939 # We need no initramfs image and do not generate one.
1940 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1946 if [[ $kernel_only != yes ]]; then
1947 # FIXME: handle legacy item split
1948 # shellcheck disable=SC2068
1949 ((${#install_items[@]} > 0)) && inst_multiple
${install_items[@]}
1950 # shellcheck disable=SC2068
1951 ((${#install_optional_items[@]} > 0)) && inst_multiple
-o ${install_optional_items[@]}
1953 if [[ $kernel_cmdline ]] && [[ $uefi != yes ]]; then
1954 printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1957 for line
in "${fstab_lines[@]}"; do
1958 read -r -a fstab_field
<<< "$line"
1959 if [ -z "${fstab_field[1]}" ]; then
1960 # Determine device and mount options from current system
1961 mountpoint
-q "${fstab_field[0]}" || derror
"${fstab_field[0]} is not a mount point!"
1962 read -r -a fstab_field
<<< "$(findmnt --raw -n --target "${fstab_field[0]}" --output=source,target,fstype,options)"
1963 dinfo
"Line for ${fstab_field[1]}: ${fstab_field[*]}"
1965 # Use default options
1966 [ -z "${fstab_field[3]}" ] && fstab_field
[3]="defaults"
1969 # Default options for freq and passno
1970 [ -z "${fstab_field[4]}" ] && fstab_field
[4]="0"
1971 [ -z "${fstab_field[5]}" ] && fstab_field
[5]="2"
1973 strstr
"${fstab_field[2]}" "nfs" && fstab_field
[5]="0"
1974 echo "${fstab_field[@]}" >> "${initdir}/etc/fstab"
1977 for f
in $add_fstab; do
1978 cat "$f" >> "${initdir}/etc/fstab"
1981 if [[ $dracutsysrootdir$systemdutildir ]]; then
1982 if [[ -d ${initdir}/$systemdutildir ]]; then
1983 mkdir
-p "${initdir}"/etc
/conf.d
1985 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1986 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1987 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1988 } > "${initdir}"/etc
/conf.d
/systemd.conf
1992 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1993 dinfo
"*** Resolving executable dependencies ***"
1994 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
1995 |
xargs -r -0 "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
1996 dinfo
"*** Resolving executable dependencies done ***"
1999 # Now we are done with lazy resolving, always install dependencies
2000 unset DRACUT_RESOLVE_LAZY
2001 export DRACUT_RESOLVE_DEPS
=1
2004 for ((i
= 0; i
< ${#include_src[@]}; i
++)); do
2005 src
="${include_src[$i]}"
2006 target
="${include_target[$i]}"
2007 if [[ $src && $target ]]; then
2008 if [[ -f $src ]]; then
2009 inst
"$src" "$target"
2010 elif [[ -d $src ]]; then
2011 ddebug
"Including directory: $src"
2012 destdir
="${initdir}/${target}"
2014 # check for preexisting symlinks, so we can cope with the
2015 # symlinks to $prefix
2016 # Objectname is a file or a directory
2017 for objectname
in "$src"/*; do
2018 [[ -e "$objectname" ||
-L "$objectname" ]] ||
continue
2019 if [[ -d "$objectname" ]]; then
2020 # objectname is a directory, let's compute the final directory name
2021 object_destdir
=${destdir}/${objectname#$src/}
2022 if ! [[ -e "$object_destdir" ]]; then
2023 # shellcheck disable=SC2174
2024 mkdir
-m 0755 -p "$object_destdir"
2025 chmod --reference="$objectname" "$object_destdir"
2027 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
2029 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
2032 elif [[ -e $src ]]; then
2033 derror
"$src is neither a directory nor a regular file"
2035 derror
"$src doesn't exist"
2040 if [[ $do_hardlink = yes ]] && command -v hardlink
> /dev
/null
; then
2041 dinfo
"*** Hardlinking files ***"
2042 hardlink
"$initdir" 2>&1
2043 dinfo
"*** Hardlinking files done ***"
2047 if [[ $do_strip = yes ]]; then
2048 # Prefer strip from elfutils for package size
2050 strip_cmd
=$
(command -v eu-strip
)
2051 [ -z "$strip_cmd" ] && strip_cmd
="strip"
2053 for p
in $strip_cmd xargs find; do
2054 if ! type -P $p > /dev
/null
; then
2055 dinfo
"Could not find '$p'. Not stripping the initramfs."
2061 # cleanup empty ldconfig_paths directories
2062 for d
in $
(ldconfig_paths
); do
2063 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" > /dev
/null
2>&1
2066 if [[ $early_microcode = yes ]]; then
2067 dinfo
"*** Generating early-microcode cpio image ***"
2068 ucode_dir
=(amd-ucode intel-ucode
)
2069 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
2070 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
2072 mkdir
-p "$_dest_dir"
2073 if [[ $hostonly ]]; then
2074 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
2075 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
2077 for idx
in $_dest_idx; do
2078 _fw
=${ucode_dir[$idx]}
2079 for _fwdir
in $fw_dir; do
2080 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
2082 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
2083 if [[ $hostonly ]]; then
2084 _src
=$
(get_ucode_file
)
2085 [[ $_src ]] ||
break
2086 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
2087 [[ -r $_fwdir/$_fw/$_src ]] ||
break
2090 for i
in $_fwdir/$_fw/$_src; do
2091 [ -e "$i" ] && break
2094 for i
in $_fwdir/$_fw/$_src; do
2095 [[ -e "$i" ]] ||
continue
2097 str_ends
"$i" ".asc" && continue
2098 cat "$i" >> "$_dest_dir/${ucode_dest[$idx]}"
2100 create_early_cpio
="yes"
2103 if [[ ! -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2104 if cd "$early_cpio_dir/d"; then
2105 for _ucodedir
in "${early_microcode_image_dir[@]}"; do
2106 for _ucodename
in "${early_microcode_image_name[@]}"; do
2107 [[ -e "$_ucodedir/$_ucodename" ]] \
2108 && cpio --extract --file "$_ucodedir/$_ucodename" --quiet \
2109 "kernel/x86/microcode/${ucode_dest[$idx]}"
2110 if [[ -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
2111 dinfo
"*** Using microcode found in '$_ucodedir/$_ucodename' ***"
2112 create_early_cpio
="yes"
2122 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
2123 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
2124 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
2125 mkdir
-p "$_dest_dir"
2126 for table
in "$acpi_table_dir"/*.aml
; do
2127 dinfo
" Adding ACPI table: $table"
2128 $DRACUT_CP "$table" "$_dest_dir"
2129 create_early_cpio
="yes"
2133 dinfo
"*** Store current command line parameters ***"
2134 if ! (echo "$PARMS_TO_STORE" > "$initdir"/lib
/dracut
/build-parameter.txt
); then
2135 dfatal
"Could not store the current command line parameters"
2139 if [[ $hostonly_cmdline == "yes" ]]; then
2140 unset _stored_cmdline
2141 if [[ -d $initdir/etc
/cmdline.d
]]; then
2142 dinfo
"Stored kernel commandline:"
2143 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2144 [ -e "$conf" ] ||
continue
2145 dinfo
"$(< "$conf")"
2149 if ! [[ $_stored_cmdline ]]; then
2150 dinfo
"No dracut internal kernel commandline stored in the initramfs"
2154 if [[ $kernel_only != yes ]]; then
2155 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
2156 for _dir
in $libdirs; do
2157 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
2158 [[ -e "$_f" ]] ||
continue
2159 inst_libdir_file
"libgcc_s.so*"
2164 # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
2165 if [[ $DRACUT_FIPS_MODE ]]; then
2166 for _dir
in $libdirs; do
2167 for _f
in "$dracutsysrootdir$_dir/libcrypto.so"*; do
2168 [[ -e "$_f" ]] ||
continue
2169 inst_libdir_file
-o "libssl.so*"
2176 if [[ $kernel_only != yes ]]; then
2177 # make sure that library links are correct and up to date
2178 for f
in "$dracutsysrootdir"/etc
/ld.so.conf
"$dracutsysrootdir"/etc
/ld.so.conf.d
/*; do
2179 [[ -f $f ]] && inst_simple
"${f#$dracutsysrootdir}"
2181 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc
/ld.so.conf
; then
2182 if [[ $EUID = 0 ]]; then
2183 derror
"ldconfig exited ungracefully"
2185 derror
"ldconfig might need uid=0 (root) for chroot()"
2190 if dracut_module_included
"squash"; then
2191 readonly squash_dir
="$initdir/squash/root"
2192 readonly squash_img
="$initdir/squash-root.img"
2193 mkdir
-p "$squash_dir"
2194 dinfo
"*** Install squash loader ***"
2195 DRACUT_SQUASH_POST_INST
=1 module_install
"squash"
2198 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2199 dinfo
"*** Stripping files ***"
2200 find "$initdir" -type f \
2201 -executable -not -path '*/lib/modules/*.ko' -print0 \
2202 |
xargs -r -0 $strip_cmd -g -p 2> /dev
/null
2204 # strip kernel modules, but do not touch signed modules
2205 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
2206 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
2207 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
2208 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
2209 done |
xargs -r -0 $strip_cmd -g -p
2210 dinfo
"*** Stripping files done ***"
2213 if dracut_module_included
"squash"; then
2214 dinfo
"*** Squashing the files inside the initramfs ***"
2215 declare squash_compress_arg
2216 # shellcheck disable=SC2086
2217 if [[ $compress ]]; then
2218 if ! mksquashfs
/dev
/null
"$DRACUT_TMPDIR"/.squash-test.img
-no-progress -comp $compress &> /dev
/null
; then
2219 dwarn
"mksquashfs doesn't support compressor '$compress', failing back to default compressor."
2221 squash_compress_arg
="$compress"
2225 # shellcheck disable=SC2086
2226 if ! mksquashfs
"$squash_dir" "$squash_img" \
2227 -no-xattrs -no-exports -noappend -no-recovery -always-use-fragments \
2228 -no-progress ${squash_compress_arg:+-comp $squash_compress_arg} 1> /dev
/null
; then
2229 dfatal
"dracut: Failed making squash image"
2233 rm -rf "$squash_dir"
2234 dinfo
"*** Squashing the files inside the initramfs done ***"
2236 # Skip initramfs compress
2240 dinfo
"*** Creating image file '$outfile' ***"
2242 if [[ $uefi = yes ]]; then
2243 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
2244 mkdir
-p "$uefi_outdir"
2247 if [[ $DRACUT_REPRODUCIBLE ]]; then
2248 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2249 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2251 if [[ "$(cpio --help)" == *--reproducible* ]]; then
2254 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
2258 [[ "$EUID" != 0 ]] && cpio_owner
="0:0"
2260 if [[ $create_early_cpio = yes ]]; then
2261 echo 1 > "$early_cpio_dir/d/early_cpio"
2263 if [[ $DRACUT_REPRODUCIBLE ]]; then
2264 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2265 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2268 # The microcode blob is _before_ the initramfs blob, not after
2271 cd "$early_cpio_dir/d"
2272 find .
-print0 |
sort -z \
2273 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
2274 ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
2276 dfatal
"dracut: creation of $outfile failed"
2281 if ! [[ $compress ]]; then
2282 # check all known compressors, if none specified
2283 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
2284 command -v "$i" &> /dev
/null ||
continue
2288 if [[ $compress = cat ]]; then
2289 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
2293 # choose the right arguments for the compressor
2296 if [[ "$compress" = lbzip2
]] ||
command -v "$DRACUT_COMPRESS_LBZIP2" &> /dev
/null
; then
2297 compress="$DRACUT_COMPRESS_LBZIP2 -9"
2299 compress="$DRACUT_COMPRESS_BZIP2 -9"
2303 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
2306 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
2309 if [[ "$compress" = pigz
]] ||
command -v "$DRACUT_COMPRESS_PIGZ" &> /dev
/null
; then
2310 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
2311 elif command -v gzip &> /dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
2312 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
2314 compress="$DRACUT_COMPRESS_GZIP -n -9"
2318 compress="$DRACUT_COMPRESS_LZOP -9"
2321 compress="$DRACUT_COMPRESS_LZ4 -l -9"
2324 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
2331 find .
-print0 |
sort -z \
2332 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet \
2333 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
2335 dfatal
"dracut: creation of $outfile failed"
2339 # shellcheck disable=SC2154
2340 if ((maxloglvl
>= 5)) && ((verbosity_mod_l
>= 0)); then
2341 if [[ $allowlocal ]]; then
2342 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug
2344 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img" | ddebug
2350 if [[ $uefi = yes ]]; then
2351 if [[ $kernel_cmdline ]]; then
2352 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
2353 elif [[ $hostonly_cmdline = yes ]] && [ -d "$initdir/etc/cmdline.d" ]; then
2354 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2355 [ -e "$conf" ] ||
continue
2356 printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
2360 if [[ $kernel_cmdline ]] ||
[[ $hostonly_cmdline = yes && -d "$initdir/etc/cmdline.d" ]]; then
2361 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
2362 dinfo
"Using UEFI kernel cmdline:"
2363 dinfo
"$(tr -d '\000' < "$uefi_outdir/cmdline.txt
")"
2364 uefi_cmdline
="${uefi_outdir}/cmdline.txt"
2369 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
2370 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
2371 if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then
2372 uefi_splash_image
="${dracutsysrootdir}${uefi_splash_image}"
2374 unset uefi_splash_image
2378 ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \
2379 ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \
2380 ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \
2381 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x2000000 \
2382 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
=0x3000000 \
2383 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
2384 if [[ -n "${uefi_secureboot_key}" && -n "${uefi_secureboot_cert}" ]]; then
2386 --key "${uefi_secureboot_key}" \
2387 --cert "${uefi_secureboot_cert}" \
2388 --output "$outfile" "${uefi_outdir}/linux.efi"; then
2389 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
2391 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2395 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2396 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2401 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2405 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2406 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2409 dfatal
"dracut: creation of $outfile failed"
2414 command -v restorecon
&> /dev
/null
&& restorecon
-- "$outfile"
2417 btrfs filesystem show
"$1" |
sed -n '1s/^.*uuid: //p'
2420 freeze_ok_for_btrfs
() {
2421 local mnt uuid1 uuid2
2422 # If the output file is on btrfs, we need to make sure that it's
2423 # not on a subvolume of the same file system as the root FS.
2424 # Otherwise, fsfreeze() might freeze the entire system.
2425 # This is most conveniently checked by comparing the FS uuid.
2427 [[ "$(stat -f -c %T -- "/")" == "btrfs" ]] ||
return 0
2428 mnt
=$
(stat
-c %m
-- "$1")
2429 uuid1
=$
(btrfs_uuid
"$mnt")
2430 uuid2
=$
(btrfs_uuid
"/")
2431 [[ "$uuid1" && "$uuid2" && "$uuid1" != "$uuid2" ]]
2434 freeze_ok_for_fstype
() {
2438 [[ "$(stat -c %m -- "$outfile")" == "/" ]] && return 1
2439 fstype
=$
(stat
-f -c %T
-- "$outfile")
2445 freeze_ok_for_btrfs
"$outfile"
2453 # We sync/fsfreeze only if we're operating on a live booted system.
2454 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2455 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2456 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2457 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2458 if [[ -d $dracutsysrootdir/run
/systemd
/system
]]; then
2459 if ! sync
"$outfile" 2> /dev
/null
; then
2460 dinfo
"dracut: sync operation on newly created initramfs $outfile failed"
2464 # use fsfreeze only if we're not writing to /
2465 if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype
"$outfile"; then
2466 FSFROZEN
="$(dirname "$outfile")"
2467 if ! (fsfreeze
-f "${FSFROZEN}" 2> /dev
/null
&& fsfreeze
-u "${FSFROZEN}" 2> /dev
/null
); then
2468 dinfo
"dracut: warning: could not fsfreeze $(dirname "$outfile")"