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]
199 If [LIST] has multiple arguments, then you have to put these in quotes.
203 # dracut --add-drivers "module1 module2" ...
209 # push values to a stack
210 # $1 = stack variable
213 # push stack 1 2 "3 4"
216 local __stack
=$1; shift
218 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
222 # Fills up host_devs stack variable and makes sure there are no duplicates
225 for _dev in ${host_devs[@]}; do
226 [ "$_dev" = "$1" ] && return
233 # pops the last value from a stack
234 # assigns value to second argument variable
235 # or echo to stdout, if no second argument
236 # $1 = stack variable
237 # $2 = optional variable to store the value
242 local __stack=$1; shift
245 # check for empty stack
246 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
248 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
250 if [[ "$__resultvar" ]]; then
251 eval $__resultvar="'$_value'"
253 printf "%s" "$_value"
255 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
259 # Little helper function for reading args from the commandline.
260 # it automatically handles -a b and -a=b variants, and returns 1 if
261 # we need to shift $3.
266 local rematch
='^[^=]*=(.*)$'
267 if [[ $2 =~
$rematch ]]; then
268 read "$1" <<< "${BASH_REMATCH[1]}"
271 # There is no way to shift our callers args, so
272 # return 1 to indicate they should do it instead.
279 local suffix
=$1; shift
284 for i
in "$d/"*"$suffix"; do
285 if [[ -e "$i" ]]; then
286 printf "%s\n" "${i##*/}"
292 for f
in "${files[@]}"; do
294 if [[ -e "$d/$f" ]]; then
295 printf "%s\n" "$d/$f"
305 # Workaround -i, --include taking 2 arguments
306 set -- "${@/--include/++include}"
308 # This prevents any long argument ending with "-i"
309 # -i, like --opt-i but I think we can just prevent that
310 set -- "${@/%-i/++include}"
312 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
313 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
317 --long add-drivers
: \
318 --long force-drivers
: \
319 --long omit-drivers
: \
323 --long filesystems
: \
325 --long install-optional
: \
346 --long print-cmdline \
347 --long kernel-cmdline
: \
369 --long no-host-only \
370 --long hostonly-cmdline \
371 --long no-hostonly-cmdline \
372 --long persistent-policy
: \
382 --long list-modules \
383 --long show-modules \
386 --long regenerate-all \
387 --long noimageifnotneeded \
388 --long early-microcode \
389 --long no-early-microcode \
390 --long reproducible \
394 if (( $?
!= 0 )); then
404 rearrange_params
"$@"
407 # parse command line args to check if '--rebuild' option is present
412 if [ "$1" == "--" ]; then
415 if [ "$1" == "--rebuild" ]; then
418 if [ ! -e $rebuild_file ]; then
419 echo "Image file '$rebuild_file', for rebuild, does not exist!"
422 abs_rebuild_file
=$
(readlink
-f "$rebuild_file") && rebuild_file
="$abs_rebuild_file"
428 # get output file name and kernel version from command line arguments
434 if ! [[ ${outfile+x} ]]; then
436 elif ! [[ ${kernel+x} ]]; then
439 printf "\nUnknown arguments: %s\n\n" "$*" >&2
447 # extract input image file provided with rebuild option to get previous parameters, if any
448 if [[ $append_args_l == "yes" ]]; then
451 # determine resultant file
452 if ! [[ $outfile ]]; then
453 outfile
=$rebuild_file
456 if ! rebuild_param
=$
(lsinitrd
$rebuild_file '*lib/dracut/build-parameter.txt'); then
457 echo "Image '$rebuild_file' has no rebuild information stored"
461 # prepend previous parameters to current command line args
462 if [[ $rebuild_param ]]; then
463 TEMP
="$rebuild_param $TEMP"
465 rearrange_params
"$@"
468 # clean the temporarily used scratch-pad directory
478 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
479 PARMS_TO_STORE
+=" $1";
482 --kver) kernel
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
483 -a|
--add) push add_dracutmodules_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
484 --force-add) push force_add_dracutmodules_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
485 --add-drivers) push add_drivers_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
486 --force-drivers) push force_drivers_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
487 --omit-drivers) push omit_drivers_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
488 -m|
--modules) push dracutmodules_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
489 -o|
--omit) push omit_dracutmodules_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
490 -d|
--drivers) push drivers_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
491 --filesystems) push filesystems_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
492 -I|
--install) push install_items_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
494 push install_optional_items_l \
495 "$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
496 --fwdir) push fw_dir_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
497 --libdirs) push libdirs_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
498 --fscks) push fscks_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
499 --add-fstab) push add_fstab_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
500 --mount) push fstab_lines
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
501 --add-device|
--device)
502 push add_device_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
503 --kernel-cmdline) push kernel_cmdline_l
"$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
504 --nofscks) nofscks_l
="yes";;
505 --ro-mnt) ro_mnt_l
="yes";;
506 -k|
--kmoddir) drivers_dir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
507 -c|
--conf) conffile
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
508 --confdir) confdir
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
509 --tmpdir) tmpdir_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
510 -L|
--stdlog) stdloglvl_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
511 --compress) compress_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
512 --prefix) prefix_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
513 --loginstall) loginstall_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
514 --rebuild) if [ $rebuild_file == $outfile ]; then
519 -f|
--force) force
=yes;;
520 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
521 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
523 print_cmdline
="yes"; hostonly_l
="yes"; kernel_only
="yes"; no_kernel
="yes";;
525 early_microcode_l
="yes";;
526 --no-early-microcode)
527 early_microcode_l
="no";;
528 --strip) do_strip_l
="yes";;
529 --nostrip) do_strip_l
="no";;
530 --prelink) do_prelink_l
="yes";;
531 --noprelink) do_prelink_l
="no";;
532 --hardlink) do_hardlink_l
="yes";;
533 --nohardlink) do_hardlink_l
="no";;
534 --noprefix) prefix_l
="/";;
535 --mdadmconf) mdadmconf_l
="yes";;
536 --nomdadmconf) mdadmconf_l
="no";;
537 --lvmconf) lvmconf_l
="yes";;
538 --nolvmconf) lvmconf_l
="no";;
539 --debug) debug
="yes";;
540 --profile) profile
="yes";;
541 --sshkey) sshkey
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
542 --logfile) logfile_l
="$2"; shift;;
543 -v|
--verbose) ((verbosity_mod_l
++));;
544 -q|
--quiet) ((verbosity_mod_l--
));;
547 [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
548 && dracutbasedir
="$(readlink -f "${0%/*}")"
550 -H|
--hostonly|
--host-only)
552 -N|
--no-hostonly|
--no-host-only)
555 hostonly_cmdline_l
="yes" ;;
556 --no-hostonly-cmdline)
557 hostonly_cmdline_l
="no" ;;
559 persistent_policy_l
="$2"; PARMS_TO_STORE
+=" '$2'"; shift;;
560 --fstab) use_fstab_l
="yes" ;;
561 -h|
--help) long_usage
; exit 1 ;;
562 -i|
--include) push include_src
"$2"; PARMS_TO_STORE
+=" '$2'";
564 --bzip2) compress_l
="bzip2";;
565 --lzma) compress_l
="lzma";;
566 --xz) compress_l
="xz";;
567 --lzo) compress_l
="lzo";;
568 --lz4) compress_l
="lz4";;
569 --no-compress) _no_compress_l
="cat";;
570 --gzip) compress_l
="gzip";;
571 --list-modules) do_list
="yes";;
576 --printsize) printsize
="yes";;
577 --regenerate-all) regenerate_all
="yes";;
578 --noimageifnotneeded) noimageifnotneeded
="yes";;
579 --reproducible) reproducible_l
="yes";;
582 *) # should not even reach this point
583 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
588 # getopt cannot handle multiple arguments, so just handle "-I,--include"
589 # the old fashioned way
592 if [ "${1%%=*}" == "++include" ]; then
593 push include_src
"$2"
594 push include_target
"$3"
595 PARMS_TO_STORE
+=" --include '$2' '$3'"
601 if [[ $regenerate_all == "yes" ]]; then
603 if [[ $kernel ]]; then
604 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
608 if [[ $outfile ]]; then
609 printf -- "--regenerate-all cannot be called with a image file\n" >&2
613 ((len
=${#dracut_args[@]}))
614 for ((i
=0; i
< len
; i
++)); do
615 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
616 unset dracut_args
[$i]
621 [[ -f $i/modules.dep
]] ||
[[ -f $i/modules.dep.bin
]] ||
continue
622 dracut
--kver="$i" "${dracut_args[@]}"
628 if ! [[ $kernel ]]; then
632 if [[ $kernel ]]; then
633 if ! [[ -d /lib
/modules
/$kernel ]] && [[ $no_kernel != yes ]]; then
634 printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2
638 if ! [[ $outfile ]]; then
639 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
641 if [[ $MACHINE_ID ]] && ( [[ -d /boot
/${MACHINE_ID} ]] ||
[[ -L /boot
/${MACHINE_ID} ]] ); then
642 outfile
="/boot/${MACHINE_ID}/$kernel/initrd"
644 outfile
="/boot/initramfs-$kernel.img"
652 unset LD_LIBRARY_PATH
656 export DRACUT_LOG_LEVEL
=warning
658 export DRACUT_LOG_LEVEL
=debug
659 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
664 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
669 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
671 # if we were not passed a config file, try the default one
672 if [[ ! -f $conffile ]]; then
673 if [[ $allowlocal ]]; then
674 conffile
="$dracutbasedir/dracut.conf"
676 conffile
="/etc/dracut.conf"
680 if [[ ! -d $confdir ]]; then
681 if [[ $allowlocal ]]; then
682 confdir
="$dracutbasedir/dracut.conf.d"
684 confdir
="/etc/dracut.conf.d"
688 # source our config file
689 [[ -f $conffile ]] && .
"$conffile"
691 # source our config dir
692 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
693 [[ -e $f ]] && .
"$f"
696 DRACUT_PATH
=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
698 for i
in $DRACUT_PATH; do
703 if [[ "$NPATH" != *:$rl* ]] ; then
707 export PATH
="${NPATH#:}"
710 # these optins add to the stuff in the config file
711 if (( ${#add_dracutmodules_l[@]} )); then
712 while pop add_dracutmodules_l val
; do
713 add_dracutmodules
+=" $val "
717 if (( ${#force_add_dracutmodules_l[@]} )); then
718 while pop force_add_dracutmodules_l val
; do
719 force_add_dracutmodules
+=" $val "
723 if (( ${#fscks_l[@]} )); then
724 while pop fscks_l val
; do
729 if (( ${#add_fstab_l[@]} )); then
730 while pop add_fstab_l val
; do
735 if (( ${#fstab_lines_l[@]} )); then
736 while pop fstab_lines_l val
; do
737 push fstab_lines
$val
741 if (( ${#install_items_l[@]} )); then
742 while pop install_items_l val
; do
743 install_items
+=" $val "
747 if (( ${#install_optional_items_l[@]} )); then
748 while pop install_optional_items_l val
; do
749 install_optional_items
+=" $val "
753 # these options override the stuff in the config file
754 if (( ${#dracutmodules_l[@]} )); then
756 while pop dracutmodules_l val
; do
757 dracutmodules
+="$val "
761 if (( ${#omit_dracutmodules_l[@]} )); then
762 omit_dracutmodules
=''
763 while pop omit_dracutmodules_l val
; do
764 omit_dracutmodules
+="$val "
768 if (( ${#filesystems_l[@]} )); then
770 while pop filesystems_l val
; do
775 if (( ${#fw_dir_l[@]} )); then
777 while pop fw_dir_l val
; do
782 if (( ${#libdirs_l[@]} )); then
784 while pop libdirs_l val
; do
789 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
790 [[ ! $stdloglvl ]] && stdloglvl
=4
791 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
792 ((stdloglvl
> 6)) && stdloglvl
=6
793 ((stdloglvl
< 0)) && stdloglvl
=0
795 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
796 [[ $do_strip_l ]] && do_strip
=$do_strip_l
797 [[ $do_strip ]] || do_strip
=yes
798 [[ $do_prelink_l ]] && do_prelink
=$do_prelink_l
799 [[ $do_prelink ]] || do_prelink
=yes
800 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
801 [[ $do_hardlink ]] || do_hardlink
=yes
802 [[ $prefix_l ]] && prefix
=$prefix_l
803 [[ $prefix = "/" ]] && unset prefix
804 [[ $hostonly_l ]] && hostonly
=$hostonly_l
805 [[ $hostonly_cmdline_l ]] && hostonly_cmdline
=$hostonly_cmdline_l
806 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline
="yes"
807 [[ $persistent_policy_l ]] && persistent_policy
=$persistent_policy_l
808 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
809 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
810 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
811 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
812 [[ $fw_dir ]] || fw_dir
="/lib/firmware/updates /lib/firmware"
813 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
814 [[ $tmpdir ]] || tmpdir
=/var
/tmp
815 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
816 [[ $compress_l ]] && compress=$compress_l
817 [[ $show_modules_l ]] && show_modules
=$show_modules_l
818 [[ $nofscks_l ]] && nofscks
="yes"
819 [[ $ro_mnt_l ]] && ro_mnt
="yes"
820 [[ $early_microcode_l ]] && early_microcode
=$early_microcode_l
821 [[ $early_microcode ]] || early_microcode
=no
822 [[ $logfile_l ]] && logfile
="$logfile_l"
823 [[ $reproducible_l ]] && reproducible
="$reproducible_l"
824 [[ $loginstall_l ]] && loginstall
="$loginstall_l"
826 # eliminate IFS hackery when messing with fw_dir
827 fw_dir
=${fw_dir//:/ }
829 # check for logfile and try to create one if it doesn't exist
830 if [[ -n "$logfile" ]];then
831 if [[ ! -f "$logfile" ]];then
833 if [ ! $?
-eq 0 ] ;then
834 printf "%s\n" "dracut: touch $logfile failed." >&2
839 # handle compression options.
840 [[ $compress ]] ||
compress="gzip"
842 bzip2) compress="bzip2 -9";;
843 lzma
) compress="lzma -9 -T0";;
844 xz
) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
845 gzip) compress="gzip -n -9";
846 if command -v pigz
> /dev
/null
2>&1; then
847 compress="pigz -9 -n -T -R"
848 elif command -v gzip --help 2>&1 |
grep -q rsyncable
; then
849 compress="gzip -n -9 --rsyncable"
852 lzo
) compress="lzop -9";;
853 lz4
) compress="lz4 -l -9";;
855 if [[ $_no_compress_l = "cat" ]]; then
859 [[ $hostonly = yes ]] && hostonly
="-h"
860 [[ $hostonly != "-h" ]] && unset hostonly
862 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE
=1
864 readonly TMPDIR
="$tmpdir"
865 readonly initdir
="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
866 [ -d "$initdir" ] ||
{
867 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
871 if [[ $early_microcode = yes ]] ||
( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
872 readonly early_cpio_dir
="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
873 [ -d "$early_cpio_dir" ] ||
{
874 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
878 # clean up after ourselves no matter how we die.
881 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
882 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
883 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
887 # clean up after ourselves no matter how we die.
888 trap 'exit 1;' SIGINT
890 export DRACUT_KERNEL_LAZY
="1"
891 export DRACUT_RESOLVE_LAZY
="1"
893 if [[ $print_cmdline ]]; then
900 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
901 .
$dracutbasedir/dracut-version.sh
904 if [[ -f $dracutbasedir/dracut-functions.sh
]]; then
905 .
$dracutbasedir/dracut-functions.sh
907 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
908 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
909 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
913 if ! [[ $print_cmdline ]]; then
915 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev
/null
; then
916 unset DRACUT_RESOLVE_LAZY
917 export DRACUT_RESOLVE_DEPS
=1
919 rm -fr -- ${initdir}/*
922 # Verify bash version, current minimum is 3.1
923 if (( BASH_VERSINFO
[0] < 4 )); then
924 dfatal
'You need at least Bash 4 to use dracut, sorry.'
928 dracutfunctions
=$dracutbasedir/dracut-functions.sh
929 export dracutfunctions
931 if (( ${#drivers_l[@]} )); then
933 while pop drivers_l val
; do
937 drivers
=${drivers/-/_}
939 if (( ${#add_drivers_l[@]} )); then
940 while pop add_drivers_l val
; do
941 add_drivers
+=" $val "
944 add_drivers
=${add_drivers/-/_}
946 if (( ${#force_drivers_l[@]} )); then
947 while pop force_drivers_l val
; do
948 force_drivers
+=" $val "
951 force_drivers
=${force_drivers/-/_}
953 if (( ${#omit_drivers_l[@]} )); then
954 while pop omit_drivers_l val
; do
955 omit_drivers
+=" $val "
958 omit_drivers
=${omit_drivers/-/_}
960 if (( ${#kernel_cmdline_l[@]} )); then
961 while pop kernel_cmdline_l val
; do
962 kernel_cmdline
+=" $val "
966 omit_drivers_corrected
=""
967 for d
in $omit_drivers; do
968 [[ " $drivers $add_drivers " == *\
$d\
* ]] && continue
969 [[ " $drivers $force_drivers " == *\
$d\
* ]] && continue
970 omit_drivers_corrected
+="$d|"
972 omit_drivers
="${omit_drivers_corrected%|}"
973 unset omit_drivers_corrected
975 # prepare args for logging
976 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
977 [[ "${dracut_args[$i]}" == *\
* ]] && \
978 dracut_args
[$i]="\"${dracut_args[$i]}\""
982 dinfo
"Executing: $0 ${dracut_args[@]}"
984 [[ $do_list = yes ]] && {
985 for mod
in $dracutbasedir/modules.d
/*; do
986 [[ -d $mod ]] ||
continue;
987 [[ -e $mod/install ||
-e $mod/installkernel || \
988 -e $mod/module-setup.sh
]] ||
continue
989 printf "%s\n" "${mod##*/??}"
994 # This is kinda legacy -- eventually it should go away.
995 case $dracutmodules in
996 ""|auto
) dracutmodules
="all" ;;
999 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
1001 if [[ -d $srcmods ]]; then
1002 [[ -f $srcmods/modules.dep
]] ||
{
1003 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
1007 if [[ ! $print_cmdline ]]; then
1008 if [[ -f $outfile && ! $force ]]; then
1009 dfatal
"Will not override existing initramfs ($outfile) without --force"
1013 outdir
=${outfile%/*}
1014 [[ $outdir ]] || outdir
="/"
1016 if [[ ! -d "$outdir" ]]; then
1017 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
1019 elif [[ ! -w "$outdir" ]]; then
1020 dfatal
"No permission to write to $outdir."
1022 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
1023 dfatal
"No permission to write $outfile."
1027 if [[ $loginstall ]]; then
1028 if ! mkdir
-p "$loginstall"; then
1029 dfatal
"Could not create directory to log installed files to '$loginstall'."
1032 loginstall
=$
(readlink
-f "$loginstall")
1036 if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE
; then
1037 dwarn
"Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y"
1041 if [[ $early_microcode = yes ]]; then
1042 if [[ $hostonly ]]; then
1043 [[ $
(get_cpu_vendor
) == "AMD" ]] \
1044 && ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
1045 && unset early_microcode
1046 [[ $
(get_cpu_vendor
) == "Intel" ]] \
1047 && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
1048 && unset early_microcode
1050 ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
1051 && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
1052 && unset early_microcode
1054 [[ $early_microcode != yes ]] \
1055 && dwarn
"Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]_EARLY!=y"
1058 # Need to be able to have non-root users read stuff (rpcbind etc)
1059 chmod 755 "$initdir"
1061 if [[ $hostonly ]]; then
1062 for i
in /sys
/proc
/run
/dev
; do
1063 if ! findmnt
--target "$i" &>/dev
/null
; then
1064 dwarning
"Turning off host-only mode: '$i' is not mounted!"
1070 declare -A host_fs_types
1072 for line
in "${fstab_lines[@]}"; do
1078 dev
=$
(blkid
-l -t UUID
=${dev#UUID=} -o device
)
1081 dev
=$
(blkid
-l -t LABEL
=${dev#LABEL=} -o device
)
1084 dev
=$
(blkid
-l -t PARTUUID
=${dev#PARTUUID=} -o device
)
1087 dev
=$
(blkid
-l -t PARTLABEL
=${dev#PARTLABEL=} -o device
)
1090 [ -z "$dev" ] && dwarn
"Bad fstab entry $@" && continue
1091 push_host_devs
"$dev"
1092 host_fs_types
["$dev"]="$3"
1095 for f
in $add_fstab; do
1096 [[ -e $f ]] ||
continue
1097 while read dev rest
; do
1098 push_host_devs
"$dev"
1102 for dev
in $add_device; do
1103 push_host_devs
"$dev"
1106 if (( ${#add_device_l[@]} )); then
1107 while pop add_device_l val
; do
1108 add_device
+=" $val "
1109 push_host_devs
"$val"
1113 if [[ $hostonly ]]; then
1114 # in hostonly mode, determine all devices, which have to be accessed
1115 # and examine them for filesystem types
1133 mp
=$
(readlink
-f "$mp")
1134 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
1135 _dev
=$
(find_block_device
"$mp")
1136 _bdev
=$
(readlink
-f "/dev/block/$_dev")
1137 [[ -b $_bdev ]] && _dev
=$_bdev
1138 push_host_devs
$_dev
1139 [[ "$mp" == "/" ]] && root_dev
="$_dev"
1140 push_host_devs
"$_dev"
1143 if [[ -f /proc
/swaps
]] && [[ -f /etc
/fstab
]]; then
1144 while read dev
type rest
; do
1145 [[ -b $dev ]] ||
continue
1146 [[ "$type" == "partition" ]] ||
continue
1148 while read _d _m _t _o _r
; do
1149 [[ "$_d" == \
#* ]] && continue
1150 [[ $_d ]] ||
continue
1151 [[ $_t != "swap" ]] && continue
1152 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1153 [[ "$_o" == *noauto
* ]] && continue
1154 _d
=$
(expand_persistent_dev
"$_d")
1155 [[ "$_d" -ef "$dev" ]] ||
continue
1157 if [[ -f /etc
/crypttab
]]; then
1158 while read _mapper _a _p _o
; do
1159 [[ $_mapper = \
#* ]] && continue
1160 [[ "$_d" -ef /dev
/mapper
/"$_mapper" ]] ||
continue
1161 [[ "$_o" ]] || _o
="$_p"
1162 # skip entries with password files
1163 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1165 [[ $_o == *swap
* ]] && continue 2
1166 done < /etc
/crypttab
1169 push_host_devs
"$(readlink -f "$dev")"
1174 # record all host modaliases
1175 declare -A host_modalias
1176 find /sys
/devices
/ -name uevent
-print > "$initdir/.modalias"
1179 [[ "$line" != MODALIAS\
=* ]] && continue
1180 modalias
="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias
["$modalias"]=1
1183 done < "$initdir/.modalias"
1185 rm -f -- "$initdir/.modalias"
1187 while read _k _s _v
; do
1188 [ "$_k" != "name" -a "$_k" != "driver" ] && continue
1189 host_modalias
["$_v"]=1
1192 # check /proc/modules
1193 declare -A host_modules
1194 while read m rest
; do
1195 host_modules
["$m"]=1
1204 if [[ -b /dev
/block
/$1 ]]; then
1205 ID_FS_TYPE
=$
(get_fs_env
"/dev/block/$1") && host_fs_types
["$(readlink -f "/dev
/block
/$1")"]="$ID_FS_TYPE"
1208 if [[ -b $1 ]]; then
1209 ID_FS_TYPE
=$
(get_fs_env
"$1") && host_fs_types
["$(readlink -f "$1")"]="$ID_FS_TYPE"
1212 if fstype
=$
(find_dev_fstype
"$1"); then
1213 host_fs_types
["$1"]="$fstype"
1219 for dev
in ${host_devs[@]}; do
1221 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1224 for dev
in "${!host_fs_types[@]}"; do
1225 [[ ${host_fs_types[$dev]} = "reiserfs" ]] ||
[[ ${host_fs_types[$dev]} = "xfs" ]] ||
continue
1226 rootopts
=$
(find_dev_fsopts
"$dev")
1227 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1228 journaldev
=$
(fs_get_option
$rootopts "jdev")
1229 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1230 journaldev
=$
(fs_get_option
$rootopts "logdev")
1232 if [[ $journaldev ]]; then
1233 dev
="$(readlink -f "$dev")"
1234 push_host_devs
"$dev"
1236 check_block_and_slaves_all _get_fs_type
"$(get_maj_min "$dev")"
1241 || udevdir
="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1242 if ! [[ -d "$udevdir" ]]; then
1243 [[ -d /lib
/udev
]] && udevdir
=/lib
/udev
1244 [[ -d /usr
/lib
/udev
]] && udevdir
=/usr
/lib
/udev
1247 [[ -d $systemdutildir ]] \
1248 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
1250 if ! [[ -d "$systemdutildir" ]]; then
1251 [[ -d /lib
/systemd
]] && systemdutildir
=/lib
/systemd
1252 [[ -d /usr
/lib
/systemd
]] && systemdutildir
=/usr
/lib
/systemd
1255 [[ -d $systemdsystemunitdir ]] \
1256 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
1258 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
1260 [[ -d $systemdsystemconfdir ]] \
1261 || systemdsystemconfdir
=$
(pkg-config systemd
--variable=systemdsystemconfdir
2>/dev
/null
)
1263 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir
=/etc
/systemd
/system
1265 [[ -d $tmpfilesdir ]] \
1266 || tmpfilesdir
=$
(pkg-config systemd
--variable=tmpfilesdir
2>/dev
/null
)
1268 if ! [[ -d "$tmpfilesdir" ]]; then
1269 [[ -f /lib
/tmpfiles.d
]] && tmpfilesdir
=/lib
/tmpfiles.d
1270 [[ -f /usr
/lib
/tmpfiles.d
]] && tmpfilesdir
=/usr
/lib
/tmpfiles.d
1273 export initdir dracutbasedir \
1274 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1276 fw_dir drivers_dir debug no_kernel kernel_only \
1277 omit_drivers mdadmconf lvmconf root_dev \
1278 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1279 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1280 debug host_fs_types host_devs sshkey add_fstab \
1281 DRACUT_VERSION udevdir prefix filesystems drivers \
1282 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1283 host_modalias host_modules hostonly_cmdline loginstall \
1287 # check all our modules to see if they should be sourced.
1288 # This builds a list of modules that we will install next.
1289 for_each_module_dir check_module
1290 for_each_module_dir check_mount
1292 dracut_module_included
"fips" && export DRACUT_FIPS_MODE
=1
1294 if [[ $print_cmdline ]]; then
1296 # source our modules.
1297 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1298 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1299 module_cmdline
"$_d_mod"
1306 # Create some directory structure first
1307 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
1309 [[ -h /lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
1310 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1312 if [[ $prefix ]]; then
1313 for d
in bin etc lib sbin tmp usr var
$libdirs; do
1314 [[ "$d" == */* ]] && continue
1315 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1319 if [[ $kernel_only != yes ]]; then
1320 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var
$libdirs; do
1321 [[ -e "${initdir}${prefix}/$d" ]] && continue
1322 if [ -L "/$d" ]; then
1323 inst_symlink
"/$d" "${prefix}/$d"
1325 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1329 for d
in dev proc sys sysroot root run
; do
1330 if [ -L "/$d" ]; then
1333 mkdir
-m 0755 -p "$initdir/$d"
1337 ln -sfn ..
/run
"$initdir/var/run"
1338 ln -sfn ..
/run
/lock
"$initdir/var/lock"
1340 for d
in lib
"$libdir"; do
1341 [[ -e "${initdir}${prefix}/$d" ]] && continue
1342 if [ -h "/$d" ]; then
1343 inst
"/$d" "${prefix}/$d"
1345 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
1350 if [[ $kernel_only != yes ]]; then
1351 mkdir
-p "${initdir}/etc/cmdline.d"
1352 for _d
in $hookdirs; do
1353 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
1355 if [[ "$UID" = "0" ]]; then
1356 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
1357 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
1358 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
1362 _isize
=0 #initramfs size
1364 # source our modules.
1365 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1366 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
1367 if [[ "$mods_to_load" == *\
$_d_mod\
* ]]; then
1368 if [[ $show_modules = yes ]]; then
1369 printf "%s\n" "$_d_mod"
1371 dinfo
"*** Including module: $_d_mod ***"
1373 if [[ $kernel_only == yes ]]; then
1374 module_installkernel
"$_d_mod" ||
{
1375 dfatal
"installkernel failed in module $_d_mod"
1379 module_install
"$_d_mod"
1380 if [[ $no_kernel != yes ]]; then
1381 module_installkernel
"$_d_mod" ||
{
1382 dfatal
"installkernel failed in module $_d_mod"
1387 mods_to_load
=${mods_to_load// $_d_mod /}
1388 modules_loaded
+="$_d_mod "
1390 #print the module install size
1391 if [ -n "$printsize" ]; then
1392 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
1393 _isize_delta
=$
((_isize_new
- _isize
))
1394 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1401 for i
in $modules_loaded; do
1402 mkdir
-p $initdir/lib
/dracut
1403 printf "%s\n" "$i" >> $initdir/lib
/dracut
/modules.txt
1406 dinfo
"*** Including modules done ***"
1408 ## final stuff that has to happen
1409 if [[ $no_kernel != yes ]]; then
1411 if [[ $drivers ]]; then
1412 hostonly
='' instmods
$drivers
1415 if [[ $add_drivers ]]; then
1416 hostonly
='' instmods
-c $add_drivers
1418 if [[ $force_drivers ]]; then
1419 hostonly
='' instmods
-c $force_drivers
1420 rm -f $initdir/etc
/cmdline.d
/20-force_driver.conf
1421 for mod
in $force_drivers; do
1422 echo "rd.driver.pre=$mod" >>$initdir/etc
/cmdline.d
/20-force_drivers.conf
1425 if [[ $filesystems ]]; then
1426 hostonly
='' instmods
-c $filesystems
1429 dinfo
"*** Installing kernel module dependencies and firmware ***"
1431 dinfo
"*** Installing kernel module dependencies and firmware done ***"
1433 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1434 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1435 [[ -f ${initdir}/lib
/modules
/$kernel/modules.dep
&& ! -s ${initdir}/lib
/modules
/$kernel/modules.dep
]]; then
1436 for i
in ${initdir}/etc
/cmdline.d
/*.conf
; do
1437 # We need no initramfs image and do not generate one.
1438 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1444 if [[ $kernel_only != yes ]]; then
1445 (( ${#install_items[@]} > 0 )) && inst_multiple
${install_items[@]}
1446 (( ${#install_optional_items[@]} > 0 )) && inst_multiple
-o ${install_optional_items[@]}
1448 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1450 while pop fstab_lines line
; do
1452 [ -z "${line[3]}" ] && line
[3]="defaults"
1453 [ -z "${line[4]}" ] && line
[4]="0"
1454 [ -z "${line[5]}" ] && line
[5]="2"
1455 echo "${line[@]}" >> "${initdir}/etc/fstab"
1458 for f
in $add_fstab; do
1459 cat "$f" >> "${initdir}/etc/fstab"
1462 if [ -d ${initdir}/$systemdutildir ]; then
1463 mkdir
-p ${initdir}/etc
/conf.d
1465 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1466 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1467 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1468 } > ${initdir}/etc
/conf.d
/systemd.conf
1471 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1472 dinfo
"*** Resolving executable dependencies ***"
1473 find "$initdir" -type f
-perm /0111 -not -path '*.ko' -print0 \
1474 |
xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1475 dinfo
"*** Resolving executable dependencies done***"
1478 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1479 for _dir
in $libdirs; do
1480 for _f
in "$_dir/libpthread.so"*; do
1481 [[ -e "$_f" ]] ||
continue
1482 inst_libdir_file
"libgcc_s.so*"
1488 while pop include_src src
&& pop include_target tgt
; do
1489 if [[ $src && $tgt ]]; then
1490 if [[ -f $src ]]; then
1493 ddebug
"Including directory: $src"
1494 destdir
="${initdir}/${tgt}"
1496 # check for preexisting symlinks, so we can cope with the
1497 # symlinks to $prefix
1498 for i
in "$src"/*; do
1499 [[ -e "$i" ||
-h "$i" ]] ||
continue
1500 s
=${destdir}/${i#$src/}
1501 if [[ -d "$i" ]]; then
1502 if ! [[ -e "$s" ]]; then
1503 mkdir
-m 0755 -p "$s"
1504 chmod --reference="$i" "$s"
1506 cp --reflink=auto
--sparse=auto
-fa -t "$s" "$i"/*
1508 cp --reflink=auto
--sparse=auto
-fa -t "$destdir" "$i"
1515 if [[ $kernel_only != yes ]]; then
1516 # make sure that library links are correct and up to date
1517 for f
in /etc
/ld.so.conf
/etc
/ld.so.conf.d
/*; do
1518 [[ -f $f ]] && inst_simple
"$f"
1520 if ! ldconfig
-r "$initdir"; then
1521 if [[ $UID = 0 ]]; then
1522 derror
"ldconfig exited ungracefully"
1524 derror
"ldconfig might need uid=0 (root) for chroot()"
1529 PRELINK_BIN
="$(command -v prelink)"
1530 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1531 if [[ $DRACUT_FIPS_MODE ]]; then
1532 dinfo
"*** Installing prelink files ***"
1533 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
/etc
/prelink.cache
1534 elif [[ $do_prelink == yes ]]; then
1535 dinfo
"*** Pre-linking files ***"
1536 inst_multiple
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
1537 chroot
"$initdir" "$PRELINK_BIN" -a
1538 rm -f -- "$initdir/$PRELINK_BIN"
1539 rm -fr -- "$initdir"/etc
/prelink.
*
1540 dinfo
"*** Pre-linking files done ***"
1544 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1545 dinfo
"*** Hardlinking files ***"
1546 hardlink
"$initdir" 2>&1
1547 dinfo
"*** Hardlinking files done ***"
1551 if [[ $do_strip = yes ]] ; then
1552 for p
in strip
xargs find; do
1553 if ! type -P $p >/dev
/null
; then
1554 dinfo
"Could not find '$p'. Not stripping the initramfs."
1560 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1561 dinfo
"*** Stripping files ***"
1562 find "$initdir" -type f \
1563 -executable -not -path '*/lib/modules/*.ko' -print0 \
1564 |
xargs -r -0 strip
-g 2>/dev
/null
1566 # strip kernel modules, but do not touch signed modules
1567 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
1568 |
while read -r -d $
'\0' f
; do
1569 SIG
=$
(tail -c 28 "$f")
1570 [[ $SIG == '~Module signature appended~' ]] ||
{ printf "%s\000" "$f"; }
1571 done |
xargs -r -0 strip
-g
1573 dinfo
"*** Stripping files done ***"
1575 if [[ $early_microcode = yes ]]; then
1576 dinfo
"*** Generating early-microcode cpio image ***"
1577 ucode_dir
=(amd-ucode intel-ucode
)
1578 ucode_dest
=(AuthenticAMD.bin GenuineIntel.bin
)
1579 _dest_dir
="$early_cpio_dir/d/kernel/x86/microcode"
1582 if [[ $hostonly ]]; then
1583 [[ $
(get_cpu_vendor
) == "AMD" ]] && _dest_idx
="0"
1584 [[ $
(get_cpu_vendor
) == "Intel" ]] && _dest_idx
="1"
1586 for idx
in $_dest_idx; do
1587 _fw
=${ucode_dir[$idx]}
1588 for _fwdir
in $fw_dir; do
1589 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1591 dinfo
"*** Constructing ${ucode_dest[$idx]} ****"
1592 if [[ $hostonly ]]; then
1593 _src
=$
(get_ucode_file
)
1594 if ! [[ -r $_fwdir/$_fw/$_src ]];then
1598 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1599 create_early_cpio
="yes"
1605 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1606 dinfo
"*** Packaging ACPI tables to override BIOS provided ones ***"
1607 _dest_dir
="$early_cpio_dir/d/kernel/firmware/acpi"
1609 for table
in $acpi_table_dir/*.aml
; do
1610 dinfo
" Adding ACPI table: $table"
1611 cp -a $table $_dest_dir
1612 create_early_cpio
="yes"
1616 dinfo
"*** Store current command line parameters ***"
1617 if ! ( echo $PARMS_TO_STORE > $initdir/lib
/dracut
/build-parameter.txt
); then
1618 dfatal
"Could not store the current command line parameters"
1622 if [[ $hostonly_cmdline ]] ; then
1623 unset _stored_cmdline
1624 if [ -d $initdir/etc
/cmdline.d
];then
1625 dinfo
"Stored kernel commandline:"
1626 for conf
in $initdir/etc
/cmdline.d
/*.conf
; do
1627 [ -e "$conf" ] ||
continue
1632 if ! [[ $_stored_cmdline ]]; then
1633 dinfo
"No dracut internal kernel commandline stored in initrd"
1637 dinfo
"*** Creating image file ***"
1639 if [[ $DRACUT_REPRODUCIBLE ]]; then
1640 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1641 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1643 [[ "$(cpio --help)" == *--reproducible* ]] && CPIO_REPRODUCIBLE
=1
1646 [[ "$UID" != 0 ]] && cpio_owner_root
="-R 0:0"
1648 if [[ $create_early_cpio = yes ]]; then
1649 echo 1 > "$early_cpio_dir/d/early_cpio"
1651 if [[ $DRACUT_REPRODUCIBLE ]]; then
1652 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1653 |
xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1656 # The microcode blob is _before_ the initramfs blob, not after
1658 cd "$early_cpio_dir/d"
1659 find .
-print0 |
sort -z \
1660 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet > $outfile
1665 umask 077; cd "$initdir"
1666 find .
-print0 |
sort -z \
1667 |
cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc
-o --quiet \
1668 |
$compress >> "$outfile"
1670 dfatal
"dracut: creation of $outfile failed"
1673 dinfo
"*** Creating image file done ***"
1675 if (( maxloglvl
>= 5 )); then
1676 if [[ $allowlocal ]]; then
1677 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1679 lsinitrd
"$outfile"| ddebug