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