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