test: include the same Makefile.testdir
[dracut.git] / dracut.sh
blobccff358adef8b9f1499fdff88c28c9398b3ed0e9
1 #!/bin/bash
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/>.
26 # store for logging
27 dracut_args=( "$@" )
29 set -o pipefail
31 usage() {
32 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
33 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
34 . $dracutbasedir/dracut-version.sh
37 # 80x25 linebreak here ^
38 cat << EOF
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.
49 For example:
51 # dracut --add-drivers "module1 module2" ...
53 EOF
56 long_usage() {
57 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
58 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
59 . $dracutbasedir/dracut-version.sh
62 # 80x25 linebreak here ^
63 cat << EOF
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 --rebuild Append arguments to those of existing image and rebuild
74 -m, --modules [LIST] Specify a space-separated list of dracut modules to
75 call when building the initramfs. Modules are located
76 in /usr/lib/dracut/modules.d.
77 -o, --omit [LIST] Omit a space-separated list of dracut modules.
78 --force-add [LIST] Force to add a space-separated list of dracut modules
79 to the default set of modules, when -H is specified.
80 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
81 exclusively include in the initramfs.
82 --add-drivers [LIST] Specify a space-separated list of kernel
83 modules to add to the initramfs.
84 --omit-drivers [LIST] Specify a space-separated list of kernel
85 modules not to add to the initramfs.
86 --filesystems [LIST] Specify a space-separated list of kernel filesystem
87 modules to exclusively include in the generic
88 initramfs.
89 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
90 modules
91 --fwdir [DIR] Specify additional directories, where to look for
92 firmwares, separated by :
93 --kernel-only Only install kernel drivers and firmware files
94 --no-kernel Do not install kernel drivers and firmware files
95 --print-cmdline Print the kernel command line for the given disk layout
96 --early-microcode Combine early microcode with ramdisk
97 --no-early-microcode Do not combine early microcode with ramdisk
98 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
99 --strip Strip binaries in the initramfs
100 --nostrip Do not strip binaries in the initramfs
101 --prelink Prelink binaries in the initramfs
102 --noprelink Do not prelink binaries in the initramfs
103 --hardlink Hardlink files in the initramfs
104 --nohardlink Do not hardlink files in the initramfs
105 --prefix [DIR] Prefix initramfs files with [DIR]
106 --noprefix Do not prefix initramfs files
107 --mdadmconf Include local /etc/mdadm.conf
108 --nomdadmconf Do not include local /etc/mdadm.conf
109 --lvmconf Include local /etc/lvm/lvm.conf
110 --nolvmconf Do not include local /etc/lvm/lvm.conf
111 --fscks [LIST] Add a space-separated list of fsck helpers.
112 --nofscks Inhibit installation of any fsck helpers.
113 --ro-mnt Mount / and /usr read-only by default.
114 -h, --help This message
115 --debug Output debug information of the build process
116 --profile Output profile information of the build process
117 -L, --stdlog [0-6] Specify logging level (to standard error)
118 0 - suppress any messages
119 1 - only fatal errors
120 2 - all errors
121 3 - warnings
122 4 - info
123 5 - debug info (here starts lots of output)
124 6 - trace info (and even more)
125 -v, --verbose Increase verbosity level
126 -q, --quiet Decrease verbosity level
127 -c, --conf [FILE] Specify configuration file to use.
128 Default: /etc/dracut.conf
129 --confdir [DIR] Specify configuration directory to use *.conf files
130 from. Default: /etc/dracut.conf.d
131 --tmpdir [DIR] Temporary directory to be used instead of default
132 /var/tmp.
133 -l, --local Local mode. Use modules from the current working
134 directory instead of the system-wide installed in
135 /usr/lib/dracut/modules.d.
136 Useful when running dracut from a git checkout.
137 -H, --hostonly Host-Only mode: Install only what is needed for
138 booting the local host instead of a generic host.
139 -N, --no-hostonly Disables Host-Only mode
140 --persistent-policy [POLICY]
141 Use [POLICY] to address disks and partitions.
142 POLICY can be any directory name found in /dev/disk.
143 E.g. "by-uuid", "by-label"
144 --fstab Use /etc/fstab to determine the root device.
145 --add-fstab [FILE] Add file to the initramfs fstab
146 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
147 Mount device [DEV] on mountpoint [MP] with filesystem
148 [FSTYPE] and options [FSOPTS] in the initramfs
149 --add-device "[DEV]" Bring up [DEV] in initramfs
150 -i, --include [SOURCE] [TARGET]
151 Include the files in the SOURCE directory into the
152 Target directory in the final initramfs.
153 If SOURCE is a file, it will be installed to TARGET
154 in the final initramfs.
155 -I, --install [LIST] Install the space separated list of files into the
156 initramfs.
157 --gzip Compress the generated initramfs using gzip.
158 This will be done by default, unless another
159 compression option or --no-compress is passed.
160 --bzip2 Compress the generated initramfs using bzip2.
161 Make sure your kernel has bzip2 decompression support
162 compiled in, otherwise you will not be able to boot.
163 --lzma Compress the generated initramfs using lzma.
164 Make sure your kernel has lzma support compiled in,
165 otherwise you will not be able to boot.
166 --xz Compress the generated initramfs using xz.
167 Make sure that your kernel has xz support compiled
168 in, otherwise you will not be able to boot.
169 --lzo Compress the generated initramfs using lzop.
170 Make sure that your kernel has lzo support compiled
171 in, otherwise you will not be able to boot.
172 --lz4 Compress the generated initramfs using lz4.
173 Make sure that your kernel has lz4 support compiled
174 in, otherwise you will not be able to boot.
175 --compress [COMPRESSION] Compress the generated initramfs with the
176 passed compression program. Make sure your kernel
177 knows how to decompress the generated initramfs,
178 otherwise you will not be able to boot.
179 --no-compress Do not compress the generated initramfs. This will
180 override any other compression options.
181 --list-modules List all available dracut modules.
182 -M, --show-modules Print included module's name to standard output during
183 build.
184 --keep Keep the temporary initramfs for debugging purposes
185 --printsize Print out the module install size
186 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
187 --logfile [FILE] Logfile to use (overrides configuration setting)
189 If [LIST] has multiple arguments, then you have to put these in quotes.
191 For example:
193 # dracut --add-drivers "module1 module2" ...
198 # function push()
199 # push values to a stack
200 # $1 = stack variable
201 # $2.. values
202 # example:
203 # push stack 1 2 "3 4"
204 push() {
205 local _i
206 local __stack=$1; shift
207 for _i in "$@"; do
208 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
209 done
212 # function pop()
213 # pops the last value from a stack
214 # assigns value to second argument variable
215 # or echo to stdout, if no second argument
216 # $1 = stack variable
217 # $2 = optional variable to store the value
218 # example:
219 # pop stack val
220 # val=$(pop stack)
221 pop() {
222 local __stack=$1; shift
223 local __resultvar=$1
224 local _value;
225 # check for empty stack
226 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
228 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
230 if [[ "$__resultvar" ]]; then
231 eval $__resultvar="'$_value'"
232 else
233 printf "%s" "$_value"
235 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
236 return 0
239 # Little helper function for reading args from the commandline.
240 # it automatically handles -a b and -a=b variants, and returns 1 if
241 # we need to shift $3.
242 read_arg() {
243 # $1 = arg name
244 # $2 = arg value
245 # $3 = arg parameter
246 local rematch='^[^=]*=(.*)$'
247 if [[ $2 =~ $rematch ]]; then
248 read "$1" <<< "${BASH_REMATCH[1]}"
249 else
250 read "$1" <<< "$3"
251 # There is no way to shift our callers args, so
252 # return 1 to indicate they should do it instead.
253 return 1
257 dropindirs_sort()
259 local suffix=$1; shift
260 local -a files
261 local f d
263 for d in "$@"; do
264 for i in "$d/"*"$suffix"; do
265 if [[ -e "$i" ]]; then
266 printf "%s\n" "${i##*/}"
268 done
269 done | sort -Vu | {
270 readarray -t files
272 for f in "${files[@]}"; do
273 for d in "$@"; do
274 if [[ -e "$d/$f" ]]; then
275 printf "%s\n" "$d/$f"
276 continue 2
278 done
279 done
283 rearrange_params()
285 # Workaround -i, --include taking 2 arguments
286 set -- "${@/--include/++include}"
288 # This prevents any long argument ending with "-i"
289 # -i, like --opt-i but I think we can just prevent that
290 set -- "${@/%-i/++include}"
292 TEMP=$(unset POSIXLY_CORRECT; getopt \
293 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
294 --long kver: \
295 --long add: \
296 --long force-add: \
297 --long add-drivers: \
298 --long omit-drivers: \
299 --long modules: \
300 --long omit: \
301 --long drivers: \
302 --long filesystems: \
303 --long install: \
304 --long fwdir: \
305 --long libdirs: \
306 --long fscks: \
307 --long add-fstab: \
308 --long mount: \
309 --long device: \
310 --long add-device: \
311 --long nofscks: \
312 --long ro-mnt \
313 --long kmoddir: \
314 --long conf: \
315 --long confdir: \
316 --long tmpdir: \
317 --long stdlog: \
318 --long compress: \
319 --long prefix: \
320 --long rebuild: \
321 --long force \
322 --long kernel-only \
323 --long no-kernel \
324 --long print-cmdline \
325 --long kernel-cmdline: \
326 --long strip \
327 --long nostrip \
328 --long prelink \
329 --long noprelink \
330 --long hardlink \
331 --long nohardlink \
332 --long noprefix \
333 --long mdadmconf \
334 --long nomdadmconf \
335 --long lvmconf \
336 --long nolvmconf \
337 --long debug \
338 --long profile \
339 --long sshkey: \
340 --long logfile: \
341 --long verbose \
342 --long quiet \
343 --long local \
344 --long hostonly \
345 --long host-only \
346 --long no-hostonly \
347 --long no-host-only \
348 --long persistent-policy: \
349 --long fstab \
350 --long help \
351 --long bzip2 \
352 --long lzma \
353 --long xz \
354 --long lzo \
355 --long lz4 \
356 --long no-compress \
357 --long gzip \
358 --long list-modules \
359 --long show-modules \
360 --long keep \
361 --long printsize \
362 --long regenerate-all \
363 --long noimageifnotneeded \
364 --long early-microcode \
365 --long no-early-microcode \
366 -- "$@")
368 if (( $? != 0 )); then
369 usage
370 exit 1
374 verbosity_mod_l=0
375 unset kernel
376 unset outfile
378 rearrange_params "$@"
379 eval set -- "$TEMP"
381 # parse command line args to check if '--rebuild' option is present
382 unset append_args_l
383 unset rebuild_file
384 while :
386 if [ "$1" == "--" ]; then
387 shift; break
389 if [ "$1" == "--rebuild" ]; then
390 append_args_l="yes"
391 rebuild_file=$2
392 if [ ! -e $rebuild_file ]; then
393 echo "Image file '$rebuild_file', for rebuild, does not exist!"
394 exit 1
396 abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
397 shift; continue
399 shift
400 done
402 # get output file name and kernel version from command line arguments
403 while (($# > 0)); do
404 case ${1%%=*} in
405 ++include)
406 shift 2;;
408 if ! [[ ${outfile+x} ]]; then
409 outfile=$1
410 elif ! [[ ${kernel+x} ]]; then
411 kernel=$1
412 else
413 printf "\nUnknown arguments: %s\n\n" "$*" >&2
414 usage; exit 1;
417 esac
418 shift
419 done
421 # extract input image file provided with rebuild option to get previous parameters, if any
422 if [[ $append_args_l == "yes" ]]; then
423 unset rebuild_param
425 # determine resultant file
426 if ! [[ $outfile ]]; then
427 outfile=$rebuild_file
430 if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
431 echo "Image '$rebuild_file' has no rebuild information stored"
432 exit 1
435 # prepend previous parameters to current command line args
436 if [[ $rebuild_param ]]; then
437 TEMP="$rebuild_param $TEMP"
438 eval set -- "$TEMP"
439 rearrange_params "$@"
442 # clean the temporarily used scratch-pad directory
443 rm -rf $scratch_dir
446 unset PARMS_TO_STORE
447 PARMS_TO_STORE=""
449 eval set -- "$TEMP"
451 while :; do
452 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
453 PARMS_TO_STORE+=" $1";
455 case $1 in
456 --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
457 -a|--add) push add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
458 --force-add) push force_add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
459 --add-drivers) push add_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
460 --omit-drivers) push omit_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
461 -m|--modules) push dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
462 -o|--omit) push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
463 -d|--drivers) push drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
464 --filesystems) push filesystems_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
465 -I|--install) push install_items_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
466 --fwdir) push fw_dir_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
467 --libdirs) push libdirs_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
468 --fscks) push fscks_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
469 --add-fstab) push add_fstab_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
470 --mount) push fstab_lines "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
471 --add-device|--device)
472 push add_device_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
473 --kernel-cmdline) push kernel_cmdline_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
474 --nofscks) nofscks_l="yes";;
475 --ro-mnt) ro_mnt_l="yes";;
476 -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
477 -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
478 --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
479 --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
480 -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
481 --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
482 --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
483 --rebuild) if [ $rebuild_file == $outfile ]; then
484 force=yes
486 shift
488 -f|--force) force=yes;;
489 --kernel-only) kernel_only="yes"; no_kernel="no";;
490 --no-kernel) kernel_only="no"; no_kernel="yes";;
491 --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
492 --early-microcode) early_microcode_l="yes";;
493 --no-early-microcode) early_microcode_l="no";;
494 --strip) do_strip_l="yes";;
495 --nostrip) do_strip_l="no";;
496 --prelink) do_prelink_l="yes";;
497 --noprelink) do_prelink_l="no";;
498 --hardlink) do_hardlink_l="yes";;
499 --nohardlink) do_hardlink_l="no";;
500 --noprefix) prefix_l="/";;
501 --mdadmconf) mdadmconf_l="yes";;
502 --nomdadmconf) mdadmconf_l="no";;
503 --lvmconf) lvmconf_l="yes";;
504 --nolvmconf) lvmconf_l="no";;
505 --debug) debug="yes";;
506 --profile) profile="yes";;
507 --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
508 --logfile) logfile_l="$2"; shift;;
509 -v|--verbose) ((verbosity_mod_l++));;
510 -q|--quiet) ((verbosity_mod_l--));;
511 -l|--local)
512 allowlocal="yes"
513 [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
514 && dracutbasedir="$(readlink -f "${0%/*}")"
516 -H|--hostonly|--host-only)
517 hostonly_l="yes" ;;
518 -N|--no-hostonly|--no-host-only)
519 hostonly_l="no" ;;
520 --persistent-policy)
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) push include_src "$2"; PARMS_TO_STORE+=" '$2'";
525 shift;;
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";;
534 -M|--show-modules)
535 show_modules_l="yes"
537 --keep) keep="yes";;
538 --printsize) printsize="yes";;
539 --regenerate-all) regenerate_all="yes";;
540 --noimageifnotneeded) noimageifnotneeded="yes";;
542 --) shift; break;;
544 *) # should not even reach this point
545 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
546 esac
547 shift
548 done
550 # getopt cannot handle multiple arguments, so just handle "-I,--include"
551 # the old fashioned way
553 while (($# > 0)); do
554 if [ ${1%%=*} == "++include" ]; then
555 push include_src "$2"
556 push include_target "$3"
557 PARMS_TO_STORE+=" --include '$2' '$3'"
558 shift 2
560 shift
561 done
563 if [[ $regenerate_all == "yes" ]]; then
564 ret=0
565 if [[ $kernel ]]; then
566 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
567 exit 1
570 if [[ $outfile ]]; then
571 printf -- "--regenerate-all cannot be called with a image file\n" >&2
572 exit 1
575 ((len=${#dracut_args[@]}))
576 for ((i=0; i < len; i++)); do
577 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
578 unset dracut_args[$i]
579 done
581 cd /lib/modules
582 for i in *; do
583 [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
584 dracut --kver="$i" "${dracut_args[@]}"
585 ((ret+=$?))
586 done
587 exit $ret
590 if ! [[ $kernel ]]; then
591 kernel=$(uname -r)
594 if [[ $kernel ]]; then
595 if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then
596 printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2
600 if ! [[ $outfile ]]; then
601 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
603 if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
604 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
605 else
606 outfile="/boot/initramfs-$kernel.img"
610 for i in /usr/sbin /sbin /usr/bin /bin; do
611 rl=$i
612 if [ -L "$i" ]; then
613 rl=$(readlink -f $i)
615 if [[ "$NPATH" != *:$rl* ]] ; then
616 NPATH+=":$rl"
618 done
619 export PATH="${NPATH#:}"
620 unset LC_MESSAGES
621 unset LC_CTYPE
622 export LC_ALL=C
623 export LANG=C
624 unset NPATH
625 unset LD_LIBRARY_PATH
626 unset LD_PRELOAD
627 unset GREP_OPTIONS
629 export DRACUT_LOG_LEVEL=warning
630 [[ $debug ]] && {
631 export DRACUT_LOG_LEVEL=debug
632 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
633 set -x
636 [[ $profile ]] && {
637 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
638 set -x
639 debug=yes
642 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
644 # if we were not passed a config file, try the default one
645 if [[ ! -f $conffile ]]; then
646 if [[ $allowlocal ]]; then
647 conffile="$dracutbasedir/dracut.conf"
648 else
649 conffile="/etc/dracut.conf"
653 if [[ ! -d $confdir ]]; then
654 if [[ $allowlocal ]]; then
655 confdir="$dracutbasedir/dracut.conf.d"
656 else
657 confdir="/etc/dracut.conf.d"
661 # source our config file
662 [[ -f $conffile ]] && . "$conffile"
664 # source our config dir
665 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
666 [[ -e $f ]] && . "$f"
667 done
669 # these optins add to the stuff in the config file
670 if (( ${#add_dracutmodules_l[@]} )); then
671 while pop add_dracutmodules_l val; do
672 add_dracutmodules+=" $val "
673 done
676 if (( ${#force_add_dracutmodules_l[@]} )); then
677 while pop force_add_dracutmodules_l val; do
678 force_add_dracutmodules+=" $val "
679 done
682 if (( ${#fscks_l[@]} )); then
683 while pop fscks_l val; do
684 fscks+=" $val "
685 done
688 if (( ${#add_fstab_l[@]} )); then
689 while pop add_fstab_l val; do
690 add_fstab+=" $val "
691 done
694 if (( ${#fstab_lines_l[@]} )); then
695 while pop fstab_lines_l val; do
696 push fstab_lines $val
697 done
700 if (( ${#install_items_l[@]} )); then
701 while pop install_items_l val; do
702 install_items+=" $val "
703 done
706 # these options override the stuff in the config file
707 if (( ${#dracutmodules_l[@]} )); then
708 dracutmodules=''
709 while pop dracutmodules_l val; do
710 dracutmodules+="$val "
711 done
714 if (( ${#omit_dracutmodules_l[@]} )); then
715 omit_dracutmodules=''
716 while pop omit_dracutmodules_l val; do
717 omit_dracutmodules+="$val "
718 done
721 if (( ${#filesystems_l[@]} )); then
722 filesystems=''
723 while pop filesystems_l val; do
724 filesystems+="$val "
725 done
728 if (( ${#fw_dir_l[@]} )); then
729 fw_dir=''
730 while pop fw_dir_l val; do
731 fw_dir+="$val "
732 done
735 if (( ${#libdirs_l[@]} )); then
736 libdirs=''
737 while pop libdirs_l val; do
738 libdirs+="$val "
739 done
742 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
743 [[ ! $stdloglvl ]] && stdloglvl=4
744 stdloglvl=$((stdloglvl + verbosity_mod_l))
745 ((stdloglvl > 6)) && stdloglvl=6
746 ((stdloglvl < 0)) && stdloglvl=0
748 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
749 [[ $do_strip_l ]] && do_strip=$do_strip_l
750 [[ $do_strip ]] || do_strip=yes
751 [[ $do_prelink_l ]] && do_prelink=$do_prelink_l
752 [[ $do_prelink ]] || do_prelink=yes
753 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
754 [[ $do_hardlink ]] || do_hardlink=yes
755 [[ $prefix_l ]] && prefix=$prefix_l
756 [[ $prefix = "/" ]] && unset prefix
757 [[ $hostonly_l ]] && hostonly=$hostonly_l
758 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
759 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
760 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
761 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
762 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
763 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
764 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
765 [[ $tmpdir ]] || tmpdir=/var/tmp
766 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
767 [[ $compress_l ]] && compress=$compress_l
768 [[ $show_modules_l ]] && show_modules=$show_modules_l
769 [[ $nofscks_l ]] && nofscks="yes"
770 [[ $ro_mnt_l ]] && ro_mnt="yes"
771 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
772 [[ $early_microcode ]] || early_microcode=no
773 [[ $logfile_l ]] && logfile="$logfile_l"
774 # eliminate IFS hackery when messing with fw_dir
775 fw_dir=${fw_dir//:/ }
777 # handle compression options.
778 [[ $compress ]] || compress="gzip"
779 case $compress in
780 bzip2) compress="bzip2 -9";;
781 lzma) compress="lzma -9 -T0";;
782 xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
783 gzip) compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
784 lzo) compress="lzop -9";;
785 lz4) compress="lz4 -9";;
786 esac
787 if [[ $_no_compress_l = "cat" ]]; then
788 compress="cat"
791 [[ $hostonly = yes ]] && hostonly="-h"
792 [[ $hostonly != "-h" ]] && unset hostonly
794 readonly TMPDIR="$tmpdir"
795 readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
796 [ -d "$initdir" ] || {
797 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
798 exit 1
801 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
802 readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
803 [ -d "$early_cpio_dir" ] || {
804 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
805 exit 1
808 # clean up after ourselves no matter how we die.
809 trap '
810 ret=$?;
811 [[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";
812 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
813 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
814 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
815 exit $ret;
816 ' EXIT
818 # clean up after ourselves no matter how we die.
819 trap 'exit 1;' SIGINT
821 export DRACUT_KERNEL_LAZY="1"
822 export DRACUT_RESOLVE_LAZY="1"
824 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
825 . $dracutbasedir/dracut-functions.sh
826 else
827 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
828 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
829 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
830 exit 1
833 if ! [[ $print_cmdline ]]; then
834 inst /bin/sh
835 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
836 unset DRACUT_RESOLVE_LAZY
837 export DRACUT_RESOLVE_DEPS=1
839 rm -fr -- ${initdir}/*
842 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
843 . $dracutbasedir/dracut-version.sh
846 # Verify bash version, current minimum is 3.1
847 if (( BASH_VERSINFO[0] < 4 )); then
848 dfatal 'You need at least Bash 4 to use dracut, sorry.'
849 exit 1
852 dracutfunctions=$dracutbasedir/dracut-functions.sh
853 export dracutfunctions
855 if (( ${#drivers_l[@]} )); then
856 drivers=''
857 while pop drivers_l val; do
858 drivers+="$val "
859 done
861 drivers=${drivers/-/_}
863 if (( ${#add_drivers_l[@]} )); then
864 while pop add_drivers_l val; do
865 add_drivers+=" $val "
866 done
868 add_drivers=${add_drivers/-/_}
870 if (( ${#omit_drivers_l[@]} )); then
871 while pop omit_drivers_l val; do
872 omit_drivers+=" $val "
873 done
875 omit_drivers=${omit_drivers/-/_}
877 if (( ${#kernel_cmdline_l[@]} )); then
878 while pop kernel_cmdline_l val; do
879 kernel_cmdline+=" $val "
880 done
883 omit_drivers_corrected=""
884 for d in $omit_drivers; do
885 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
886 omit_drivers_corrected+="$d|"
887 done
888 omit_drivers="${omit_drivers_corrected%|}"
889 unset omit_drivers_corrected
891 # prepare args for logging
892 for ((i=0; i < ${#dracut_args[@]}; i++)); do
893 [[ "${dracut_args[$i]}" == *\ * ]] && \
894 dracut_args[$i]="\"${dracut_args[$i]}\""
895 #" keep vim happy
896 done
897 dinfo "Executing: $0 ${dracut_args[@]}"
899 [[ $do_list = yes ]] && {
900 for mod in $dracutbasedir/modules.d/*; do
901 [[ -d $mod ]] || continue;
902 [[ -e $mod/install || -e $mod/installkernel || \
903 -e $mod/module-setup.sh ]] || continue
904 printf "%s\n" "${mod##*/??}"
905 done
906 exit 0
909 # This is kinda legacy -- eventually it should go away.
910 case $dracutmodules in
911 ""|auto) dracutmodules="all" ;;
912 esac
914 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
916 if [[ -d $srcmods ]]; then
917 [[ -f $srcmods/modules.dep ]] || {
918 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
922 if [[ ! $print_cmdline ]]; then
923 if [[ -f $outfile && ! $force ]]; then
924 dfatal "Will not override existing initramfs ($outfile) without --force"
925 exit 1
928 outdir=${outfile%/*}
929 [[ $outdir ]] || outdir="/"
931 if [[ ! -d "$outdir" ]]; then
932 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
933 exit 1
934 elif [[ ! -w "$outdir" ]]; then
935 dfatal "No permission to write to $outdir."
936 exit 1
937 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
938 dfatal "No permission to write $outfile."
939 exit 1
943 # Need to be able to have non-root users read stuff (rpcbind etc)
944 chmod 755 "$initdir"
946 if [[ $hostonly ]]; then
947 for i in /sys /proc /run /dev; do
948 if ! findmnt --target "$i" &>/dev/null; then
949 dwarning "Turning off host-only mode: '$i' is not mounted!"
950 unset hostonly
952 done
955 declare -A host_fs_types
957 for line in "${fstab_lines[@]}"; do
958 set -- $line
959 #dev mp fs fsopts
960 push host_devs "$1"
961 host_fs_types["$1"]="$3"
962 done
964 for f in $add_fstab; do
965 [[ -e $f ]] || continue
966 while read dev rest; do
967 push host_devs "$dev"
968 done < "$f"
969 done
971 for dev in $add_device; do
972 push host_devs "$dev"
973 done
975 if (( ${#add_device_l[@]} )); then
976 while pop add_device_l val; do
977 add_device+=" $val "
978 push host_devs "$val"
979 done
982 if [[ $hostonly ]]; then
983 # in hostonly mode, determine all devices, which have to be accessed
984 # and examine them for filesystem types
986 for mp in \
987 "/" \
988 "/etc" \
989 "/bin" \
990 "/sbin" \
991 "/lib" \
992 "/lib64" \
993 "/usr" \
994 "/usr/bin" \
995 "/usr/sbin" \
996 "/usr/lib" \
997 "/usr/lib64" \
998 "/boot" \
999 "/boot/efi" \
1002 mp=$(readlink -f "$mp")
1003 mountpoint "$mp" >/dev/null 2>&1 || continue
1004 _dev=$(find_block_device "$mp")
1005 _bdev=$(readlink -f "/dev/block/$_dev")
1006 [[ -b $_bdev ]] && _dev=$_bdev
1007 push host_devs $_dev
1008 [[ "$_mp" == "/" ]] && root_dev="$_dev"
1009 push host_devs "$_dev"
1010 done
1012 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
1013 while read dev type rest; do
1014 [[ -b $dev ]] || continue
1015 [[ "$type" == "partition" ]] || continue
1017 while read _d _m _t _o _r; do
1018 [[ "$_d" == \#* ]] && continue
1019 [[ $_d ]] || continue
1020 [[ $_t != "swap" ]] && continue
1021 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1022 [[ "$_o" == *noauto* ]] && continue
1023 _d=$(expand_persistent_dev "$_d")
1024 [[ "$_d" -ef "$dev" ]] || continue
1026 if [[ -f /etc/crypttab ]]; then
1027 while read _mapper _a _p _o; do
1028 [[ $_mapper = \#* ]] && continue
1029 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
1030 [[ "$_o" ]] || _o="$_p"
1031 # skip entries with password files
1032 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1033 # skip mkswap swap
1034 [[ $_o == *swap* ]] && continue 2
1035 done < /etc/crypttab
1038 push host_devs "$(readlink -f "$dev")"
1039 break
1040 done < /etc/fstab
1041 done < /proc/swaps
1043 # record all host modaliases
1044 declare -A host_modalias
1045 find /sys/devices/ -name uevent -print > "$initdir/.modalias"
1046 while read m; do
1047 while read line; do
1048 [[ "$line" != MODALIAS\=* ]] && continue
1049 modalias="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias["$modalias"]=1
1050 break
1051 done < "$m"
1052 done < "$initdir/.modalias"
1054 rm -f -- "$initdir/.modalias"
1056 while read _k _s _v; do
1057 [ "$_k" != "name" -a "$_k" != "driver" ] && continue
1058 host_modalias["$_v"]=1
1059 done </proc/crypto
1061 # check /proc/modules
1062 declare -A host_modules
1063 while read m rest; do
1064 host_modules["$m"]=1
1065 done </proc/modules
1068 unset m
1069 unset rest
1071 _get_fs_type() {
1072 [[ $1 ]] || return
1073 if [[ -b /dev/block/$1 ]]; then
1074 ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
1075 return 1
1077 if [[ -b $1 ]]; then
1078 ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
1079 return 1
1081 if fstype=$(find_dev_fstype "$1"); then
1082 host_fs_types["$1"]="$fstype"
1083 return 1
1085 return 1
1088 for dev in ${host_devs[@]}; do
1089 _get_fs_type "$dev"
1090 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1091 done
1093 for dev in "${!host_fs_types[@]}"; do
1094 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
1095 rootopts=$(find_dev_fsopts "$dev")
1096 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1097 journaldev=$(fs_get_option $rootopts "jdev")
1098 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1099 journaldev=$(fs_get_option $rootopts "logdev")
1101 if [[ $journaldev ]]; then
1102 dev="$(readlink -f "$dev")"
1103 push host_devs "$dev"
1104 _get_fs_type "$dev"
1105 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1107 done
1109 [[ -d $udevdir ]] \
1110 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1111 if ! [[ -d "$udevdir" ]]; then
1112 [[ -d /lib/udev ]] && udevdir=/lib/udev
1113 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
1116 [[ -d $systemdutildir ]] \
1117 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
1119 if ! [[ -d "$systemdutildir" ]]; then
1120 [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
1121 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
1124 [[ -d $systemdsystemunitdir ]] \
1125 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
1127 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
1129 [[ -d $systemdsystemconfdir ]] \
1130 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
1132 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
1134 export initdir dracutbasedir dracutmodules \
1135 fw_dir drivers_dir debug no_kernel kernel_only \
1136 omit_drivers mdadmconf lvmconf root_dev \
1137 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1138 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1139 debug host_fs_types host_devs sshkey add_fstab \
1140 DRACUT_VERSION udevdir prefix filesystems drivers \
1141 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1142 host_modalias host_modules
1144 mods_to_load=""
1145 # check all our modules to see if they should be sourced.
1146 # This builds a list of modules that we will install next.
1147 for_each_module_dir check_module
1148 for_each_module_dir check_mount
1150 dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
1152 if [[ $print_cmdline ]]; then
1153 modules_loaded=" "
1154 # source our modules.
1155 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1156 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1157 module_cmdline "$_d_mod"
1158 done
1159 unset moddir
1160 printf "\n"
1161 exit 0
1164 # Create some directory structure first
1165 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1167 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1168 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1170 if [[ $prefix ]]; then
1171 for d in bin etc lib sbin tmp usr var $libdirs; do
1172 [[ "$d" == */* ]] && continue
1173 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1174 done
1177 if [[ $kernel_only != yes ]]; then
1178 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
1179 [[ -e "${initdir}${prefix}/$d" ]] && continue
1180 if [ -L "/$d" ]; then
1181 inst_symlink "/$d" "${prefix}/$d"
1182 else
1183 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1185 done
1187 for d in dev proc sys sysroot root run; do
1188 if [ -L "/$d" ]; then
1189 inst_symlink "/$d"
1190 else
1191 mkdir -m 0755 -p "$initdir/$d"
1193 done
1195 ln -sfn ../run "$initdir/var/run"
1196 ln -sfn ../run/lock "$initdir/var/lock"
1197 ln -sfn ../run/log "$initdir/var/log"
1198 else
1199 for d in lib "$libdir"; do
1200 [[ -e "${initdir}${prefix}/$d" ]] && continue
1201 if [ -h "/$d" ]; then
1202 inst "/$d" "${prefix}/$d"
1203 else
1204 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1206 done
1209 if [[ $kernel_only != yes ]]; then
1210 mkdir -p "${initdir}/etc/cmdline.d"
1211 for _d in $hookdirs; do
1212 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1213 done
1214 if [[ "$UID" = "0" ]]; then
1215 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1216 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1217 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1221 _isize=0 #initramfs size
1222 modules_loaded=" "
1223 # source our modules.
1224 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1225 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1226 if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
1227 if [[ $show_modules = yes ]]; then
1228 printf "%s\n" "$_d_mod"
1229 else
1230 dinfo "*** Including module: $_d_mod ***"
1232 if [[ $kernel_only == yes ]]; then
1233 module_installkernel "$_d_mod" || {
1234 dfatal "installkernel failed in module $_d_mod"
1235 exit 1
1237 else
1238 module_install "$_d_mod"
1239 if [[ $no_kernel != yes ]]; then
1240 module_installkernel "$_d_mod" || {
1241 dfatal "installkernel failed in module $_d_mod"
1242 exit 1
1246 mods_to_load=${mods_to_load// $_d_mod /}
1247 modules_loaded+="$_d_mod "
1249 #print the module install size
1250 if [ -n "$printsize" ]; then
1251 _isize_new=$(du -sk ${initdir}|cut -f1)
1252 _isize_delta=$((_isize_new - _isize))
1253 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1254 _isize=$_isize_new
1257 done
1258 unset moddir
1260 for i in $modules_loaded; do
1261 mkdir -p $initdir/lib/dracut
1262 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1263 done
1265 dinfo "*** Including modules done ***"
1267 ## final stuff that has to happen
1268 if [[ $no_kernel != yes ]]; then
1270 if [[ $drivers ]]; then
1271 hostonly='' instmods $drivers
1274 if [[ $add_drivers ]]; then
1275 hostonly='' instmods -c $add_drivers
1277 if [[ $filesystems ]]; then
1278 hostonly='' instmods -c $filesystems
1281 dinfo "*** Installing kernel module dependencies and firmware ***"
1282 dracut_kernel_post
1283 dinfo "*** Installing kernel module dependencies and firmware done ***"
1285 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1286 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1287 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1288 for i in ${initdir}/etc/cmdline.d/*.conf; do
1289 # We need no initramfs image and do not generate one.
1290 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1291 done
1296 if [[ $kernel_only != yes ]]; then
1297 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1299 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1301 while pop fstab_lines line; do
1302 printf "%s\n" "$line 0 0" >> "${initdir}/etc/fstab"
1303 done
1305 for f in $add_fstab; do
1306 cat "$f" >> "${initdir}/etc/fstab"
1307 done
1309 if [ -d ${initdir}/$systemdutildir ]; then
1310 mkdir -p ${initdir}/etc/conf.d
1312 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1313 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1314 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1315 } > ${initdir}/etc/conf.d/systemd.conf
1318 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1319 dinfo "*** Resolving executable dependencies ***"
1320 find "$initdir" -type f \
1321 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1322 -not -path '*.ko' -print0 \
1323 | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1324 dinfo "*** Resolving executable dependencies done***"
1328 while pop include_src src && pop include_target tgt; do
1329 if [[ $src && $tgt ]]; then
1330 if [[ -f $src ]]; then
1331 inst $src $tgt
1332 else
1333 ddebug "Including directory: $src"
1334 mkdir -p "${initdir}/${tgt}"
1335 # check for preexisting symlinks, so we can cope with the
1336 # symlinks to $prefix
1337 for i in "$src"/*; do
1338 [[ -e "$i" || -h "$i" ]] || continue
1339 s=${initdir}/${tgt}/${i#$src/}
1340 if [[ -d "$i" ]]; then
1341 if ! [[ -e "$s" ]]; then
1342 mkdir -m 0755 -p "$s"
1343 chmod --reference="$i" "$s"
1345 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
1346 else
1347 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
1349 done
1352 done
1354 if [[ $kernel_only != yes ]]; then
1355 # make sure that library links are correct and up to date
1356 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1357 [[ -f $f ]] && inst_simple "$f"
1358 done
1359 if ! ldconfig -r "$initdir"; then
1360 if [[ $UID = 0 ]]; then
1361 derror "ldconfig exited ungracefully"
1362 else
1363 derror "ldconfig might need uid=0 (root) for chroot()"
1368 if [[ $do_prelink == yes ]]; then
1369 PRELINK_BIN="$(command -v prelink)"
1370 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1371 if [[ $DRACUT_FIPS_MODE ]]; then
1372 dinfo "*** Installing prelink files ***"
1373 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1374 else
1375 dinfo "*** Pre-linking files ***"
1376 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1377 chroot "$initdir" "$PRELINK_BIN" -a
1378 rm -f -- "$initdir/$PRELINK_BIN"
1379 rm -fr -- "$initdir"/etc/prelink.*
1380 dinfo "*** Pre-linking files done ***"
1385 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1386 dinfo "*** Hardlinking files ***"
1387 hardlink "$initdir" 2>&1
1388 dinfo "*** Hardlinking files done ***"
1391 # strip binaries
1392 if [[ $do_strip = yes ]] ; then
1393 for p in strip xargs find; do
1394 if ! type -P $p >/dev/null; then
1395 dinfo "Could not find '$p'. Not stripping the initramfs."
1396 do_strip=no
1398 done
1401 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1402 dinfo "*** Stripping files ***"
1403 find "$initdir" -type f \
1404 -executable -not -path '*/lib/modules/*.ko' -print0 \
1405 | xargs -r -0 strip -g 2>/dev/null
1407 # strip kernel modules, but do not touch signed modules
1408 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1409 | while read -r -d $'\0' f; do
1410 SIG=$(tail -c 28 "$f")
1411 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1412 done | xargs -r -0 strip -g
1414 dinfo "*** Stripping files done ***"
1416 if [[ $early_microcode = yes ]]; then
1417 dinfo "*** Generating early-microcode cpio image ***"
1418 ucode_dir=(amd-ucode intel-ucode)
1419 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1420 _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
1421 _dest_idx="0 1"
1422 mkdir -p $_dest_dir
1423 if [[ $hostonly ]]; then
1424 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1425 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1427 for idx in $_dest_idx; do
1428 _fw=${ucode_dir[$idx]}
1429 for _fwdir in $fw_dir; do
1430 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1431 _src="*"
1432 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1433 if [[ $hostonly ]]; then
1434 _src=$(get_ucode_file)
1435 if ! [[ -r $_fwdir/$_fw/$_src ]];then
1436 break;
1439 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1440 create_early_cpio="yes"
1442 done
1443 done
1446 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1447 dinfo "*** Packaging ACPI tables to override BIOS provided ones ***"
1448 _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi"
1449 mkdir -p $_dest_dir
1450 for table in $acpi_table_dir/*.aml; do
1451 dinfo " Adding ACPI table: $table"
1452 cp $table $_dest_dir
1453 create_early_cpio="yes"
1454 done
1457 dinfo "*** Store current command line parameters ***"
1458 if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
1459 dfatal "Could not store the current command line parameters"
1460 exit 1
1463 rm -f -- "$outfile"
1464 dinfo "*** Creating image file ***"
1466 [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"
1468 if [[ $create_early_cpio = yes ]]; then
1469 echo 1 > "$early_cpio_dir/d/early_cpio"
1470 # The microcode blob is _before_ the initramfs blob, not after
1471 (cd "$early_cpio_dir/d"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet >../early.cpio)
1472 mv $early_cpio_dir/early.cpio $outfile.$$
1474 if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
1475 $compress >> "$outfile.$$"; ); then
1476 dfatal "dracut: creation of $outfile.$$ failed"
1477 exit 1
1479 mv -- "$outfile.$$" "$outfile"
1480 dinfo "*** Creating image file done ***"
1482 if (( maxloglvl >= 5 )); then
1483 if [[ $allowlocal ]]; then
1484 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1485 else
1486 lsinitrd "$outfile"| ddebug
1490 exit 0