]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut
fs-lib: add ability to choose fsck tools
[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
73198d53 38 in /usr/share/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
73198d53 83 /usr/share/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;;
207 -I|--install) push_arg install_items "$@" || shift;;
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;;
5e6c3b03
VL
215 -I|--install) read_arg install_items "$@" || shift;;
216 --fwdir) read_arg fw_dir_l "$@" || shift;;
3a714439 217 --compress) read_arg compress_l "$@" || shift;;
fd786adc 218 --prefix) read_arg prefix_l "$@" || shift;;
cc02093d
HH
219 -f|--force) force=yes;;
220 --kernel-only) kernel_only="yes"; no_kernel="no";;
221 --no-kernel) kernel_only="no"; no_kernel="yes";;
222 --strip) do_strip_l="yes";;
223 --nostrip) do_strip_l="no";;
fd786adc 224 --noprefix) prefix_l="/";;
690396a5
VL
225 --mdadmconf) mdadmconf_l="yes";;
226 --nomdadmconf) mdadmconf_l="no";;
227 --lvmconf) lvmconf_l="yes";;
228 --nolvmconf) lvmconf_l="no";;
cc02093d 229 --debug) debug="yes";;
57258a2c 230 --profile) profile="yes";;
432196ae
231 -v|--verbose) ((verbosity_mod_l++));;
232 -q|--quiet) ((verbosity_mod_l--));;
cc02093d
HH
233 -l|--local) allowlocal="yes" ;;
234 -H|--hostonly) hostonly_l="yes" ;;
235 --fstab) use_fstab_l="yes" ;;
236 -h|--help) usage; exit 1 ;;
2aad2344
HH
237 -i|--include) push include_src "$2"
238 push include_target "$3"
239 shift 2;;
3a714439
VL
240 --bzip2) compress_l="bzip2";;
241 --lzma) compress_l="lzma";;
242 --xz) compress_l="xz";;
243 --no-compress) _no_compress_l="cat";;
244 --gzip) compress_l="gzip";;
5b11bb73
HH
245 --list-modules)
246 do_list="yes";
247 ;;
956af8f2
248 -M|--show-modules)
249 show_modules_l="yes"
250 ;;
5fe5c7d0 251 --keep) keep="yes";;
cc02093d 252 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
3b403b32 253 *)
dbf381f7 254 if ! [[ ${outfile+x} ]]; then
486a1b93 255 outfile=$1
8a5354a9 256 elif ! [[ ${kernel+x} ]]; then
486a1b93
HH
257 kernel=$1
258 else
259 usage; exit 1;
260 fi
261 ;;
641cc356 262 esac
b368a5f3 263 shift
641cc356 264done
8a5354a9 265if ! [[ $kernel ]]; then
486a1b93
HH
266 kernel=$(uname -r)
267fi
268[[ $outfile ]] || outfile="/boot/initramfs-$kernel.img"
4cba351e 269
f8545d04
HH
270PATH=/sbin:/bin:/usr/sbin:/usr/bin
271export PATH
d619fb5e 272unset LD_LIBRARY_PATH
a55711cd 273
3b403b32 274[[ $debug ]] && {
c36ce334
VL
275 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
276 set -x
277}
278
57258a2c
HH
279[[ $profile ]] && {
280 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
281 set -x
282 debug=yes
283}
284
5d791c0e
HH
285[[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
286
cc02093d 287[[ $allowlocal && -f "$(readlink -f ${0%/*})/dracut-functions" ]] && \
3b403b32 288 dracutbasedir="$(readlink -f ${0%/*})"
42c71947 289
f1336ac7 290# if we were not passed a config file, try the default one
42c71947 291if [[ ! -f $conffile ]]; then
eebc929a
VL
292 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
293 conffile="/etc/dracut.conf"
42c71947 294fi
f1336ac7 295
2c2c4580 296if [[ ! -d $confdir ]]; then
ae24b114 297 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
eebc929a 298 confdir="/etc/dracut.conf.d"
2c2c4580
HH
299fi
300
2245f372
AB
301# source our config file
302[[ -f $conffile ]] && . "$conffile"
303
2c2c4580 304# source our config dir
6438b4fe 305if [[ $confdir && -d $confdir ]]; then
3b403b32 306 for f in "$confdir"/*.conf; do
cc02093d 307 [[ -e $f ]] && . "$f"
2c2c4580
HH
308 done
309fi
310
d87c2708 311# these optins add to the stuff in the config file
e5e5c895 312if (( ${#add_dracutmodules_l[@]} )); then
661f9a34
HH
313 while pop add_dracutmodules_l val; do
314 add_dracutmodules+=" $val "
315 done
316fi
317
31f1c02d
AW
318if (( ${#force_add_dracutmodules_l[@]} )); then
319 while pop force_add_dracutmodules_l val; do
320 force_add_dracutmodules+=" $val "
321 done
322fi
323
324
e5e5c895 325if (( ${#add_drivers_l[@]} )); then
661f9a34
HH
326 while pop add_drivers_l val; do
327 add_drivers+=" $val "
328 done
329fi
d87c2708 330
25b45979
MS
331if (( ${#fscks_l[@]} )); then
332 while pop fscks_l val; do
333 fscks+=" $val "
334 done
335fi
336
f1336ac7 337# these options override the stuff in the config file
e5e5c895 338if (( ${#dracutmodules_l[@]} )); then
661f9a34
HH
339 dracutmodules=''
340 while pop dracutmodules_l val; do
341 dracutmodules+="$val "
342 done
343fi
344
e5e5c895 345if (( ${#omit_dracutmodules_l[@]} )); then
661f9a34
HH
346 omit_dracutmodules=''
347 while pop omit_dracutmodules_l val; do
348 omit_dracutmodules+="$val "
349 done
350fi
351
e5e5c895 352if (( ${#drivers_l[@]} )); then
661f9a34
HH
353 drivers=''
354 while pop drivers_l val; do
355 drivers+="$val "
356 done
357fi
358
e5e5c895 359if (( ${#filesystems_l[@]} )); then
661f9a34
HH
360 filesystems=''
361 while pop filesystems_l val; do
362 filesystems+="$val "
363 done
364fi
365
e5e5c895 366if (( ${#fw_dir_l[@]} )); then
661f9a34
HH
367 fw_dir=''
368 while pop fw_dir_l val; do
369 fw_dir+="$val "
370 done
371fi
372
e103615b 373[[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
b991617f 374[[ ! $stdloglvl ]] && stdloglvl=4
432196ae
375stdloglvl=$((stdloglvl + verbosity_mod_l))
376((stdloglvl > 6)) && stdloglvl=6
377((stdloglvl < 0)) && stdloglvl=0
378
26537a5b 379[[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
31f7db66 380[[ $do_strip_l ]] && do_strip=$do_strip_l
fd786adc
HH
381[[ $prefix_l ]] && prefix=$prefix_l
382[[ $prefix = "/" ]] && unset prefix
ba726310 383[[ $hostonly_l ]] && hostonly=$hostonly_l
7c179686 384[[ $use_fstab_l ]] && use_fstab=$use_fstab_l
2f02ae9d 385[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
7a34efa5 386[[ $lvmconf_l ]] && lvmconf=$lvmconf_l
73198d53 387[[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
8bc650d9 388[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
5be225d2 389[[ $do_strip ]] || do_strip=no
3a714439 390[[ $compress_l ]] && compress=$compress_l
956af8f2 391[[ $show_modules_l ]] && show_modules=$show_modules_l
25b45979 392[[ $nofscks_l ]] && nofscks="yes"
ddfd1d10
VL
393# eliminate IFS hackery when messing with fw_dir
394fw_dir=${fw_dir//:/ }
9a8a00cf 395
3a714439 396# handle compression options.
55468fb9 397[[ $compress ]] || compress="gzip"
3a714439 398case $compress in
6f223367 399 bzip2) compress="bzip2 -9";;
3a714439
VL
400 lzma) compress="lzma -9";;
401 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
55468fb9 402 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
3a714439
VL
403 compress="gzip -9";;
404esac
405if [[ $_no_compress_l = "cat" ]]; then
406 compress="cat"
407fi
408
ba726310 409[[ $hostonly = yes ]] && hostonly="-h"
ba67b923 410[[ $hostonly != "-h" ]] && unset hostonly
ba726310 411
5d791c0e 412if [[ -f $dracutbasedir/dracut-functions ]]; then
cc02093d 413 . $dracutbasedir/dracut-functions
adbc8a42 414else
6f590cd1
HH
415 echo "Cannot find $dracutbasedir/dracut-functions." >&2
416 echo "Are you running from a git checkout?" >&2
417 echo "Try passing -l as an argument to $0" >&2
cc02093d 418 exit 1
adbc8a42 419fi
22fd1627 420
5d791c0e 421dracutfunctions=$dracutbasedir/dracut-functions
5cad5bb5 422export dracutfunctions
9a8a00cf 423
432196ae 424ddebug "Executing $0 $dracut_args"
58dad702 425
5b11bb73
HH
426[[ $do_list = yes ]] && {
427 for mod in $dracutbasedir/modules.d/*; do
428 [[ -d $mod ]] || continue;
d8e8e14e
429 [[ -e $mod/install || -e $mod/installkernel || \
430 -e $mod/module-setup.sh ]] || continue
5b11bb73
HH
431 echo ${mod##*/??}
432 done
433 exit 0
434}
435
fa5cd2bf
436# Detect lib paths
437[[ $libdir ]] || for libdir in /lib64 /lib; do
438 [[ -d $libdir ]] && break
439done || {
432196ae 440 dfatal 'No lib directory?!!!'
fa5cd2bf
441 exit 1
442}
432196ae 443
fa5cd2bf
444[[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
445 [[ -d $usrlibdir ]] && break
432196ae 446done || dwarn 'No usr/lib directory!'
fa5cd2bf 447
66ac3cd1 448# This is kinda legacy -- eventually it should go away.
f1336ac7 449case $dracutmodules in
66ac3cd1 450 ""|auto) dracutmodules="all" ;;
f1336ac7 451esac
e12aac5e 452
454771cd 453abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
ec9315e5 454
f24a2d46 455srcmods="/lib/modules/$kernel/"
ecf42850 456[[ $drivers_dir ]] && {
22ecea45 457 if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
432196ae 458 dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
ecf42850
459 exit 1
460 fi
461 srcmods="$drivers_dir"
462}
f24a2d46
HH
463export srcmods
464
c8937ec4 465if [[ -f $outfile && ! $force ]]; then
432196ae 466 dfatal "Will not override existing initramfs ($outfile) without --force"
ec9315e5
JK
467 exit 1
468fi
469
ebfdb219 470outdir=${outfile%/*}
52eed268
HH
471[[ $outdir ]] || outdir="/"
472
ebfdb219 473if [[ ! -d "$outdir" ]]; then
432196ae 474 dfatal "Can't write $outfile: Directory $outdir does not exist."
454771cd 475 exit 1
ebfdb219 476elif [[ ! -w "$outdir" ]]; then
432196ae 477 dfatal "No permission to write $outdir."
454771cd 478 exit 1
0a325a91 479elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
432196ae 480 dfatal "No permission to write $outfile."
734a0d9e
HH
481 exit 1
482fi
483
6787b8cc 484readonly TMPDIR=/var/tmp
9a5393ac 485readonly initdir=$(mktemp --tmpdir=/var/tmp/ -d -t initramfs.XXXXXX)
88b3e005
DY
486[ -d "$initdir" ] || {
487 dfatal "mktemp failed."
488 exit 1
489}
734a0d9e 490
cc02093d 491# clean up after ourselves no matter how we die.
5fe5c7d0 492trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
cc02093d 493# clean up after ourselves no matter how we die.
3b403b32 494trap 'exit 1;' SIGINT
ec9315e5 495
f6f74096
DD
496# Need to be able to have non-root users read stuff (rpcbind etc)
497chmod 755 "$initdir"
498
0b53ca70 499export initdir dracutbasedir dracutmodules drivers \
e103615b 500 fw_dir drivers_dir debug no_kernel kernel_only \
9d1015b6 501 add_drivers mdadmconf lvmconf filesystems \
25b45979 502 use_fstab libdir usrlibdir fscks nofscks \
1e64e493
HH
503 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
504 debug
f4fff04e 505
dbad9f46 506# Create some directory structure first
fd786adc 507[[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
dbad9f46 508
785a6cd2 509[[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
fd786adc 510[[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
dbad9f46 511
785a6cd2 512if [[ $prefix ]]; then
3b403b32 513 for d in bin etc lib "$libdir" sbin tmp usr var; do
785a6cd2
HH
514 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
515 done
516fi
517
518if [[ $kernel_only != yes ]]; then
519 for d in bin etc lib "$libdir" sbin tmp usr var usr/bin usr/sbin; do
fd786adc 520 [[ -e "${initdir}${prefix}/$d" ]] && continue
785a6cd2
HH
521 if [ -h "/$d" ]; then
522 inst "/$d" "${prefix}/$d"
523 else
524 mkdir -m 0755 -p "${initdir}${prefix}/$d"
525 fi
3b403b32 526 done
dbad9f46 527
7c14b368 528 for d in dev proc sys sysroot root run run/lock run/initramfs; do
785a6cd2
HH
529 if [ -h "/$d" ]; then
530 inst "/$d"
531 else
532 mkdir -m 0755 -p "$initdir/$d"
533 fi
33ee031c 534 done
dbad9f46
HH
535
536 ln -sfn /run "$initdir/var/run"
537 ln -sfn /run/lock "$initdir/var/lock"
6f09acf8
HH
538else
539 for d in lib "$libdir"; do
540 [[ -e "${initdir}${prefix}/$d" ]] && continue
541 if [ -h "/$d" ]; then
542 inst "/$d" "${prefix}/$d"
543 else
544 mkdir -m 0755 -p "${initdir}${prefix}/$d"
545 fi
546 done
33ee031c 547fi
0f86847d 548
66ac3cd1
VL
549# check all our modules to see if they should be sourced.
550# This builds a list of modules that we will install next.
95d2dabc 551check_module_dir
979c4a93 552modules_loaded=" "
95bde758 553# source our modules.
5d791c0e 554for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
979c4a93
HH
555 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
556 if strstr "$mods_to_load" " $_d_mod "; then
557 [[ $show_modules = yes ]] && echo "$_d_mod" || \
558 dinfo "*** Including module: $_d_mod ***"
cc02093d 559 if [[ $kernel_only = yes ]]; then
979c4a93 560 module_installkernel $_d_mod
cc02093d 561 else
979c4a93 562 module_install $_d_mod
95d2dabc 563 if [[ $no_kernel != yes ]]; then
979c4a93 564 module_installkernel $_d_mod
cc02093d
HH
565 fi
566 fi
979c4a93
HH
567 mods_to_load=${mods_to_load// $_d_mod /}
568 modules_loaded+="$_d_mod "
66ac3cd1 569 fi
15136762 570done
20abd914 571unset moddir
ea216a65 572dinfo "*** Including modules done ***"
aabc0553 573
0f86847d 574## final stuff that has to happen
bc6b0dec 575
0f86847d 576# generate module dependencies for the initrd
8a474569
VL
577if [[ -d $initdir/lib/modules/$kernel ]] && \
578 ! depmod -a -b "$initdir" $kernel; then
432196ae 579 dfatal "\"depmod -a $kernel\" failed."
8a474569 580 exit 1
f1336ac7 581fi
ec9315e5 582
661f9a34
HH
583while pop include_src src && pop include_target tgt; do
584 if [[ $src && $tgt ]]; then
585 if [[ -f $src ]]; then
586 inst $src $tgt
587 else
3b403b32 588 ddebug "Including directory: $src"
661f9a34 589 mkdir -p "${initdir}/${tgt}"
dbad9f46 590 # check for preexisting symlinks, so we can cope with the
fd786adc 591 # symlinks to $prefix
dbad9f46
HH
592 for i in "$src"/*; do
593 [[ -e "$i" || -h "$i" ]] || continue
594 s=${initdir}/${tgt}/${i#$src/}
595 if [[ -d "$i" ]]; then
596 if ! [[ -e "$s" ]]; then
597 mkdir -m 0755 -p "$s"
598 chmod --reference="$i" "$s"
599 fi
600 cp -a -t "$s" "$i"/*
601 else
602 cp -a -t "$s" "$i"
3b403b32 603 fi
dbad9f46 604 done
661f9a34 605 fi
4fea3ea6 606 fi
661f9a34 607done
88ffd2df 608
661f9a34
HH
609while pop install_items items; do
610 for item in $items; do
611 dracut_install "$item"
612 done
39ff0682
AT
613done
614unset item
615
1254925f
HH
616
617if [[ $kernel_only != yes ]]; then
618 # make sure that library links are correct and up to date
619 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
e59f58f8 620 [[ -e $f ]] && inst_simple "$f"
1254925f
HH
621 done
622 if ! ldconfig -r "$initdir"; then
623 if [[ $UID = 0 ]]; then
624 derror "ldconfig exited ungracefully"
625 else
626 derror "ldconfig might need uid=0 (root) for chroot()"
627 fi
432196ae
628 fi
629fi
fdc421db 630
432196ae
631if (($maxloglvl >= 5)); then
632 ddebug "Listing sizes of included files:"
633 du -c "$initdir" | sort -n | ddebug
634fi
c4ad7fff 635
3b403b32 636# strip binaries
98adb06e 637if [[ $do_strip = yes ]] ; then
3b403b32 638 for p in strip grep find; do
cc02093d
HH
639 if ! type -P $p >/dev/null; then
640 derror "Could not find '$p'. You should run $0 with '--nostrip'."
641 do_strip=no
642 fi
31f7db66
HH
643 done
644fi
645
98adb06e 646if [[ $do_strip = yes ]] ; then
cc02093d
HH
647 for f in $(find "$initdir" -type f \
648 \( -perm -0100 -or -perm -0010 -or -perm -0001 \
649 -or -path '*/lib/modules/*.ko' \) ); do
650 dinfo "Stripping $f"
651 strip -g "$f" 2>/dev/null|| :
31f7db66
HH
652 done
653fi
654
6292ee9d 655type hardlink &>/dev/null && {
cc02093d 656 hardlink "$initdir" 2>&1
6292ee9d
HH
657}
658
979c4a93
HH
659if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
660 for i in $initdir/bin/* \
bc313467 661 $initdir/sbin/* \
979c4a93
HH
662 $initdir/usr/bin/* \
663 $initdir/usr/sbin/*; do
664 [ -x $i ] && prelink -u $i &>/dev/null
665 done
666fi
667
59f288ce 668if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
3b403b32 669 $compress > "$outfile"; ); then
432196ae 670 dfatal "dracut: creation of $outfile failed"
734a0d9e 671 exit 1
3b403b32 672fi
432196ae
673
674dinfo "Wrote $outfile:"
675dinfo "$(ls -l "$outfile")"
1faecdc1 676
3da58569 677exit 0