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