]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut.sh
dracut.sh: turn off host-only mode, if essential system filesystems not mounted
[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.
5616feb0
AT
73 -m, --modules [LIST] Specify a space-separated list of dracut modules to
74 call when building the initramfs. Modules are located
c5a65990 75 in /usr/lib/dracut/modules.d.
39ff0682 76 -o, --omit [LIST] Omit a space-separated list of dracut modules.
5616feb0 77 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
cb47caf7 78 exclusively include in the initramfs.
fcbcb252 79 --add-drivers [LIST] Specify a space-separated list of kernel
cb47caf7 80 modules to add to the initramfs.
fcbcb252
HH
81 --omit-drivers [LIST] Specify a space-separated list of kernel
82 modules not to add to the initramfs.
8fa510d4
DH
83 --filesystems [LIST] Specify a space-separated list of kernel filesystem
84 modules to exclusively include in the generic
85 initramfs.
3b403b32 86 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
2b9dfbbe 87 modules
3b403b32 88 --fwdir [DIR] Specify additional directories, where to look for
33ee031c
HH
89 firmwares, separated by :
90 --kernel-only Only install kernel drivers and firmware files
91 --no-kernel Do not install kernel drivers and firmware files
d20fb951 92 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
54e7d7c3 93 --strip Strip binaries in the initramfs
6c128565 94 --nostrip Do not strip binaries in the initramfs
54e7d7c3 95 --hardlink Hardlink files in the initramfs
04d18f55 96 --nohardlink Do not hardlink files in the initramfs
fd786adc 97 --prefix [DIR] Prefix initramfs files with [DIR]
54e7d7c3 98 --noprefix Do not prefix initramfs files
2f02ae9d
HH
99 --mdadmconf Include local /etc/mdadm.conf
100 --nomdadmconf Do not include local /etc/mdadm.conf
7a34efa5 101 --lvmconf Include local /etc/lvm/lvm.conf
cc02093d 102 --nolvmconf Do not include local /etc/lvm/lvm.conf
25b45979
MS
103 --fscks [LIST] Add a space-separated list of fsck helpers.
104 --nofscks Inhibit installation of any fsck helpers.
ff3953ef 105 --ro-mnt Mount / and /usr read-only by default.
5616feb0 106 -h, --help This message
00531568 107 --debug Output debug information of the build process
57258a2c 108 --profile Output profile information of the build process
e103615b
109 -L, --stdlog [0-6] Specify logging level (to standard error)
110 0 - suppress any messages
111 1 - only fatal errors
112 2 - all errors
113 3 - warnings
54e7d7c3 114 4 - info
e103615b
115 5 - debug info (here starts lots of output)
116 6 - trace info (and even more)
54e7d7c3
HH
117 -v, --verbose Increase verbosity level
118 -q, --quiet Decrease verbosity level
5616feb0
AT
119 -c, --conf [FILE] Specify configuration file to use.
120 Default: /etc/dracut.conf
3b403b32 121 --confdir [DIR] Specify configuration directory to use *.conf files
cc02093d 122 from. Default: /etc/dracut.conf.d
882c4c5a
123 --tmpdir [DIR] Temporary directory to be used instead of default
124 /var/tmp.
5616feb0
AT
125 -l, --local Local mode. Use modules from the current working
126 directory instead of the system-wide installed in
c5a65990 127 /usr/lib/dracut/modules.d.
5616feb0 128 Useful when running dracut from a git checkout.
7c179686 129 -H, --hostonly Host-Only mode: Install only what is needed for
5616feb0 130 booting the local host instead of a generic host.
472189da 131 -N, --no-hostonly Disables Host-Only mode
7c179686 132 --fstab Use /etc/fstab to determine the root device.
70cb8a68
HH
133 --add-fstab [FILE] Add file to the initramfs fstab
134 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
135 Mount device [DEV] on mountpoint [MP] with filesystem
136 [FSTYPE] and options [FSOPTS] in the initramfs
c586b033 137 --add-device "[DEV]" Bring up [DEV] in initramfs
5616feb0 138 -i, --include [SOURCE] [TARGET]
39ff0682
AT
139 Include the files in the SOURCE directory into the
140 Target directory in the final initramfs.
3b403b32 141 If SOURCE is a file, it will be installed to TARGET
4fea3ea6 142 in the final initramfs.
39ff0682
AT
143 -I, --install [LIST] Install the space separated list of files into the
144 initramfs.
5b158ad3 145 --gzip Compress the generated initramfs using gzip.
cc02093d
HH
146 This will be done by default, unless another
147 compression option or --no-compress is passed.
5b158ad3 148 --bzip2 Compress the generated initramfs using bzip2.
cc02093d
HH
149 Make sure your kernel has bzip2 decompression support
150 compiled in, otherwise you will not be able to boot.
151 --lzma Compress the generated initramfs using lzma.
3b403b32 152 Make sure your kernel has lzma support compiled in,
cc02093d 153 otherwise you will not be able to boot.
5e6c3b03
VL
154 --xz Compress the generated initramfs using xz.
155 Make sure that your kernel has xz support compiled
156 in, otherwise you will not be able to boot.
157 --compress [COMPRESSION] Compress the generated initramfs with the
158 passed compression program. Make sure your kernel
3b403b32 159 knows how to decompress the generated initramfs,
5e6c3b03 160 otherwise you will not be able to boot.
5b158ad3 161 --no-compress Do not compress the generated initramfs. This will
cc02093d 162 override any other compression options.
5b11bb73 163 --list-modules List all available dracut modules.
956af8f2
164 -M, --show-modules Print included module's name to standard output during
165 build.
5fe5c7d0 166 --keep Keep the temporary initramfs for debugging purposes
ec3c5951 167 --printsize Print out the module install size
cdfeb278 168 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
ccaa9bee
HH
169
170If [LIST] has multiple arguments, then you have to put these in quotes.
ffa71b4a 171
ccaa9bee 172For example:
ffa71b4a
HH
173
174 # dracut --add-drivers "module1 module2" ...
175
cc02093d 176EOF
5616feb0
AT
177}
178
8466db96
HH
179# function push()
180# push values to a stack
181# $1 = stack variable
182# $2.. values
183# example:
184# push stack 1 2 "3 4"
185push() {
ffa71b4a 186 local _i
8466db96 187 local __stack=$1; shift
ffa71b4a
HH
188 for _i in "$@"; do
189 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
8466db96
HH
190 done
191}
192
193# function pop()
194# pops the last value from a stack
195# assigns value to second argument variable
196# or echo to stdout, if no second argument
197# $1 = stack variable
198# $2 = optional variable to store the value
199# example:
200# pop stack val
201# val=$(pop stack)
202pop() {
203 local __stack=$1; shift
3b403b32 204 local __resultvar=$1
ffa71b4a 205 local _value;
8466db96
HH
206 # check for empty stack
207 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
208
ffa71b4a 209 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
8466db96
HH
210
211 if [[ "$__resultvar" ]]; then
ffa71b4a 212 eval $__resultvar="'$_value'"
8466db96 213 else
ffa71b4a 214 echo "$_value"
8466db96
HH
215 fi
216 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
217 return 0
218}
219
5bc545ed
VL
220# Little helper function for reading args from the commandline.
221# it automatically handles -a b and -a=b variants, and returns 1 if
222# we need to shift $3.
223read_arg() {
224 # $1 = arg name
225 # $2 = arg value
226 # $3 = arg parameter
227 local rematch='^[^=]*=(.*)$'
228 if [[ $2 =~ $rematch ]]; then
cc02093d 229 read "$1" <<< "${BASH_REMATCH[1]}"
5bc545ed 230 else
cc02093d
HH
231 read "$1" <<< "$3"
232 # There is no way to shift our callers args, so
233 # return 1 to indicate they should do it instead.
234 return 1
5bc545ed
VL
235 fi
236}
237
a42b2b81 238
335bc217 239dropindirs_sort()
a42b2b81
HH
240{
241 suffix=$1; shift
242 args=("$@")
243 files=$(
244 while (( $# > 0 )); do
245 for i in ${1}/*${suffix}; do
246 [[ -f $i ]] && echo ${i##*/}
247 done
248 shift
249 done | sort -Vu
250 )
251
252 for f in $files; do
253 for d in "${args[@]}"; do
254 if [[ -f "$d/$f" ]]; then
255 echo "$d/$f"
256 continue 2
257 fi
258 done
259 done
260}
261
432196ae 262verbosity_mod_l=0
f79e587c
HH
263unset kernel
264unset outfile
486a1b93 265
ffa71b4a
HH
266# Workaround -i, --include taking 2 arguments
267set -- "${@/--include/++include}"
268
269# This prevents any long argument ending with "-i"
270# -i, like --opt-i but I think we can just prevent that
271set -- "${@/%-i/++include}"
272
273TEMP=$(unset POSIXLY_CORRECT; getopt \
472189da 274 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
e65caf36 275 --long kver: \
ffa71b4a
HH
276 --long add: \
277 --long force-add: \
278 --long add-drivers: \
279 --long omit-drivers: \
280 --long modules: \
281 --long omit: \
282 --long drivers: \
283 --long filesystems: \
284 --long install: \
285 --long fwdir: \
286 --long libdirs: \
287 --long fscks: \
288 --long add-fstab: \
289 --long mount: \
52f1b041 290 --long device: \
ffa71b4a 291 --long nofscks: \
ff3953ef 292 --long ro-mnt \
ffa71b4a
HH
293 --long kmoddir: \
294 --long conf: \
295 --long confdir: \
296 --long tmpdir: \
297 --long stdlog: \
298 --long compress: \
299 --long prefix: \
300 --long force \
301 --long kernel-only \
302 --long no-kernel \
d20fb951 303 --long kernel-cmdline: \
ffa71b4a
HH
304 --long strip \
305 --long nostrip \
306 --long hardlink \
307 --long nohardlink \
308 --long noprefix \
309 --long mdadmconf \
310 --long nomdadmconf \
311 --long lvmconf \
312 --long nolvmconf \
313 --long debug \
314 --long profile \
315 --long sshkey: \
316 --long verbose \
317 --long quiet \
318 --long local \
319 --long hostonly \
320 --long no-hostonly \
321 --long fstab \
322 --long help \
323 --long bzip2 \
324 --long lzma \
325 --long xz \
326 --long no-compress \
327 --long gzip \
328 --long list-modules \
329 --long show-modules \
330 --long keep \
331 --long printsize \
7d848c55 332 --long regenerate-all \
83bb0893 333 --long noimageifnotneeded \
ffa71b4a
HH
334 -- "$@")
335
336if (( $? != 0 )); then
337 usage
338 exit 1
339fi
340
341eval set -- "$TEMP"
342
343while :; do
344 case $1 in
e65caf36 345 --kver) kernel="$2"; shift;;
ffa71b4a
HH
346 -a|--add) push add_dracutmodules_l "$2"; shift;;
347 --force-add) push force_add_dracutmodules_l "$2"; shift;;
348 --add-drivers) push add_drivers_l "$2"; shift;;
349 --omit-drivers) push omit_drivers_l "$2"; shift;;
350 -m|--modules) push dracutmodules_l "$2"; shift;;
351 -o|--omit) push omit_dracutmodules_l "$2"; shift;;
352 -d|--drivers) push drivers_l "$2"; shift;;
353 --filesystems) push filesystems_l "$2"; shift;;
354 -I|--install) push install_items_l "$2"; shift;;
355 --fwdir) push fw_dir_l "$2"; shift;;
356 --libdirs) push libdirs_l "$2"; shift;;
357 --fscks) push fscks_l "$2"; shift;;
358 --add-fstab) push add_fstab_l "$2"; shift;;
359 --mount) push fstab_lines "$2"; shift;;
c586b033
CG
360 --add-device|--device)
361 push add_device_l "$2"; shift;;
d20fb951 362 --kernel-cmdline) push kernel_cmdline_l "$2"; shift;;
25b45979 363 --nofscks) nofscks_l="yes";;
ff3953ef 364 --ro-mnt) ro_mnt_l="yes";;
ffa71b4a
HH
365 -k|--kmoddir) drivers_dir_l="$2"; shift;;
366 -c|--conf) conffile="$2"; shift;;
367 --confdir) confdir="$2"; shift;;
368 --tmpdir) tmpdir_l="$2"; shift;;
369 -L|--stdlog) stdloglvl_l="$2"; shift;;
370 --compress) compress_l="$2"; shift;;
371 --prefix) prefix_l="$2"; shift;;
cc02093d
HH
372 -f|--force) force=yes;;
373 --kernel-only) kernel_only="yes"; no_kernel="no";;
374 --no-kernel) kernel_only="no"; no_kernel="yes";;
375 --strip) do_strip_l="yes";;
376 --nostrip) do_strip_l="no";;
04d18f55
HH
377 --hardlink) do_hardlink_l="yes";;
378 --nohardlink) do_hardlink_l="no";;
fd786adc 379 --noprefix) prefix_l="/";;
690396a5
VL
380 --mdadmconf) mdadmconf_l="yes";;
381 --nomdadmconf) mdadmconf_l="no";;
382 --lvmconf) lvmconf_l="yes";;
383 --nolvmconf) lvmconf_l="no";;
cc02093d 384 --debug) debug="yes";;
57258a2c 385 --profile) profile="yes";;
ffa71b4a 386 --sshkey) sshkey="$2"; shift;;
432196ae
387 -v|--verbose) ((verbosity_mod_l++));;
388 -q|--quiet) ((verbosity_mod_l--));;
dbf8f6ba
HH
389 -l|--local)
390 allowlocal="yes"
391 [[ -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] \
392 && dracutbasedir="$(readlink -f ${0%/*})"
393 ;;
cc02093d 394 -H|--hostonly) hostonly_l="yes" ;;
472189da 395 -N|--no-hostonly) hostonly_l="no" ;;
cc02093d 396 --fstab) use_fstab_l="yes" ;;
ffa71b4a 397 -h|--help) long_usage; exit 1 ;;
2aad2344 398 -i|--include) push include_src "$2"
ffa71b4a 399 shift;;
3a714439
VL
400 --bzip2) compress_l="bzip2";;
401 --lzma) compress_l="lzma";;
402 --xz) compress_l="xz";;
403 --no-compress) _no_compress_l="cat";;
404 --gzip) compress_l="gzip";;
ffa71b4a 405 --list-modules) do_list="yes";;
956af8f2
406 -M|--show-modules)
407 show_modules_l="yes"
408 ;;
5fe5c7d0 409 --keep) keep="yes";;
ec3c5951 410 --printsize) printsize="yes";;
7d848c55 411 --regenerate-all) regenerate_all="yes";;
83bb0893 412 --noimageifnotneeded) noimageifnotneeded="yes";;
ffa71b4a
HH
413
414 --) shift; break;;
415
416 *) # should not even reach this point
417 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
418 esac
419 shift
420done
421
422# getopt cannot handle multiple arguments, so just handle "-I,--include"
423# the old fashioned way
424
425while (($# > 0)); do
426 case ${1%%=*} in
427 ++include) push include_src "$2"
428 push include_target "$3"
429 shift 2;;
3b403b32 430 *)
dbf381f7 431 if ! [[ ${outfile+x} ]]; then
486a1b93 432 outfile=$1
8a5354a9 433 elif ! [[ ${kernel+x} ]]; then
486a1b93
HH
434 kernel=$1
435 else
ffa71b4a 436 printf "\nUnknown arguments: %s\n\n" "$*" >&2
486a1b93
HH
437 usage; exit 1;
438 fi
439 ;;
641cc356 440 esac
b368a5f3 441 shift
641cc356 442done
ffa71b4a 443
7d848c55
HH
444if [[ $regenerate_all == "yes" ]]; then
445 ret=0
446 if [[ $kernel ]]; then
447 echo "--regenerate-all cannot be called with a kernel version" >&2
448 exit 1
449 fi
450
451 if [[ $outfile ]]; then
452 echo "--regenerate-all cannot be called with a image file" >&2
453 exit 1
454 fi
455
456 ((len=${#dracut_args[@]}))
457 for ((i=0; i < len; i++)); do
458 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
459 unset dracut_args[$i]
460 done
461
462 cd /lib/modules
463 for i in *; do
464 [[ -f $i/modules.builtin ]] || continue
465 dracut --kver=$i "${dracut_args[@]}"
466 ((ret+=$?))
467 done
468 exit $ret
469fi
470
8a5354a9 471if ! [[ $kernel ]]; then
486a1b93
HH
472 kernel=$(uname -r)
473fi
ffa71b4a
HH
474
475if ! [[ $outfile ]]; then
cc230300
HH
476 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
477
478 if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
479 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
480 else
481 outfile="/boot/initramfs-$kernel.img"
482 fi
ffa71b4a 483fi
4cba351e 484
7b2d3d99 485for i in /usr/sbin /sbin /usr/bin /bin; do
65fe8ae8
HH
486 rl=$i
487 if [ -L "$i" ]; then
488 rl=$(readlink -f $i)
489 fi
ffa71b4a
HH
490 if [[ "$NPATH" != "*:$rl*" ]] ; then
491 NPATH+=":$rl"
492 fi
65fe8ae8 493done
7b2d3d99 494export PATH="${NPATH#:}"
68910ba4 495unset NPATH
d619fb5e 496unset LD_LIBRARY_PATH
1fcf2d2f 497unset GREP_OPTIONS
a55711cd 498
89d44e72 499export DRACUT_LOG_LEVEL=warning
3b403b32 500[[ $debug ]] && {
89d44e72 501 export DRACUT_LOG_LEVEL=debug
c36ce334
VL
502 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
503 set -x
504}
505
57258a2c
HH
506[[ $profile ]] && {
507 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
508 set -x
509 debug=yes
510}
511
c5a65990 512[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
5d791c0e 513
f1336ac7 514# if we were not passed a config file, try the default one
42c71947 515if [[ ! -f $conffile ]]; then
eebc929a
VL
516 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
517 conffile="/etc/dracut.conf"
42c71947 518fi
f1336ac7 519
2c2c4580 520if [[ ! -d $confdir ]]; then
ae24b114 521 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
eebc929a 522 confdir="/etc/dracut.conf.d"
2c2c4580
HH
523fi
524
2245f372
AB
525# source our config file
526[[ -f $conffile ]] && . "$conffile"
527
2c2c4580 528# source our config dir
335bc217 529for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
a42b2b81
HH
530 [[ -e $f ]] && . "$f"
531done
2c2c4580 532
d87c2708 533# these optins add to the stuff in the config file
e5e5c895 534if (( ${#add_dracutmodules_l[@]} )); then
661f9a34
HH
535 while pop add_dracutmodules_l val; do
536 add_dracutmodules+=" $val "
537 done
538fi
539
31f1c02d
AW
540if (( ${#force_add_dracutmodules_l[@]} )); then
541 while pop force_add_dracutmodules_l val; do
542 force_add_dracutmodules+=" $val "
543 done
544fi
545
25b45979
MS
546if (( ${#fscks_l[@]} )); then
547 while pop fscks_l val; do
548 fscks+=" $val "
549 done
550fi
551
70cb8a68
HH
552if (( ${#add_fstab_l[@]} )); then
553 while pop add_fstab_l val; do
554 add_fstab+=" $val "
555 done
556fi
557
558if (( ${#fstab_lines_l[@]} )); then
559 while pop fstab_lines_l val; do
560 push fstab_lines $val
561 done
562fi
563
0ec40e08
HH
564if (( ${#install_items_l[@]} )); then
565 while pop install_items_l val; do
c6c6a088 566 install_items+=" $val "
0ec40e08
HH
567 done
568fi
569
f1336ac7 570# these options override the stuff in the config file
e5e5c895 571if (( ${#dracutmodules_l[@]} )); then
661f9a34
HH
572 dracutmodules=''
573 while pop dracutmodules_l val; do
574 dracutmodules+="$val "
575 done
576fi
577
e5e5c895 578if (( ${#omit_dracutmodules_l[@]} )); then
661f9a34
HH
579 omit_dracutmodules=''
580 while pop omit_dracutmodules_l val; do
581 omit_dracutmodules+="$val "
582 done
583fi
584
e5e5c895 585if (( ${#filesystems_l[@]} )); then
661f9a34
HH
586 filesystems=''
587 while pop filesystems_l val; do
588 filesystems+="$val "
589 done
590fi
591
e5e5c895 592if (( ${#fw_dir_l[@]} )); then
661f9a34
HH
593 fw_dir=''
594 while pop fw_dir_l val; do
595 fw_dir+="$val "
596 done
597fi
598
c9143a63
JAH
599if (( ${#libdirs_l[@]} )); then
600 libdirs=''
601 while pop libdirs_l val; do
602 libdirs+="$val "
603 done
604fi
605
e103615b 606[[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
b991617f 607[[ ! $stdloglvl ]] && stdloglvl=4
432196ae
608stdloglvl=$((stdloglvl + verbosity_mod_l))
609((stdloglvl > 6)) && stdloglvl=6
610((stdloglvl < 0)) && stdloglvl=0
611
26537a5b 612[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
31f7db66 613[[ $do_strip_l ]] && do_strip=$do_strip_l
6c128565 614[[ $do_strip ]] || do_strip=yes
04d18f55
HH
615[[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
616[[ $do_hardlink ]] || do_hardlink=yes
fd786adc
HH
617[[ $prefix_l ]] && prefix=$prefix_l
618[[ $prefix = "/" ]] && unset prefix
ba726310 619[[ $hostonly_l ]] && hostonly=$hostonly_l
7c179686 620[[ $use_fstab_l ]] && use_fstab=$use_fstab_l
2f02ae9d 621[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
7a34efa5 622[[ $lvmconf_l ]] && lvmconf=$lvmconf_l
c5a65990 623[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
8bc650d9 624[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
882c4c5a
625[[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
626[[ $tmpdir ]] || tmpdir=/var/tmp
3a714439 627[[ $compress_l ]] && compress=$compress_l
956af8f2 628[[ $show_modules_l ]] && show_modules=$show_modules_l
25b45979 629[[ $nofscks_l ]] && nofscks="yes"
ff3953ef 630[[ $ro_mnt_l ]] && ro_mnt="yes"
ddfd1d10
VL
631# eliminate IFS hackery when messing with fw_dir
632fw_dir=${fw_dir//:/ }
9a8a00cf 633
3a714439 634# handle compression options.
55468fb9 635[[ $compress ]] || compress="gzip"
3a714439 636case $compress in
6f223367 637 bzip2) compress="bzip2 -9";;
3a714439
VL
638 lzma) compress="lzma -9";;
639 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
55468fb9 640 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
3a714439
VL
641 compress="gzip -9";;
642esac
643if [[ $_no_compress_l = "cat" ]]; then
644 compress="cat"
645fi
646
ba726310 647[[ $hostonly = yes ]] && hostonly="-h"
ba67b923 648[[ $hostonly != "-h" ]] && unset hostonly
ba726310 649
26c231f1
HH
650readonly TMPDIR="$tmpdir"
651readonly initdir=$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)
652[ -d "$initdir" ] || {
fbf658fe 653 echo "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
26c231f1
HH
654 exit 1
655}
656
d008b6b8 657# clean up after ourselves no matter how we die.
02566acd 658trap 'ret=$?;[[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f "$outfile.$$";[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf "$initdir";exit $ret; };' EXIT
d008b6b8
HH
659# clean up after ourselves no matter how we die.
660trap 'exit 1;' SIGINT
661
89d44e72
HH
662export DRACUT_KERNEL_LAZY="1"
663export DRACUT_RESOLVE_LAZY="1"
664
552ecca6
HH
665if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
666 . $dracutbasedir/dracut-functions.sh
adbc8a42 667else
26c231f1
HH
668 echo "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
669 echo "dracut: Are you running from a git checkout?" >&2
670 echo "dracut: Try passing -l as an argument to $0" >&2
cc02093d 671 exit 1
adbc8a42 672fi
22fd1627 673
bfd2e8c2
HH
674inst /bin/sh
675if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
676 unset DRACUT_RESOLVE_LAZY
677 export DRACUT_RESOLVE_DEPS=1
678fi
679rm -fr ${initdir}/*
680
dbf8f6ba
HH
681if [[ -f $dracutbasedir/dracut-version.sh ]]; then
682 . $dracutbasedir/dracut-version.sh
683fi
684
bfd2e8c2 685# Verify bash version, current minimum is 3.1
d239b550
MS
686if (( ${BASH_VERSINFO[0]} < 3 ||
687 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
688 dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
689 exit 1
690fi
691
552ecca6 692dracutfunctions=$dracutbasedir/dracut-functions.sh
5cad5bb5 693export dracutfunctions
9a8a00cf 694
fcbcb252
HH
695if (( ${#drivers_l[@]} )); then
696 drivers=''
697 while pop drivers_l val; do
698 drivers+="$val "
699 done
700fi
701drivers=${drivers/-/_}
702
703if (( ${#add_drivers_l[@]} )); then
704 while pop add_drivers_l val; do
705 add_drivers+=" $val "
706 done
707fi
708add_drivers=${add_drivers/-/_}
709
710if (( ${#omit_drivers_l[@]} )); then
711 while pop omit_drivers_l val; do
712 omit_drivers+=" $val "
713 done
714fi
715omit_drivers=${omit_drivers/-/_}
716
d20fb951
HH
717if (( ${#kernel_cmdline_l[@]} )); then
718 while pop kernel_cmdline_l val; do
719 kernel_cmdline+=" $val "
720 done
721fi
722
34248c92 723omit_drivers_corrected=""
fcbcb252
HH
724for d in $omit_drivers; do
725 strstr " $drivers $add_drivers " " $d " && continue
34248c92 726 omit_drivers_corrected+="$d|"
fcbcb252 727done
34248c92 728omit_drivers="${omit_drivers_corrected%|}"
fcbcb252
HH
729unset omit_drivers_corrected
730
ffa71b4a
HH
731# prepare args for logging
732for ((i=0; i < ${#dracut_args[@]}; i++)); do
733 strstr "${dracut_args[$i]}" " " && \
734 dracut_args[$i]="\"${dracut_args[$i]}\""
a4210166 735 #" keep vim happy
ffa71b4a
HH
736done
737ddebug "Executing: $0 ${dracut_args[@]}"
58dad702 738
5b11bb73
HH
739[[ $do_list = yes ]] && {
740 for mod in $dracutbasedir/modules.d/*; do
741 [[ -d $mod ]] || continue;
d8e8e14e
742 [[ -e $mod/install || -e $mod/installkernel || \
743 -e $mod/module-setup.sh ]] || continue
5b11bb73
HH
744 echo ${mod##*/??}
745 done
746 exit 0
747}
748
66ac3cd1 749# This is kinda legacy -- eventually it should go away.
f1336ac7 750case $dracutmodules in
66ac3cd1 751 ""|auto) dracutmodules="all" ;;
f1336ac7 752esac
e12aac5e 753
454771cd 754abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
ec9315e5 755
5db6ca5a
HH
756if [[ -d $srcmods ]]; then
757 [[ -f $srcmods/modules.dep ]] || {
758 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
759 }
760fi
fe1484f3 761
c8937ec4 762if [[ -f $outfile && ! $force ]]; then
432196ae 763 dfatal "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
764 exit 1
765fi
766
ebfdb219 767outdir=${outfile%/*}
52eed268
HH
768[[ $outdir ]] || outdir="/"
769
ebfdb219 770if [[ ! -d "$outdir" ]]; then
cc230300 771 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
454771cd 772 exit 1
ebfdb219 773elif [[ ! -w "$outdir" ]]; then
ffa71b4a 774 dfatal "No permission to write to $outdir."
454771cd 775 exit 1
0a325a91 776elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
432196ae 777 dfatal "No permission to write $outfile."
734a0d9e
HH
778 exit 1
779fi
780
f6f74096
DD
781# Need to be able to have non-root users read stuff (rpcbind etc)
782chmod 755 "$initdir"
783
5bfa3b36
HH
784if [[ $hostonly ]]; then
785 for i in /sys /proc /run /dev; do
786 if ! findmnt "$i" &>/dev/null; then
787 dwarning "Turning off host-only mode: '$i' is not mounted!"
788 unset hostonly
789 fi
790 done
791fi
792
d351541e
HH
793declare -A host_fs_types
794
cd7ff122
AW
795for line in "${fstab_lines[@]}"; do
796 set -- $line
797 #dev mp fs fsopts
d0096de7 798 push host_devs "$1"
d351541e 799 host_fs_types["$1"]="$3"
cd7ff122
AW
800done
801
802for f in $add_fstab; do
803 [ -e $f ] || continue
804 while read dev rest; do
805 push host_devs $dev
806 done < $f
807done
808
c586b033
CG
809if (( ${#add_device_l[@]} )); then
810 while pop add_device_l val; do
811 add_device+=" $val "
812 done
813fi
814
815for dev in $add_device; do
816 push host_devs $dev
817done
818
7ae5d9d1 819if [[ $hostonly ]]; then
480d772f
HH
820 # in hostonly mode, determine all devices, which have to be accessed
821 # and examine them for filesystem types
822
7ae5d9d1
HH
823 push host_mp \
824 "/" \
825 "/etc" \
826 "/usr" \
827 "/usr/bin" \
828 "/usr/sbin" \
829 "/usr/lib" \
830 "/usr/lib64" \
831 "/boot"
832
7ae5d9d1
HH
833 for mp in "${host_mp[@]}"; do
834 mountpoint "$mp" >/dev/null 2>&1 || continue
d0096de7 835 push host_devs $(readlink -f "/dev/block/$(find_block_device "$mp")")
7ae5d9d1 836 done
dd587549
HH
837
838 while read dev type rest; do
839 [[ -b $dev ]] || continue
840 [[ "$type" == "partition" ]] || continue
841 while read _d _m _t _o _r; do
842 [[ "$_d" == \#* ]] && continue
843 [[ $_d ]] || continue
844 [[ $_t != "swap" ]] || [[ $_m != "swap" ]] && continue
845 [[ "$_o" == *noauto* ]] && continue
846 [[ "$_d" == UUID\=* ]] && _d="/dev/disk/by-uuid/${_d#UUID=}"
847 [[ "$_d" == LABEL\=* ]] && _d="/dev/disk/by-label/$_d#LABEL=}"
848 [[ "$_d" -ef "$dev" ]] || continue
849 push host_devs $(readlink -f $dev)
850 break
851 done < /etc/fstab
852 done < /proc/swaps
853
7ae5d9d1 854fi
7ae5d9d1 855
cd7ff122 856_get_fs_type() (
19bab59c 857 [[ $1 ]] || return
d0096de7 858 if [[ -b $1 ]] && get_fs_env $1; then
d351541e 859 echo "$(readlink -f $1) $ID_FS_TYPE"
19bab59c 860 return 1
cd7ff122 861 fi
4f10ae2b 862 if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
d351541e 863 echo "$(readlink -f /dev/block/$1) $ID_FS_TYPE"
19bab59c 864 return 1
4f10ae2b 865 fi
cd7ff122 866 if fstype=$(find_dev_fstype $1); then
d351541e 867 echo "$1 $fstype"
19bab59c 868 return 1
cd7ff122
AW
869 fi
870 return 1
871)
872
873for dev in "${host_devs[@]}"; do
d351541e
HH
874 while read key val; do
875 host_fs_types["$key"]="$val"
876 done < <(
877 _get_fs_type $dev
878 check_block_and_slaves_all _get_fs_type $(get_maj_min $dev)
879 )
cd7ff122
AW
880done
881
d1615612
HH
882[[ -d $udevdir ]] \
883 || udevdir=$(pkg-config udev --variable=udevdir 2>/dev/null)
884if ! [[ -d "$udevdir" ]]; then
885 [[ -d /lib/udev ]] && udevdir=/lib/udev
886 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
887fi
888
889[[ -d $systemdutildir ]] \
890 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
891[[ -d $systemdsystemunitdir ]] \
892 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
893
894if ! [[ -d "$systemdutildir" ]]; then
895 [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
896 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
897fi
898[[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
899
aec9f902 900export initdir dracutbasedir dracutmodules \
e103615b 901 fw_dir drivers_dir debug no_kernel kernel_only \
aec9f902 902 omit_drivers mdadmconf lvmconf \
ff3953ef 903 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1e64e493 904 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
dbf8f6ba 905 debug host_fs_types host_devs sshkey add_fstab \
e09048aa 906 DRACUT_VERSION udevdir systemdutildir systemdsystemunitdir \
3e964eeb 907 prefix filesystems drivers
f4fff04e 908
dbad9f46 909# Create some directory structure first
fd786adc 910[[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
dbad9f46 911
785a6cd2 912[[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
fd786adc 913[[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
dbad9f46 914
785a6cd2 915if [[ $prefix ]]; then
d2a9c4a8
HH
916 for d in bin etc lib sbin tmp usr var $libdirs; do
917 strstr "$d" "/" && continue
785a6cd2
HH
918 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
919 done
920fi
921
922if [[ $kernel_only != yes ]]; then
3f54a83c 923 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
fd786adc 924 [[ -e "${initdir}${prefix}/$d" ]] && continue
d433da44
HH
925 if [ -L "/$d" ]; then
926 inst_symlink "/$d" "${prefix}/$d"
785a6cd2
HH
927 else
928 mkdir -m 0755 -p "${initdir}${prefix}/$d"
929 fi
3b403b32 930 done
dbad9f46 931
7c14b368 932 for d in dev proc sys sysroot root run run/lock run/initramfs; do
d433da44
HH
933 if [ -L "/$d" ]; then
934 inst_symlink "/$d"
785a6cd2
HH
935 else
936 mkdir -m 0755 -p "$initdir/$d"
937 fi
33ee031c 938 done
dbad9f46 939
506b2192
HH
940 ln -sfn ../run "$initdir/var/run"
941 ln -sfn ../run/lock "$initdir/var/lock"
3f54a83c 942 ln -sfn ../run/log "$initdir/var/log"
6f09acf8
HH
943else
944 for d in lib "$libdir"; do
945 [[ -e "${initdir}${prefix}/$d" ]] && continue
946 if [ -h "/$d" ]; then
947 inst "/$d" "${prefix}/$d"
948 else
949 mkdir -m 0755 -p "${initdir}${prefix}/$d"
950 fi
951 done
33ee031c 952fi
0f86847d 953
14c47b0e
HH
954if [[ $kernel_only != yes ]]; then
955 mkdir -p "${initdir}/etc/cmdline.d"
4fed3ddf
HH
956 for _d in $hookdirs; do
957 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
958 done
26144216 959 if [[ "$UID" = "0" ]]; then
ad200fbc
HH
960 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
961 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
962 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
26144216 963 fi
14c47b0e 964fi
96b8d60a 965
1b7fd0fa 966mods_to_load=""
66ac3cd1
VL
967# check all our modules to see if they should be sourced.
968# This builds a list of modules that we will install next.
1b7fd0fa
AW
969for_each_module_dir check_module
970for_each_module_dir check_mount
971
89d44e72
HH
972strstr "$mods_to_load" "fips" && export DRACUT_FIPS_MODE=1
973
ec3c5951 974_isize=0 #initramfs size
979c4a93 975modules_loaded=" "
95bde758 976# source our modules.
5d791c0e 977for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
979c4a93
HH
978 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
979 if strstr "$mods_to_load" " $_d_mod "; then
980 [[ $show_modules = yes ]] && echo "$_d_mod" || \
981 dinfo "*** Including module: $_d_mod ***"
cc02093d 982 if [[ $kernel_only = yes ]]; then
a6d3be9d
AW
983 module_installkernel $_d_mod || {
984 dfatal "installkernel failed in module $_d_mod"
985 exit 1
986 }
cc02093d 987 else
979c4a93 988 module_install $_d_mod
95d2dabc 989 if [[ $no_kernel != yes ]]; then
a6d3be9d
AW
990 module_installkernel $_d_mod || {
991 dfatal "installkernel failed in module $_d_mod"
992 exit 1
993 }
cc02093d
HH
994 fi
995 fi
979c4a93
HH
996 mods_to_load=${mods_to_load// $_d_mod /}
997 modules_loaded+="$_d_mod "
ec3c5951
DY
998
999 #print the module install size
1000 if [ -n "$printsize" ]; then
1001 _isize_new=$(du -sk ${initdir}|cut -f1)
1002 _isize_delta=$(($_isize_new - $_isize))
1003 echo "$_d_mod install size: ${_isize_delta}k"
1004 _isize=$_isize_new
1005 fi
66ac3cd1 1006 fi
15136762 1007done
20abd914 1008unset moddir
0a35a80b
HH
1009
1010for i in $modules_loaded; do
43fed151 1011 mkdir -p $initdir/lib/dracut
0a35a80b
HH
1012 echo "$i" >> $initdir/lib/dracut/modules.txt
1013done
1014
ea216a65 1015dinfo "*** Including modules done ***"
aabc0553 1016
0f86847d 1017## final stuff that has to happen
89d44e72 1018if [[ $no_kernel != yes ]]; then
aec9f902
HH
1019
1020 if [[ $drivers ]]; then
1021 hostonly='' instmods $drivers
1022 fi
1023
1024 if [[ $add_drivers ]]; then
1025 hostonly='' instmods -c $add_drivers
1026 fi
1027 if [[ $filesystems ]]; then
1028 hostonly='' instmods -c $filesystems
1029 fi
1030
89d44e72
HH
1031 dinfo "*** Installing kernel module dependencies and firmware ***"
1032 dracut_kernel_post
1033 dinfo "*** Installing kernel module dependencies and firmware done ***"
83bb0893
HH
1034
1035 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1036 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1037 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1038 for i in ${initdir}/etc/cmdline.d/*.conf; do
1039 # We need no initramfs image and do not generate one.
1040 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1041 done
1042 fi
1043 fi
89d44e72 1044fi
d8aeb3a7 1045
998bf6e0
HH
1046if [[ $kernel_only != yes ]]; then
1047 (( ${#install_items[@]} > 0 )) && dracut_install ${install_items[@]}
1048
636e5cd2 1049 [[ $kernel_cmdline ]] && echo "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
d20fb951 1050
998bf6e0
HH
1051 while pop fstab_lines line; do
1052 echo "$line 0 0" >> "${initdir}/etc/fstab"
1053 done
1054
1055 for f in $add_fstab; do
1056 cat $f >> "${initdir}/etc/fstab"
1057 done
1058
1059 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1060 dinfo "*** Resolving executable dependencies ***"
1061 find "$initdir" -type f \
1062 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1063 -not -path '*.ko' -print0 \
1064 | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H}
1065 dinfo "*** Resolving executable dependencies done***"
1066 fi
1067fi
1068
661f9a34
HH
1069while pop include_src src && pop include_target tgt; do
1070 if [[ $src && $tgt ]]; then
1071 if [[ -f $src ]]; then
1072 inst $src $tgt
1073 else
3b403b32 1074 ddebug "Including directory: $src"
661f9a34 1075 mkdir -p "${initdir}/${tgt}"
dbad9f46 1076 # check for preexisting symlinks, so we can cope with the
fd786adc 1077 # symlinks to $prefix
dbad9f46
HH
1078 for i in "$src"/*; do
1079 [[ -e "$i" || -h "$i" ]] || continue
1080 s=${initdir}/${tgt}/${i#$src/}
1081 if [[ -d "$i" ]]; then
1082 if ! [[ -e "$s" ]]; then
1083 mkdir -m 0755 -p "$s"
1084 chmod --reference="$i" "$s"
1085 fi
98eb6d57 1086 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
dbad9f46 1087 else
98eb6d57 1088 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
3b403b32 1089 fi
dbad9f46 1090 done
661f9a34 1091 fi
4fea3ea6 1092 fi
661f9a34 1093done
88ffd2df 1094
14c47b0e 1095if [[ $kernel_only != yes ]]; then
1254925f
HH
1096 # make sure that library links are correct and up to date
1097 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
482c573d 1098 [[ -f $f ]] && inst_simple "$f"
1254925f
HH
1099 done
1100 if ! ldconfig -r "$initdir"; then
1101 if [[ $UID = 0 ]]; then
1102 derror "ldconfig exited ungracefully"
1103 else
1104 derror "ldconfig might need uid=0 (root) for chroot()"
1105 fi
432196ae
1106 fi
1107fi
fdc421db 1108
432196ae
1109if (($maxloglvl >= 5)); then
1110 ddebug "Listing sizes of included files:"
1111 du -c "$initdir" | sort -n | ddebug
1112fi
c4ad7fff 1113
404815ea
HH
1114PRELINK_BIN=$(command -v prelink)
1115if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1116 if [[ $DRACUT_FIPS_MODE ]]; then
1117 dinfo "*** Pre-unlinking files ***"
1118 dracut_install -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1119 chroot "$initdir" $PRELINK_BIN -u -a
1120 rm -f "$initdir"/$PRELINK_BIN
1121 rm -fr "$initdir"/etc/prelink.*
1122 dinfo "*** Pre-unlinking files done ***"
1123 else
1124 dinfo "*** Pre-linking files ***"
1125 dracut_install -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1126 chroot "$initdir" $PRELINK_BIN -a
1127 rm -f "$initdir"/$PRELINK_BIN
1128 rm -fr "$initdir"/etc/prelink.*
1129 dinfo "*** Pre-linking files done ***"
1130 fi
1131fi
1132
1133if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1134 dinfo "*** Hardlinking files ***"
1135 hardlink "$initdir" 2>&1
1136 dinfo "*** Hardlinking files done ***"
1137fi
1138
3b403b32 1139# strip binaries
98adb06e 1140if [[ $do_strip = yes ]] ; then
69b35075 1141 for p in strip xargs find; do
cc02093d 1142 if ! type -P $p >/dev/null; then
b26897fb 1143 dwarn "Could not find '$p'. Not stripping the initramfs."
cc02093d
HH
1144 do_strip=no
1145 fi
31f7db66
HH
1146 done
1147fi
1148
89d44e72
HH
1149if [[ $do_strip = yes ]] ; then
1150 dinfo "*** Stripping files ***"
6c128565
HH
1151 if [[ $DRACUT_FIPS_MODE ]]; then
1152 find "$initdir" -type f \
2d9b156e 1153 -executable -not -path '*/lib/modules/*.ko' -print0 \
6c128565
HH
1154 | while read -r -d $'\0' f; do
1155 if ! [[ -e "${f%/*}/.${f##*/}.hmac" ]] \
1156 && ! [[ -e "/lib/fipscheck/${f##*/}.hmac" ]] \
1157 && ! [[ -e "/lib64/fipscheck/${f##*/}.hmac" ]]; then
1158 echo -n "$f"; echo -n -e "\000"
1159 fi
2d9b156e 1160 done | xargs -r -0 strip -g 2>/dev/null
6c128565
HH
1161 else
1162 find "$initdir" -type f \
2d9b156e 1163 -executable -not -path '*/lib/modules/*.ko' -print0 \
6c128565
HH
1164 | xargs -r -0 strip -g 2>/dev/null
1165 fi
2d9b156e
HH
1166
1167 # strip kernel modules, but do not touch signed modules
1168 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1169 | while read -r -d $'\0' f; do
1170 SIG=$(tail -c 28 "$f")
1171 [[ $SIG == '~Module signature appended~' ]] || { echo -n "$f"; echo -n -e "\000"; }
1172 done | xargs -r -0 strip -g
1173
89d44e72 1174 dinfo "*** Stripping files done ***"
979c4a93
HH
1175fi
1176
e1b48995 1177rm -f "$outfile"
89d44e72 1178dinfo "*** Creating image file ***"
e1b48995 1179if ! ( umask 077; cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
9a9c6e12
LD
1180 $compress > "$outfile.$$"; ); then
1181 dfatal "dracut: creation of $outfile.$$ failed"
734a0d9e 1182 exit 1
3b403b32 1183fi
9a9c6e12 1184mv $outfile.$$ $outfile
89d44e72 1185dinfo "*** Creating image file done ***"
432196ae
1186
1187dinfo "Wrote $outfile:"
1188dinfo "$(ls -l "$outfile")"
1faecdc1 1189
3da58569 1190exit 0