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
276 host_devs
+=( "$_dev" )
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.
300 if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
301 printf '\ndracut: WARNING: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
302 printf 'dracut: WARNING: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
308 local suffix
=$1; shift
313 for i
in "$d/"*"$suffix"; do
314 if [[ -e "$i" ]]; then
315 printf "%s\n" "${i##*/}"
321 for f
in "${files[@]}"; do
323 if [[ -e "$d/$f" ]]; then
324 printf "%s\n" "$d/$f"
334 # Workaround -i, --include taking 2 arguments
337 if [[ $i == "-i" ]] ||
[[ $i == "--include" ]]; then
338 newat
+=("++include") # Replace --include by ++include
343 set -- "${newat[@]}" # Set new $@
345 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
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 \
440 # shellcheck disable=SC2181
441 if (( $?
!= 0 )); then
451 rearrange_params
"$@"
454 # parse command line args to check if '--rebuild' option is present
459 if [ "$1" == "--" ]; then
462 if [ "$1" == "--rebuild" ]; then
465 if [ ! -e "$rebuild_file" ]; then
466 echo "Image file '$rebuild_file', for rebuild, does not exist!"
469 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
475 # get output file name and kernel version from command line arguments
481 if ! [[ ${outfile+x} ]]; then
483 elif ! [[ ${kernel+x} ]]; then
486 printf "\nUnknown arguments: %s\n\n" "$*" >&2
494 # extract input image file provided with rebuild option to get previous parameters, if any
495 if [[ $append_args_l == "yes" ]]; then
498 # determine resultant file
499 if ! [[ $outfile ]]; then
500 outfile
=$rebuild_file
503 if ! rebuild_param
=$
(lsinitrd
"$rebuild_file" '*lib/dracut/build-parameter.txt'); then
504 echo "Image '$rebuild_file' has no rebuild information stored"
508 # prepend previous parameters to current command line args
509 if [[ $rebuild_param ]]; then
510 TEMP
="$rebuild_param $TEMP"
512 rearrange_params
"$@"
522 if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
523 PARMS_TO_STORE
+=" $1";
526 --kver) kernel
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
527 -a|
--add) add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
528 --force-add) force_add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
529 --add-drivers) add_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
530 --force-drivers) force_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
531 --omit-drivers) omit_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
532 -m|
--modules) dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
533 -o|
--omit) omit_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
534 -d|
--drivers) drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
535 --filesystems) filesystems_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
536 -I|
--install) install_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
537 --install-optional) install_optional_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
538 --fwdir) fw_dir_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
539 --libdirs) libdirs_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
540 --fscks) fscks_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
541 --add-fstab) add_fstab_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
542 --mount) fstab_lines
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
543 --add-device|
--device) add_device_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
544 --kernel-cmdline) kernel_cmdline_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
545 --nofscks) nofscks_l
="yes";;
546 --ro-mnt) ro_mnt_l
="yes";;
547 -k|
--kmoddir) drivers_dir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
548 -c|
--conf) conffile
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
549 --confdir) confdir
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
550 --tmpdir) tmpdir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
551 -r|
--sysroot) sysroot_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
552 -L|
--stdlog) stdloglvl_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
553 --compress) compress_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
554 --prefix) prefix_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
555 --loginstall) loginstall_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
556 --rebuild) if [[ $rebuild_file == "$outfile" ]]; then
561 -f|
--force) force
=yes;;
562 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
563 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
565 print_cmdline
="yes"; hostonly_l
="yes"; kernel_only
="yes"; no_kernel
="yes";;
567 early_microcode_l
="yes";;
568 --no-early-microcode)
569 early_microcode_l
="no";;
570 --strip) do_strip_l
="yes";;
571 --nostrip) do_strip_l
="no";;
572 --hardlink) do_hardlink_l
="yes";;
573 --nohardlink) do_hardlink_l
="no";;
574 --noprefix) prefix_l
="/";;
575 --mdadmconf) mdadmconf_l
="yes";;
576 --nomdadmconf) mdadmconf_l
="no";;
577 --lvmconf) lvmconf_l
="yes";;
578 --nolvmconf) lvmconf_l
="no";;
579 --debug) debug
="yes";;
580 --profile) profile
="yes";;
581 --sshkey) sshkey
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
582 --logfile) logfile_l
="$2"; shift;;
583 -v|
--verbose) ((verbosity_mod_l
++));;
584 -q|
--quiet) ((verbosity_mod_l--
));;
587 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
588 && dracutbasedir
="$(readlink -f "${0%/*}")"
590 -H|
--hostonly|
--host-only)
592 -N|
--no-hostonly|
--no-host-only)
595 hostonly_mode_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
597 hostonly_cmdline_l
="yes" ;;
599 i18n_install_all_l
="no" ;;
601 hostonly_nics_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
603 i18n_install_all_l
="yes" ;;
604 --no-hostonly-cmdline)
605 hostonly_cmdline_l
="no" ;;
606 --no-hostonly-default-device)
607 hostonly_default_device
="no" ;;
609 persistent_policy_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
610 --fstab) use_fstab_l
="yes" ;;
611 -h|
--help) long_usage
; exit 1 ;;
612 --bzip2) compress_l
="bzip2";;
613 --lzma) compress_l
="lzma";;
614 --xz) compress_l
="xz";;
615 --lzo) compress_l
="lzo";;
616 --lz4) compress_l
="lz4";;
617 --zstd) compress_l
="zstd";;
618 --no-compress) _no_compress_l
="cat";;
619 --gzip) compress_l
="gzip";;
620 --list-modules) do_list
="yes";;
625 --printsize) printsize
="yes";;
626 --regenerate-all) regenerate_all
="yes";;
627 --noimageifnotneeded) noimageifnotneeded
="yes";;
628 --reproducible) reproducible_l
="yes";;
629 --no-reproducible) reproducible_l
="no";;
630 --uefi) uefi_l
="yes";;
631 --no-uefi) uefi_l
="no";;
633 uefi_stub_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
635 uefi_splash_image_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
637 kernel_image_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
640 --version) long_version
; exit 1 ;;
643 *) # should not even reach this point
644 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
649 # getopt cannot handle multiple arguments, so just handle "-I,--include"
650 # the old fashioned way
653 if [ "${1%%=*}" == "++include" ]; then
655 include_target
+=("$3")
656 PARMS_TO_STORE
+=" --include '$2' '$3'"
662 [[ $sysroot_l ]] && dracutsysrootdir
="$sysroot_l"
664 if [[ $regenerate_all == "yes" ]]; then
666 if [[ $kernel ]]; then
667 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
671 if [[ $outfile ]]; then
672 printf -- "--regenerate-all cannot be called with a image file\n" >&2
676 ((len
=${#dracut_args[@]}))
677 for ((i
=0; i
< len
; i
++)); do
678 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
679 unset "dracut_args[$i]"
682 cd "$dracutsysrootdir"/lib
/modules ||
exit 1
684 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
685 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
691 if ! [[ $kernel ]]; then
699 unset LD_LIBRARY_PATH
703 export DRACUT_LOG_LEVEL
=warning
705 export DRACUT_LOG_LEVEL
=debug
706 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
711 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
716 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
718 # if we were not passed a config file, try the default one
719 if [[ ! -f $conffile ]]; then
720 if [[ $allowlocal ]]; then
721 conffile
="$dracutbasedir/dracut.conf"
723 conffile
="$dracutsysrootdir/etc/dracut.conf"
727 if [[ ! -d $confdir ]]; then
728 if [[ $allowlocal ]]; then
729 confdir
="$dracutbasedir/dracut.conf.d"
731 confdir
="$dracutsysrootdir/etc/dracut.conf.d"
735 # source our config file
736 if [[ -f $conffile ]]; then
737 check_conf_file
"$conffile"
738 # shellcheck disable=SC1090
742 # source our config dir
743 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
745 # shellcheck disable=SC1090
746 [[ -e $f ]] && .
"$f"
749 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
751 for i
in $DRACUT_PATH; do
753 if [ -L "$dracutsysrootdir$i" ]; then
754 rl
=$
(readlink
-f "$dracutsysrootdir$i")
756 rl
="${rl#$dracutsysrootdir}"
757 if [[ "$NPATH" != *:$rl* ]] ; then
761 [[ -z "$dracutsysrootdir" ]] && export PATH
="${NPATH#:}"
764 export SYSTEMCTL
=${SYSTEMCTL:-systemctl}
766 # these options add to the stuff in the config file
767 (( ${#add_dracutmodules_l[@]} )) && add_dracutmodules
+=" ${add_dracutmodules_l[*]} "
768 (( ${#force_add_dracutmodules_l[@]} )) && force_add_dracutmodules
+=" ${force_add_dracutmodules_l[*]} "
769 (( ${#fscks_l[@]} )) && fscks
+=" ${fscks_l[*]} "
770 (( ${#add_fstab_l[@]} )) && add_fstab
+=" ${add_fstab_l[*]} "
771 (( ${#install_items_l[@]} )) && install_items
+=" ${install_items_l[*]} "
772 (( ${#install_optional_items_l[@]} )) && install_optional_items
+=" ${install_optional_items_l[*]} "
773 (( ${#hostonly_nics_l[@]} )) && hostonly_nics
+=" ${hostonly_nics_l[*]} "
775 # these options override the stuff in the config file
776 (( ${#dracutmodules_l[@]} )) && dracutmodules
="${dracutmodules_l[*]}"
777 (( ${#omit_dracutmodules_l[@]} )) && omit_dracutmodules
="${omit_dracutmodules_l[*]}"
778 (( ${#filesystems_l[@]} )) && filesystems
="${filesystems_l[*]}"
779 (( ${#fw_dir_l[@]} )) && fw_dir
="${fw_dir_l[*]}"
780 (( ${#libdirs_l[@]} ))&& libdirs
="${libdirs_l[*]}"
782 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
783 [[ ! $stdloglvl ]] && stdloglvl
=4
784 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
785 ((stdloglvl
> 6)) && stdloglvl
=6
786 ((stdloglvl
< 0)) && stdloglvl
=0
788 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
789 [[ $do_strip_l ]] && do_strip
=$do_strip_l
790 [[ $do_strip ]] || do_strip
=yes
791 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
792 [[ $do_hardlink ]] || do_hardlink
=yes
793 [[ $prefix_l ]] && prefix
=$prefix_l
794 [[ $prefix = "/" ]] && unset prefix
795 [[ $hostonly_l ]] && hostonly
=$hostonly_l
796 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
797 [[ $hostonly_mode_l ]] && hostonly_mode
=$hostonly_mode_l
798 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
799 # shellcheck disable=SC2034
800 [[ $i18n_install_all_l ]] && i18n_install_all
=$i18n_install_all_l
801 # shellcheck disable=SC2034
802 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
803 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
804 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
805 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
806 [[ $dracutbasedir ]] || dracutbasedir
="$dracutsysrootdir"/usr
/lib
/dracut
807 [[ $fw_dir ]] || fw_dir
="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
808 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
809 [[ $tmpdir ]] || tmpdir
="$TMPDIR"
810 [[ $tmpdir ]] || tmpdir
="$dracutsysrootdir"/var
/tmp
811 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
812 [[ $compress_l ]] && compress=$compress_l
813 [[ $show_modules_l ]] && show_modules
=$show_modules_l
814 [[ $nofscks_l ]] && nofscks
="yes"
815 [[ $ro_mnt_l ]] && ro_mnt
="yes"
816 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
817 [[ $early_microcode ]] || early_microcode
=yes
818 [[ $early_microcode_image_dir ]] || early_microcode_image_dir
=('/boot')
819 [[ $early_microcode_image_name ]] || \
820 early_microcode_image_name
=('intel-uc.img' 'intel-ucode.img' 'amd-uc.img' 'amd-ucode.img' 'early_ucode.cpio' 'microcode.cpio')
821 [[ $logfile_l ]] && logfile
="$logfile_l"
822 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
823 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
824 [[ $uefi_l ]] && uefi
=$uefi_l
825 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
826 [[ $uefi_splash_image_l ]] && uefi_splash_image
="$uefi_splash_image_l"
827 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
828 [[ $machine_id_l ]] && machine_id
="$machine_id_l"
830 if ! [[ $outfile ]]; then
831 if [[ $machine_id != "no" ]]; then
832 [[ -f "$dracutsysrootdir"/etc
/machine-id
]] && read -r MACHINE_ID
< "$dracutsysrootdir"/etc
/machine-id
835 if [[ $uefi == "yes" ]]; then
836 # shellcheck disable=SC2154
837 if [[ -n "$uefi_secureboot_key" && -z "$uefi_secureboot_cert" ]] ||
[[ -z $uefi_secureboot_key && -n $uefi_secureboot_cert ]]; then
838 dfatal
"Need 'uefi_secureboot_key' and 'uefi_secureboot_cert' both to be set."
842 if [[ -n "$uefi_secureboot_key" && -n "$uefi_secureboot_cert" ]] && ! command -v sbsign
&>/dev
/null
; then
843 dfatal
"Need 'sbsign' to create a signed UEFI executable"
847 BUILD_ID
=$
(cat "$dracutsysrootdir"/etc
/os-release
"$dracutsysrootdir"/usr
/lib
/os-release \
848 |
while read -r line ||
[[ $line ]]; do \
849 [[ $line =~ BUILD_ID\
=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
851 if [[ -z $dracutsysrootdir ]]; then
852 if [[ -d /efi
]] && mountpoint
-q /efi
; then
856 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
862 if [[ -d $dracutsysrootdir/boot
/efi
/EFI
]]; then
866 mkdir
-p "$dracutsysrootdir$efidir/Linux"
867 outfile
="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
869 if [[ -e $dracutsysrootdir/boot
/vmlinuz-
$kernel ]]; then
870 outfile
="/boot/initramfs-$kernel.img"
871 elif [[ $MACHINE_ID ]] && { [[ -d $dracutsysrootdir/boot
/${MACHINE_ID} ]] || [[ -L $dracutsysrootdir/boot/${MACHINE_ID} ]] ;}; then
872 outfile
="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
874 outfile
="$dracutsysrootdir/boot/initramfs-$kernel.img"
879 # eliminate IFS hackery when messing with fw_dir
880 export DRACUT_FIRMWARE_PATH
=${fw_dir// /:}
881 fw_dir
=${fw_dir//:/ }
883 # check for logfile and try to create one if it doesn't exist
884 if [[ -n "$logfile" ]]; then
885 if [[ ! -f "$logfile" ]]; then
886 if touch "$logfile"; then
887 printf "%s\n" "dracut: touch $logfile failed." >&2
892 # handle compression options.
893 DRACUT_COMPRESS_BZIP2
=${DRACUT_COMPRESS_BZIP2:-bzip2}
894 DRACUT_COMPRESS_LBZIP2
=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
895 DRACUT_COMPRESS_LZMA
=${DRACUT_COMPRESS_LZMA:-lzma}
896 DRACUT_COMPRESS_XZ
=${DRACUT_COMPRESS_XZ:-xz}
897 DRACUT_COMPRESS_GZIP
=${DRACUT_COMPRESS_GZIP:-gzip}
898 DRACUT_COMPRESS_PIGZ
=${DRACUT_COMPRESS_PIGZ:-pigz}
899 DRACUT_COMPRESS_LZOP
=${DRACUT_COMPRESS_LZOP:-lzop}
900 DRACUT_COMPRESS_ZSTD
=${DRACUT_COMPRESS_ZSTD:-zstd}
901 DRACUT_COMPRESS_LZ4
=${DRACUT_COMPRESS_LZ4:-lz4}
902 DRACUT_COMPRESS_CAT
=${DRACUT_COMPRESS_CAT:-cat}
904 if [[ $_no_compress_l = "$DRACUT_COMPRESS_CAT" ]]; then
905 compress="$DRACUT_COMPRESS_CAT"
908 if ! [[ $compress ]]; then
909 # check all known compressors, if none specified
910 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
911 command -v "$i" &>/dev
/null ||
continue
915 if [[ $compress = cat ]]; then
916 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
920 # choose the right arguments for the compressor
923 if [[ "$compress" = lbzip2
]] ||
command -v "$DRACUT_COMPRESS_LBZIP2" &>/dev
/null
; then
924 compress="$DRACUT_COMPRESS_LBZIP2 -9"
926 compress="$DRACUT_COMPRESS_BZIP2 -9"
930 compress="$DRACUT_COMPRESS_LZMA -9 -T0"
933 compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
936 if [[ "$compress" = pigz
]] ||
command -v "$DRACUT_COMPRESS_PIGZ" &>/dev
/null
; then
937 compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
938 elif command -v gzip &>/dev
/null
&& $DRACUT_COMPRESS_GZIP --help 2>&1 |
grep -q rsyncable
; then
939 compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
941 compress="$DRACUT_COMPRESS_GZIP -n -9"
945 compress="$DRACUT_COMPRESS_LZOP -9"
948 compress="$DRACUT_COMPRESS_LZ4 -l -9"
951 compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
955 [[ $hostonly = yes ]] && hostonly
="-h"
956 [[ $hostonly != "-h" ]] && unset hostonly
958 case $hostonly_mode in
960 [[ $hostonly ]] && hostonly_mode
="sloppy" ;;
962 if [[ ! $hostonly ]]; then
967 printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
971 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
973 case "${drivers_dir}" in
974 ''|
*lib
/modules
/${kernel}|
*lib
/modules
/${kernel}/) ;;
976 [[ "$DRACUT_KMODDIR_OVERRIDE" ]] ||
{
977 printf "%s\n" "dracut: -k/--kmoddir path must contain \"lib/modules\" as a parent of your kernel module directory,"
978 printf "%s\n" "dracut: or modules may not be placed in the correct location inside the initramfs."
979 printf "%s\n" "dracut: was given: ${drivers_dir}"
980 printf "%s\n" "dracut: expected: $(dirname "${drivers_dir}")/lib/modules/${kernel}"
981 printf "%s\n" "dracut: Please move your modules into the correct directory structure and pass the new location,"
982 printf "%s\n" "dracut: or set DRACUT_KMODDIR_OVERRIDE=1 to ignore this check."
988 readonly TMPDIR
="$(realpath -e "$tmpdir")"
989 [ -d "$TMPDIR" ] ||
{
990 printf "%s\n" "dracut: Invalid tmpdir '$tmpdir'." >&2
994 if findmnt
--raw -n --target "$tmpdir" --output=options |
grep -q noexec
; then
995 [[ $debug == yes ]] && printf "%s\n" "dracut: Tmpdir '$tmpdir' is mounted with 'noexec'."
999 readonly DRACUT_TMPDIR
="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
1000 [ -d "$DRACUT_TMPDIR" ] ||
{
1001 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2
1005 # clean up after ourselves no matter how we die.
1008 [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; };
1009 if [[ ${FSFROZEN} ]]; then
1010 fsfreeze -u "${FSFROZEN}"
1015 # clean up after ourselves no matter how we die.
1016 trap 'exit 1;' SIGINT
1018 readonly initdir
="${DRACUT_TMPDIR}/initramfs"
1021 # shellcheck disable=SC2154
1022 if [[ $early_microcode = yes ]] ||
{ [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ;}; then
1023 readonly early_cpio_dir
="${DRACUT_TMPDIR}/earlycpio"
1024 mkdir
"$early_cpio_dir"
1027 [[ "$dracutsysrootdir" ]] ||
[[ "$noexec" ]] ||
export DRACUT_RESOLVE_LAZY
="1"
1029 if [[ $print_cmdline ]]; then
1036 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
1037 # shellcheck source=./dracut-version.sh
1038 .
"$dracutbasedir"/dracut-version.sh
1041 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
1042 # shellcheck source=./dracut-init.sh
1043 .
"$dracutbasedir"/dracut-init.sh
1045 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
1046 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
1047 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
1051 # shellcheck disable=SC2154
1052 if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
1053 printf "%s\n" "dracut: Cannot find module directory $srcmods" >&2
1054 printf "%s\n" "dracut: and --no-kernel was not specified" >&2
1058 if ! [[ $print_cmdline ]]; then
1059 inst
"$DRACUT_TESTBIN"
1060 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &>/dev
/null
; then
1061 unset DRACUT_RESOLVE_LAZY
1062 export DRACUT_RESOLVE_DEPS
=1
1064 rm -fr -- "${initdir:?}"/*
1067 dracutfunctions
=$dracutbasedir/dracut-functions.sh
1068 export dracutfunctions
1070 (( ${#drivers_l[@]} )) && drivers
="${drivers_l[*]}"
1071 drivers
=${drivers/-/_}
1073 (( ${#add_drivers_l[@]} )) && add_drivers
+=" ${add_drivers_l[*]} "
1074 add_drivers
=${add_drivers/-/_}
1076 (( ${#force_drivers_l[@]} )) && force_drivers
+=" ${force_drivers_l[*]} "
1077 force_drivers
=${force_drivers/-/_}
1079 (( ${#omit_drivers_l[@]} )) && omit_drivers
+=" ${omit_drivers_l[*]} "
1080 omit_drivers
=${omit_drivers/-/_}
1082 (( ${#kernel_cmdline_l[@]} )) && kernel_cmdline
+=" ${kernel_cmdline_l[*]} "
1084 omit_drivers_corrected
=""
1085 for d
in $omit_drivers; do
1086 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
1087 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
1088 omit_drivers_corrected
+="$d|"
1090 omit_drivers
="${omit_drivers_corrected%|}"
1091 unset omit_drivers_corrected
1093 # prepare args for logging
1094 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
1095 [[ "${dracut_args[$i]}" == *\
* ]] && \
1096 dracut_args
[$i]="\"${dracut_args[$i]}\""
1100 dinfo
"Executing: $dracut_cmd ${dracut_args[*]}"
1102 [[ $do_list = yes ]] && {
1103 for mod
in "$dracutbasedir"/modules.d
/*; do
1104 [[ -d $mod ]] ||
continue;
1105 [[ -e $mod/install ||
-e $mod/installkernel || \
1106 -e $mod/module-setup.sh
]] ||
continue
1107 printf "%s\n" "${mod##*/??}"
1112 # This is kinda legacy -- eventually it should go away.
1113 case $dracutmodules in
1114 ""|auto
) dracutmodules
="all" ;;
1117 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1120 [[ -d $dracutsysrootdir$systemdutildir ]] \
1121 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
1123 if ! [[ -d $dracutsysrootdir$systemdutildir ]]; then
1124 [[ -e $dracutsysrootdir/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/lib
/systemd
1125 [[ -e $dracutsysrootdir/usr
/lib
/systemd
/systemd-udevd
]] && systemdutildir
=/usr
/lib
/systemd
1128 [[ -d $dracutsysrootdir$systemdutilconfdir ]] \
1129 || systemdutilconfdir
=$
(pkg-config systemd
--variable=systemdutilconfdir
2>/dev
/null
)
1131 [[ -d $dracutsysrootdir$systemdutilconfdir ]] || systemdutilconfdir
=/etc
/systemd
1133 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
1134 if ! [[ -f $srcmods/modules.dep
]]; then
1135 if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then
1136 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
1139 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1141 elif ! ( command -v gzip &>/dev
/null
&& command -v xz
&>/dev
/null
); then
1142 read -r _mod
< "$srcmods"/modules.dep
1144 if [[ -f $srcmods/"$_mod" ]]; then
1145 # Check, if kernel modules are compressed, and if we can uncompress them
1147 *.ko.gz
) kcompress
=gzip;;
1148 *.ko.xz
) kcompress
=xz
;;
1150 if [[ $kcompress ]]; then
1151 if ! command -v "$kcompress" &>/dev
/null
; then
1152 dfatal
"Kernel modules are compressed with $kcompress, but $kcompress is not available."
1160 if [[ ! $print_cmdline ]]; then
1161 if [[ -f $outfile && ! $force ]]; then
1162 dfatal
"Will not override existing initramfs ($outfile) without --force"
1166 outdir
=${outfile%/*}
1167 [[ $outdir ]] || outdir
="/"
1169 if [[ ! -d "$outdir" ]]; then
1170 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1172 elif [[ ! -w "$outdir" ]]; then
1173 dfatal
"No permission to write to $outdir."
1175 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1176 dfatal
"No permission to write $outfile."
1180 if [[ $loginstall ]]; then
1181 if ! mkdir
-p "$loginstall"; then
1182 dfatal
"Could not create directory to log installed files to '$loginstall'."
1185 loginstall
=$
(readlink
-f "$loginstall")
1188 if [[ $uefi = yes ]]; then
1189 if ! command -v objcopy
&>/dev
/null
; then
1190 dfatal
"Need 'objcopy' to create a UEFI executable"
1193 unset EFI_MACHINE_TYPE_NAME
1196 EFI_MACHINE_TYPE_NAME
=x64
;;
1198 EFI_MACHINE_TYPE_NAME
=ia32
;;
1200 dfatal
"Architecture '$(uname -m)' not supported to create a UEFI executable"
1205 if ! [[ -s $uefi_stub ]]; then
1207 "$dracutsysrootdir${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1208 "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1209 [[ -s $uefi_stub ]] ||
continue
1213 if ! [[ -s $uefi_stub ]]; then
1214 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1218 if ! [[ $kernel_image ]]; then
1219 for kernel_image
in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
1220 [[ -s "$kernel_image" ]] ||
continue
1224 if ! [[ -s $kernel_image ]]; then
1225 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1231 if [[ $acpi_override = yes ]] && ! ( check_kernel_config CONFIG_ACPI_TABLE_UPGRADE || check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
); then
1232 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y or CONFIG_ACPI_TABLE_UPGRADE!=y"
1236 if [[ $early_microcode = yes ]]; then
1237 if [[ $hostonly ]]; then
1238 if [[ $
(get_cpu_vendor
) == "AMD" ]]; then
1239 check_kernel_config CONFIG_MICROCODE_AMD ||
unset early_microcode
1240 elif [[ $
(get_cpu_vendor
) == "Intel" ]]; then
1241 check_kernel_config CONFIG_MICROCODE_INTEL ||
unset early_microcode
1243 unset early_microcode
1246 ! check_kernel_config CONFIG_MICROCODE_AMD \
1247 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1248 && unset early_microcode
1250 # Do not complain on non-x86 architectures as it makes no sense
1253 [[ $early_microcode != yes ]] \
1254 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1260 # Need to be able to have non-root users read stuff (rpcbind etc)
1261 chmod 755 "$initdir"
1263 if [[ $hostonly ]]; then
1264 for i
in /sys
/proc
/run
/dev
; do
1265 if ! findmnt
--target "$i" &>/dev
/null
; then
1266 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1272 declare -A host_fs_types
1274 for line
in "${fstab_lines[@]}"; do
1275 # shellcheck disable=SC2086
1281 dev
=$
(blkid
-l -t "UUID=${dev#UUID=}" -o device
)
1284 dev
=$
(blkid
-l -t "LABEL=${dev#LABEL=}" -o device
)
1287 dev
=$
(blkid
-l -t "PARTUUID=${dev#PARTUUID=}" -o device
)
1290 dev
=$
(blkid
-l -t "PARTLABEL=${dev#PARTLABEL=}" -o device
)
1293 [ -z "$dev" ] && dwarn
"Bad fstab entry $*" && continue
1294 if [[ "$3" == btrfs
]]; then
1295 for i
in $
(btrfs_devs
"$2"); do
1299 push_host_devs
"$dev"
1300 host_fs_types
["$dev"]="$3"
1303 for f
in $add_fstab; do
1304 [[ -e $f ]] ||
continue
1305 while read -r dev rest ||
[ -n "$dev" ]; do
1306 push_host_devs
"$dev"
1310 for dev
in $add_device; do
1311 push_host_devs
"$dev"
1314 if (( ${#add_device_l[@]} )); then
1315 add_device
+=" ${add_device_l[*]} "
1316 push_host_devs
"${add_device_l[@]}"
1319 if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
1320 # in hostonly mode, determine all devices, which have to be accessed
1321 # and examine them for filesystem types
1340 mp
=$
(readlink
-f "$dracutsysrootdir$mp")
1341 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
1342 _dev
=$
(find_block_device
"$mp")
1343 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1344 [[ -b $_bdev ]] && _dev
=$_bdev
1345 [[ "$mp" == "/" ]] && root_devs
+=("$_dev")
1346 push_host_devs
"$_dev"
1347 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1348 for i
in $
(btrfs_devs
"$mp"); do
1349 [[ "$mp" == "/" ]] && root_devs
+=("$i")
1355 # TODO - with sysroot, /proc/swaps is not relevant
1356 if [[ -f /proc
/swaps
]] && [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1357 while read -r dev
type rest ||
[ -n "$dev" ]; do
1358 [[ -b $dev ]] ||
continue
1359 [[ "$type" == "partition" ]] ||
continue
1361 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1362 [[ "$_d" == \
#* ]] && continue
1363 [[ $_d ]] ||
continue
1364 [[ $_t != "swap" ]] && continue
1365 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1366 [[ "$_o" == *noauto
* ]] && continue
1367 _d
=$
(expand_persistent_dev
"$_d")
1368 [[ "$_d" -ef "$dev" ]] ||
continue
1370 if [[ -f $dracutsysrootdir/etc
/crypttab
]]; then
1371 while read -r _mapper _ _p _o ||
[ -n "$_mapper" ]; do
1372 [[ $_mapper = \
#* ]] && continue
1373 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1374 [[ "$_o" ]] || _o
="$_p"
1375 # skip entries with password files
1376 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1378 [[ $_o == *swap
* ]] && continue 2
1379 done < "$dracutsysrootdir"/etc
/crypttab
1382 _dev
="$(readlink -f "$dev")"
1383 push_host_devs
"$_dev"
1384 swap_devs
+=("$_dev")
1386 done < "$dracutsysrootdir"/etc
/fstab
1390 # collect all "x-initrd.mount" entries from /etc/fstab
1391 if [[ -f $dracutsysrootdir/etc
/fstab
]]; then
1392 while read -r _d _m _t _o _ ||
[ -n "$_d" ]; do
1393 [[ "$_d" == \
#* ]] && continue
1394 [[ $_d ]] ||
continue
1395 [[ "$_o" != *x-initrd.mount
* ]] && continue
1396 _dev
=$
(expand_persistent_dev
"$_d")
1397 _dev
="$(readlink -f "$_dev")"
1398 [[ -b $_dev ]] ||
continue
1400 push_host_devs
"$_dev"
1401 if [[ "$_t" == btrfs
]]; then
1402 for i
in $
(btrfs_devs
"$_m"); do
1406 done < "$dracutsysrootdir"/etc
/fstab
1415 if [[ -b /dev
/block
/$1 ]]; then
1416 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1419 if [[ -b $1 ]]; then
1420 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1423 if fstype
=$
(find_dev_fstype
"$1"); then
1424 host_fs_types
["$1"]="$fstype"
1430 for dev
in "${host_devs[@]}"; do
1432 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1435 for dev
in "${!host_fs_types[@]}"; do
1436 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
1437 rootopts
=$
(find_dev_fsopts
"$dev")
1438 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1439 journaldev
=$
(fs_get_option
"$rootopts" "jdev")
1440 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1441 journaldev
=$
(fs_get_option
"$rootopts" "logdev")
1443 if [[ $journaldev ]]; then
1444 dev
="$(readlink -f "$dev")"
1445 push_host_devs
"$dev"
1447 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1451 [[ -d $dracutsysrootdir$dbus ]] \
1452 || dbus
=$
(pkg-config dbus
--variable=dbus
2>/dev
/null
)
1454 [[ -d $dracutsysrootdir$dbus ]] || dbus
=/usr
/share
/dbus-1
1456 [[ -d $dracutsysrootdir$dbusconfdir ]] \
1457 || dbusconfdir
=$
(pkg-config dbus
--variable=dbusconfdir
2>/dev
/null
)
1459 [[ -d $dracutsysrootdir$dbusconfdir ]] || dbusconfdir
=/etc
/dbus-1
1461 [[ -d $dracutsysrootdir$dbusinterfaces ]] \
1462 || dbusinterfaces
=$
(pkg-config dbus
--variable=dbusinterfaces
2>/dev
/null
)
1464 [[ -d $dracutsysrootdir$dbusinterfaces ]] || dbusinterfaces
=${dbus}/interfaces
1466 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] \
1467 || dbusinterfacesconfdir
=$
(pkg-config dbus
--variable=dbusinterfacesconfdir
2>/dev
/null
)
1469 [[ -d $dracutsysrootdir$dbusinterfacesconfdir ]] || dbusinterfacesconfdir
=${dbusconfdir}/interfaces
1471 [[ -d $dracutsysrootdir$dbusservices ]] \
1472 || dbusservices
=$
(pkg-config dbus
--variable=dbusservices
2>/dev
/null
)
1474 [[ -d $dracutsysrootdir$dbusservices ]] || dbusservices
=${dbus}/services
1476 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] \
1477 || dbusservicesconfdir
=$
(pkg-config dbus
--variable=dbusservicesconfdir
2>/dev
/null
)
1479 [[ -d $dracutsysrootdir$dbusservicesconfdir ]] || dbusservicesconfdir
=${dbusconfdir}/services
1481 [[ -d $dracutsysrootdir$dbussession ]] \
1482 || dbussession
=$
(pkg-config dbus
--variable=dbussession
2>/dev
/null
)
1484 [[ -d $dracutsysrootdir$dbussession ]] || dbussession
=${dbus}/session.d
1486 [[ -d $dracutsysrootdir$dbussessionconfdir ]] \
1487 || dbussessionconfdir
=$
(pkg-config dbus
--variable=dbussessionconfdir
2>/dev
/null
)
1489 [[ -d $dracutsysrootdir$dbussessionconfdir ]] || dbussessionconfdir
=${dbusconfdir}/session.d
1491 [[ -d $dracutsysrootdir$dbussystem ]] \
1492 || dbussystem
=$
(pkg-config dbus
--variable=dbussystem
2>/dev
/null
)
1494 [[ -d $dracutsysrootdir$dbussystem ]] || dbussystem
=${dbus}/system.d
1496 [[ -d $dracutsysrootdir$dbussystemconfdir ]] \
1497 || dbussystemconfdir
=$
(pkg-config dbus
--variable=dbussystemconfdir
2>/dev
/null
)
1499 [[ -d $dracutsysrootdir$dbussystemconfdir ]] || dbussystemconfdir
=${dbusconfdir}/system.d
1501 [[ -d $dracutsysrootdir$dbussystemservices ]] \
1502 || dbussystemservices
=$
(pkg-config dbus
--variable=dbussystemservices
2>/dev
/null
)
1504 [[ -d $dracutsysrootdir$dbussystemservices ]] || dbussystemservices
=${dbus}/system-services
1506 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] \
1507 || dbussystemservicesconfdir
=$
(pkg-config dbus
--variable=dbussystemservicesconfdir
2>/dev
/null
)
1509 [[ -d $dracutsysrootdir$dbussystemservicesconfdir ]] || dbussystemservicesconfdir
=${dbusconfdir}/system-services
1511 [[ -d $dracutsysrootdir$udevdir ]] \
1512 || udevdir
="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1513 if ! [[ -d $dracutsysrootdir$udevdir ]]; then
1514 [[ -e $dracutsysrootdir/lib
/udev
/ata_id
]] && udevdir
=/lib
/udev
1515 [[ -e $dracutsysrootdir/usr
/lib
/udev
/ata_id
]] && udevdir
=/usr
/lib
/udev
1518 [[ -d $dracutsysrootdir$sysctl ]] \
1519 || sysctl
=$
(pkg-config systemd
--variable=sysctl
2>/dev
/null
)
1521 [[ -d $dracutsysrootdir$sysctl ]] || sysctl
=/usr
/lib
/sysctl.d
1523 [[ -d $dracutsysrootdir$sysctlconfdir ]] \
1524 || sysctlconfdir
=$
(pkg-config systemd
--variable=sysctlconfdir
2>/dev
/null
)
1526 [[ -d $dracutsysrootdir$sysctlconfdir ]] || sysctlconfdir
=/etc
/sysctl.d
1528 [[ -d $dracutsysrootdir$environment ]] \
1529 || environment
=$
(pkg-config systemd
--variable=environment
2>/dev
/null
)
1531 [[ -d $dracutsysrootdir$environment ]] || environment
=/usr
/lib
/environment.d
1533 [[ -d $dracutsysrootdir$environmentconfdir ]] \
1534 || environmentconfdir
=$
(pkg-config systemd
--variable=environmentconfdir
2>/dev
/null
)
1536 [[ -d $dracutsysrootdir$environmentconfdir ]] || environmentconfdir
=/etc
/environment.d
1538 [[ -d $dracutsysrootdir$systemdcatalog ]] \
1539 || systemdcatalog
=$
(pkg-config systemd
--variable=systemdcatalog
2>/dev
/null
)
1541 [[ -d $dracutsysrootdir$systemdcatalog ]] || systemdcatalog
=${systemdutildir}/catalog
1543 [[ -d $dracutsysrootdir$systemdnetwork ]] \
1544 || systemdnetwork
=$
(pkg-config systemd
--variable=systemdnetwork
2>/dev
/null
)
1546 [[ -d $dracutsysrootdir$systemdnetwork ]] || systemdnetwork
=${systemdutildir}/network
1548 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] \
1549 || systemdnetworkconfdir
=$
(pkg-config systemd
--variable=systemdnetworkconfdir
2>/dev
/null
)
1551 [[ -d $dracutsysrootdir$systemdnetworkconfdir ]] || systemdnetworkconfdir
=${systemdsystemconfdir}/network
1553 [[ -d $dracutsysrootdir$systemdntpunits ]] \
1554 || systemdntpunits
=$
(pkg-config systemd
--variable=systemdntpunits
2>/dev
/null
)
1556 [[ -d $dracutsysrootdir$systemdntpunits ]] || systemdntpunits
=${systemdutildir}/ntp-units.d
1558 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] \
1559 || systemdntpunitsconfdir
=$
(pkg-config systemd
--variable=systemdntpunitsconfdir
2>/dev
/null
)
1561 [[ -d $dracutsysrootdir$systemdntpunitsconfdir ]] || systemdntpunitsconfdir
=${systemdsystemconfdir}/ntp-units.d
1563 [[ -d $dracutsysrootdir$systemdportable ]] \
1564 || systemdportable
=$
(pkg-config systemd
--variable=systemdportable
2>/dev
/null
)
1566 [[ -d $dracutsysrootdir$systemdportable ]] || systemdportable
=${systemdutildir}/portable
1568 [[ -d $dracutsysrootdir$systemdportableconfdir ]] \
1569 || systemdportableconfdir
=$
(pkg-config systemd
--variable=systemdportableconfdir
2>/dev
/null
)
1571 [[ -d "$dracutsysrootdir$systemdportableconfdir" ]] || systemdportableconfdir
=${systemdsystemconfdir}/portable
1573 [[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
1574 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
1576 [[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1578 [[ -d $dracutsysrootdir$systemduser ]] \
1579 || systemduser
=$
(pkg-config systemd
--variable=systemduser
2>/dev
/null
)
1581 [[ -d $dracutsysrootdir$systemduser ]] || systemduser
=${systemdutildir}/user
1583 [[ -d $dracutsysrootdir$systemduserconfdir ]] \
1584 || systemduserconfdir
=$
(pkg-config systemd
--variable=systemduserconfdir
2>/dev
/null
)
1586 [[ -d $dracutsysrootdir$systemduserconfdir ]] || systemduserconfdir
=${systemdsystemconfdir}/user
1588 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
1589 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2>/dev
/null
)
1591 [[ -d $dracutsysrootdir$systemdsystemconfdir ]] || systemdsystemconfdir
=/etc
/systemd
/system
1593 [[ -d $dracutsysrootdir$sysusers ]] \
1594 || sysusers
=$
(pkg-config systemd
--variable=sysusers
2>/dev
/null
)
1596 [[ -d $dracutsysrootdir$sysusers ]] || sysusers
=/usr
/lib
/sysusers.d
1598 [[ -d $dracutsysrootdir$sysusersconfdir ]] \
1599 || sysusersconfdir
=$
(pkg-config systemd
--variable=sysusersconfdir
2>/dev
/null
)
1601 [[ -d $dracutsysrootdir$sysusersconfdir ]] || sysusersconfdir
=/etc
/sysusers.d
1603 [[ -d $dracutsysrootdir$tmpfilesdir ]] \
1604 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2>/dev
/null
)
1606 if ! [[ -d $dracutsysrootdir$tmpfilesdir ]]; then
1607 [[ -d $dracutsysrootdir/lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1608 [[ -d $dracutsysrootdir/usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1611 export initdir dracutbasedir \
1612 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1614 fw_dir drivers_dir debug no_kernel kernel_only \
1615 omit_drivers mdadmconf lvmconf root_devs \
1616 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1617 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1618 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1619 DRACUT_VERSION udevdir prefix filesystems drivers \
1620 dbus dbusconfdir dbusinterfaces dbusinterfacesconfdir \
1621 dbusservices dbusservicesconfdir dbussession dbussessionconfdir \
1622 dbussystem dbussystemconfdir dbussystemservices dbussystemservicesconfdir \
1623 environment environmentconfdir sysctl sysctlconfdir sysusers sysusersconfdir \
1624 systemdutildir systemdutilconfdir systemdcatalog systemdntpunits \
1625 systemdntpunitsconfdir systemdsystemunitdir systemdsystemconfdir \
1626 hostonly_cmdline loginstall \
1630 # check all our modules to see if they should be sourced.
1631 # This builds a list of modules that we will install next.
1632 for_each_module_dir check_module
1633 for_each_module_dir check_mount
1635 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1639 local -A _mods_to_print
1640 for i
in $modules_loaded $mods_to_load; do
1641 _mods_to_print
[$i]=1
1644 # source our modules.
1645 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1646 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1647 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1648 module_cmdline
"$_d_mod" "$moddir"
1653 if [[ $print_cmdline ]]; then
1659 # Create some directory structure first
1660 # shellcheck disable=SC2174
1661 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1663 # shellcheck disable=SC2174
1664 [[ -h $dracutsysrootdir/lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1665 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1667 if [[ $prefix ]]; then
1668 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1669 [[ "$d" == */* ]] && continue
1670 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1674 if [[ $kernel_only != yes ]]; then
1675 for d
in usr usr
/bin usr
/sbin bin etc lib sbin tmp var var
/tmp
$libdirs; do
1676 [[ -e "${initdir}${prefix}/$d" ]] && continue
1677 if [ -L "/$d" ]; then
1678 inst_symlink
"/$d" "${prefix}/$d"
1680 # shellcheck disable=SC2174
1681 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1685 for d
in dev proc sys sysroot root run
; do
1686 if [ -L "/$d" ]; then
1689 # shellcheck disable=SC2174
1690 mkdir
-m 0755 -p "$initdir/$d"
1694 ln -sfn ..
/run
"$initdir/var/run"
1695 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1697 for d
in lib
"$libdirs"; do
1698 [[ -e "${initdir}${prefix}/$d" ]] && continue
1699 if [ -h "/$d" ]; then
1700 inst
"/$d" "${prefix}/$d"
1702 # shellcheck disable=SC2174
1703 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1708 if [[ $kernel_only != yes ]]; then
1709 mkdir
-p "${initdir}/etc/cmdline.d"
1710 # shellcheck disable=SC2174
1711 mkdir
-m 0755 -p "${initdir}"/lib "${initdir}"/lib/dracut "${initdir}"/lib
/dracut
/hooks
1712 # shellcheck disable=SC2154
1713 for _d
in $hookdirs; do
1714 # shellcheck disable=SC2174
1715 mkdir
-m 0755 -p "${initdir}/lib/dracut/hooks/$_d"
1717 if [[ "$EUID" = "0" ]]; then
1718 [[ -c ${initdir}/dev
/null
]] || mknod
"${initdir}"/dev
/null c
1 3
1719 [[ -c ${initdir}/dev
/kmsg
]] || mknod
"${initdir}"/dev
/kmsg c
1 11
1720 [[ -c ${initdir}/dev
/console
]] || mknod
"${initdir}"/dev
/console c
5 1
1721 [[ -c ${initdir}/dev
/random
]] || mknod
"${initdir}"/dev
/random c
1 8
1722 [[ -c ${initdir}/dev
/urandom
]] || mknod
"${initdir}"/dev
/urandom c
1 9
1726 _isize
=0 #initramfs size
1728 # source our modules.
1729 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1730 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1731 [[ "$mods_to_load" == *\
$_d_mod\
* ]] ||
continue
1732 if [[ $show_modules = yes ]]; then
1733 printf "%s\n" "$_d_mod"
1735 dinfo
"*** Including module: $_d_mod ***"
1737 if [[ $kernel_only == yes ]]; then
1738 module_installkernel
"$_d_mod" "$moddir" ||
{
1739 dfatal
"installkernel failed in module $_d_mod"
1743 module_install
"$_d_mod" "$moddir"
1744 if [[ $no_kernel != yes ]]; then
1745 module_installkernel
"$_d_mod" "$moddir" ||
{
1746 dfatal
"installkernel failed in module $_d_mod"
1751 mods_to_load
=${mods_to_load// $_d_mod /}
1752 modules_loaded
+="$_d_mod "
1754 #print the module install size
1755 if [ -n "$printsize" ]; then
1756 _isize_new
=$
(du
-sk "${initdir}" |
{ read -r a _
; echo -n "$a"; })
1757 _isize_delta
=$
((_isize_new
- _isize
))
1758 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1764 for i
in $modules_loaded; do
1765 mkdir
-p "$initdir"/lib
/dracut
1766 printf "%s\n" "$i" >> "$initdir"/lib
/dracut
/modules.txt
1769 dinfo
"*** Including modules done ***"
1771 ## final stuff that has to happen
1772 if [[ $no_kernel != yes ]]; then
1773 if [[ $hostonly_mode = "strict" ]]; then
1774 cp "$DRACUT_KERNEL_MODALIASES" "$initdir"/lib
/dracut
/hostonly-kernel-modules.txt
1777 if [[ $drivers ]]; then
1778 # shellcheck disable=SC2086
1779 hostonly
='' instmods
$drivers
1782 if [[ -n "${add_drivers// }" ]]; then
1783 # shellcheck disable=SC2086
1784 hostonly
='' instmods
-c $add_drivers
1786 if [[ $force_drivers ]]; then
1787 # shellcheck disable=SC2086
1788 hostonly
='' instmods
-c $force_drivers
1789 rm -f "$initdir"/etc
/cmdline.d
/20-force_driver.conf
1790 for mod
in $force_drivers; do
1791 echo "rd.driver.pre=$mod" >>"$initdir"/etc
/cmdline.d
/20-force_drivers.conf
1794 if [[ $filesystems ]]; then
1795 # shellcheck disable=SC2086
1796 hostonly
='' instmods
-c $filesystems
1799 dinfo
"*** Installing kernel module dependencies ***"
1801 dinfo
"*** Installing kernel module dependencies done ***"
1803 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1804 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1805 [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1806 for i
in "${initdir}"/etc
/cmdline.d
/*.conf
; do
1807 # We need no initramfs image and do not generate one.
1808 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1814 if [[ $kernel_only != yes ]]; then
1815 # FIXME: handle legacy item split
1816 # shellcheck disable=SC2068
1817 (( ${#install_items[@]} > 0 )) && inst_multiple
${install_items[@]}
1818 # shellcheck disable=SC2068
1819 (( ${#install_optional_items[@]} > 0 )) && inst_multiple
-o ${install_optional_items[@]}
1821 if [[ $kernel_cmdline ]] && [[ $uefi != yes ]]; then
1822 printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1825 for line
in "${fstab_lines[@]}"; do
1826 read -r -a fstab_field
<<< "$line"
1827 if [ -z "${fstab_field[1]}" ]; then
1828 # Determine device and mount options from current system
1829 mountpoint
-q "${fstab_field[0]}" || derror
"${fstab_field[0]} is not a mount point!"
1830 read -r -a fstab_field
<<< "$(findmnt --raw -n --target "${fstab_field[0]}" --output=source,target,fstype,options)"
1831 dinfo
"Line for ${fstab_field[1]}: ${fstab_field[*]}"
1833 # Use default options
1834 [ -z "${fstab_field[3]}" ] && fstab_field
[3]="defaults"
1837 # Default options for freq and passno
1838 [ -z "${fstab_field[4]}" ] && fstab_field
[4]="0"
1839 [ -z "${fstab_field[5]}" ] && fstab_field
[5]="2"
1841 strstr
"${fstab_field[2]}" "nfs" && fstab_field
[5]="0"
1842 echo "${fstab_field[@]}" >> "${initdir}/etc/fstab"
1845 for f
in $add_fstab; do
1846 cat "$f" >> "${initdir}/etc/fstab"
1849 if [[ $dracutsysrootdir$systemdutildir ]]; then
1850 if [[ -d ${initdir}/$systemdutildir ]]; then
1851 mkdir
-p "${initdir}"/etc
/conf.d
1853 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1854 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1855 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1856 } > "${initdir}"/etc
/conf.d
/systemd.conf
1860 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1861 dinfo
"*** Resolving executable dependencies ***"
1862 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
1863 |
xargs -r -0 "$DRACUT_INSTALL" ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
1864 dinfo
"*** Resolving executable dependencies done ***"
1867 # Now we are done with lazy resolving, always install dependencies
1868 unset DRACUT_RESOLVE_LAZY
1869 export DRACUT_RESOLVE_DEPS
=1
1872 for ((i
=0; i
< ${#include_src[@]}; i
++)); do
1873 src
="${include_src[$i]}"
1874 target
="${include_target[$i]}"
1875 if [[ $src && $target ]]; then
1876 if [[ -f $src ]]; then
1877 inst
"$src" "$target"
1878 elif [[ -d $src ]]; then
1879 ddebug
"Including directory: $src"
1880 destdir
="${initdir}/${target}"
1882 # check for preexisting symlinks, so we can cope with the
1883 # symlinks to $prefix
1884 # Objectname is a file or a directory
1885 for objectname
in "$src"/*; do
1886 [[ -e "$objectname" ||
-h "$objectname" ]] ||
continue
1887 if [[ -d "$objectname" ]]; then
1888 # objectname is a directory, let's compute the final directory name
1889 object_destdir
=${destdir}/${objectname#$src/}
1890 if ! [[ -e "$object_destdir" ]]; then
1891 # shellcheck disable=SC2174
1892 mkdir
-m 0755 -p "$object_destdir"
1893 chmod --reference="$objectname" "$object_destdir"
1895 $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
1897 $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
1900 elif [[ -e $src ]]; then
1901 derror
"$src is neither a directory nor a regular file"
1903 derror
"$src doesn't exist"
1908 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1909 dinfo
"*** Hardlinking files ***"
1910 hardlink
"$initdir" 2>&1
1911 dinfo
"*** Hardlinking files done ***"
1915 if [[ $do_strip = yes ]] ; then
1916 # Prefer strip from elfutils for package size
1918 strip_cmd
=$
(command -v eu-strip
)
1919 [ -z "$strip_cmd" ] && strip_cmd
="strip"
1921 for p
in $strip_cmd xargs find; do
1922 if ! type -P $p >/dev
/null
; then
1923 dinfo
"Could not find '$p'. Not stripping the initramfs."
1929 # cleanup empty ldconfig_paths directories
1930 for d
in $
(ldconfig_paths
); do
1931 rmdir -p --ignore-fail-on-non-empty "$initdir/$d" >/dev
/null
2>&1
1934 if [[ $early_microcode = yes ]]; then
1935 dinfo
"*** Generating early-microcode cpio image ***"
1936 ucode_dir
=(amd-ucode intel-ucode
)
1937 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
1938 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
1940 mkdir
-p "$_dest_dir"
1941 if [[ $hostonly ]]; then
1942 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
1943 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
1945 for idx
in $_dest_idx; do
1946 _fw
=${ucode_dir[$idx]}
1947 for _fwdir
in $fw_dir; do
1948 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1950 dinfo
"*** Constructing ${ucode_dest[$idx]} ***"
1951 if [[ $hostonly ]]; then
1952 _src
=$
(get_ucode_file
)
1953 [[ $_src ]] ||
break
1954 [[ -r $_fwdir/$_fw/$_src ]] || _src
="${_src}.early"
1955 [[ -r $_fwdir/$_fw/$_src ]] ||
break
1958 for i
in $_fwdir/$_fw/$_src; do
1959 [ -e "$i" ] && break
1962 for i
in $_fwdir/$_fw/$_src; do
1963 [[ -e "$i" ]] ||
continue
1965 str_ends
"$i" ".asc" && continue
1966 cat "$i" >> "$_dest_dir/${ucode_dest[$idx]}"
1968 create_early_cpio
="yes"
1971 if [[ ! -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
1972 if cd "$early_cpio_dir/d"; then
1973 for _ucodedir
in "${early_microcode_image_dir[@]}"; do
1974 for _ucodename
in "${early_microcode_image_name[@]}"; do
1975 [[ -e "$_ucodedir/$_ucodename" ]] && \
1976 cpio --extract --file "$_ucodedir/$_ucodename" --quiet \
1977 "kernel/x86/microcode/${ucode_dest[$idx]}"
1978 if [[ -e "$_dest_dir/${ucode_dest[$idx]}" ]]; then
1979 dinfo
"*** Using microcode found in '$_ucodedir/$_ucodename' ***"
1980 create_early_cpio
="yes"
1990 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1991 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
1992 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
1993 mkdir
-p "$_dest_dir"
1994 for table
in "$acpi_table_dir"/*.aml
; do
1995 dinfo
" Adding ACPI table: $table"
1996 $DRACUT_CP "$table" "$_dest_dir"
1997 create_early_cpio
="yes"
2001 dinfo
"*** Store current command line parameters ***"
2002 if ! ( echo "$PARMS_TO_STORE" > "$initdir"/lib
/dracut
/build-parameter.txt
); then
2003 dfatal
"Could not store the current command line parameters"
2007 if [[ $hostonly_cmdline == "yes" ]] ; then
2008 unset _stored_cmdline
2009 if [[ -d $initdir/etc
/cmdline.d
]];then
2010 dinfo
"Stored kernel commandline:"
2011 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2012 [ -e "$conf" ] ||
continue
2013 dinfo
"$(< "$conf")"
2017 if ! [[ $_stored_cmdline ]]; then
2018 dinfo
"No dracut internal kernel commandline stored in the initramfs"
2022 if dracut_module_included
"squash"; then
2023 dinfo
"*** Install squash loader ***"
2024 readonly squash_dir
="$initdir/squash/root"
2025 readonly squash_img
="$initdir/squash/root.img"
2026 readonly squash_candidate
=( "usr" "etc" )
2028 # shellcheck disable=SC2174
2029 mkdir
-m 0755 -p "$squash_dir"
2030 for folder
in "${squash_candidate[@]}"; do
2031 mv "$initdir/$folder" "$squash_dir/$folder"
2034 # Move some files out side of the squash image, including:
2035 # - Files required to boot and mount the squashfs image
2036 # - Files need to be accessible without mounting the squash image
2037 # - Initramfs marker
2039 "$squash_dir"/usr
/lib
/modules
/*/modules.
* \
2040 "$squash_dir"/usr
/lib
/dracut
/* \
2041 "$squash_dir"/etc
/initrd-release
2043 [[ -f $file ]] ||
continue
2044 DRACUT_RESOLVE_DEPS
=1 dracutsysrootdir
="$squash_dir" inst
"${file#$squash_dir}"
2048 mv "$initdir"/init
"$initdir"/init.stock
2049 ln -s squash
/init.sh
"$initdir"/init
2051 # Reinstall required files for the squash image setup script.
2052 # We have moved them inside the squashed image, but they need to be
2053 # accessible before mounting the image.
2054 inst_multiple
"echo" "sh" "mount" "modprobe" "mkdir"
2055 hostonly
="" instmods
"loop" "squashfs" "overlay"
2056 # Only keep systemctl outsite if we need switch root
2057 if [[ ! -f "$initdir/lib/dracut/no-switch-root" ]]; then
2061 # Remove duplicated files
2062 for folder
in "${squash_candidate[@]}"; do
2063 find "$initdir/$folder/" -not -type d \
2064 -exec bash
-c 'mv -f "$squash_dir${1#$initdir}" "$1"' -- "{}" \
;
2068 if [[ $kernel_only != yes ]]; then
2069 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
2070 for _dir
in $libdirs; do
2071 for _f
in "$dracutsysrootdir$_dir/libpthread.so"*; do
2072 [[ -e "$_f" ]] ||
continue
2073 inst_libdir_file
"libgcc_s.so*"
2078 # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
2079 if [[ $DRACUT_FIPS_MODE ]]; then
2080 for _dir
in $libdirs; do
2081 for _f
in "$dracutsysrootdir$_dir/libcrypto.so"*; do
2082 [[ -e "$_f" ]] ||
continue
2083 inst_libdir_file
-o "libssl.so*"
2090 if [[ $kernel_only != yes ]]; then
2091 # make sure that library links are correct and up to date
2092 for f
in "$dracutsysrootdir"/etc
/ld.so.conf
"$dracutsysrootdir"/etc
/ld.so.conf.d
/*; do
2093 [[ -f $f ]] && inst_simple
"${f#$dracutsysrootdir}"
2095 if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc
/ld.so.conf
; then
2096 if [[ $EUID = 0 ]]; then
2097 derror
"ldconfig exited ungracefully"
2099 derror
"ldconfig might need uid=0 (root) for chroot()"
2104 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
2105 dinfo
"*** Stripping files ***"
2106 find "$initdir" -type f \
2107 -executable -not -path '*/lib/modules/*.ko' -print0 \
2108 |
xargs -r -0 $strip_cmd -g -p 2>/dev
/null
2110 # strip kernel modules, but do not touch signed modules
2111 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
2112 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
2113 SIG
=$
(tail -c 28 "$f" |
tr -d '\000')
2114 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
2115 done |
xargs -r -0 $strip_cmd -g -p
2116 dinfo
"*** Stripping files done ***"
2119 if dracut_module_included
"squash"; then
2120 dinfo
"*** Squashing the files inside the initramfs ***"
2121 if ! mksquashfs
"$squash_dir" "$squash_img" \
2122 -no-xattrs -no-exports -noappend -always-use-fragments \
2123 -comp xz
-Xdict-size 100% -no-progress \
2125 dfatal
"dracut: Failed making squash image"
2129 rm -rf "$squash_dir"
2130 dinfo
"*** Squashing the files inside the initramfs done ***"
2133 dinfo
"*** Creating image file '$outfile' ***"
2135 if [[ $uefi = yes ]]; then
2136 readonly uefi_outdir
="$DRACUT_TMPDIR/uefi"
2137 mkdir
-p "$uefi_outdir"
2140 if [[ $DRACUT_REPRODUCIBLE ]]; then
2141 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2142 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2144 if [[ "$(cpio --help)" == *--reproducible* ]]; then
2147 dinfo
"cpio does not support '--reproducible'. Resulting image will not be reproducible."
2151 [[ "$EUID" != 0 ]] && cpio_owner
="0:0"
2153 if [[ $create_early_cpio = yes ]]; then
2154 echo 1 > "$early_cpio_dir/d/early_cpio"
2156 if [[ $DRACUT_REPRODUCIBLE ]]; then
2157 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
2158 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
2161 # The microcode blob is _before_ the initramfs blob, not after
2163 umask 077; cd "$early_cpio_dir/d"
2164 find .
-print0 |
sort -z \
2165 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null \
2166 ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet > "${DRACUT_TMPDIR}/initramfs.img"
2168 dfatal
"dracut: creation of $outfile failed"
2174 umask 077; cd "$initdir"
2175 find .
-print0 |
sort -z \
2176 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null ${cpio_owner:+-R "$cpio_owner"} -H newc
-o --quiet \
2177 |
$compress >> "${DRACUT_TMPDIR}/initramfs.img"
2179 dfatal
"dracut: creation of $outfile failed"
2183 # shellcheck disable=SC2154
2184 if (( maxloglvl
>= 5 )) && (( verbosity_mod_l
>= 0 )); then
2185 if [[ $allowlocal ]]; then
2186 "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img"| ddebug
2188 lsinitrd
"${DRACUT_TMPDIR}/initramfs.img"| ddebug
2194 if [[ $uefi = yes ]]; then
2195 if [[ $kernel_cmdline ]]; then
2196 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
2197 elif [[ $hostonly_cmdline = yes ]] && [ -d "$initdir/etc/cmdline.d" ];then
2198 for conf
in "$initdir"/etc
/cmdline.d
/*.conf
; do
2199 [ -e "$conf" ] ||
continue
2200 printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
2204 if [[ $kernel_cmdline ]] ||
[[ $hostonly_cmdline = yes && -d "$initdir/etc/cmdline.d" ]]; then
2205 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
2206 dinfo
"Using UEFI kernel cmdline:"
2207 dinfo
"$(tr -d '\000' < "$uefi_outdir/cmdline.txt
")"
2208 uefi_cmdline
="${uefi_outdir}/cmdline.txt"
2213 [[ -s $dracutsysrootdir/usr
/lib
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/usr/lib/os-release"
2214 [[ -s $dracutsysrootdir/etc
/os-release
]] && uefi_osrelease
="$dracutsysrootdir/etc/os-release"
2215 if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then
2216 uefi_splash_image
="${dracutsysrootdir}${uefi_splash_image}"
2218 unset uefi_splash_image
2222 ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \
2223 ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \
2224 ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \
2225 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x2000000 \
2226 --add-section .initrd
="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd
=0x3000000 \
2227 "$uefi_stub" "${uefi_outdir}/linux.efi"; then
2228 if [[ -n "${uefi_secureboot_key}" && -n "${uefi_secureboot_cert}" ]]; then \
2230 --key "${uefi_secureboot_key}" \
2231 --cert "${uefi_secureboot_cert}" \
2232 --output "$outfile" "${uefi_outdir}/linux.efi"; then
2233 dinfo
"*** Creating signed UEFI image file '$outfile' done ***"
2235 dfatal
"*** Creating signed UEFI image file '$outfile' failed ***"
2239 if cp --reflink=auto
"${uefi_outdir}/linux.efi" "$outfile"; then
2240 dinfo
"*** Creating UEFI image file '$outfile' done ***"
2245 dfatal
"*** Creating UEFI image file '$outfile' failed ***"
2249 if cp --reflink=auto
"${DRACUT_TMPDIR}/initramfs.img" "$outfile"; then
2250 dinfo
"*** Creating initramfs image file '$outfile' done ***"
2253 dfatal
"dracut: creation of $outfile failed"
2258 command -v restorecon
&>/dev
/null
&& restorecon
-- "$outfile"
2261 btrfs filesystem show
"$1" |
sed -n '1s/^.*uuid: //p'
2264 freeze_ok_for_btrfs
() {
2265 local mnt uuid1 uuid2
2266 # If the output file is on btrfs, we need to make sure that it's
2267 # not on a subvolume of the same file system as the root FS.
2268 # Otherwise, fsfreeze() might freeze the entire system.
2269 # This is most conveniently checked by comparing the FS uuid.
2271 [[ "$(stat -f -c %T -- "/")" == "btrfs" ]] ||
return 0
2272 mnt
=$
(stat
-c %m
-- "$1")
2273 uuid1
=$
(btrfs_uuid
"$mnt")
2274 uuid2
=$
(btrfs_uuid
"/")
2275 [[ "$uuid1" && "$uuid2" && "$uuid1" != "$uuid2" ]]
2278 freeze_ok_for_fstype
() {
2282 [[ "$(stat -c %m -- "$outfile")" == "/" ]] && return 1
2283 fstype
=$
(stat
-f -c %T
-- "$outfile")
2288 freeze_ok_for_btrfs
"$outfile";;
2294 # We sync/fsfreeze only if we're operating on a live booted system.
2295 # It's possible for e.g. `kernel` to be installed as an RPM BuildRequires or equivalent,
2296 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
2297 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
2298 # globally. See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
2299 if [[ -d $dracutsysrootdir/run
/systemd
/system
]]; then
2300 if ! sync
"$outfile" 2> /dev
/null
; then
2301 dinfo
"dracut: sync operation on newly created initramfs $outfile failed"
2305 # use fsfreeze only if we're not writing to /
2306 if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype
"$outfile"; then
2307 FSFROZEN
="$(dirname "$outfile")"
2308 if ! (fsfreeze
-f "${FSFROZEN}" 2>/dev
/null
&& fsfreeze
-u "${FSFROZEN}" 2>/dev
/null
); then
2309 dinfo
"dracut: warning: could not fsfreeze $(dirname "$outfile")"