2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Generator script for a dracut initramfs
6 # Tries to retain some degree of compatibility with the command line
7 # of the various mkinitrd implementations out there
10 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
33 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
34 .
$dracutbasedir/dracut-version.sh
37 # 80x25 linebreak here ^
39 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
41 Version: $DRACUT_VERSION
43 Creates initial ramdisk images for preloading modules
45 -h, --help Display all options
47 If a [LIST] has multiple arguments, then you have to put these in quotes.
51 # dracut --add-drivers "module1 module2" ...
57 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
58 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
59 .
$dracutbasedir/dracut-version.sh
62 # 80x25 linebreak here ^
64 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
66 Version: $DRACUT_VERSION
68 Creates initial ramdisk images for preloading modules
70 --kver [VERSION] Set kernel version to [VERSION].
71 -f, --force Overwrite existing initramfs file.
72 -a, --add [LIST] Add a space-separated list of dracut modules.
73 -m, --modules [LIST] Specify a space-separated list of dracut modules to
74 call when building the initramfs. Modules are located
75 in /usr/lib/dracut/modules.d.
76 -o, --omit [LIST] Omit a space-separated list of dracut modules.
77 --force-add [LIST] Force to add a space-separated list of dracut modules
78 to the default set of modules, when -H is specified.
79 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
80 exclusively include in the initramfs.
81 --add-drivers [LIST] Specify a space-separated list of kernel
82 modules to add to the initramfs.
83 --omit-drivers [LIST] Specify a space-separated list of kernel
84 modules not to add to the initramfs.
85 --filesystems [LIST] Specify a space-separated list of kernel filesystem
86 modules to exclusively include in the generic
88 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
90 --fwdir [DIR] Specify additional directories, where to look for
91 firmwares, separated by :
92 --kernel-only Only install kernel drivers and firmware files
93 --no-kernel Do not install kernel drivers and firmware files
94 --print-cmdline Print the kernel command line for the given disk layout
95 --early-microcode Combine early microcode with ramdisk
96 --no-early-microcode Do not combine early microcode with ramdisk
97 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
98 --strip Strip binaries in the initramfs
99 --nostrip Do not strip binaries in the initramfs
100 --prelink Prelink binaries in the initramfs
101 --noprelink Do not prelink binaries in the initramfs
102 --hardlink Hardlink files in the initramfs
103 --nohardlink Do not hardlink files in the initramfs
104 --prefix [DIR] Prefix initramfs files with [DIR]
105 --noprefix Do not prefix initramfs files
106 --mdadmconf Include local /etc/mdadm.conf
107 --nomdadmconf Do not include local /etc/mdadm.conf
108 --lvmconf Include local /etc/lvm/lvm.conf
109 --nolvmconf Do not include local /etc/lvm/lvm.conf
110 --fscks [LIST] Add a space-separated list of fsck helpers.
111 --nofscks Inhibit installation of any fsck helpers.
112 --ro-mnt Mount / and /usr read-only by default.
113 -h, --help This message
114 --debug Output debug information of the build process
115 --profile Output profile information of the build process
116 -L, --stdlog [0-6] Specify logging level (to standard error)
117 0 - suppress any messages
118 1 - only fatal errors
122 5 - debug info (here starts lots of output)
123 6 - trace info (and even more)
124 -v, --verbose Increase verbosity level
125 -q, --quiet Decrease verbosity level
126 -c, --conf [FILE] Specify configuration file to use.
127 Default: /etc/dracut.conf
128 --confdir [DIR] Specify configuration directory to use *.conf files
129 from. Default: /etc/dracut.conf.d
130 --tmpdir [DIR] Temporary directory to be used instead of default
132 -l, --local Local mode. Use modules from the current working
133 directory instead of the system-wide installed in
134 /usr/lib/dracut/modules.d.
135 Useful when running dracut from a git checkout.
136 -H, --hostonly Host-Only mode: Install only what is needed for
137 booting the local host instead of a generic host.
138 -N, --no-hostonly Disables Host-Only mode
139 --persistent-policy [POLICY]
140 Use [POLICY] to address disks and partitions.
141 POLICY can be any directory name found in /dev/disk.
142 E.g. "by-uuid", "by-label"
143 --fstab Use /etc/fstab to determine the root device.
144 --add-fstab [FILE] Add file to the initramfs fstab
145 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
146 Mount device [DEV] on mountpoint [MP] with filesystem
147 [FSTYPE] and options [FSOPTS] in the initramfs
148 --add-device "[DEV]" Bring up [DEV] in initramfs
149 -i, --include [SOURCE] [TARGET]
150 Include the files in the SOURCE directory into the
151 Target directory in the final initramfs.
152 If SOURCE is a file, it will be installed to TARGET
153 in the final initramfs.
154 -I, --install [LIST] Install the space separated list of files into the
156 --gzip Compress the generated initramfs using gzip.
157 This will be done by default, unless another
158 compression option or --no-compress is passed.
159 --bzip2 Compress the generated initramfs using bzip2.
160 Make sure your kernel has bzip2 decompression support
161 compiled in, otherwise you will not be able to boot.
162 --lzma Compress the generated initramfs using lzma.
163 Make sure your kernel has lzma support compiled in,
164 otherwise you will not be able to boot.
165 --xz Compress the generated initramfs using xz.
166 Make sure that your kernel has xz support compiled
167 in, otherwise you will not be able to boot.
168 --compress [COMPRESSION] Compress the generated initramfs with the
169 passed compression program. Make sure your kernel
170 knows how to decompress the generated initramfs,
171 otherwise you will not be able to boot.
172 --no-compress Do not compress the generated initramfs. This will
173 override any other compression options.
174 --list-modules List all available dracut modules.
175 -M, --show-modules Print included module's name to standard output during
177 --keep Keep the temporary initramfs for debugging purposes
178 --printsize Print out the module install size
179 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
181 If [LIST] has multiple arguments, then you have to put these in quotes.
185 # dracut --add-drivers "module1 module2" ...
191 # push values to a stack
192 # $1 = stack variable
195 # push stack 1 2 "3 4"
198 local __stack
=$1; shift
200 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
205 # pops the last value from a stack
206 # assigns value to second argument variable
207 # or echo to stdout, if no second argument
208 # $1 = stack variable
209 # $2 = optional variable to store the value
214 local __stack=$1; shift
217 # check for empty stack
218 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
220 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
222 if [[ "$__resultvar" ]]; then
223 eval $__resultvar="'$_value'"
225 printf "%s" "$_value"
227 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
231 # Little helper function for reading args from the commandline.
232 # it automatically handles -a b and -a=b variants, and returns 1 if
233 # we need to shift $3.
238 local rematch
='^[^=]*=(.*)$'
239 if [[ $2 =~
$rematch ]]; then
240 read "$1" <<< "${BASH_REMATCH[1]}"
243 # There is no way to shift our callers args, so
244 # return 1 to indicate they should do it instead.
251 local suffix
=$1; shift
256 for i
in "$d/"*"$suffix"; do
257 if [[ -e "$i" ]]; then
258 printf "%s\n" "${i##*/}"
264 for f
in "${files[@]}"; do
266 if [[ -e "$d/$f" ]]; then
267 printf "%s\n" "$d/$f"
279 # Workaround -i, --include taking 2 arguments
280 set -- "${@/--include/++include}"
282 # This prevents any long argument ending with "-i"
283 # -i, like --opt-i but I think we can just prevent that
284 set -- "${@/%-i/++include}"
286 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
287 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
291 --long add-drivers
: \
292 --long omit-drivers
: \
296 --long filesystems
: \
316 --long print-cmdline \
317 --long kernel-cmdline
: \
338 --long no-host-only \
339 --long persistent-policy
: \
347 --long list-modules \
348 --long show-modules \
351 --long regenerate-all \
352 --long noimageifnotneeded \
353 --long early-microcode \
354 --long no-early-microcode \
357 if (( $?
!= 0 )); then
366 --kver) kernel
="$2"; shift;;
367 -a|
--add) push add_dracutmodules_l
"$2"; shift;;
368 --force-add) push force_add_dracutmodules_l
"$2"; shift;;
369 --add-drivers) push add_drivers_l
"$2"; shift;;
370 --omit-drivers) push omit_drivers_l
"$2"; shift;;
371 -m|
--modules) push dracutmodules_l
"$2"; shift;;
372 -o|
--omit) push omit_dracutmodules_l
"$2"; shift;;
373 -d|
--drivers) push drivers_l
"$2"; shift;;
374 --filesystems) push filesystems_l
"$2"; shift;;
375 -I|
--install) push install_items_l
"$2"; shift;;
376 --fwdir) push fw_dir_l
"$2"; shift;;
377 --libdirs) push libdirs_l
"$2"; shift;;
378 --fscks) push fscks_l
"$2"; shift;;
379 --add-fstab) push add_fstab_l
"$2"; shift;;
380 --mount) push fstab_lines
"$2"; shift;;
381 --add-device|
--device)
382 push add_device_l
"$2"; shift;;
383 --kernel-cmdline) push kernel_cmdline_l
"$2"; shift;;
384 --nofscks) nofscks_l
="yes";;
385 --ro-mnt) ro_mnt_l
="yes";;
386 -k|
--kmoddir) drivers_dir_l
="$2"; shift;;
387 -c|
--conf) conffile
="$2"; shift;;
388 --confdir) confdir
="$2"; shift;;
389 --tmpdir) tmpdir_l
="$2"; shift;;
390 -L|
--stdlog) stdloglvl_l
="$2"; shift;;
391 --compress) compress_l
="$2"; shift;;
392 --prefix) prefix_l
="$2"; shift;;
393 -f|
--force) force
=yes;;
394 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
395 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
396 --print-cmdline) print_cmdline
="yes"; hostonly_l
="yes"; kernel_only
="yes"; no_kernel
="yes";;
397 --early-microcode) early_microcode_l
="yes";;
398 --no-early-microcode) early_microcode_l
="no";;
399 --strip) do_strip_l
="yes";;
400 --nostrip) do_strip_l
="no";;
401 --prelink) do_prelink_l
="yes";;
402 --noprelink) do_prelink_l
="no";;
403 --hardlink) do_hardlink_l
="yes";;
404 --nohardlink) do_hardlink_l
="no";;
405 --noprefix) prefix_l
="/";;
406 --mdadmconf) mdadmconf_l
="yes";;
407 --nomdadmconf) mdadmconf_l
="no";;
408 --lvmconf) lvmconf_l
="yes";;
409 --nolvmconf) lvmconf_l
="no";;
410 --debug) debug
="yes";;
411 --profile) profile
="yes";;
412 --sshkey) sshkey
="$2"; shift;;
413 -v|
--verbose) ((verbosity_mod_l
++));;
414 -q|
--quiet) ((verbosity_mod_l--
));;
417 [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
418 && dracutbasedir
="$(readlink -f "${0%/*}")"
420 -H|
--hostonly|
--host-only)
422 -N|
--no-hostonly|
--no-host-only)
425 persistent_policy_l
="$2"; shift;;
426 --fstab) use_fstab_l
="yes" ;;
427 -h|
--help) long_usage
; exit 1 ;;
428 -i|
--include) push include_src
"$2"
430 --bzip2) compress_l
="bzip2";;
431 --lzma) compress_l
="lzma";;
432 --xz) compress_l
="xz";;
433 --no-compress) _no_compress_l
="cat";;
434 --gzip) compress_l
="gzip";;
435 --list-modules) do_list
="yes";;
440 --printsize) printsize
="yes";;
441 --regenerate-all) regenerate_all
="yes";;
442 --noimageifnotneeded) noimageifnotneeded
="yes";;
446 *) # should not even reach this point
447 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
452 # getopt cannot handle multiple arguments, so just handle "-I,--include"
453 # the old fashioned way
457 ++include
) push include_src
"$2"
458 push include_target
"$3"
461 if ! [[ ${outfile+x} ]]; then
463 elif ! [[ ${kernel+x} ]]; then
466 printf "\nUnknown arguments: %s\n\n" "$*" >&2
474 if [[ $regenerate_all == "yes" ]]; then
476 if [[ $kernel ]]; then
477 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
481 if [[ $outfile ]]; then
482 printf -- "--regenerate-all cannot be called with a image file\n" >&2
486 ((len
=${#dracut_args[@]}))
487 for ((i
=0; i
< len
; i
++)); do
488 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
489 unset dracut_args
[$i]
494 [[ -f $i/modules.
builtin ]] ||
continue
495 dracut
--kver="$i" "${dracut_args[@]}"
499 elif [[ $kernel ]]; then
500 if ! [[ -d /lib
/modules
/$kernel ]] && [[ $no_kernel != yes ]]; then
501 printf -- "Kernel version $kernel has no modules in /lib/modules/$kernel\n" >&2
506 if ! [[ $kernel ]]; then
510 if ! [[ $outfile ]]; then
511 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
513 if [[ $MACHINE_ID ]] && ( [[ -d /boot
/${MACHINE_ID} ]] ||
[[ -L /boot
/${MACHINE_ID} ]] ); then
514 outfile
="/boot/${MACHINE_ID}/$kernel/initrd"
516 outfile
="/boot/initramfs-$kernel.img"
520 for i
in /usr
/sbin
/sbin
/usr
/bin
/bin
; do
525 if [[ "$NPATH" != "*:$rl*" ]] ; then
529 export PATH
="${NPATH#:}"
535 unset LD_LIBRARY_PATH
538 export DRACUT_LOG_LEVEL
=warning
540 export DRACUT_LOG_LEVEL
=debug
541 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
546 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
551 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
553 # if we were not passed a config file, try the default one
554 if [[ ! -f $conffile ]]; then
555 if [[ $allowlocal ]]; then
556 conffile
="$dracutbasedir/dracut.conf"
558 conffile
="/etc/dracut.conf"
562 if [[ ! -d $confdir ]]; then
563 if [[ $allowlocal ]]; then
564 confdir
="$dracutbasedir/dracut.conf.d"
566 confdir
="/etc/dracut.conf.d"
570 # source our config file
571 [[ -f $conffile ]] && .
"$conffile"
573 # source our config dir
574 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
575 [[ -e $f ]] && .
"$f"
578 # these optins add to the stuff in the config file
579 if (( ${#add_dracutmodules_l[@]} )); then
580 while pop add_dracutmodules_l val
; do
581 add_dracutmodules
+=" $val "
585 if (( ${#force_add_dracutmodules_l[@]} )); then
586 while pop force_add_dracutmodules_l val
; do
587 force_add_dracutmodules
+=" $val "
591 if (( ${#fscks_l[@]} )); then
592 while pop fscks_l val
; do
597 if (( ${#add_fstab_l[@]} )); then
598 while pop add_fstab_l val
; do
603 if (( ${#fstab_lines_l[@]} )); then
604 while pop fstab_lines_l val
; do
605 push fstab_lines
$val
609 if (( ${#install_items_l[@]} )); then
610 while pop install_items_l val
; do
611 install_items
+=" $val "
615 # these options override the stuff in the config file
616 if (( ${#dracutmodules_l[@]} )); then
618 while pop dracutmodules_l val
; do
619 dracutmodules
+="$val "
623 if (( ${#omit_dracutmodules_l[@]} )); then
624 omit_dracutmodules
=''
625 while pop omit_dracutmodules_l val
; do
626 omit_dracutmodules
+="$val "
630 if (( ${#filesystems_l[@]} )); then
632 while pop filesystems_l val
; do
637 if (( ${#fw_dir_l[@]} )); then
639 while pop fw_dir_l val
; do
644 if (( ${#libdirs_l[@]} )); then
646 while pop libdirs_l val
; do
651 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
652 [[ ! $stdloglvl ]] && stdloglvl
=4
653 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
654 ((stdloglvl
> 6)) && stdloglvl
=6
655 ((stdloglvl
< 0)) && stdloglvl
=0
657 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
658 [[ $do_strip_l ]] && do_strip
=$do_strip_l
659 [[ $do_strip ]] || do_strip
=yes
660 [[ $do_prelink_l ]] && do_prelink
=$do_prelink_l
661 [[ $do_prelink ]] || do_prelink
=yes
662 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
663 [[ $do_hardlink ]] || do_hardlink
=yes
664 [[ $prefix_l ]] && prefix
=$prefix_l
665 [[ $prefix = "/" ]] && unset prefix
666 [[ $hostonly_l ]] && hostonly
=$hostonly_l
667 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
668 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
669 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
670 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
671 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
672 [[ $fw_dir ]] || fw_dir
="/lib/firmware/updates /lib/firmware"
673 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
674 [[ $tmpdir ]] || tmpdir
=/var
/tmp
675 [[ $compress_l ]] && compress=$compress_l
676 [[ $show_modules_l ]] && show_modules
=$show_modules_l
677 [[ $nofscks_l ]] && nofscks
="yes"
678 [[ $ro_mnt_l ]] && ro_mnt
="yes"
679 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
680 [[ $early_microcode ]] || early_microcode
=no
681 # eliminate IFS hackery when messing with fw_dir
682 fw_dir
=${fw_dir//:/ }
684 # handle compression options.
685 [[ $compress ]] ||
compress="gzip"
687 bzip2) compress="bzip2 -9";;
688 lzma
) compress="lzma -9";;
689 xz
) compress="xz --check=crc32 --lzma2=dict=1MiB";;
690 gzip) compress="gzip -9"; command -v pigz
> /dev
/null
2>&1 && compress="pigz -9";;
692 if [[ $_no_compress_l = "cat" ]]; then
696 [[ $hostonly = yes ]] && hostonly
="-h"
697 [[ $hostonly != "-h" ]] && unset hostonly
699 readonly TMPDIR
="$tmpdir"
700 readonly initdir
="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
701 [ -d "$initdir" ] ||
{
702 printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
706 if [[ $early_microcode = yes ]]; then
707 readonly early_cpio_dir
="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
708 [ -d "$early_cpio_dir" ] ||
{
709 printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_cpio.XXXXXX failed." >&2
713 # clean up after ourselves no matter how we die.
716 [[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";
717 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
718 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
719 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
723 # clean up after ourselves no matter how we die.
724 trap 'exit 1;' SIGINT
726 export DRACUT_KERNEL_LAZY
="1"
727 export DRACUT_RESOLVE_LAZY
="1"
729 if [[ -f $dracutbasedir/dracut-functions.sh
]]; then
730 .
$dracutbasedir/dracut-functions.sh
732 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
733 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
734 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
738 if ! [[ $print_cmdline ]]; then
740 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev
/null
; then
741 unset DRACUT_RESOLVE_LAZY
742 export DRACUT_RESOLVE_DEPS
=1
744 rm -fr -- ${initdir}/*
747 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
748 .
$dracutbasedir/dracut-version.sh
751 # Verify bash version, current minimum is 3.1
752 if (( BASH_VERSINFO
[0] < 4 )); then
753 dfatal
'You need at least Bash 4 to use dracut, sorry.'
757 dracutfunctions
=$dracutbasedir/dracut-functions.sh
758 export dracutfunctions
760 if (( ${#drivers_l[@]} )); then
762 while pop drivers_l val
; do
766 drivers
=${drivers/-/_}
768 if (( ${#add_drivers_l[@]} )); then
769 while pop add_drivers_l val
; do
770 add_drivers
+=" $val "
773 add_drivers
=${add_drivers/-/_}
775 if (( ${#omit_drivers_l[@]} )); then
776 while pop omit_drivers_l val
; do
777 omit_drivers
+=" $val "
780 omit_drivers
=${omit_drivers/-/_}
782 if (( ${#kernel_cmdline_l[@]} )); then
783 while pop kernel_cmdline_l val
; do
784 kernel_cmdline
+=" $val "
788 omit_drivers_corrected
=""
789 for d
in $omit_drivers; do
790 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
791 omit_drivers_corrected
+="$d|"
793 omit_drivers
="${omit_drivers_corrected%|}"
794 unset omit_drivers_corrected
796 # prepare args for logging
797 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
798 [[ "${dracut_args[$i]}" == *\
* ]] && \
799 dracut_args
[$i]="\"${dracut_args[$i]}\""
802 dinfo
"Executing: $0 ${dracut_args[@]}"
804 [[ $do_list = yes ]] && {
805 for mod
in $dracutbasedir/modules.d
/*; do
806 [[ -d $mod ]] ||
continue;
807 [[ -e $mod/install ||
-e $mod/installkernel || \
808 -e $mod/module-setup.sh
]] ||
continue
809 printf "%s\n" "${mod##*/??}"
814 # This is kinda legacy -- eventually it should go away.
815 case $dracutmodules in
816 ""|auto
) dracutmodules
="all" ;;
819 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
821 if [[ -d $srcmods ]]; then
822 [[ -f $srcmods/modules.dep
]] ||
{
823 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
827 if [[ -f $outfile && ! $force && ! $print_cmdline ]]; then
828 dfatal
"Will not override existing initramfs ($outfile) without --force"
832 # Need to be able to have non-root users read stuff (rpcbind etc)
835 if [[ $hostonly ]]; then
836 for i
in /sys
/proc
/run
/dev
; do
837 if ! findmnt
--target "$i" &>/dev
/null
; then
838 dwarning
"Turning off host-only mode: '$i' is not mounted!"
844 declare -A host_fs_types
846 for line
in "${fstab_lines[@]}"; do
850 host_fs_types
["$1"]="$3"
853 for f
in $add_fstab; do
854 [[ -e $f ]] ||
continue
855 while read dev rest
; do
856 push host_devs
"$dev"
860 for dev
in $add_device; do
861 push host_devs
"$dev"
864 if (( ${#add_device_l[@]} )); then
865 while pop add_device_l val
; do
867 push host_devs
"$val"
871 if [[ $hostonly ]]; then
872 # in hostonly mode, determine all devices, which have to be accessed
873 # and examine them for filesystem types
889 mp
=$
(readlink
-f "$mp")
890 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
891 _dev
=$
(find_block_device
"$mp")
892 _bdev
=$
(readlink
-f "/dev/block/$_dev")
893 [[ -b $_bdev ]] && _dev
=$_bdev
895 [[ "$_mp" == "/" ]] && root_dev
="$_dev"
896 push host_devs
"$_dev"
899 if [[ -f /proc
/swaps
]] && [[ -f /etc
/fstab
]]; then
900 while read dev
type rest
; do
901 [[ -b $dev ]] ||
continue
902 [[ "$type" == "partition" ]] ||
continue
904 while read _d _m _t _o _r
; do
905 [[ "$_d" == \
#* ]] && continue
906 [[ $_d ]] ||
continue
907 [[ $_t != "swap" ]] && continue
908 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
909 [[ "$_o" == *noauto
* ]] && continue
910 _d
=$
(expand_persistent_dev
"$_d")
911 [[ "$_d" -ef "$dev" ]] ||
continue
913 if [[ -f /etc
/crypttab
]]; then
914 while read _mapper _a _p _o
; do
915 [[ $_mapper = \
#* ]] && continue
916 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
917 [[ "$_o" ]] || _o
="$_p"
919 [[ $_o == *swap
* ]] && continue 2
923 push host_devs
"$(readlink -f "$dev")"
928 # record all host modaliases
929 declare -A host_modalias
930 find /sys
/devices
/ -name uevent
-print > "$initdir/.modalias"
933 [[ "$line" != MODALIAS\
=* ]] && continue
934 modalias
="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias
["$modalias"]=1
937 done < "$initdir/.modalias"
939 rm -f -- "$initdir/.modalias"
941 # check /proc/modules
942 declare -A host_modules
943 while read m rest
; do
953 if [[ -b /dev
/block
/$1 ]] && ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1"); then
954 host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
957 if [[ -b $1 ]] && ID_FS_TYPE
=$
(get_fs_env
"$1"); then
958 host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
961 if fstype
=$
(find_dev_fstype
"$1"); then
962 host_fs_types
["$1"]="$fstype"
968 for dev
in ${host_devs[@]}; do
970 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
973 for dev
in "${!host_fs_types[@]}"; do
974 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
975 rootopts
=$
(find_dev_fsopts
"$dev")
976 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
977 journaldev
=$
(fs_get_option
$rootopts "jdev")
978 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
979 journaldev
=$
(fs_get_option
$rootopts "logdev")
981 if [[ $journaldev ]]; then
982 dev
="$(readlink -f "$dev")"
983 push host_devs
"$dev"
985 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
990 || udevdir
="$(pkg-config udev --variable=udevdir 2>/dev/null)"
991 if ! [[ -d "$udevdir" ]]; then
992 [[ -d /lib
/udev
]] && udevdir
=/lib
/udev
993 [[ -d /usr
/lib
/udev
]] && udevdir
=/usr
/lib
/udev
996 [[ -d $systemdutildir ]] \
997 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
999 if ! [[ -d "$systemdutildir" ]]; then
1000 [[ -d /lib
/systemd
]] && systemdutildir
=/lib
/systemd
1001 [[ -d /usr
/lib
/systemd
]] && systemdutildir
=/usr
/lib
/systemd
1004 [[ -d $systemdsystemunitdir ]] \
1005 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
1007 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1009 [[ -d $systemdsystemconfdir ]] \
1010 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2>/dev
/null
)
1012 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir
=/etc
/systemd
/system
1014 export initdir dracutbasedir dracutmodules \
1015 fw_dir drivers_dir debug no_kernel kernel_only \
1016 omit_drivers mdadmconf lvmconf root_dev \
1017 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1018 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1019 debug host_fs_types host_devs sshkey add_fstab \
1020 DRACUT_VERSION udevdir prefix filesystems drivers \
1021 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1022 host_modalias host_modules
1025 # check all our modules to see if they should be sourced.
1026 # This builds a list of modules that we will install next.
1027 for_each_module_dir check_module
1028 for_each_module_dir check_mount
1030 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1032 if [[ $print_cmdline ]]; then
1034 # source our modules.
1035 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1036 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1037 module_cmdline
"$_d_mod"
1044 outdir
=${outfile%/*}
1045 [[ $outdir ]] || outdir
="/"
1047 if [[ ! -d "$outdir" ]]; then
1048 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1050 elif [[ ! -w "$outdir" ]]; then
1051 dfatal
"No permission to write to $outdir."
1053 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1054 dfatal
"No permission to write $outfile."
1058 # Create some directory structure first
1059 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1061 [[ -h /lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1062 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1064 if [[ $prefix ]]; then
1065 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1066 [[ "$d" == */* ]] && continue
1067 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1071 if [[ $kernel_only != yes ]]; then
1072 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var
$libdirs; do
1073 [[ -e "${initdir}${prefix}/$d" ]] && continue
1074 if [ -L "/$d" ]; then
1075 inst_symlink
"/$d" "${prefix}/$d"
1077 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1081 for d
in dev proc sys sysroot root run run
/lock run
/initramfs
; do
1082 if [ -L "/$d" ]; then
1085 mkdir
-m 0755 -p "$initdir/$d"
1089 ln -sfn ..
/run
"$initdir/var/run"
1090 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1091 ln -sfn ..
/run
/log
"$initdir/var/log"
1093 for d
in lib
"$libdir"; do
1094 [[ -e "${initdir}${prefix}/$d" ]] && continue
1095 if [ -h "/$d" ]; then
1096 inst
"/$d" "${prefix}/$d"
1098 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1103 if [[ $kernel_only != yes ]]; then
1104 mkdir
-p "${initdir}/etc/cmdline.d"
1105 for _d
in $hookdirs; do
1106 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
1108 if [[ "$UID" = "0" ]]; then
1109 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
1110 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
1111 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
1115 _isize
=0 #initramfs size
1117 # source our modules.
1118 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1119 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1120 if [[ "$mods_to_load" == *\
$_d_mod\
* ]]; then
1121 if [[ $show_modules = yes ]]; then
1122 printf "%s\n" "$_d_mod"
1124 dinfo
"*** Including module: $_d_mod ***"
1126 if [[ $kernel_only == yes ]]; then
1127 module_installkernel
"$_d_mod" ||
{
1128 dfatal
"installkernel failed in module $_d_mod"
1132 module_install
"$_d_mod"
1133 if [[ $no_kernel != yes ]]; then
1134 module_installkernel
"$_d_mod" ||
{
1135 dfatal
"installkernel failed in module $_d_mod"
1140 mods_to_load
=${mods_to_load// $_d_mod /}
1141 modules_loaded
+="$_d_mod "
1143 #print the module install size
1144 if [ -n "$printsize" ]; then
1145 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
1146 _isize_delta
=$
((_isize_new
- _isize
))
1147 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1154 for i
in $modules_loaded; do
1155 mkdir
-p $initdir/lib
/dracut
1156 printf "%s\n" "$i" >> $initdir/lib
/dracut
/modules.txt
1159 dinfo
"*** Including modules done ***"
1161 ## final stuff that has to happen
1162 if [[ $no_kernel != yes ]]; then
1164 if [[ $drivers ]]; then
1165 hostonly
='' instmods
$drivers
1168 if [[ $add_drivers ]]; then
1169 hostonly
='' instmods
-c $add_drivers
1171 if [[ $filesystems ]]; then
1172 hostonly
='' instmods
-c $filesystems
1175 dinfo
"*** Installing kernel module dependencies and firmware ***"
1177 dinfo
"*** Installing kernel module dependencies and firmware done ***"
1179 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1180 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1181 [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1182 for i
in ${initdir}/etc
/cmdline.d
/*.conf
; do
1183 # We need no initramfs image and do not generate one.
1184 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1190 if [[ $kernel_only != yes ]]; then
1191 (( ${#install_items[@]} > 0 )) && inst_multiple
${install_items[@]}
1193 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1195 while pop fstab_lines line
; do
1196 printf "%s\n" "$line 0 0" >> "${initdir}/etc/fstab"
1199 for f
in $add_fstab; do
1200 cat "$f" >> "${initdir}/etc/fstab"
1203 if [ -d ${initdir}/$systemdutildir ]; then
1204 mkdir
-p ${initdir}/etc
/conf.d
1206 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1207 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1208 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1209 } > ${initdir}/etc
/conf.d
/systemd.conf
1212 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1213 dinfo
"*** Resolving executable dependencies ***"
1214 find "$initdir" -type f \
1215 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1216 -not -path '*.ko' -print0 \
1217 |
xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1218 dinfo
"*** Resolving executable dependencies done***"
1222 while pop include_src src
&& pop include_target tgt
; do
1223 if [[ $src && $tgt ]]; then
1224 if [[ -f $src ]]; then
1227 ddebug
"Including directory: $src"
1228 mkdir
-p "${initdir}/${tgt}"
1229 # check for preexisting symlinks, so we can cope with the
1230 # symlinks to $prefix
1231 for i
in "$src"/*; do
1232 [[ -e "$i" ||
-h "$i" ]] ||
continue
1233 s
=${initdir}/${tgt}/${i#$src/}
1234 if [[ -d "$i" ]]; then
1235 if ! [[ -e "$s" ]]; then
1236 mkdir
-m 0755 -p "$s"
1237 chmod --reference="$i" "$s"
1239 cp --reflink=auto
--sparse=auto
-fa -t "$s" "$i"/*
1241 cp --reflink=auto
--sparse=auto
-fa -t "$s" "$i"
1248 if [[ $kernel_only != yes ]]; then
1249 # make sure that library links are correct and up to date
1250 for f
in /etc
/ld.so.conf
/etc
/ld.so.conf.d
/*; do
1251 [[ -f $f ]] && inst_simple
"$f"
1253 if ! ldconfig
-r "$initdir"; then
1254 if [[ $UID = 0 ]]; then
1255 derror
"ldconfig exited ungracefully"
1257 derror
"ldconfig might need uid=0 (root) for chroot()"
1262 if [[ $do_prelink == yes ]]; then
1263 PRELINK_BIN
="$(command -v prelink)"
1264 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1265 if [[ $DRACUT_FIPS_MODE ]]; then
1266 dinfo
"*** Installing prelink files ***"
1267 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
/etc
/prelink.cache
1269 dinfo
"*** Pre-linking files ***"
1270 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
1271 chroot
"$initdir" "$PRELINK_BIN" -a
1272 rm -f -- "$initdir/$PRELINK_BIN"
1273 rm -fr -- "$initdir"/etc
/prelink.
*
1274 dinfo
"*** Pre-linking files done ***"
1279 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1280 dinfo
"*** Hardlinking files ***"
1281 hardlink
"$initdir" 2>&1
1282 dinfo
"*** Hardlinking files done ***"
1286 if [[ $do_strip = yes ]] ; then
1287 for p
in strip
xargs find; do
1288 if ! type -P $p >/dev
/null
; then
1289 dinfo
"Could not find '$p'. Not stripping the initramfs."
1295 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1296 dinfo
"*** Stripping files ***"
1297 find "$initdir" -type f \
1298 -executable -not -path '*/lib/modules/*.ko' -print0 \
1299 |
xargs -r -0 strip
-g 2>/dev
/null
1301 # strip kernel modules, but do not touch signed modules
1302 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
1303 |
while read -r -d $
'\0' f
; do
1304 SIG
=$
(tail -c 28 "$f")
1305 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
1306 done |
xargs -r -0 strip
-g
1308 dinfo
"*** Stripping files done ***"
1310 if [[ $early_microcode = yes ]]; then
1311 dinfo
"*** Generating early-microcode cpio image ***"
1312 ucode_dir
=(amd-ucode intel-ucode
)
1313 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
1314 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
1317 if [[ $hostonly ]]; then
1318 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
1319 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
1321 for idx
in $_dest_idx; do
1322 _fw
=${ucode_dir[$idx]}
1323 for _fwdir
in $fw_dir; do
1324 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1326 dinfo
"*** Constructing ${ucode_dest[$idx]} ****"
1327 if [[ $hostonly ]]; then
1328 _src
=$
(get_ucode_file
)
1329 if ! [[ -r $_fwdir/$_fw/$_src ]];then
1333 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1334 create_early_cpio
="yes"
1340 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1341 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
1342 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
1344 for table
in $acpi_table_dir/*.aml
; do
1345 dinfo
" Adding ACPI table: $table"
1346 cp $table $_dest_dir
1347 create_early_cpio
="yes"
1352 dinfo
"*** Creating image file ***"
1353 if [[ $create_early_cpio = yes ]]; then
1354 # The microcode blob is _before_ the initramfs blob, not after
1355 (cd "$early_cpio_dir/d"; find .
-print0 |
cpio --null -o -H newc
--quiet >..
/early.
cpio)
1356 mv $early_cpio_dir/early.
cpio $outfile.$$
1358 if ! ( umask 077; cd "$initdir"; find .
-print0 |
cpio --null -R 0:0 -H newc
-o --quiet| \
1359 $compress >> "$outfile.$$"; ); then
1360 dfatal
"dracut: creation of $outfile.$$ failed"
1363 mv -- "$outfile.$$" "$outfile"
1364 dinfo
"*** Creating image file done ***"
1366 if (( maxloglvl
>= 5 )); then
1367 if [[ $allowlocal ]]; then
1368 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1370 lsinitrd
"$outfile"| ddebug