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/>.
30 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
31 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
32 .
$dracutbasedir/dracut-version.sh
35 # 80x25 linebreak here ^
37 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
39 Version: $DRACUT_VERSION
41 Creates initial ramdisk images for preloading modules
43 -h, --help Display all options
45 If a [LIST] has multiple arguments, then you have to put these in quotes.
49 # dracut --add-drivers "module1 module2" ...
55 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
56 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
57 .
$dracutbasedir/dracut-version.sh
60 # 80x25 linebreak here ^
62 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
64 Version: $DRACUT_VERSION
66 Creates initial ramdisk images for preloading modules
68 --kver [VERSION] Set kernel version to [VERSION].
69 -f, --force Overwrite existing initramfs file.
70 -a, --add [LIST] Add a space-separated list of dracut modules.
71 --rebuild Append arguments to those of existing image and rebuild
72 -m, --modules [LIST] Specify a space-separated list of dracut modules to
73 call when building the initramfs. Modules are located
74 in /usr/lib/dracut/modules.d.
75 -o, --omit [LIST] Omit a space-separated list of dracut modules.
76 --force-add [LIST] Force to add a space-separated list of dracut modules
77 to the default set of modules, when -H is specified.
78 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
79 exclusively include in the initramfs.
80 --add-drivers [LIST] Specify a space-separated list of kernel
81 modules to add to the initramfs.
82 --force-drivers [LIST] Specify a space-separated list of kernel
83 modules to add to the initramfs and make sure they
84 are tried to be loaded via modprobe same as passing
85 rd.driver.pre=DRIVER kernel parameter.
86 --omit-drivers [LIST] Specify a space-separated list of kernel
87 modules not to add to the initramfs.
88 --filesystems [LIST] Specify a space-separated list of kernel filesystem
89 modules to exclusively include in the generic
91 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
93 --fwdir [DIR] Specify additional directories, where to look for
94 firmwares, separated by :
95 --kernel-only Only install kernel drivers and firmware files
96 --no-kernel Do not install kernel drivers and firmware files
97 --print-cmdline Print the kernel command line for the given disk layout
98 --early-microcode Combine early microcode with ramdisk
99 --no-early-microcode Do not combine early microcode with ramdisk
100 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
101 --strip Strip binaries in the initramfs
102 --nostrip Do not strip binaries in the initramfs
103 --prelink Prelink binaries in the initramfs
104 --noprelink Do not prelink binaries in the initramfs
105 --hardlink Hardlink files in the initramfs
106 --nohardlink Do not hardlink files in the initramfs
107 --prefix [DIR] Prefix initramfs files with [DIR]
108 --noprefix Do not prefix initramfs files
109 --mdadmconf Include local /etc/mdadm.conf
110 --nomdadmconf Do not include local /etc/mdadm.conf
111 --lvmconf Include local /etc/lvm/lvm.conf
112 --nolvmconf Do not include local /etc/lvm/lvm.conf
113 --fscks [LIST] Add a space-separated list of fsck helpers.
114 --nofscks Inhibit installation of any fsck helpers.
115 --ro-mnt Mount / and /usr read-only by default.
116 -h, --help This message
117 --debug Output debug information of the build process
118 --profile Output profile information of the build process
119 -L, --stdlog [0-6] Specify logging level (to standard error)
120 0 - suppress any messages
121 1 - only fatal errors
125 5 - debug info (here starts lots of output)
126 6 - trace info (and even more)
127 -v, --verbose Increase verbosity level
128 -q, --quiet Decrease verbosity level
129 -c, --conf [FILE] Specify configuration file to use.
130 Default: /etc/dracut.conf
131 --confdir [DIR] Specify configuration directory to use *.conf files
132 from. Default: /etc/dracut.conf.d
133 --tmpdir [DIR] Temporary directory to be used instead of default
135 -l, --local Local mode. Use modules from the current working
136 directory instead of the system-wide installed in
137 /usr/lib/dracut/modules.d.
138 Useful when running dracut from a git checkout.
139 -H, --hostonly Host-Only mode: Install only what is needed for
140 booting the local host instead of a generic host.
141 -N, --no-hostonly Disables Host-Only mode
142 --hostonly-cmdline Store kernel command line arguments needed
144 --no-hostonly-cmdline Do not store kernel command line arguments needed
146 --persistent-policy [POLICY]
147 Use [POLICY] to address disks and partitions.
148 POLICY can be any directory name found in /dev/disk.
149 E.g. "by-uuid", "by-label"
150 --fstab Use /etc/fstab to determine the root device.
151 --add-fstab [FILE] Add file to the initramfs fstab
152 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
153 Mount device [DEV] on mountpoint [MP] with filesystem
154 [FSTYPE] and options [FSOPTS] in the initramfs
155 --add-device "[DEV]" Bring up [DEV] in initramfs
156 -i, --include [SOURCE] [TARGET]
157 Include the files in the SOURCE directory into the
158 Target directory in the final initramfs.
159 If SOURCE is a file, it will be installed to TARGET
160 in the final initramfs.
161 -I, --install [LIST] Install the space separated list of files into the
163 --install-optional [LIST] Install the space separated list of files into the
164 initramfs, if they exist.
165 --gzip Compress the generated initramfs using gzip.
166 This will be done by default, unless another
167 compression option or --no-compress is passed.
168 --bzip2 Compress the generated initramfs using bzip2.
169 Make sure your kernel has bzip2 decompression support
170 compiled in, otherwise you will not be able to boot.
171 --lzma Compress the generated initramfs using lzma.
172 Make sure your kernel has lzma support compiled in,
173 otherwise you will not be able to boot.
174 --xz Compress the generated initramfs using xz.
175 Make sure that your kernel has xz support compiled
176 in, otherwise you will not be able to boot.
177 --lzo Compress the generated initramfs using lzop.
178 Make sure that your kernel has lzo support compiled
179 in, otherwise you will not be able to boot.
180 --lz4 Compress the generated initramfs using lz4.
181 Make sure that your kernel has lz4 support compiled
182 in, otherwise you will not be able to boot.
183 --compress [COMPRESSION] Compress the generated initramfs with the
184 passed compression program. Make sure your kernel
185 knows how to decompress the generated initramfs,
186 otherwise you will not be able to boot.
187 --no-compress Do not compress the generated initramfs. This will
188 override any other compression options.
189 --list-modules List all available dracut modules.
190 -M, --show-modules Print included module's name to standard output during
192 --keep Keep the temporary initramfs for debugging purposes
193 --printsize Print out the module install size
194 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
195 --logfile [FILE] Logfile to use (overrides configuration setting)
196 --reproducible Create reproducible images
197 --loginstall [DIR] Log all files installed from the host to [DIR]
198 --uefi Create an UEFI executable with the kernel cmdline and
200 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
201 --kernel-image [FILE] location of the kernel image
203 If [LIST] has multiple arguments, then you have to put these in quotes.
207 # dracut --add-drivers "module1 module2" ...
212 # Fills up host_devs stack variable and makes sure there are no duplicates
216 [[ " ${host_devs[@]} " == *" $_dev "* ]] && return
217 host_devs
+=( "$_dev" )
221 # Little helper function for reading args from the commandline.
222 # it automatically handles -a b and -a=b variants, and returns 1 if
223 # we need to shift $3.
228 local rematch
='^[^=]*=(.*)$'
229 if [[ $2 =~
$rematch ]]; then
230 read "$1" <<< "${BASH_REMATCH[1]}"
233 # There is no way to shift our callers args, so
234 # return 1 to indicate they should do it instead.
241 local suffix
=$1; shift
246 for i
in "$d/"*"$suffix"; do
247 if [[ -e "$i" ]]; then
248 printf "%s\n" "${i##*/}"
254 for f
in "${files[@]}"; do
256 if [[ -e "$d/$f" ]]; then
257 printf "%s\n" "$d/$f"
267 # Workaround -i, --include taking 2 arguments
268 set -- "${@/--include/++include}"
270 # This prevents any long argument ending with "-i"
271 # -i, like --opt-i but I think we can just prevent that
272 set -- "${@/%-i/++include}"
274 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
275 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
279 --long add-drivers
: \
280 --long force-drivers
: \
281 --long omit-drivers
: \
285 --long filesystems
: \
287 --long install-optional
: \
308 --long print-cmdline \
309 --long kernel-cmdline
: \
331 --long no-host-only \
332 --long hostonly-cmdline \
333 --long no-hostonly-cmdline \
334 --long persistent-policy
: \
344 --long list-modules \
345 --long show-modules \
348 --long regenerate-all \
349 --long noimageifnotneeded \
350 --long early-microcode \
351 --long no-early-microcode \
352 --long reproducible \
356 --long kernel-image
: \
359 if (( $?
!= 0 )); then
369 rearrange_params
"$@"
372 # parse command line args to check if '--rebuild' option is present
377 if [ "$1" == "--" ]; then
380 if [ "$1" == "--rebuild" ]; then
383 if [ ! -e $rebuild_file ]; then
384 echo "Image file '$rebuild_file', for rebuild, does not exist!"
387 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
393 # get output file name and kernel version from command line arguments
399 if ! [[ ${outfile+x} ]]; then
401 elif ! [[ ${kernel+x} ]]; then
404 printf "\nUnknown arguments: %s\n\n" "$*" >&2
412 # extract input image file provided with rebuild option to get previous parameters, if any
413 if [[ $append_args_l == "yes" ]]; then
416 # determine resultant file
417 if ! [[ $outfile ]]; then
418 outfile
=$rebuild_file
421 if ! rebuild_param
=$
(lsinitrd
$rebuild_file '*lib/dracut/build-parameter.txt'); then
422 echo "Image '$rebuild_file' has no rebuild information stored"
426 # prepend previous parameters to current command line args
427 if [[ $rebuild_param ]]; then
428 TEMP
="$rebuild_param $TEMP"
430 rearrange_params
"$@"
433 # clean the temporarily used scratch-pad directory
443 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
444 PARMS_TO_STORE
+=" $1";
447 --kver) kernel
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
448 -a|
--add) add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
449 --force-add) force_add_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
450 --add-drivers) add_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
451 --force-drivers) force_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
452 --omit-drivers) omit_drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
453 -m|
--modules) dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
454 -o|
--omit) omit_dracutmodules_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
455 -d|
--drivers) drivers_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
456 --filesystems) filesystems_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
457 -I|
--install) install_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
458 --install-optional) install_optional_items_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
459 --fwdir) fw_dir_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
460 --libdirs) libdirs_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
461 --fscks) fscks_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
462 --add-fstab) add_fstab_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
463 --mount) fstab_lines
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
464 --add-device|
--device) add_device_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
465 --kernel-cmdline) kernel_cmdline_l
+=("$2"); PARMS_TO_STORE
+=" '$2'"; shift;;
466 --nofscks) nofscks_l
="yes";;
467 --ro-mnt) ro_mnt_l
="yes";;
468 -k|
--kmoddir) drivers_dir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
469 -c|
--conf) conffile
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
470 --confdir) confdir
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
471 --tmpdir) tmpdir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
472 -L|
--stdlog) stdloglvl_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
473 --compress) compress_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
474 --prefix) prefix_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
475 --loginstall) loginstall_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
476 --rebuild) if [ $rebuild_file == $outfile ]; then
481 -f|
--force) force
=yes;;
482 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
483 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
485 print_cmdline
="yes"; hostonly_l
="yes"; kernel_only
="yes"; no_kernel
="yes";;
487 early_microcode_l
="yes";;
488 --no-early-microcode)
489 early_microcode_l
="no";;
490 --strip) do_strip_l
="yes";;
491 --nostrip) do_strip_l
="no";;
492 --prelink) do_prelink_l
="yes";;
493 --noprelink) do_prelink_l
="no";;
494 --hardlink) do_hardlink_l
="yes";;
495 --nohardlink) do_hardlink_l
="no";;
496 --noprefix) prefix_l
="/";;
497 --mdadmconf) mdadmconf_l
="yes";;
498 --nomdadmconf) mdadmconf_l
="no";;
499 --lvmconf) lvmconf_l
="yes";;
500 --nolvmconf) lvmconf_l
="no";;
501 --debug) debug
="yes";;
502 --profile) profile
="yes";;
503 --sshkey) sshkey
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
504 --logfile) logfile_l
="$2"; shift;;
505 -v|
--verbose) ((verbosity_mod_l
++));;
506 -q|
--quiet) ((verbosity_mod_l--
));;
509 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
510 && dracutbasedir
="$(readlink -f "${0%/*}")"
512 -H|
--hostonly|
--host-only)
514 -N|
--no-hostonly|
--no-host-only)
517 hostonly_cmdline_l
="yes" ;;
518 --no-hostonly-cmdline)
519 hostonly_cmdline_l
="no" ;;
521 persistent_policy_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
522 --fstab) use_fstab_l
="yes" ;;
523 -h|
--help) long_usage
; exit 1 ;;
524 -i|
--include) include_src
+=("$2"); PARMS_TO_STORE
+=" '$2'";
526 --bzip2) compress_l
="bzip2";;
527 --lzma) compress_l
="lzma";;
528 --xz) compress_l
="xz";;
529 --lzo) compress_l
="lzo";;
530 --lz4) compress_l
="lz4";;
531 --no-compress) _no_compress_l
="cat";;
532 --gzip) compress_l
="gzip";;
533 --list-modules) do_list
="yes";;
538 --printsize) printsize
="yes";;
539 --regenerate-all) regenerate_all
="yes";;
540 --noimageifnotneeded) noimageifnotneeded
="yes";;
541 --reproducible) reproducible_l
="yes";;
544 uefi_stub_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
546 kernel_image_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
549 *) # should not even reach this point
550 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
555 # getopt cannot handle multiple arguments, so just handle "-I,--include"
556 # the old fashioned way
559 if [ "${1%%=*}" == "++include" ]; then
561 include_target
+=("$3")
562 PARMS_TO_STORE
+=" --include '$2' '$3'"
568 if [[ $regenerate_all == "yes" ]]; then
570 if [[ $kernel ]]; then
571 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
575 if [[ $outfile ]]; then
576 printf -- "--regenerate-all cannot be called with a image file\n" >&2
580 ((len
=${#dracut_args[@]}))
581 for ((i
=0; i
< len
; i
++)); do
582 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
583 unset dracut_args
[$i]
588 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
589 dracut
--kver="$i" "${dracut_args[@]}"
595 if ! [[ $kernel ]]; then
599 if [[ $kernel ]]; then
600 if ! [[ -d /lib
/modules
/$kernel ]] && [[ $no_kernel != yes ]]; then
601 printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2
605 if ! [[ $outfile ]]; then
606 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
608 if [[ $MACHINE_ID ]] && ( [[ -d /boot
/${MACHINE_ID} ]] ||
[[ -L /boot
/${MACHINE_ID} ]] ); then
609 outfile
="/boot/${MACHINE_ID}/$kernel/initrd"
611 outfile
="/boot/initramfs-$kernel.img"
619 unset LD_LIBRARY_PATH
623 export DRACUT_LOG_LEVEL
=warning
625 export DRACUT_LOG_LEVEL
=debug
626 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
631 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
636 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
638 # if we were not passed a config file, try the default one
639 if [[ ! -f $conffile ]]; then
640 if [[ $allowlocal ]]; then
641 conffile
="$dracutbasedir/dracut.conf"
643 conffile
="/etc/dracut.conf"
647 if [[ ! -d $confdir ]]; then
648 if [[ $allowlocal ]]; then
649 confdir
="$dracutbasedir/dracut.conf.d"
651 confdir
="/etc/dracut.conf.d"
655 # source our config file
656 [[ -f $conffile ]] && .
"$conffile"
658 # source our config dir
659 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
660 [[ -e $f ]] && .
"$f"
663 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
665 for i
in $DRACUT_PATH; do
670 if [[ "$NPATH" != *:$rl* ]] ; then
674 export PATH
="${NPATH#:}"
677 # these optins add to the stuff in the config file
678 if (( ${#add_dracutmodules_l[@]} )); then
679 add_dracutmodules
+=" ${add_dracutmodules_l[@]} "
682 if (( ${#force_add_dracutmodules_l[@]} )); then
683 force_add_dracutmodules
+=" ${force_add_dracutmodules_l[@]} "
686 if (( ${#fscks_l[@]} )); then
687 fscks
+=" ${fscks_l[@]} "
690 if (( ${#add_fstab_l[@]} )); then
691 add_fstab
+=" ${add_fstab_l[@]} "
694 if (( ${#fstab_lines_l[@]} )); then
695 fstab_lines
+=( "${fstab_lines_l[@]}" )
698 if (( ${#install_items_l[@]} )); then
699 install_items
+=" ${install_items_l[@]} "
702 if (( ${#install_optional_items_l[@]} )); then
703 install_optional_items
+=" ${install_optional_items_l[@]} "
706 # these options override the stuff in the config file
707 if (( ${#dracutmodules_l[@]} )); then
708 dracutmodules
="${dracutmodules_l[@]}"
711 if (( ${#omit_dracutmodules_l[@]} )); then
712 omit_dracutmodules
="${omit_dracutmodules_l[@]}"
715 if (( ${#filesystems_l[@]} )); then
716 filesystems
="${filesystems_l[@]}"
719 if (( ${#fw_dir_l[@]} )); then
720 fw_dir
="${fw_dir_l[@]}"
723 if (( ${#libdirs_l[@]} )); then
724 libdirs
="${libdirs_l[@]}"
727 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
728 [[ ! $stdloglvl ]] && stdloglvl
=4
729 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
730 ((stdloglvl
> 6)) && stdloglvl
=6
731 ((stdloglvl
< 0)) && stdloglvl
=0
733 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
734 [[ $do_strip_l ]] && do_strip
=$do_strip_l
735 [[ $do_strip ]] || do_strip
=yes
736 [[ $do_prelink_l ]] && do_prelink
=$do_prelink_l
737 [[ $do_prelink ]] || do_prelink
=yes
738 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
739 [[ $do_hardlink ]] || do_hardlink
=yes
740 [[ $prefix_l ]] && prefix
=$prefix_l
741 [[ $prefix = "/" ]] && unset prefix
742 [[ $hostonly_l ]] && hostonly
=$hostonly_l
743 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
744 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
745 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
746 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
747 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
748 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
749 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
750 [[ $fw_dir ]] || fw_dir
="/lib/firmware/updates /lib/firmware /lib/firmware/$kernel"
751 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
752 [[ $tmpdir ]] || tmpdir
=/var
/tmp
753 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
754 [[ $compress_l ]] && compress=$compress_l
755 [[ $show_modules_l ]] && show_modules
=$show_modules_l
756 [[ $nofscks_l ]] && nofscks
="yes"
757 [[ $ro_mnt_l ]] && ro_mnt
="yes"
758 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
759 [[ $early_microcode ]] || early_microcode
=no
760 [[ $logfile_l ]] && logfile
="$logfile_l"
761 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
762 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
763 [[ $uefi_stub_l ]] && uefi_stub
="$uefi_stub_l"
764 [[ $kernel_image_l ]] && kernel_image
="$kernel_image_l"
766 # eliminate IFS hackery when messing with fw_dir
767 fw_dir
=${fw_dir//:/ }
769 # check for logfile and try to create one if it doesn't exist
770 if [[ -n "$logfile" ]];then
771 if [[ ! -f "$logfile" ]];then
773 if [ ! $?
-eq 0 ] ;then
774 printf "%s\n" "dracut: touch $logfile failed." >&2
779 # handle compression options.
780 [[ $compress ]] ||
compress="gzip"
782 bzip2) compress="bzip2 -9";
783 command -v lbzip2
> /dev
/null
2>&1 && compress="lbzip2 -9";;
784 lzma
) compress="lzma -9 -T0";;
785 xz
) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
786 gzip) compress="gzip -n -9";
787 if command -v pigz
> /dev
/null
2>&1; then
788 compress="pigz -9 -n -T -R"
789 elif command -v gzip --help 2>&1 |
grep -q rsyncable
; then
790 compress="gzip -n -9 --rsyncable"
793 lzo
) compress="lzop -9";;
794 lz4
) compress="lz4 -l -9";;
796 if [[ $_no_compress_l = "cat" ]]; then
800 [[ $hostonly = yes ]] && hostonly
="-h"
801 [[ $hostonly != "-h" ]] && unset hostonly
803 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
805 readonly TMPDIR
="$tmpdir"
806 readonly initdir
="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
807 [ -d "$initdir" ] ||
{
808 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
812 if [[ $early_microcode = yes ]] ||
( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
813 readonly early_cpio_dir
="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
814 [ -d "$early_cpio_dir" ] ||
{
815 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
819 # clean up after ourselves no matter how we die.
822 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
823 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
824 [[ $keep ]] && echo "Not removing $uefi_outdir." >&2 || { [[ $uefi_outdir ]] && rm -Rf -- "$uefi_outdir"; };
825 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
829 # clean up after ourselves no matter how we die.
830 trap 'exit 1;' SIGINT
832 export DRACUT_KERNEL_LAZY
="1"
833 export DRACUT_RESOLVE_LAZY
="1"
835 if [[ $print_cmdline ]]; then
842 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
843 .
$dracutbasedir/dracut-version.sh
846 if [[ -f $dracutbasedir/dracut-init.sh
]]; then
847 .
$dracutbasedir/dracut-init.sh
849 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
850 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
851 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
855 if ! [[ $print_cmdline ]]; then
857 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev
/null
; then
858 unset DRACUT_RESOLVE_LAZY
859 export DRACUT_RESOLVE_DEPS
=1
861 rm -fr -- ${initdir}/*
864 # Verify bash version, current minimum is 4
865 if (( BASH_VERSINFO
[0] < 4 )); then
866 dfatal
'You need at least Bash 4 to use dracut, sorry.'
870 dracutfunctions
=$dracutbasedir/dracut-functions.sh
871 export dracutfunctions
873 if (( ${#drivers_l[@]} )); then
874 drivers
="${drivers_l[@]}"
876 drivers
=${drivers/-/_}
878 if (( ${#add_drivers_l[@]} )); then
879 add_drivers
+=" ${add_drivers_l[@]} "
881 add_drivers
=${add_drivers/-/_}
883 if (( ${#force_drivers_l[@]} )); then
884 force_drivers
+=" ${force_drivers_l[@]} "
886 force_drivers
=${force_drivers/-/_}
888 if (( ${#omit_drivers_l[@]} )); then
889 omit_drivers
+=" ${omit_drivers_l[@]} "
891 omit_drivers
=${omit_drivers/-/_}
893 if (( ${#kernel_cmdline_l[@]} )); then
894 kernel_cmdline
+=" ${kernel_cmdline_l[@]} "
897 omit_drivers_corrected
=""
898 for d
in $omit_drivers; do
899 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
900 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
901 omit_drivers_corrected
+="$d|"
903 omit_drivers
="${omit_drivers_corrected%|}"
904 unset omit_drivers_corrected
906 # prepare args for logging
907 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
908 [[ "${dracut_args[$i]}" == *\
* ]] && \
909 dracut_args
[$i]="\"${dracut_args[$i]}\""
913 dinfo
"Executing: $0 ${dracut_args[@]}"
915 [[ $do_list = yes ]] && {
916 for mod
in $dracutbasedir/modules.d
/*; do
917 [[ -d $mod ]] ||
continue;
918 [[ -e $mod/install ||
-e $mod/installkernel || \
919 -e $mod/module-setup.sh
]] ||
continue
920 printf "%s\n" "${mod##*/??}"
925 # This is kinda legacy -- eventually it should go away.
926 case $dracutmodules in
927 ""|auto
) dracutmodules
="all" ;;
930 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
932 if [[ -d $srcmods ]]; then
933 [[ -f $srcmods/modules.dep
]] ||
{
934 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
938 if [[ ! $print_cmdline ]]; then
939 if [[ -f $outfile && ! $force ]]; then
940 dfatal
"Will not override existing initramfs ($outfile) without --force"
945 [[ $outdir ]] || outdir
="/"
947 if [[ ! -d "$outdir" ]]; then
948 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
950 elif [[ ! -w "$outdir" ]]; then
951 dfatal
"No permission to write to $outdir."
953 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
954 dfatal
"No permission to write $outfile."
958 if [[ $loginstall ]]; then
959 if ! mkdir
-p "$loginstall"; then
960 dfatal
"Could not create directory to log installed files to '$loginstall'."
963 loginstall
=$
(readlink
-f "$loginstall")
966 if [[ $uefi = yes ]]; then
967 if ! command -v objcopy
&>/dev
/null
; then
968 dfatal
"Need 'objcopy' to create a UEFI executable"
971 unset EFI_MACHINE_TYPE_NAME
974 EFI_MACHINE_TYPE_NAME
=x64
;;
976 EFI_MACHINE_TYPE_NAME
=ia32
;;
978 dfatal
"Architecture '$(arch)' not supported to create a UEFI executable"
983 if ! [[ -s $uefi_stub ]]; then
985 "/lib/systemd/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
986 "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
987 [[ -s $uefi_stub ]] ||
continue
991 if ! [[ -s $uefi_stub ]]; then
992 dfatal
"Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
996 if ! [[ $kernel_image ]]; then
997 for kernel_image
in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
998 [[ -s "$kernel_image" ]] ||
continue
1002 if ! [[ -s $kernel_image ]]; then
1003 dfatal
"Can't find a kernel image '$kernel_image' to create a UEFI executable"
1009 if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
; then
1010 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y"
1014 if [[ $early_microcode = yes ]]; then
1015 if [[ $hostonly ]]; then
1016 [[ $
(get_cpu_vendor
) == "AMD" ]] \
1017 && ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
1018 && unset early_microcode
1019 [[ $
(get_cpu_vendor
) == "Intel" ]] \
1020 && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
1021 && unset early_microcode
1023 ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
1024 && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
1025 && unset early_microcode
1027 [[ $early_microcode != yes ]] \
1028 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]_EARLY!=y"
1031 # Need to be able to have non-root users read stuff (rpcbind etc)
1032 chmod 755 "$initdir"
1034 if [[ $hostonly ]]; then
1035 for i
in /sys
/proc
/run
/dev
; do
1036 if ! findmnt
--target "$i" &>/dev
/null
; then
1037 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1043 declare -A host_fs_types
1045 for line
in "${fstab_lines[@]}"; do
1051 dev
=$
(blkid
-l -t UUID
=${dev#UUID=} -o device
)
1054 dev
=$
(blkid
-l -t LABEL
=${dev#LABEL=} -o device
)
1057 dev
=$
(blkid
-l -t PARTUUID
=${dev#PARTUUID=} -o device
)
1060 dev
=$
(blkid
-l -t PARTLABEL
=${dev#PARTLABEL=} -o device
)
1063 [ -z "$dev" ] && dwarn
"Bad fstab entry $@" && continue
1064 if [[ "$3" == btrfs
]]; then
1065 for i
in $
(btrfs_devs
"$2"); do
1069 push_host_devs
"$dev"
1070 host_fs_types
["$dev"]="$3"
1073 for f
in $add_fstab; do
1074 [[ -e $f ]] ||
continue
1075 while read dev rest ||
[ -n "$dev" ]; do
1076 push_host_devs
"$dev"
1080 for dev
in $add_device; do
1081 push_host_devs
"$dev"
1084 if (( ${#add_device_l[@]} )); then
1085 add_device
+=" ${add_device_l[@]} "
1086 push_host_devs
"${add_device_l[@]}"
1089 if [[ $hostonly ]]; then
1090 # in hostonly mode, determine all devices, which have to be accessed
1091 # and examine them for filesystem types
1109 mp
=$
(readlink
-f "$mp")
1110 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
1111 _dev
=$
(find_block_device
"$mp")
1112 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1113 [[ -b $_bdev ]] && _dev
=$_bdev
1114 push_host_devs
$_dev
1115 [[ "$mp" == "/" ]] && root_devs
+=("$_dev")
1116 push_host_devs
"$_dev"
1117 if [[ $
(find_mp_fstype
"$mp") == btrfs
]]; then
1118 for i
in $
(btrfs_devs
"$mp"); do
1119 [[ "$mp" == "/" ]] && root_devs
+=("$i")
1125 if [[ -f /proc
/swaps
]] && [[ -f /etc
/fstab
]]; then
1126 while read dev
type rest ||
[ -n "$dev" ]; do
1127 [[ -b $dev ]] ||
continue
1128 [[ "$type" == "partition" ]] ||
continue
1130 while read _d _m _t _o _r ||
[ -n "$_d" ]; do
1131 [[ "$_d" == \
#* ]] && continue
1132 [[ $_d ]] ||
continue
1133 [[ $_t != "swap" ]] && continue
1134 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1135 [[ "$_o" == *noauto
* ]] && continue
1136 _d
=$
(expand_persistent_dev
"$_d")
1137 [[ "$_d" -ef "$dev" ]] ||
continue
1139 if [[ -f /etc
/crypttab
]]; then
1140 while read _mapper _a _p _o ||
[ -n "$_mapper" ]; do
1141 [[ $_mapper = \
#* ]] && continue
1142 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1143 [[ "$_o" ]] || _o
="$_p"
1144 # skip entries with password files
1145 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1147 [[ $_o == *swap
* ]] && continue 2
1148 done < /etc
/crypttab
1151 _dev
="$(readlink -f "$dev")"
1152 push_host_devs
"$_dev"
1153 swap_devs
+=("$_dev")
1159 # collect all "x-initrd.mount" entries from /etc/fstab
1160 if [[ -f /etc
/fstab
]]; then
1161 while read _d _m _t _o _r ||
[ -n "$_d" ]; do
1162 [[ "$_d" == \
#* ]] && continue
1163 [[ $_d ]] ||
continue
1164 [[ "$_o" != *x-initrd.mount
* ]] && continue
1165 _dev
=$
(expand_persistent_dev
"$_d")
1166 _dev
="$(readlink -f "$_dev")"
1167 [[ -b $_dev ]] ||
continue
1169 push_host_devs
"$_dev"
1170 if [[ "$_t" == btrfs
]]; then
1171 for i
in $
(find_btrfs_devs
"$_m"); do
1178 # record all host modaliases
1179 declare -A host_modalias
1180 find /sys
/devices
/ -name uevent
-print > "$initdir/.modalias"
1181 while read m ||
[ -n "$m" ]; do
1182 while read line ||
[ -n "$line" ]; do
1183 [[ "$line" != MODALIAS\
=* ]] && continue
1184 modalias
="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias
["$modalias"]=1
1187 done < "$initdir/.modalias"
1189 rm -f -- "$initdir/.modalias"
1191 while read _k _s _v ||
[ -n "$_k" ]; do
1192 [ "$_k" != "name" -a "$_k" != "driver" ] && continue
1193 host_modalias
["$_v"]=1
1196 # check /proc/modules
1197 declare -A host_modules
1198 while read m rest ||
[ -n "$m" ]; do
1199 host_modules
["$m"]=1
1208 if [[ -b /dev
/block
/$1 ]]; then
1209 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1212 if [[ -b $1 ]]; then
1213 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1216 if fstype
=$
(find_dev_fstype
"$1"); then
1217 host_fs_types
["$1"]="$fstype"
1223 for dev
in "${host_devs[@]}"; do
1225 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1228 for dev
in "${!host_fs_types[@]}"; do
1229 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
1230 rootopts
=$
(find_dev_fsopts
"$dev")
1231 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1232 journaldev
=$
(fs_get_option
$rootopts "jdev")
1233 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1234 journaldev
=$
(fs_get_option
$rootopts "logdev")
1236 if [[ $journaldev ]]; then
1237 dev
="$(readlink -f "$dev")"
1238 push_host_devs
"$dev"
1240 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1245 || udevdir
="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1246 if ! [[ -d "$udevdir" ]]; then
1247 [[ ! -h /lib
]] && [[ -d /lib
/udev
]] && udevdir
=/lib
/udev
1248 [[ -d /usr
/lib
/udev
]] && udevdir
=/usr
/lib
/udev
1251 [[ -d $systemdutildir ]] \
1252 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
1254 if ! [[ -d "$systemdutildir" ]]; then
1255 [[ ! -h /lib
]] && [[ -d /lib
/systemd
]] && systemdutildir
=/lib
/systemd
1256 [[ -d /usr
/lib
/systemd
]] && systemdutildir
=/usr
/lib
/systemd
1259 [[ -d $systemdsystemunitdir ]] \
1260 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
1262 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1264 [[ -d $systemdsystemconfdir ]] \
1265 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2>/dev
/null
)
1267 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir
=/etc
/systemd
/system
1269 [[ -d $tmpfilesdir ]] \
1270 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2>/dev
/null
)
1272 if ! [[ -d "$tmpfilesdir" ]]; then
1273 [[ -f /lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1274 [[ -f /usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1277 export initdir dracutbasedir \
1278 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1280 fw_dir drivers_dir debug no_kernel kernel_only \
1281 omit_drivers mdadmconf lvmconf root_dev \
1282 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1283 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1284 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1285 DRACUT_VERSION udevdir prefix filesystems drivers \
1286 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1287 host_modalias host_modules hostonly_cmdline loginstall \
1291 # check all our modules to see if they should be sourced.
1292 # This builds a list of modules that we will install next.
1293 for_each_module_dir check_module
1294 for_each_module_dir check_mount
1296 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1300 local -A _mods_to_print
1301 for i
in $modules_loaded $mods_to_load; do
1302 _mods_to_print
[$i]=1
1305 # source our modules.
1306 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1307 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1308 [[ ${_mods_to_print[$_d_mod]} ]] ||
continue
1309 module_cmdline
"$_d_mod"
1314 if [[ $print_cmdline ]]; then
1320 # Create some directory structure first
1321 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1323 [[ -h /lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1324 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1326 if [[ $prefix ]]; then
1327 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1328 [[ "$d" == */* ]] && continue
1329 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1333 if [[ $kernel_only != yes ]]; then
1334 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var var
/tmp
$libdirs; do
1335 [[ -e "${initdir}${prefix}/$d" ]] && continue
1336 if [ -L "/$d" ]; then
1337 inst_symlink
"/$d" "${prefix}/$d"
1339 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1343 for d
in dev proc sys sysroot root run
; do
1344 if [ -L "/$d" ]; then
1347 mkdir
-m 0755 -p "$initdir/$d"
1351 ln -sfn ..
/run
"$initdir/var/run"
1352 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1354 for d
in lib
"$libdir"; do
1355 [[ -e "${initdir}${prefix}/$d" ]] && continue
1356 if [ -h "/$d" ]; then
1357 inst
"/$d" "${prefix}/$d"
1359 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1364 if [[ $kernel_only != yes ]]; then
1365 mkdir
-p "${initdir}/etc/cmdline.d"
1366 for _d
in $hookdirs; do
1367 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
1369 if [[ "$UID" = "0" ]]; then
1370 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
1371 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
1372 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
1376 _isize
=0 #initramfs size
1378 # source our modules.
1379 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1380 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1381 [[ "$mods_to_load" == *\
$_d_mod\
* ]] ||
continue
1382 if [[ $show_modules = yes ]]; then
1383 printf "%s\n" "$_d_mod"
1385 dinfo
"*** Including module: $_d_mod ***"
1387 if [[ $kernel_only == yes ]]; then
1388 module_installkernel
"$_d_mod" ||
{
1389 dfatal
"installkernel failed in module $_d_mod"
1393 module_install
"$_d_mod"
1394 if [[ $no_kernel != yes ]]; then
1395 module_installkernel
"$_d_mod" ||
{
1396 dfatal
"installkernel failed in module $_d_mod"
1401 mods_to_load
=${mods_to_load// $_d_mod /}
1402 modules_loaded
+="$_d_mod "
1404 #print the module install size
1405 if [ -n "$printsize" ]; then
1406 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
1407 _isize_delta
=$
((_isize_new
- _isize
))
1408 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1414 for i
in $modules_loaded; do
1415 mkdir
-p $initdir/lib
/dracut
1416 printf "%s\n" "$i" >> $initdir/lib
/dracut
/modules.txt
1419 dinfo
"*** Including modules done ***"
1421 ## final stuff that has to happen
1422 if [[ $no_kernel != yes ]]; then
1424 if [[ $drivers ]]; then
1425 hostonly
='' instmods
$drivers
1428 if [[ $add_drivers ]]; then
1429 hostonly
='' instmods
-c $add_drivers
1431 if [[ $force_drivers ]]; then
1432 hostonly
='' instmods
-c $force_drivers
1433 rm -f $initdir/etc
/cmdline.d
/20-force_driver.conf
1434 for mod
in $force_drivers; do
1435 echo "rd.driver.pre=$mod" >>$initdir/etc
/cmdline.d
/20-force_drivers.conf
1438 if [[ $filesystems ]]; then
1439 hostonly
='' instmods
-c $filesystems
1442 dinfo
"*** Installing kernel module dependencies and firmware ***"
1444 dinfo
"*** Installing kernel module dependencies and firmware done ***"
1446 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1447 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1448 [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1449 for i
in ${initdir}/etc
/cmdline.d
/*.conf
; do
1450 # We need no initramfs image and do not generate one.
1451 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1457 if [[ $kernel_only != yes ]]; then
1458 (( ${#install_items[@]} > 0 )) && inst_multiple
"${install_items[@]}"
1459 (( ${#install_optional_items[@]} > 0 )) && inst_multiple
-o "${install_optional_items[@]}"
1461 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1463 for line
in "${fstab_lines[@]}"; do
1465 [ -z "${line[3]}" ] && line
[3]="defaults"
1466 [ -z "${line[4]}" ] && line
[4]="0"
1467 [ -z "${line[5]}" ] && line
[5]="2"
1468 strstr
"${line[2]}" "nfs" && line
[5]="0"
1469 echo "${line[@]}" >> "${initdir}/etc/fstab"
1472 for f
in $add_fstab; do
1473 cat "$f" >> "${initdir}/etc/fstab"
1476 if [ -d ${initdir}/$systemdutildir ]; then
1477 mkdir
-p ${initdir}/etc
/conf.d
1479 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1480 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1481 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1482 } > ${initdir}/etc
/conf.d
/systemd.conf
1485 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1486 dinfo
"*** Resolving executable dependencies ***"
1487 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
1488 |
xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1489 dinfo
"*** Resolving executable dependencies done***"
1492 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1493 for _dir
in $libdirs; do
1494 for _f
in "$_dir/libpthread.so"*; do
1495 [[ -e "$_f" ]] ||
continue
1496 inst_libdir_file
"libgcc_s.so*"
1502 for ((i
=0; i
< ${#include_src[@]}; i
++)); do
1503 src
="${include_src[$i]}"
1504 target
="${include_target[$i]}"
1505 if [[ $src && $target ]]; then
1506 if [[ -f $src ]]; then
1509 ddebug
"Including directory: $src"
1510 destdir
="${initdir}/${target}"
1512 # check for preexisting symlinks, so we can cope with the
1513 # symlinks to $prefix
1514 # Objectname is a file or a directory
1515 for objectname
in "$src"/*; do
1516 [[ -e "$objectname" ||
-h "$objectname" ]] ||
continue
1517 if [[ -d "$objectname" ]]; then
1518 # objectname is a directory, let's compute the final directory name
1519 object_destdir
=${destdir}/${objectname#$src/}
1520 if ! [[ -e "$object_destdir" ]]; then
1521 mkdir
-m 0755 -p "$object_destdir"
1522 chmod --reference="$objectname" "$object_destdir"
1524 cp --reflink=auto
--sparse=auto
-fa -t "$object_destdir" "$objectname"/*
1526 cp --reflink=auto
--sparse=auto
-fa -t "$destdir" "$objectname"
1533 if [[ $kernel_only != yes ]]; then
1534 # make sure that library links are correct and up to date
1535 for f
in /etc
/ld.so.conf
/etc
/ld.so.conf.d
/*; do
1536 [[ -f $f ]] && inst_simple
"$f"
1538 if ! ldconfig
-r "$initdir"; then
1539 if [[ $UID = 0 ]]; then
1540 derror
"ldconfig exited ungracefully"
1542 derror
"ldconfig might need uid=0 (root) for chroot()"
1547 PRELINK_BIN
="$(command -v prelink)"
1548 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1549 if [[ $DRACUT_FIPS_MODE ]]; then
1550 dinfo
"*** Installing prelink files ***"
1551 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
/etc
/prelink.cache
1552 elif [[ $do_prelink == yes ]]; then
1553 dinfo
"*** Pre-linking files ***"
1554 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
1555 chroot
"$initdir" "$PRELINK_BIN" -a
1556 rm -f -- "$initdir/$PRELINK_BIN"
1557 rm -fr -- "$initdir"/etc
/prelink.
*
1558 dinfo
"*** Pre-linking files done ***"
1562 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1563 dinfo
"*** Hardlinking files ***"
1564 hardlink
"$initdir" 2>&1
1565 dinfo
"*** Hardlinking files done ***"
1569 if [[ $do_strip = yes ]] ; then
1570 for p
in strip
xargs find; do
1571 if ! type -P $p >/dev
/null
; then
1572 dinfo
"Could not find '$p'. Not stripping the initramfs."
1578 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1579 dinfo
"*** Stripping files ***"
1580 find "$initdir" -type f \
1581 -executable -not -path '*/lib/modules/*.ko' -print0 \
1582 |
xargs -r -0 strip
-g 2>/dev
/null
1584 # strip kernel modules, but do not touch signed modules
1585 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
1586 |
while read -r -d $
'\0' f ||
[ -n "$f" ]; do
1587 SIG
=$
(tail -c 28 "$f")
1588 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
1589 done |
xargs -r -0 strip
-g
1591 dinfo
"*** Stripping files done ***"
1593 if [[ $early_microcode = yes ]]; then
1594 dinfo
"*** Generating early-microcode cpio image ***"
1595 ucode_dir
=(amd-ucode intel-ucode
)
1596 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
1597 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
1600 if [[ $hostonly ]]; then
1601 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
1602 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
1604 for idx
in $_dest_idx; do
1605 _fw
=${ucode_dir[$idx]}
1606 for _fwdir
in $fw_dir; do
1607 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1609 dinfo
"*** Constructing ${ucode_dest[$idx]} ****"
1610 if [[ $hostonly ]]; then
1611 _src
=$
(get_ucode_file
)
1612 if ! [[ -r $_fwdir/$_fw/$_src ]];then
1616 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1617 create_early_cpio
="yes"
1623 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1624 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
1625 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
1627 for table
in $acpi_table_dir/*.aml
; do
1628 dinfo
" Adding ACPI table: $table"
1629 cp -a $table $_dest_dir
1630 create_early_cpio
="yes"
1634 dinfo
"*** Store current command line parameters ***"
1635 if ! ( echo $PARMS_TO_STORE > $initdir/lib
/dracut
/build-parameter.txt
); then
1636 dfatal
"Could not store the current command line parameters"
1640 if [[ $hostonly_cmdline ]] ; then
1641 unset _stored_cmdline
1642 if [ -d $initdir/etc
/cmdline.d
];then
1643 dinfo
"Stored kernel commandline:"
1644 for conf
in $initdir/etc
/cmdline.d
/*.conf
; do
1645 [ -e "$conf" ] ||
continue
1650 if ! [[ $_stored_cmdline ]]; then
1651 dinfo
"No dracut internal kernel commandline stored in initrd"
1655 dinfo
"*** Creating image file '$outfile' ***"
1657 if [[ $uefi = yes ]]; then
1658 uefi_outfile
="$outfile"
1659 readonly uefi_outdir
="$(mktemp --tmpdir="$TMPDIR/" -d -t initrd.XXXXXX)"
1660 # redirect initrd output
1661 outfile
="$uefi_outdir/initrd"
1664 if [[ $DRACUT_REPRODUCIBLE ]]; then
1665 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1666 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1668 [[ "$(cpio --help)" == *--reproducible* ]] && CPIO_REPRODUCIBLE
=1
1671 [[ "$UID" != 0 ]] && cpio_owner_root
="-R 0:0"
1673 if [[ $create_early_cpio = yes ]]; then
1674 echo 1 > "$early_cpio_dir/d/early_cpio"
1676 if [[ $DRACUT_REPRODUCIBLE ]]; then
1677 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1678 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1681 # The microcode blob is _before_ the initramfs blob, not after
1683 cd "$early_cpio_dir/d"
1684 find .
-print0 |
sort -z \
1685 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet > $outfile
1690 umask 077; cd "$initdir"
1691 find .
-print0 |
sort -z \
1692 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet \
1693 |
$compress >> "$outfile"
1695 dfatal
"dracut: creation of $outfile failed"
1698 dinfo
"*** Creating initrd image file '$outfile' done ***"
1700 if (( maxloglvl
>= 5 )); then
1701 if [[ $allowlocal ]]; then
1702 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1704 lsinitrd
"$outfile"| ddebug
1708 if [[ $uefi = yes ]]; then
1709 if [[ $kernel_cmdline ]]; then
1710 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
1711 elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc
/cmdline.d
];then
1712 for conf
in $initdir/etc
/cmdline.d
/*.conf
; do
1713 [ -e "$conf" ] ||
continue
1714 printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
1717 do_print_cmdline
> "$uefi_outdir/cmdline.txt"
1719 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
1721 dinfo
"Using UEFI kernel cmdline:"
1722 dinfo $
(< "$uefi_outdir/cmdline.txt")
1724 [[ -s /usr
/lib
/os-release
]] && uefi_osrelease
="/usr/lib/os-release"
1725 [[ -s /etc
/os-release
]] && uefi_osrelease
="/etc/os-release"
1728 ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
1729 --add-section .cmdline
="$uefi_outdir/cmdline.txt" --change-section-vma .cmdline
=0x30000 \
1730 --add-section .linux
="$kernel_image" --change-section-vma .linux
=0x40000 \
1731 --add-section .initrd
="$outfile" --change-section-vma .initrd
=0x3000000 \
1732 "$uefi_stub" "$uefi_outfile"
1733 dinfo
"*** Creating UEFI image file '$uefi_outfile' done ***"