]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
dracut: export host_fs_types host_devs
[thirdparty/dracut.git] / dracut
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
cc02093d 10# Copyright 2005-2010 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
HH
26# store for logging
27dracut_args="$@"
5616feb0
AT
28
29usage() {
30# 80x25 linebreak here ^
cc02093d
HH
31 cat << EOF
32Usage: $0 [OPTION]... <initramfs> <kernel-version>
5616feb0
AT
33Creates initial ramdisk images for preloading modules
34
39ff0682 35 -f, --force Overwrite existing initramfs file.
5616feb0
AT
36 -m, --modules [LIST] Specify a space-separated list of dracut modules to
37 call when building the initramfs. Modules are located
c5a65990 38 in /usr/lib/dracut/modules.d.
39ff0682 39 -o, --omit [LIST] Omit a space-separated list of dracut modules.
3e17f33b 40 -a, --add [LIST] Add a space-separated list of dracut modules.
5616feb0 41 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
cb47caf7 42 exclusively include in the initramfs.
3b403b32 43 --add-drivers [LIST] Specify a space-separated list of kernel
cb47caf7 44 modules to add to the initramfs.
8fa510d4
DH
45 --filesystems [LIST] Specify a space-separated list of kernel filesystem
46 modules to exclusively include in the generic
47 initramfs.
3b403b32 48 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
2b9dfbbe 49 modules
3b403b32 50 --fwdir [DIR] Specify additional directories, where to look for
33ee031c
HH
51 firmwares, separated by :
52 --kernel-only Only install kernel drivers and firmware files
53 --no-kernel Do not install kernel drivers and firmware files
5be225d2
HH
54 --strip Strip binaries in the initramfs
55 --nostrip Do not strip binaries in the initramfs (default)
fd786adc
HH
56 --prefix [DIR] Prefix initramfs files with [DIR]
57 --noprefix Do not prefix initramfs files (default)
2f02ae9d
HH
58 --mdadmconf Include local /etc/mdadm.conf
59 --nomdadmconf Do not include local /etc/mdadm.conf
7a34efa5 60 --lvmconf Include local /etc/lvm/lvm.conf
cc02093d 61 --nolvmconf Do not include local /etc/lvm/lvm.conf
25b45979
MS
62 --fscks [LIST] Add a space-separated list of fsck helpers.
63 --nofscks Inhibit installation of any fsck helpers.
5616feb0 64 -h, --help This message
00531568 65 --debug Output debug information of the build process
57258a2c 66 --profile Output profile information of the build process
e103615b
67 -L, --stdlog [0-6] Specify logging level (to standard error)
68 0 - suppress any messages
69 1 - only fatal errors
70 2 - all errors
71 3 - warnings
72 4 - info (default)
73 5 - debug info (here starts lots of output)
74 6 - trace info (and even more)
432196ae
75 -v, --verbose Increase verbosity level (default is info(4))
76 -q, --quiet Decrease verbosity level (default is info(4))
5616feb0
AT
77 -c, --conf [FILE] Specify configuration file to use.
78 Default: /etc/dracut.conf
3b403b32 79 --confdir [DIR] Specify configuration directory to use *.conf files
cc02093d 80 from. Default: /etc/dracut.conf.d
5616feb0
AT
81 -l, --local Local mode. Use modules from the current working
82 directory instead of the system-wide installed in
c5a65990 83 /usr/lib/dracut/modules.d.
5616feb0 84 Useful when running dracut from a git checkout.
7c179686 85 -H, --hostonly Host-Only mode: Install only what is needed for
5616feb0 86 booting the local host instead of a generic host.
7c179686 87 --fstab Use /etc/fstab to determine the root device.
5616feb0 88 -i, --include [SOURCE] [TARGET]
39ff0682
AT
89 Include the files in the SOURCE directory into the
90 Target directory in the final initramfs.
3b403b32 91 If SOURCE is a file, it will be installed to TARGET
4fea3ea6 92 in the final initramfs.
39ff0682
AT
93 -I, --install [LIST] Install the space separated list of files into the
94 initramfs.
5b158ad3 95 --gzip Compress the generated initramfs using gzip.
cc02093d
HH
96 This will be done by default, unless another
97 compression option or --no-compress is passed.
5b158ad3 98 --bzip2 Compress the generated initramfs using bzip2.
cc02093d
HH
99 Make sure your kernel has bzip2 decompression support
100 compiled in, otherwise you will not be able to boot.
101 --lzma Compress the generated initramfs using lzma.
3b403b32 102 Make sure your kernel has lzma support compiled in,
cc02093d 103 otherwise you will not be able to boot.
5e6c3b03
VL
104 --xz Compress the generated initramfs using xz.
105 Make sure that your kernel has xz support compiled
106 in, otherwise you will not be able to boot.
107 --compress [COMPRESSION] Compress the generated initramfs with the
108 passed compression program. Make sure your kernel
3b403b32 109 knows how to decompress the generated initramfs,
5e6c3b03 110 otherwise you will not be able to boot.
5b158ad3 111 --no-compress Do not compress the generated initramfs. This will
cc02093d 112 override any other compression options.
5b11bb73 113 --list-modules List all available dracut modules.
956af8f2
114 -M, --show-modules Print included module's name to standard output during
115 build.
5fe5c7d0 116 --keep Keep the temporary initramfs for debugging purposes
cc02093d 117EOF
5616feb0
AT
118}
119
8466db96
HH
120# function push()
121# push values to a stack
122# $1 = stack variable
123# $2.. values
124# example:
125# push stack 1 2 "3 4"
126push() {
127 local __stack=$1; shift
128 for i in "$@"; do
129 eval ${__stack}'[${#'${__stack}'[@]}]="$i"'
130 done
131}
132
133# function pop()
134# pops the last value from a stack
135# assigns value to second argument variable
136# or echo to stdout, if no second argument
137# $1 = stack variable
138# $2 = optional variable to store the value
139# example:
140# pop stack val
141# val=$(pop stack)
142pop() {
143 local __stack=$1; shift
3b403b32 144 local __resultvar=$1
8466db96
HH
145 local myresult;
146 # check for empty stack
147 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
148
149 eval myresult='${'${__stack}'[${#'${__stack}'[@]}-1]}'
150
151 if [[ "$__resultvar" ]]; then
152 eval $__resultvar="'$myresult'"
153 else
154 echo "$myresult"
155 fi
156 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
157 return 0
158}
159
5bc545ed
VL
160# Little helper function for reading args from the commandline.
161# it automatically handles -a b and -a=b variants, and returns 1 if
162# we need to shift $3.
163read_arg() {
164 # $1 = arg name
165 # $2 = arg value
166 # $3 = arg parameter
167 local rematch='^[^=]*=(.*)$'
168 if [[ $2 =~ $rematch ]]; then
cc02093d 169 read "$1" <<< "${BASH_REMATCH[1]}"
5bc545ed 170 else
cc02093d
HH
171 read "$1" <<< "$3"
172 # There is no way to shift our callers args, so
173 # return 1 to indicate they should do it instead.
174 return 1
5bc545ed
VL
175 fi
176}
177
661f9a34
HH
178# Little helper function for reading args from the commandline to a stack.
179# it automatically handles -a b and -a=b variants, and returns 1 if
180# we need to shift $3.
181push_arg() {
182 # $1 = arg name
183 # $2 = arg value
184 # $3 = arg parameter
185 local rematch='^[^=]*=(.*)$'
186 if [[ $2 =~ $rematch ]]; then
187 push "$1" "${BASH_REMATCH[1]}"
188 else
189 push "$1" "$3"
190 # There is no way to shift our callers args, so
191 # return 1 to indicate they should do it instead.
192 return 1
193 fi
194}
195
432196ae 196verbosity_mod_l=0
486a1b93 197
b368a5f3 198while (($# > 0)); do
5bc545ed 199 case ${1%%=*} in
661f9a34 200 -a|--add) push_arg add_dracutmodules_l "$@" || shift;;
31f1c02d 201 --force-add) push_arg force_add_dracutmodules_l "$@" || shift;;
661f9a34
HH
202 --add-drivers) push_arg add_drivers_l "$@" || shift;;
203 -m|--modules) push_arg dracutmodules_l "$@" || shift;;
204 -o|--omit) push_arg omit_dracutmodules_l "$@" || shift;;
205 -d|--drivers) push_arg drivers_l "$@" || shift;;
206 --filesystems) push_arg filesystems_l "$@" || shift;;
0ec40e08 207 -I|--install) push_arg install_items_l "$@" || shift;;
661f9a34 208 --fwdir) push_arg fw_dir_l "$@" || shift;;
25b45979
MS
209 --fscks) push_arg fscks_l "$@" || shift;;
210 --nofscks) nofscks_l="yes";;
cc02093d
HH
211 -k|--kmoddir) read_arg drivers_dir_l "$@" || shift;;
212 -c|--conf) read_arg conffile "$@" || shift;;
213 --confdir) read_arg confdir "$@" || shift;;
e103615b 214 -L|--stdlog) read_arg stdloglvl_l "$@" || shift;;
3a714439 215 --compress) read_arg compress_l "$@" || shift;;
fd786adc 216 --prefix) read_arg prefix_l "$@" || shift;;
cc02093d
HH
217 -f|--force) force=yes;;
218 --kernel-only) kernel_only="yes"; no_kernel="no";;
219 --no-kernel) kernel_only="no"; no_kernel="yes";;
220 --strip) do_strip_l="yes";;
221 --nostrip) do_strip_l="no";;
fd786adc 222 --noprefix) prefix_l="/";;
690396a5
VL
223 --mdadmconf) mdadmconf_l="yes";;
224 --nomdadmconf) mdadmconf_l="no";;
225 --lvmconf) lvmconf_l="yes";;
226 --nolvmconf) lvmconf_l="no";;
cc02093d 227 --debug) debug="yes";;
57258a2c 228 --profile) profile="yes";;
432196ae
229 -v|--verbose) ((verbosity_mod_l++));;
230 -q|--quiet) ((verbosity_mod_l--));;
cc02093d
HH
231 -l|--local) allowlocal="yes" ;;
232 -H|--hostonly) hostonly_l="yes" ;;
233 --fstab) use_fstab_l="yes" ;;
234 -h|--help) usage; exit 1 ;;
2aad2344
HH
235 -i|--include) push include_src "$2"
236 push include_target "$3"
237 shift 2;;
3a714439
VL
238 --bzip2) compress_l="bzip2";;
239 --lzma) compress_l="lzma";;
240 --xz) compress_l="xz";;
241 --no-compress) _no_compress_l="cat";;
242 --gzip) compress_l="gzip";;
5b11bb73
HH
243 --list-modules)
244 do_list="yes";
245 ;;
956af8f2
246 -M|--show-modules)
247 show_modules_l="yes"
248 ;;
5fe5c7d0 249 --keep) keep="yes";;
cc02093d 250 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
3b403b32 251 *)
dbf381f7 252 if ! [[ ${outfile+x} ]]; then
486a1b93 253 outfile=$1
8a5354a9 254 elif ! [[ ${kernel+x} ]]; then
486a1b93
HH
255 kernel=$1
256 else
257 usage; exit 1;
258 fi
259 ;;
641cc356 260 esac
b368a5f3 261 shift
641cc356 262done
8a5354a9 263if ! [[ $kernel ]]; then
486a1b93
HH
264 kernel=$(uname -r)
265fi
266[[ $outfile ]] || outfile="/boot/initramfs-$kernel.img"
4cba351e 267
f8545d04
HH
268PATH=/sbin:/bin:/usr/sbin:/usr/bin
269export PATH
d619fb5e 270unset LD_LIBRARY_PATH
a55711cd 271
3b403b32 272[[ $debug ]] && {
c36ce334
VL
273 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
274 set -x
275}
276
57258a2c
HH
277[[ $profile ]] && {
278 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
279 set -x
280 debug=yes
281}
282
c5a65990 283[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
5d791c0e 284
cc02093d 285[[ $allowlocal && -f "$(readlink -f ${0%/*})/dracut-functions" ]] && \
3b403b32 286 dracutbasedir="$(readlink -f ${0%/*})"
42c71947 287
f1336ac7 288# if we were not passed a config file, try the default one
42c71947 289if [[ ! -f $conffile ]]; then
eebc929a
VL
290 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
291 conffile="/etc/dracut.conf"
42c71947 292fi
f1336ac7 293
2c2c4580 294if [[ ! -d $confdir ]]; then
ae24b114 295 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
eebc929a 296 confdir="/etc/dracut.conf.d"
2c2c4580
HH
297fi
298
2245f372
AB
299# source our config file
300[[ -f $conffile ]] && . "$conffile"
301
2c2c4580 302# source our config dir
6438b4fe 303if [[ $confdir && -d $confdir ]]; then
3b403b32 304 for f in "$confdir"/*.conf; do
cc02093d 305 [[ -e $f ]] && . "$f"
2c2c4580
HH
306 done
307fi
308
d87c2708 309# these optins add to the stuff in the config file
e5e5c895 310if (( ${#add_dracutmodules_l[@]} )); then
661f9a34
HH
311 while pop add_dracutmodules_l val; do
312 add_dracutmodules+=" $val "
313 done
314fi
315
31f1c02d
AW
316if (( ${#force_add_dracutmodules_l[@]} )); then
317 while pop force_add_dracutmodules_l val; do
318 force_add_dracutmodules+=" $val "
319 done
320fi
321
322
e5e5c895 323if (( ${#add_drivers_l[@]} )); then
661f9a34
HH
324 while pop add_drivers_l val; do
325 add_drivers+=" $val "
326 done
327fi
d87c2708 328
25b45979
MS
329if (( ${#fscks_l[@]} )); then
330 while pop fscks_l val; do
331 fscks+=" $val "
332 done
333fi
334
0ec40e08
HH
335if (( ${#install_items_l[@]} )); then
336 while pop install_items_l val; do
337 push install_items $val
338 done
339fi
340
f1336ac7 341# these options override the stuff in the config file
e5e5c895 342if (( ${#dracutmodules_l[@]} )); then
661f9a34
HH
343 dracutmodules=''
344 while pop dracutmodules_l val; do
345 dracutmodules+="$val "
346 done
347fi
348
e5e5c895 349if (( ${#omit_dracutmodules_l[@]} )); then
661f9a34
HH
350 omit_dracutmodules=''
351 while pop omit_dracutmodules_l val; do
352 omit_dracutmodules+="$val "
353 done
354fi
355
e5e5c895 356if (( ${#drivers_l[@]} )); then
661f9a34
HH
357 drivers=''
358 while pop drivers_l val; do
359 drivers+="$val "
360 done
361fi
362
e5e5c895 363if (( ${#filesystems_l[@]} )); then
661f9a34
HH
364 filesystems=''
365 while pop filesystems_l val; do
366 filesystems+="$val "
367 done
368fi
369
e5e5c895 370if (( ${#fw_dir_l[@]} )); then
661f9a34
HH
371 fw_dir=''
372 while pop fw_dir_l val; do
373 fw_dir+="$val "
374 done
375fi
376
e103615b 377[[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
b991617f 378[[ ! $stdloglvl ]] && stdloglvl=4
432196ae
379stdloglvl=$((stdloglvl + verbosity_mod_l))
380((stdloglvl > 6)) && stdloglvl=6
381((stdloglvl < 0)) && stdloglvl=0
382
26537a5b 383[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
31f7db66 384[[ $do_strip_l ]] && do_strip=$do_strip_l
fd786adc
HH
385[[ $prefix_l ]] && prefix=$prefix_l
386[[ $prefix = "/" ]] && unset prefix
ba726310 387[[ $hostonly_l ]] && hostonly=$hostonly_l
7c179686 388[[ $use_fstab_l ]] && use_fstab=$use_fstab_l
2f02ae9d 389[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
7a34efa5 390[[ $lvmconf_l ]] && lvmconf=$lvmconf_l
c5a65990 391[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
8bc650d9 392[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
5be225d2 393[[ $do_strip ]] || do_strip=no
3a714439 394[[ $compress_l ]] && compress=$compress_l
956af8f2 395[[ $show_modules_l ]] && show_modules=$show_modules_l
25b45979 396[[ $nofscks_l ]] && nofscks="yes"
ddfd1d10
VL
397# eliminate IFS hackery when messing with fw_dir
398fw_dir=${fw_dir//:/ }
9a8a00cf 399
3a714439 400# handle compression options.
55468fb9 401[[ $compress ]] || compress="gzip"
3a714439 402case $compress in
6f223367 403 bzip2) compress="bzip2 -9";;
3a714439
VL
404 lzma) compress="lzma -9";;
405 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
55468fb9 406 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
3a714439
VL
407 compress="gzip -9";;
408esac
409if [[ $_no_compress_l = "cat" ]]; then
410 compress="cat"
411fi
412
ba726310 413[[ $hostonly = yes ]] && hostonly="-h"
ba67b923 414[[ $hostonly != "-h" ]] && unset hostonly
ba726310 415
5d791c0e 416if [[ -f $dracutbasedir/dracut-functions ]]; then
cc02093d 417 . $dracutbasedir/dracut-functions
adbc8a42 418else
6f590cd1
HH
419 echo "Cannot find $dracutbasedir/dracut-functions." >&2
420 echo "Are you running from a git checkout?" >&2
421 echo "Try passing -l as an argument to $0" >&2
cc02093d 422 exit 1
adbc8a42 423fi
22fd1627 424
d239b550
MS
425# Verify bash version, curret minimum is 3.1
426if (( ${BASH_VERSINFO[0]} < 3 ||
427 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
428 dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
429 exit 1
430fi
431
5d791c0e 432dracutfunctions=$dracutbasedir/dracut-functions
5cad5bb5 433export dracutfunctions
9a8a00cf 434
432196ae 435ddebug "Executing $0 $dracut_args"
58dad702 436
5b11bb73
HH
437[[ $do_list = yes ]] && {
438 for mod in $dracutbasedir/modules.d/*; do
439 [[ -d $mod ]] || continue;
d8e8e14e
440 [[ -e $mod/install || -e $mod/installkernel || \
441 -e $mod/module-setup.sh ]] || continue
5b11bb73
HH
442 echo ${mod##*/??}
443 done
444 exit 0
445}
446
fa5cd2bf
447# Detect lib paths
448[[ $libdir ]] || for libdir in /lib64 /lib; do
449 [[ -d $libdir ]] && break
450done || {
432196ae 451 dfatal 'No lib directory?!!!'
fa5cd2bf
452 exit 1
453}
432196ae 454
fa5cd2bf
455[[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
456 [[ -d $usrlibdir ]] && break
432196ae 457done || dwarn 'No usr/lib directory!'
fa5cd2bf 458
66ac3cd1 459# This is kinda legacy -- eventually it should go away.
f1336ac7 460case $dracutmodules in
66ac3cd1 461 ""|auto) dracutmodules="all" ;;
f1336ac7 462esac
e12aac5e 463
454771cd 464abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
ec9315e5 465
f24a2d46 466srcmods="/lib/modules/$kernel/"
ecf42850 467[[ $drivers_dir ]] && {
22ecea45 468 if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
432196ae 469 dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
ecf42850
470 exit 1
471 fi
472 srcmods="$drivers_dir"
473}
f24a2d46
HH
474export srcmods
475
c8937ec4 476if [[ -f $outfile && ! $force ]]; then
432196ae 477 dfatal "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
478 exit 1
479fi
480
ebfdb219 481outdir=${outfile%/*}
52eed268
HH
482[[ $outdir ]] || outdir="/"
483
ebfdb219 484if [[ ! -d "$outdir" ]]; then
432196ae 485 dfatal "Can't write $outfile: Directory $outdir does not exist."
454771cd 486 exit 1
ebfdb219 487elif [[ ! -w "$outdir" ]]; then
432196ae 488 dfatal "No permission to write $outdir."
454771cd 489 exit 1
0a325a91 490elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
432196ae 491 dfatal "No permission to write $outfile."
734a0d9e
HH
492 exit 1
493fi
494
6787b8cc 495readonly TMPDIR=/var/tmp
9a5393ac 496readonly initdir=$(mktemp --tmpdir=/var/tmp/ -d -t initramfs.XXXXXX)
88b3e005
DY
497[ -d "$initdir" ] || {
498 dfatal "mktemp failed."
499 exit 1
500}
734a0d9e 501
cc02093d 502# clean up after ourselves no matter how we die.
5fe5c7d0 503trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
cc02093d 504# clean up after ourselves no matter how we die.
3b403b32 505trap 'exit 1;' SIGINT
ec9315e5 506
f6f74096
DD
507# Need to be able to have non-root users read stuff (rpcbind etc)
508chmod 755 "$initdir"
509
7ae5d9d1
HH
510if [[ $hostonly ]]; then
511
512 _get_fs_type() (
513 [[ $1 ]] || return
514 if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
515 echo -n "$ID_FS_TYPE "
516 return 1
517 fi
518 if find_dev_fstype $1; then
519 echo -n " "
520 return 1
521 fi
522 return 1
523 )
524
525 push host_mp \
526 "/" \
527 "/etc" \
528 "/usr" \
529 "/usr/bin" \
530 "/usr/sbin" \
531 "/usr/lib" \
532 "/usr/lib64" \
533 "/boot"
534
535 host_fs_types=""
536 for mp in "${host_mp[@]}"; do
537 mountpoint "$mp" >/dev/null 2>&1 || continue
538 push host_devs $(find_block_device "$mp")
539 done
540 for dev in "${host_devs[@]}"; do
541 unset fs_type
542 for fstype in $(_get_fs_type $dev) \
543 $(check_block_and_slaves _get_fs_type $dev); do
544 strstr " $host_fs_types " "$fstype" || host_fs_types+="$fstype "
545 done
546 done
547fi
548echo "host_fs_types=$host_fs_types"
549
0b53ca70 550export initdir dracutbasedir dracutmodules drivers \
e103615b 551 fw_dir drivers_dir debug no_kernel kernel_only \
9d1015b6 552 add_drivers mdadmconf lvmconf filesystems \
25b45979 553 use_fstab libdir usrlibdir fscks nofscks \
1e64e493 554 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
7ae5d9d1 555 debug host_fs_types host_devs
f4fff04e 556
dbad9f46 557# Create some directory structure first
fd786adc 558[[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
dbad9f46 559
785a6cd2 560[[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
fd786adc 561[[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
dbad9f46 562
785a6cd2 563if [[ $prefix ]]; then
3b403b32 564 for d in bin etc lib "$libdir" sbin tmp usr var; do
785a6cd2
HH
565 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
566 done
567fi
568
569if [[ $kernel_only != yes ]]; then
ef6900eb 570 for d in bin etc lib "$libdir" sbin tmp usr var var/log usr/bin usr/sbin; do
fd786adc 571 [[ -e "${initdir}${prefix}/$d" ]] && continue
785a6cd2
HH
572 if [ -h "/$d" ]; then
573 inst "/$d" "${prefix}/$d"
574 else
575 mkdir -m 0755 -p "${initdir}${prefix}/$d"
576 fi
3b403b32 577 done
dbad9f46 578
7c14b368 579 for d in dev proc sys sysroot root run run/lock run/initramfs; do
785a6cd2
HH
580 if [ -h "/$d" ]; then
581 inst "/$d"
582 else
583 mkdir -m 0755 -p "$initdir/$d"
584 fi
33ee031c 585 done
dbad9f46
HH
586
587 ln -sfn /run "$initdir/var/run"
588 ln -sfn /run/lock "$initdir/var/lock"
6f09acf8
HH
589else
590 for d in lib "$libdir"; do
591 [[ -e "${initdir}${prefix}/$d" ]] && continue
592 if [ -h "/$d" ]; then
593 inst "/$d" "${prefix}/$d"
594 else
595 mkdir -m 0755 -p "${initdir}${prefix}/$d"
596 fi
597 done
33ee031c 598fi
0f86847d 599
66ac3cd1
VL
600# check all our modules to see if they should be sourced.
601# This builds a list of modules that we will install next.
95d2dabc 602check_module_dir
979c4a93 603modules_loaded=" "
95bde758 604# source our modules.
5d791c0e 605for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
979c4a93
HH
606 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
607 if strstr "$mods_to_load" " $_d_mod "; then
608 [[ $show_modules = yes ]] && echo "$_d_mod" || \
609 dinfo "*** Including module: $_d_mod ***"
cc02093d 610 if [[ $kernel_only = yes ]]; then
979c4a93 611 module_installkernel $_d_mod
cc02093d 612 else
979c4a93 613 module_install $_d_mod
95d2dabc 614 if [[ $no_kernel != yes ]]; then
979c4a93 615 module_installkernel $_d_mod
cc02093d
HH
616 fi
617 fi
979c4a93
HH
618 mods_to_load=${mods_to_load// $_d_mod /}
619 modules_loaded+="$_d_mod "
66ac3cd1 620 fi
15136762 621done
20abd914 622unset moddir
ea216a65 623dinfo "*** Including modules done ***"
aabc0553 624
0f86847d 625## final stuff that has to happen
bc6b0dec 626
0f86847d 627# generate module dependencies for the initrd
8a474569
VL
628if [[ -d $initdir/lib/modules/$kernel ]] && \
629 ! depmod -a -b "$initdir" $kernel; then
432196ae 630 dfatal "\"depmod -a $kernel\" failed."
8a474569 631 exit 1
f1336ac7 632fi
ec9315e5 633
661f9a34
HH
634while pop include_src src && pop include_target tgt; do
635 if [[ $src && $tgt ]]; then
636 if [[ -f $src ]]; then
637 inst $src $tgt
638 else
3b403b32 639 ddebug "Including directory: $src"
661f9a34 640 mkdir -p "${initdir}/${tgt}"
dbad9f46 641 # check for preexisting symlinks, so we can cope with the
fd786adc 642 # symlinks to $prefix
dbad9f46
HH
643 for i in "$src"/*; do
644 [[ -e "$i" || -h "$i" ]] || continue
645 s=${initdir}/${tgt}/${i#$src/}
646 if [[ -d "$i" ]]; then
647 if ! [[ -e "$s" ]]; then
648 mkdir -m 0755 -p "$s"
649 chmod --reference="$i" "$s"
650 fi
651 cp -a -t "$s" "$i"/*
652 else
653 cp -a -t "$s" "$i"
3b403b32 654 fi
dbad9f46 655 done
661f9a34 656 fi
4fea3ea6 657 fi
661f9a34 658done
88ffd2df 659
661f9a34
HH
660while pop install_items items; do
661 for item in $items; do
662 dracut_install "$item"
663 done
39ff0682
AT
664done
665unset item
666
1254925f
HH
667
668if [[ $kernel_only != yes ]]; then
669 # make sure that library links are correct and up to date
670 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
e59f58f8 671 [[ -e $f ]] && inst_simple "$f"
1254925f
HH
672 done
673 if ! ldconfig -r "$initdir"; then
674 if [[ $UID = 0 ]]; then
675 derror "ldconfig exited ungracefully"
676 else
677 derror "ldconfig might need uid=0 (root) for chroot()"
678 fi
432196ae
679 fi
680fi
fdc421db 681
432196ae
682if (($maxloglvl >= 5)); then
683 ddebug "Listing sizes of included files:"
684 du -c "$initdir" | sort -n | ddebug
685fi
c4ad7fff 686
3b403b32 687# strip binaries
98adb06e 688if [[ $do_strip = yes ]] ; then
3b403b32 689 for p in strip grep find; do
cc02093d
HH
690 if ! type -P $p >/dev/null; then
691 derror "Could not find '$p'. You should run $0 with '--nostrip'."
692 do_strip=no
693 fi
31f7db66
HH
694 done
695fi
696
98adb06e 697if [[ $do_strip = yes ]] ; then
cc02093d
HH
698 for f in $(find "$initdir" -type f \
699 \( -perm -0100 -or -perm -0010 -or -perm -0001 \
700 -or -path '*/lib/modules/*.ko' \) ); do
701 dinfo "Stripping $f"
702 strip -g "$f" 2>/dev/null|| :
31f7db66
HH
703 done
704fi
705
6292ee9d 706type hardlink &>/dev/null && {
cc02093d 707 hardlink "$initdir" 2>&1
6292ee9d
HH
708}
709
979c4a93
HH
710if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
711 for i in $initdir/bin/* \
bc313467 712 $initdir/sbin/* \
979c4a93
HH
713 $initdir/usr/bin/* \
714 $initdir/usr/sbin/*; do
715 [ -x $i ] && prelink -u $i &>/dev/null
716 done
717fi
718
59f288ce 719if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
3b403b32 720 $compress > "$outfile"; ); then
432196ae 721 dfatal "dracut: creation of $outfile failed"
734a0d9e 722 exit 1
3b403b32 723fi
432196ae
724
725dinfo "Wrote $outfile:"
726dinfo "$(ls -l "$outfile")"
1faecdc1 727
3da58569 728exit 0