]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
dracut.sh: add libgcc_s, if libpthread is installed
[thirdparty/dracut.git] / dracut.sh
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
4 #
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
8 #
9
10 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
11 #
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.
16 #
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.
21 #
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/>.
24 #
25
26 # store for logging
27 dracut_args=( "$@" )
28
29 set -o pipefail
30
31 usage() {
32 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
33 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
34 . $dracutbasedir/dracut-version.sh
35 fi
36
37 # 80x25 linebreak here ^
38 cat << EOF
39 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
40
41 Version: $DRACUT_VERSION
42
43 Creates initial ramdisk images for preloading modules
44
45 -h, --help Display all options
46
47 If a [LIST] has multiple arguments, then you have to put these in quotes.
48
49 For example:
50
51 # dracut --add-drivers "module1 module2" ...
52
53 EOF
54 }
55
56 long_usage() {
57 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
58 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
59 . $dracutbasedir/dracut-version.sh
60 fi
61
62 # 80x25 linebreak here ^
63 cat << EOF
64 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
65
66 Version: $DRACUT_VERSION
67
68 Creates initial ramdisk images for preloading modules
69
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 --hostonly-cmdline Store kernel command line arguments needed
141 in the initramfs
142 --no-hostonly-cmdline Do not store kernel command line arguments needed
143 in the initramfs
144 --persistent-policy [POLICY]
145 Use [POLICY] to address disks and partitions.
146 POLICY can be any directory name found in /dev/disk.
147 E.g. "by-uuid", "by-label"
148 --fstab Use /etc/fstab to determine the root device.
149 --add-fstab [FILE] Add file to the initramfs fstab
150 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
151 Mount device [DEV] on mountpoint [MP] with filesystem
152 [FSTYPE] and options [FSOPTS] in the initramfs
153 --add-device "[DEV]" Bring up [DEV] in initramfs
154 -i, --include [SOURCE] [TARGET]
155 Include the files in the SOURCE directory into the
156 Target directory in the final initramfs.
157 If SOURCE is a file, it will be installed to TARGET
158 in the final initramfs.
159 -I, --install [LIST] Install the space separated list of files into the
160 initramfs.
161 --gzip Compress the generated initramfs using gzip.
162 This will be done by default, unless another
163 compression option or --no-compress is passed.
164 --bzip2 Compress the generated initramfs using bzip2.
165 Make sure your kernel has bzip2 decompression support
166 compiled in, otherwise you will not be able to boot.
167 --lzma Compress the generated initramfs using lzma.
168 Make sure your kernel has lzma support compiled in,
169 otherwise you will not be able to boot.
170 --xz Compress the generated initramfs using xz.
171 Make sure that your kernel has xz support compiled
172 in, otherwise you will not be able to boot.
173 --lzo Compress the generated initramfs using lzop.
174 Make sure that your kernel has lzo support compiled
175 in, otherwise you will not be able to boot.
176 --lz4 Compress the generated initramfs using lz4.
177 Make sure that your kernel has lz4 support compiled
178 in, otherwise you will not be able to boot.
179 --compress [COMPRESSION] Compress the generated initramfs with the
180 passed compression program. Make sure your kernel
181 knows how to decompress the generated initramfs,
182 otherwise you will not be able to boot.
183 --no-compress Do not compress the generated initramfs. This will
184 override any other compression options.
185 --list-modules List all available dracut modules.
186 -M, --show-modules Print included module's name to standard output during
187 build.
188 --keep Keep the temporary initramfs for debugging purposes
189 --printsize Print out the module install size
190 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
191 --logfile [FILE] Logfile to use (overrides configuration setting)
192
193 If [LIST] has multiple arguments, then you have to put these in quotes.
194
195 For example:
196
197 # dracut --add-drivers "module1 module2" ...
198
199 EOF
200 }
201
202 # function push()
203 # push values to a stack
204 # $1 = stack variable
205 # $2.. values
206 # example:
207 # push stack 1 2 "3 4"
208 push() {
209 local _i
210 local __stack=$1; shift
211 for _i in "$@"; do
212 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
213 done
214 }
215
216 # function pop()
217 # pops the last value from a stack
218 # assigns value to second argument variable
219 # or echo to stdout, if no second argument
220 # $1 = stack variable
221 # $2 = optional variable to store the value
222 # example:
223 # pop stack val
224 # val=$(pop stack)
225 pop() {
226 local __stack=$1; shift
227 local __resultvar=$1
228 local _value;
229 # check for empty stack
230 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
231
232 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
233
234 if [[ "$__resultvar" ]]; then
235 eval $__resultvar="'$_value'"
236 else
237 printf "%s" "$_value"
238 fi
239 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
240 return 0
241 }
242
243 # Little helper function for reading args from the commandline.
244 # it automatically handles -a b and -a=b variants, and returns 1 if
245 # we need to shift $3.
246 read_arg() {
247 # $1 = arg name
248 # $2 = arg value
249 # $3 = arg parameter
250 local rematch='^[^=]*=(.*)$'
251 if [[ $2 =~ $rematch ]]; then
252 read "$1" <<< "${BASH_REMATCH[1]}"
253 else
254 read "$1" <<< "$3"
255 # There is no way to shift our callers args, so
256 # return 1 to indicate they should do it instead.
257 return 1
258 fi
259 }
260
261 dropindirs_sort()
262 {
263 local suffix=$1; shift
264 local -a files
265 local f d
266
267 for d in "$@"; do
268 for i in "$d/"*"$suffix"; do
269 if [[ -e "$i" ]]; then
270 printf "%s\n" "${i##*/}"
271 fi
272 done
273 done | sort -Vu | {
274 readarray -t files
275
276 for f in "${files[@]}"; do
277 for d in "$@"; do
278 if [[ -e "$d/$f" ]]; then
279 printf "%s\n" "$d/$f"
280 continue 2
281 fi
282 done
283 done
284 }
285 }
286
287 rearrange_params()
288 {
289 # Workaround -i, --include taking 2 arguments
290 set -- "${@/--include/++include}"
291
292 # This prevents any long argument ending with "-i"
293 # -i, like --opt-i but I think we can just prevent that
294 set -- "${@/%-i/++include}"
295
296 TEMP=$(unset POSIXLY_CORRECT; getopt \
297 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
298 --long kver: \
299 --long add: \
300 --long force-add: \
301 --long add-drivers: \
302 --long omit-drivers: \
303 --long modules: \
304 --long omit: \
305 --long drivers: \
306 --long filesystems: \
307 --long install: \
308 --long fwdir: \
309 --long libdirs: \
310 --long fscks: \
311 --long add-fstab: \
312 --long mount: \
313 --long device: \
314 --long add-device: \
315 --long nofscks: \
316 --long ro-mnt \
317 --long kmoddir: \
318 --long conf: \
319 --long confdir: \
320 --long tmpdir: \
321 --long stdlog: \
322 --long compress: \
323 --long prefix: \
324 --long rebuild: \
325 --long force \
326 --long kernel-only \
327 --long no-kernel \
328 --long print-cmdline \
329 --long kernel-cmdline: \
330 --long strip \
331 --long nostrip \
332 --long prelink \
333 --long noprelink \
334 --long hardlink \
335 --long nohardlink \
336 --long noprefix \
337 --long mdadmconf \
338 --long nomdadmconf \
339 --long lvmconf \
340 --long nolvmconf \
341 --long debug \
342 --long profile \
343 --long sshkey: \
344 --long logfile: \
345 --long verbose \
346 --long quiet \
347 --long local \
348 --long hostonly \
349 --long host-only \
350 --long no-hostonly \
351 --long no-host-only \
352 --long hostonly-cmdline \
353 --long no-hostonly-cmdline \
354 --long persistent-policy: \
355 --long fstab \
356 --long help \
357 --long bzip2 \
358 --long lzma \
359 --long xz \
360 --long lzo \
361 --long lz4 \
362 --long no-compress \
363 --long gzip \
364 --long list-modules \
365 --long show-modules \
366 --long keep \
367 --long printsize \
368 --long regenerate-all \
369 --long noimageifnotneeded \
370 --long early-microcode \
371 --long no-early-microcode \
372 -- "$@")
373
374 if (( $? != 0 )); then
375 usage
376 exit 1
377 fi
378 }
379
380 verbosity_mod_l=0
381 unset kernel
382 unset outfile
383
384 rearrange_params "$@"
385 eval set -- "$TEMP"
386
387 # parse command line args to check if '--rebuild' option is present
388 unset append_args_l
389 unset rebuild_file
390 while :
391 do
392 if [ "$1" == "--" ]; then
393 shift; break
394 fi
395 if [ "$1" == "--rebuild" ]; then
396 append_args_l="yes"
397 rebuild_file=$2
398 if [ ! -e $rebuild_file ]; then
399 echo "Image file '$rebuild_file', for rebuild, does not exist!"
400 exit 1
401 fi
402 abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
403 shift; continue
404 fi
405 shift
406 done
407
408 # get output file name and kernel version from command line arguments
409 while (($# > 0)); do
410 case ${1%%=*} in
411 ++include)
412 shift 2;;
413 *)
414 if ! [[ ${outfile+x} ]]; then
415 outfile=$1
416 elif ! [[ ${kernel+x} ]]; then
417 kernel=$1
418 else
419 printf "\nUnknown arguments: %s\n\n" "$*" >&2
420 usage; exit 1;
421 fi
422 ;;
423 esac
424 shift
425 done
426
427 # extract input image file provided with rebuild option to get previous parameters, if any
428 if [[ $append_args_l == "yes" ]]; then
429 unset rebuild_param
430
431 # determine resultant file
432 if ! [[ $outfile ]]; then
433 outfile=$rebuild_file
434 fi
435
436 if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
437 echo "Image '$rebuild_file' has no rebuild information stored"
438 exit 1
439 fi
440
441 # prepend previous parameters to current command line args
442 if [[ $rebuild_param ]]; then
443 TEMP="$rebuild_param $TEMP"
444 eval set -- "$TEMP"
445 rearrange_params "$@"
446 fi
447
448 # clean the temporarily used scratch-pad directory
449 rm -rf $scratch_dir
450 fi
451
452 unset PARMS_TO_STORE
453 PARMS_TO_STORE=""
454
455 eval set -- "$TEMP"
456
457 while :; do
458 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
459 PARMS_TO_STORE+=" $1";
460 fi
461 case $1 in
462 --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
463 -a|--add) push add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
464 --force-add) push force_add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
465 --add-drivers) push add_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
466 --omit-drivers) push omit_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
467 -m|--modules) push dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
468 -o|--omit) push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
469 -d|--drivers) push drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
470 --filesystems) push filesystems_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
471 -I|--install) push install_items_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
472 --fwdir) push fw_dir_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
473 --libdirs) push libdirs_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
474 --fscks) push fscks_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
475 --add-fstab) push add_fstab_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
476 --mount) push fstab_lines "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
477 --add-device|--device)
478 push add_device_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
479 --kernel-cmdline) push kernel_cmdline_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
480 --nofscks) nofscks_l="yes";;
481 --ro-mnt) ro_mnt_l="yes";;
482 -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
483 -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
484 --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
485 --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
486 -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
487 --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
488 --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
489 --rebuild) if [ $rebuild_file == $outfile ]; then
490 force=yes
491 fi
492 shift
493 ;;
494 -f|--force) force=yes;;
495 --kernel-only) kernel_only="yes"; no_kernel="no";;
496 --no-kernel) kernel_only="no"; no_kernel="yes";;
497 --print-cmdline)
498 print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
499 --early-microcode)
500 early_microcode_l="yes";;
501 --no-early-microcode)
502 early_microcode_l="no";;
503 --strip) do_strip_l="yes";;
504 --nostrip) do_strip_l="no";;
505 --prelink) do_prelink_l="yes";;
506 --noprelink) do_prelink_l="no";;
507 --hardlink) do_hardlink_l="yes";;
508 --nohardlink) do_hardlink_l="no";;
509 --noprefix) prefix_l="/";;
510 --mdadmconf) mdadmconf_l="yes";;
511 --nomdadmconf) mdadmconf_l="no";;
512 --lvmconf) lvmconf_l="yes";;
513 --nolvmconf) lvmconf_l="no";;
514 --debug) debug="yes";;
515 --profile) profile="yes";;
516 --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
517 --logfile) logfile_l="$2"; shift;;
518 -v|--verbose) ((verbosity_mod_l++));;
519 -q|--quiet) ((verbosity_mod_l--));;
520 -l|--local)
521 allowlocal="yes"
522 [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
523 && dracutbasedir="$(readlink -f "${0%/*}")"
524 ;;
525 -H|--hostonly|--host-only)
526 hostonly_l="yes" ;;
527 -N|--no-hostonly|--no-host-only)
528 hostonly_l="no" ;;
529 --hostonly-cmdline)
530 hostonly_cmdline_l="yes" ;;
531 --no-hostonly-cmdline)
532 hostonly_cmdline_l="no" ;;
533 --persistent-policy)
534 persistent_policy_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
535 --fstab) use_fstab_l="yes" ;;
536 -h|--help) long_usage; exit 1 ;;
537 -i|--include) push include_src "$2"; PARMS_TO_STORE+=" '$2'";
538 shift;;
539 --bzip2) compress_l="bzip2";;
540 --lzma) compress_l="lzma";;
541 --xz) compress_l="xz";;
542 --lzo) compress_l="lzo";;
543 --lz4) compress_l="lz4";;
544 --no-compress) _no_compress_l="cat";;
545 --gzip) compress_l="gzip";;
546 --list-modules) do_list="yes";;
547 -M|--show-modules)
548 show_modules_l="yes"
549 ;;
550 --keep) keep="yes";;
551 --printsize) printsize="yes";;
552 --regenerate-all) regenerate_all="yes";;
553 --noimageifnotneeded) noimageifnotneeded="yes";;
554
555 --) shift; break;;
556
557 *) # should not even reach this point
558 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
559 esac
560 shift
561 done
562
563 # getopt cannot handle multiple arguments, so just handle "-I,--include"
564 # the old fashioned way
565
566 while (($# > 0)); do
567 if [ "${1%%=*}" == "++include" ]; then
568 push include_src "$2"
569 push include_target "$3"
570 PARMS_TO_STORE+=" --include '$2' '$3'"
571 shift 2
572 fi
573 shift
574 done
575
576 if [[ $regenerate_all == "yes" ]]; then
577 ret=0
578 if [[ $kernel ]]; then
579 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
580 exit 1
581 fi
582
583 if [[ $outfile ]]; then
584 printf -- "--regenerate-all cannot be called with a image file\n" >&2
585 exit 1
586 fi
587
588 ((len=${#dracut_args[@]}))
589 for ((i=0; i < len; i++)); do
590 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
591 unset dracut_args[$i]
592 done
593
594 cd /lib/modules
595 for i in *; do
596 [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
597 dracut --kver="$i" "${dracut_args[@]}"
598 ((ret+=$?))
599 done
600 exit $ret
601 fi
602
603 if ! [[ $kernel ]]; then
604 kernel=$(uname -r)
605 fi
606
607 if [[ $kernel ]]; then
608 if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then
609 printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2
610 fi
611 fi
612
613 if ! [[ $outfile ]]; then
614 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
615
616 if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
617 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
618 else
619 outfile="/boot/initramfs-$kernel.img"
620 fi
621 fi
622
623 for i in /usr/sbin /sbin /usr/bin /bin; do
624 rl=$i
625 if [ -L "$i" ]; then
626 rl=$(readlink -f $i)
627 fi
628 if [[ "$NPATH" != *:$rl* ]] ; then
629 NPATH+=":$rl"
630 fi
631 done
632 export PATH="${NPATH#:}"
633 unset LC_MESSAGES
634 unset LC_CTYPE
635 export LC_ALL=C
636 export LANG=C
637 unset NPATH
638 unset LD_LIBRARY_PATH
639 unset LD_PRELOAD
640 unset GREP_OPTIONS
641
642 export DRACUT_LOG_LEVEL=warning
643 [[ $debug ]] && {
644 export DRACUT_LOG_LEVEL=debug
645 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
646 set -x
647 }
648
649 [[ $profile ]] && {
650 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
651 set -x
652 debug=yes
653 }
654
655 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
656
657 # if we were not passed a config file, try the default one
658 if [[ ! -f $conffile ]]; then
659 if [[ $allowlocal ]]; then
660 conffile="$dracutbasedir/dracut.conf"
661 else
662 conffile="/etc/dracut.conf"
663 fi
664 fi
665
666 if [[ ! -d $confdir ]]; then
667 if [[ $allowlocal ]]; then
668 confdir="$dracutbasedir/dracut.conf.d"
669 else
670 confdir="/etc/dracut.conf.d"
671 fi
672 fi
673
674 # source our config file
675 [[ -f $conffile ]] && . "$conffile"
676
677 # source our config dir
678 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
679 [[ -e $f ]] && . "$f"
680 done
681
682 # these optins add to the stuff in the config file
683 if (( ${#add_dracutmodules_l[@]} )); then
684 while pop add_dracutmodules_l val; do
685 add_dracutmodules+=" $val "
686 done
687 fi
688
689 if (( ${#force_add_dracutmodules_l[@]} )); then
690 while pop force_add_dracutmodules_l val; do
691 force_add_dracutmodules+=" $val "
692 done
693 fi
694
695 if (( ${#fscks_l[@]} )); then
696 while pop fscks_l val; do
697 fscks+=" $val "
698 done
699 fi
700
701 if (( ${#add_fstab_l[@]} )); then
702 while pop add_fstab_l val; do
703 add_fstab+=" $val "
704 done
705 fi
706
707 if (( ${#fstab_lines_l[@]} )); then
708 while pop fstab_lines_l val; do
709 push fstab_lines $val
710 done
711 fi
712
713 if (( ${#install_items_l[@]} )); then
714 while pop install_items_l val; do
715 install_items+=" $val "
716 done
717 fi
718
719 # these options override the stuff in the config file
720 if (( ${#dracutmodules_l[@]} )); then
721 dracutmodules=''
722 while pop dracutmodules_l val; do
723 dracutmodules+="$val "
724 done
725 fi
726
727 if (( ${#omit_dracutmodules_l[@]} )); then
728 omit_dracutmodules=''
729 while pop omit_dracutmodules_l val; do
730 omit_dracutmodules+="$val "
731 done
732 fi
733
734 if (( ${#filesystems_l[@]} )); then
735 filesystems=''
736 while pop filesystems_l val; do
737 filesystems+="$val "
738 done
739 fi
740
741 if (( ${#fw_dir_l[@]} )); then
742 fw_dir=''
743 while pop fw_dir_l val; do
744 fw_dir+="$val "
745 done
746 fi
747
748 if (( ${#libdirs_l[@]} )); then
749 libdirs=''
750 while pop libdirs_l val; do
751 libdirs+="$val "
752 done
753 fi
754
755 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
756 [[ ! $stdloglvl ]] && stdloglvl=4
757 stdloglvl=$((stdloglvl + verbosity_mod_l))
758 ((stdloglvl > 6)) && stdloglvl=6
759 ((stdloglvl < 0)) && stdloglvl=0
760
761 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
762 [[ $do_strip_l ]] && do_strip=$do_strip_l
763 [[ $do_strip ]] || do_strip=yes
764 [[ $do_prelink_l ]] && do_prelink=$do_prelink_l
765 [[ $do_prelink ]] || do_prelink=yes
766 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
767 [[ $do_hardlink ]] || do_hardlink=yes
768 [[ $prefix_l ]] && prefix=$prefix_l
769 [[ $prefix = "/" ]] && unset prefix
770 [[ $hostonly_l ]] && hostonly=$hostonly_l
771 [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
772 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
773 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
774 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
775 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
776 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
777 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
778 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
779 [[ $tmpdir ]] || tmpdir=/var/tmp
780 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
781 [[ $compress_l ]] && compress=$compress_l
782 [[ $show_modules_l ]] && show_modules=$show_modules_l
783 [[ $nofscks_l ]] && nofscks="yes"
784 [[ $ro_mnt_l ]] && ro_mnt="yes"
785 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
786 [[ $early_microcode ]] || early_microcode=no
787 [[ $logfile_l ]] && logfile="$logfile_l"
788 # eliminate IFS hackery when messing with fw_dir
789 fw_dir=${fw_dir//:/ }
790
791 # handle compression options.
792 [[ $compress ]] || compress="gzip"
793 case $compress in
794 bzip2) compress="bzip2 -9";;
795 lzma) compress="lzma -9 -T0";;
796 xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
797 gzip) compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
798 lzo) compress="lzop -9";;
799 lz4) compress="lz4 -l -9";;
800 esac
801 if [[ $_no_compress_l = "cat" ]]; then
802 compress="cat"
803 fi
804
805 [[ $hostonly = yes ]] && hostonly="-h"
806 [[ $hostonly != "-h" ]] && unset hostonly
807
808 readonly TMPDIR="$tmpdir"
809 readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
810 [ -d "$initdir" ] || {
811 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
812 exit 1
813 }
814
815 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
816 readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
817 [ -d "$early_cpio_dir" ] || {
818 printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
819 exit 1
820 }
821 fi
822 # clean up after ourselves no matter how we die.
823 trap '
824 ret=$?;
825 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
826 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
827 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
828 exit $ret;
829 ' EXIT
830
831 # clean up after ourselves no matter how we die.
832 trap 'exit 1;' SIGINT
833
834 export DRACUT_KERNEL_LAZY="1"
835 export DRACUT_RESOLVE_LAZY="1"
836
837 if [[ $print_cmdline ]]; then
838 stdloglvl=0
839 sysloglvl=0
840 fileloglvl=0
841 kmsgloglvl=0
842 fi
843
844 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
845 . $dracutbasedir/dracut-functions.sh
846 else
847 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
848 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
849 printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
850 exit 1
851 fi
852
853 if ! [[ $print_cmdline ]]; then
854 inst /bin/sh
855 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
856 unset DRACUT_RESOLVE_LAZY
857 export DRACUT_RESOLVE_DEPS=1
858 fi
859 rm -fr -- ${initdir}/*
860 fi
861
862 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
863 . $dracutbasedir/dracut-version.sh
864 fi
865
866 # Verify bash version, current minimum is 3.1
867 if (( BASH_VERSINFO[0] < 4 )); then
868 dfatal 'You need at least Bash 4 to use dracut, sorry.'
869 exit 1
870 fi
871
872 dracutfunctions=$dracutbasedir/dracut-functions.sh
873 export dracutfunctions
874
875 if (( ${#drivers_l[@]} )); then
876 drivers=''
877 while pop drivers_l val; do
878 drivers+="$val "
879 done
880 fi
881 drivers=${drivers/-/_}
882
883 if (( ${#add_drivers_l[@]} )); then
884 while pop add_drivers_l val; do
885 add_drivers+=" $val "
886 done
887 fi
888 add_drivers=${add_drivers/-/_}
889
890 if (( ${#omit_drivers_l[@]} )); then
891 while pop omit_drivers_l val; do
892 omit_drivers+=" $val "
893 done
894 fi
895 omit_drivers=${omit_drivers/-/_}
896
897 if (( ${#kernel_cmdline_l[@]} )); then
898 while pop kernel_cmdline_l val; do
899 kernel_cmdline+=" $val "
900 done
901 fi
902
903 omit_drivers_corrected=""
904 for d in $omit_drivers; do
905 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
906 omit_drivers_corrected+="$d|"
907 done
908 omit_drivers="${omit_drivers_corrected%|}"
909 unset omit_drivers_corrected
910
911 # prepare args for logging
912 for ((i=0; i < ${#dracut_args[@]}; i++)); do
913 [[ "${dracut_args[$i]}" == *\ * ]] && \
914 dracut_args[$i]="\"${dracut_args[$i]}\""
915 #" keep vim happy
916 done
917
918 dinfo "Executing: $0 ${dracut_args[@]}"
919
920 [[ $do_list = yes ]] && {
921 for mod in $dracutbasedir/modules.d/*; do
922 [[ -d $mod ]] || continue;
923 [[ -e $mod/install || -e $mod/installkernel || \
924 -e $mod/module-setup.sh ]] || continue
925 printf "%s\n" "${mod##*/??}"
926 done
927 exit 0
928 }
929
930 # This is kinda legacy -- eventually it should go away.
931 case $dracutmodules in
932 ""|auto) dracutmodules="all" ;;
933 esac
934
935 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
936
937 if [[ -d $srcmods ]]; then
938 [[ -f $srcmods/modules.dep ]] || {
939 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
940 }
941 fi
942
943 if [[ ! $print_cmdline ]]; then
944 if [[ -f $outfile && ! $force ]]; then
945 dfatal "Will not override existing initramfs ($outfile) without --force"
946 exit 1
947 fi
948
949 outdir=${outfile%/*}
950 [[ $outdir ]] || outdir="/"
951
952 if [[ ! -d "$outdir" ]]; then
953 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
954 exit 1
955 elif [[ ! -w "$outdir" ]]; then
956 dfatal "No permission to write to $outdir."
957 exit 1
958 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
959 dfatal "No permission to write $outfile."
960 exit 1
961 fi
962 fi
963
964 # Need to be able to have non-root users read stuff (rpcbind etc)
965 chmod 755 "$initdir"
966
967 if [[ $hostonly ]]; then
968 for i in /sys /proc /run /dev; do
969 if ! findmnt --target "$i" &>/dev/null; then
970 dwarning "Turning off host-only mode: '$i' is not mounted!"
971 unset hostonly
972 fi
973 done
974 fi
975
976 declare -A host_fs_types
977
978 for line in "${fstab_lines[@]}"; do
979 set -- $line
980 #dev mp fs fsopts
981 push host_devs "$1"
982 host_fs_types["$1"]="$3"
983 done
984
985 for f in $add_fstab; do
986 [[ -e $f ]] || continue
987 while read dev rest; do
988 push host_devs "$dev"
989 done < "$f"
990 done
991
992 for dev in $add_device; do
993 push host_devs "$dev"
994 done
995
996 if (( ${#add_device_l[@]} )); then
997 while pop add_device_l val; do
998 add_device+=" $val "
999 push host_devs "$val"
1000 done
1001 fi
1002
1003 if [[ $hostonly ]]; then
1004 # in hostonly mode, determine all devices, which have to be accessed
1005 # and examine them for filesystem types
1006
1007 for mp in \
1008 "/" \
1009 "/etc" \
1010 "/bin" \
1011 "/sbin" \
1012 "/lib" \
1013 "/lib64" \
1014 "/usr" \
1015 "/usr/bin" \
1016 "/usr/sbin" \
1017 "/usr/lib" \
1018 "/usr/lib64" \
1019 "/boot" \
1020 "/boot/efi" \
1021 ;
1022 do
1023 mp=$(readlink -f "$mp")
1024 mountpoint "$mp" >/dev/null 2>&1 || continue
1025 _dev=$(find_block_device "$mp")
1026 _bdev=$(readlink -f "/dev/block/$_dev")
1027 [[ -b $_bdev ]] && _dev=$_bdev
1028 push host_devs $_dev
1029 [[ "$mp" == "/" ]] && root_dev="$_dev"
1030 push host_devs "$_dev"
1031 done
1032
1033 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
1034 while read dev type rest; do
1035 [[ -b $dev ]] || continue
1036 [[ "$type" == "partition" ]] || continue
1037
1038 while read _d _m _t _o _r; do
1039 [[ "$_d" == \#* ]] && continue
1040 [[ $_d ]] || continue
1041 [[ $_t != "swap" ]] && continue
1042 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1043 [[ "$_o" == *noauto* ]] && continue
1044 _d=$(expand_persistent_dev "$_d")
1045 [[ "$_d" -ef "$dev" ]] || continue
1046
1047 if [[ -f /etc/crypttab ]]; then
1048 while read _mapper _a _p _o; do
1049 [[ $_mapper = \#* ]] && continue
1050 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
1051 [[ "$_o" ]] || _o="$_p"
1052 # skip entries with password files
1053 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1054 # skip mkswap swap
1055 [[ $_o == *swap* ]] && continue 2
1056 done < /etc/crypttab
1057 fi
1058
1059 push host_devs "$(readlink -f "$dev")"
1060 break
1061 done < /etc/fstab
1062 done < /proc/swaps
1063 fi
1064 # record all host modaliases
1065 declare -A host_modalias
1066 find /sys/devices/ -name uevent -print > "$initdir/.modalias"
1067 while read m; do
1068 while read line; do
1069 [[ "$line" != MODALIAS\=* ]] && continue
1070 modalias="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias["$modalias"]=1
1071 break
1072 done < "$m"
1073 done < "$initdir/.modalias"
1074
1075 rm -f -- "$initdir/.modalias"
1076
1077 while read _k _s _v; do
1078 [ "$_k" != "name" -a "$_k" != "driver" ] && continue
1079 host_modalias["$_v"]=1
1080 done </proc/crypto
1081
1082 # check /proc/modules
1083 declare -A host_modules
1084 while read m rest; do
1085 host_modules["$m"]=1
1086 done </proc/modules
1087 fi
1088
1089 unset m
1090 unset rest
1091
1092 _get_fs_type() {
1093 [[ $1 ]] || return
1094 if [[ -b /dev/block/$1 ]]; then
1095 ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
1096 return 1
1097 fi
1098 if [[ -b $1 ]]; then
1099 ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
1100 return 1
1101 fi
1102 if fstype=$(find_dev_fstype "$1"); then
1103 host_fs_types["$1"]="$fstype"
1104 return 1
1105 fi
1106 return 1
1107 }
1108
1109 for dev in ${host_devs[@]}; do
1110 _get_fs_type "$dev"
1111 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1112 done
1113
1114 for dev in "${!host_fs_types[@]}"; do
1115 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
1116 rootopts=$(find_dev_fsopts "$dev")
1117 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1118 journaldev=$(fs_get_option $rootopts "jdev")
1119 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1120 journaldev=$(fs_get_option $rootopts "logdev")
1121 fi
1122 if [[ $journaldev ]]; then
1123 dev="$(readlink -f "$dev")"
1124 push host_devs "$dev"
1125 _get_fs_type "$dev"
1126 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1127 fi
1128 done
1129
1130 [[ -d $udevdir ]] \
1131 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1132 if ! [[ -d "$udevdir" ]]; then
1133 [[ -d /lib/udev ]] && udevdir=/lib/udev
1134 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
1135 fi
1136
1137 [[ -d $systemdutildir ]] \
1138 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
1139
1140 if ! [[ -d "$systemdutildir" ]]; then
1141 [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
1142 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
1143 fi
1144
1145 [[ -d $systemdsystemunitdir ]] \
1146 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
1147
1148 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
1149
1150 [[ -d $systemdsystemconfdir ]] \
1151 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
1152
1153 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
1154
1155 export initdir dracutbasedir dracutmodules \
1156 fw_dir drivers_dir debug no_kernel kernel_only \
1157 omit_drivers mdadmconf lvmconf root_dev \
1158 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1159 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1160 debug host_fs_types host_devs sshkey add_fstab \
1161 DRACUT_VERSION udevdir prefix filesystems drivers \
1162 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1163 host_modalias host_modules hostonly_cmdline
1164
1165 mods_to_load=""
1166 # check all our modules to see if they should be sourced.
1167 # This builds a list of modules that we will install next.
1168 for_each_module_dir check_module
1169 for_each_module_dir check_mount
1170
1171 dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
1172
1173 if [[ $print_cmdline ]]; then
1174 modules_loaded=" "
1175 # source our modules.
1176 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1177 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1178 module_cmdline "$_d_mod"
1179 done
1180 unset moddir
1181 printf "\n"
1182 exit 0
1183 fi
1184
1185 # Create some directory structure first
1186 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1187
1188 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1189 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1190
1191 if [[ $prefix ]]; then
1192 for d in bin etc lib sbin tmp usr var $libdirs; do
1193 [[ "$d" == */* ]] && continue
1194 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1195 done
1196 fi
1197
1198 if [[ $kernel_only != yes ]]; then
1199 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
1200 [[ -e "${initdir}${prefix}/$d" ]] && continue
1201 if [ -L "/$d" ]; then
1202 inst_symlink "/$d" "${prefix}/$d"
1203 else
1204 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1205 fi
1206 done
1207
1208 for d in dev proc sys sysroot root run; do
1209 if [ -L "/$d" ]; then
1210 inst_symlink "/$d"
1211 else
1212 mkdir -m 0755 -p "$initdir/$d"
1213 fi
1214 done
1215
1216 ln -sfn ../run "$initdir/var/run"
1217 ln -sfn ../run/lock "$initdir/var/lock"
1218 ln -sfn ../run/log "$initdir/var/log"
1219 else
1220 for d in lib "$libdir"; do
1221 [[ -e "${initdir}${prefix}/$d" ]] && continue
1222 if [ -h "/$d" ]; then
1223 inst "/$d" "${prefix}/$d"
1224 else
1225 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1226 fi
1227 done
1228 fi
1229
1230 if [[ $kernel_only != yes ]]; then
1231 mkdir -p "${initdir}/etc/cmdline.d"
1232 for _d in $hookdirs; do
1233 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1234 done
1235 if [[ "$UID" = "0" ]]; then
1236 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1237 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1238 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1239 fi
1240 fi
1241
1242 _isize=0 #initramfs size
1243 modules_loaded=" "
1244 # source our modules.
1245 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1246 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1247 if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
1248 if [[ $show_modules = yes ]]; then
1249 printf "%s\n" "$_d_mod"
1250 else
1251 dinfo "*** Including module: $_d_mod ***"
1252 fi
1253 if [[ $kernel_only == yes ]]; then
1254 module_installkernel "$_d_mod" || {
1255 dfatal "installkernel failed in module $_d_mod"
1256 exit 1
1257 }
1258 else
1259 module_install "$_d_mod"
1260 if [[ $no_kernel != yes ]]; then
1261 module_installkernel "$_d_mod" || {
1262 dfatal "installkernel failed in module $_d_mod"
1263 exit 1
1264 }
1265 fi
1266 fi
1267 mods_to_load=${mods_to_load// $_d_mod /}
1268 modules_loaded+="$_d_mod "
1269
1270 #print the module install size
1271 if [ -n "$printsize" ]; then
1272 _isize_new=$(du -sk ${initdir}|cut -f1)
1273 _isize_delta=$((_isize_new - _isize))
1274 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1275 _isize=$_isize_new
1276 fi
1277 fi
1278 done
1279 unset moddir
1280
1281 for i in $modules_loaded; do
1282 mkdir -p $initdir/lib/dracut
1283 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1284 done
1285
1286 dinfo "*** Including modules done ***"
1287
1288 ## final stuff that has to happen
1289 if [[ $no_kernel != yes ]]; then
1290
1291 if [[ $drivers ]]; then
1292 hostonly='' instmods $drivers
1293 fi
1294
1295 if [[ $add_drivers ]]; then
1296 hostonly='' instmods -c $add_drivers
1297 fi
1298 if [[ $filesystems ]]; then
1299 hostonly='' instmods -c $filesystems
1300 fi
1301
1302 dinfo "*** Installing kernel module dependencies and firmware ***"
1303 dracut_kernel_post
1304 dinfo "*** Installing kernel module dependencies and firmware done ***"
1305
1306 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1307 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1308 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1309 for i in ${initdir}/etc/cmdline.d/*.conf; do
1310 # We need no initramfs image and do not generate one.
1311 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1312 done
1313 fi
1314 fi
1315 fi
1316
1317 if [[ $kernel_only != yes ]]; then
1318 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1319
1320 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1321
1322 while pop fstab_lines line; do
1323 line=($line)
1324 [ -z "${line[3]}" ] && line[3]="defaults"
1325 [ -z "${line[4]}" ] && line[4]="0"
1326 [ -z "${line[5]}" ] && line[5]="2"
1327 echo "${line[@]}" >> "${initdir}/etc/fstab"
1328 done
1329
1330 for f in $add_fstab; do
1331 cat "$f" >> "${initdir}/etc/fstab"
1332 done
1333
1334 if [ -d ${initdir}/$systemdutildir ]; then
1335 mkdir -p ${initdir}/etc/conf.d
1336 {
1337 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1338 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1339 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1340 } > ${initdir}/etc/conf.d/systemd.conf
1341 fi
1342
1343 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1344 dinfo "*** Resolving executable dependencies ***"
1345 find "$initdir" -type f \
1346 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1347 -not -path '*.ko' -print0 \
1348 | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1349 dinfo "*** Resolving executable dependencies done***"
1350 fi
1351
1352 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1353 for _dir in $libdirs; do
1354 for _f in "$_dir/libpthread.so"*; do
1355 [[ -e "$_f" ]] || continue
1356 inst_libdir_file "libgcc_s.so*"
1357 break 2
1358 done
1359 done
1360 fi
1361
1362 while pop include_src src && pop include_target tgt; do
1363 if [[ $src && $tgt ]]; then
1364 if [[ -f $src ]]; then
1365 inst $src $tgt
1366 else
1367 ddebug "Including directory: $src"
1368 mkdir -p "${initdir}/${tgt}"
1369 # check for preexisting symlinks, so we can cope with the
1370 # symlinks to $prefix
1371 for i in "$src"/*; do
1372 [[ -e "$i" || -h "$i" ]] || continue
1373 s=${initdir}/${tgt}/${i#$src/}
1374 if [[ -d "$i" ]]; then
1375 if ! [[ -e "$s" ]]; then
1376 mkdir -m 0755 -p "$s"
1377 chmod --reference="$i" "$s"
1378 fi
1379 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
1380 else
1381 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
1382 fi
1383 done
1384 fi
1385 fi
1386 done
1387
1388 if [[ $kernel_only != yes ]]; then
1389 # make sure that library links are correct and up to date
1390 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1391 [[ -f $f ]] && inst_simple "$f"
1392 done
1393 if ! ldconfig -r "$initdir"; then
1394 if [[ $UID = 0 ]]; then
1395 derror "ldconfig exited ungracefully"
1396 else
1397 derror "ldconfig might need uid=0 (root) for chroot()"
1398 fi
1399 fi
1400 fi
1401
1402 if [[ $do_prelink == yes ]]; then
1403 PRELINK_BIN="$(command -v prelink)"
1404 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1405 if [[ $DRACUT_FIPS_MODE ]]; then
1406 dinfo "*** Installing prelink files ***"
1407 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1408 else
1409 dinfo "*** Pre-linking files ***"
1410 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1411 chroot "$initdir" "$PRELINK_BIN" -a
1412 rm -f -- "$initdir/$PRELINK_BIN"
1413 rm -fr -- "$initdir"/etc/prelink.*
1414 dinfo "*** Pre-linking files done ***"
1415 fi
1416 fi
1417 fi
1418
1419 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1420 dinfo "*** Hardlinking files ***"
1421 hardlink "$initdir" 2>&1
1422 dinfo "*** Hardlinking files done ***"
1423 fi
1424
1425 # strip binaries
1426 if [[ $do_strip = yes ]] ; then
1427 for p in strip xargs find; do
1428 if ! type -P $p >/dev/null; then
1429 dinfo "Could not find '$p'. Not stripping the initramfs."
1430 do_strip=no
1431 fi
1432 done
1433 fi
1434
1435 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1436 dinfo "*** Stripping files ***"
1437 find "$initdir" -type f \
1438 -executable -not -path '*/lib/modules/*.ko' -print0 \
1439 | xargs -r -0 strip -g 2>/dev/null
1440
1441 # strip kernel modules, but do not touch signed modules
1442 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1443 | while read -r -d $'\0' f; do
1444 SIG=$(tail -c 28 "$f")
1445 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1446 done | xargs -r -0 strip -g
1447
1448 dinfo "*** Stripping files done ***"
1449 fi
1450 if [[ $early_microcode = yes ]]; then
1451 dinfo "*** Generating early-microcode cpio image ***"
1452 ucode_dir=(amd-ucode intel-ucode)
1453 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1454 _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
1455 _dest_idx="0 1"
1456 mkdir -p $_dest_dir
1457 if [[ $hostonly ]]; then
1458 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1459 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1460 fi
1461 for idx in $_dest_idx; do
1462 _fw=${ucode_dir[$idx]}
1463 for _fwdir in $fw_dir; do
1464 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1465 _src="*"
1466 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1467 if [[ $hostonly ]]; then
1468 _src=$(get_ucode_file)
1469 if ! [[ -r $_fwdir/$_fw/$_src ]];then
1470 break;
1471 fi
1472 fi
1473 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1474 create_early_cpio="yes"
1475 fi
1476 done
1477 done
1478 fi
1479
1480 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1481 dinfo "*** Packaging ACPI tables to override BIOS provided ones ***"
1482 _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi"
1483 mkdir -p $_dest_dir
1484 for table in $acpi_table_dir/*.aml; do
1485 dinfo " Adding ACPI table: $table"
1486 cp $table $_dest_dir
1487 create_early_cpio="yes"
1488 done
1489 fi
1490
1491 dinfo "*** Store current command line parameters ***"
1492 if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
1493 dfatal "Could not store the current command line parameters"
1494 exit 1
1495 fi
1496
1497 rm -f -- "$outfile"
1498 dinfo "*** Creating image file ***"
1499
1500 [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"
1501
1502 if [[ $create_early_cpio = yes ]]; then
1503 echo 1 > "$early_cpio_dir/d/early_cpio"
1504 # The microcode blob is _before_ the initramfs blob, not after
1505 (cd "$early_cpio_dir/d"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > $outfile)
1506 fi
1507 if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \
1508 $compress >> "$outfile"; ); then
1509 dfatal "dracut: creation of $outfile failed"
1510 exit 1
1511 fi
1512 dinfo "*** Creating image file done ***"
1513
1514 if (( maxloglvl >= 5 )); then
1515 if [[ $allowlocal ]]; then
1516 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1517 else
1518 lsinitrd "$outfile"| ddebug
1519 fi
1520 fi
1521
1522 exit 0