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