]>
Commit | Line | Data |
---|---|---|
c0815e4e | 1 | #!/bin/bash |
3b403b32 | 2 | # |
641cc356 JK |
3 | # Generator script for a dracut initramfs |
4 | # Tries to retain some degree of compatibility with the command line | |
5 | # of the various mkinitrd implementations out there | |
6 | # | |
70c26b7f | 7 | |
7d848c55 | 8 | # Copyright 2005-2013 Red Hat, Inc. All rights reserved. |
4f18fe82 HH |
9 | # |
10 | # This program is free software; you can redistribute it and/or modify | |
11 | # it under the terms of the GNU General Public License as published by | |
12 | # the Free Software Foundation; either version 2 of the License, or | |
13 | # (at your option) any later version. | |
14 | # | |
15 | # This program is distributed in the hope that it will be useful, | |
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | # GNU General Public License for more details. | |
19 | # | |
20 | # You should have received a copy of the GNU General Public License | |
21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 | # | |
ec9315e5 | 23 | |
58dad702 | 24 | # store for logging |
ffa71b4a | 25 | dracut_args=( "$@" ) |
5616feb0 | 26 | |
7abd4264 HH |
27 | set -o pipefail |
28 | ||
5616feb0 | 29 | usage() { |
dbf8f6ba HH |
30 | [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut |
31 | if [[ -f $dracutbasedir/dracut-version.sh ]]; then | |
32 | . $dracutbasedir/dracut-version.sh | |
33 | fi | |
34 | ||
5616feb0 | 35 | # 80x25 linebreak here ^ |
cc02093d | 36 | cat << EOF |
ffa71b4a HH |
37 | Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]] |
38 | ||
39 | Version: $DRACUT_VERSION | |
40 | ||
41 | Creates initial ramdisk images for preloading modules | |
42 | ||
43 | -h, --help Display all options | |
44 | ||
45 | If a [LIST] has multiple arguments, then you have to put these in quotes. | |
46 | ||
47 | For example: | |
48 | ||
49 | # dracut --add-drivers "module1 module2" ... | |
50 | ||
51 | EOF | |
52 | } | |
53 | ||
54 | long_usage() { | |
55 | [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut | |
56 | if [[ -f $dracutbasedir/dracut-version.sh ]]; then | |
57 | . $dracutbasedir/dracut-version.sh | |
58 | fi | |
59 | ||
60 | # 80x25 linebreak here ^ | |
61 | cat << EOF | |
62 | Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]] | |
dbf8f6ba HH |
63 | |
64 | Version: $DRACUT_VERSION | |
65 | ||
5616feb0 AT |
66 | Creates initial ramdisk images for preloading modules |
67 | ||
e65caf36 | 68 | --kver [VERSION] Set kernel version to [VERSION]. |
39ff0682 | 69 | -f, --force Overwrite existing initramfs file. |
54e7d7c3 | 70 | -a, --add [LIST] Add a space-separated list of dracut modules. |
659dc319 | 71 | --rebuild Append arguments to those of existing image and rebuild |
5616feb0 AT |
72 | -m, --modules [LIST] Specify a space-separated list of dracut modules to |
73 | call when building the initramfs. Modules are located | |
c5a65990 | 74 | in /usr/lib/dracut/modules.d. |
39ff0682 | 75 | -o, --omit [LIST] Omit a space-separated list of dracut modules. |
ea3c4e82 HH |
76 | --force-add [LIST] Force to add a space-separated list of dracut modules |
77 | to the default set of modules, when -H is specified. | |
5616feb0 | 78 | -d, --drivers [LIST] Specify a space-separated list of kernel modules to |
ea3c4e82 HH |
79 | exclusively include in the initramfs. |
80 | --add-drivers [LIST] Specify a space-separated list of kernel | |
81 | modules to add to the initramfs. | |
cea907f6 TR |
82 | --force-drivers [LIST] Specify a space-separated list of kernel |
83 | modules to add to the initramfs and make sure they | |
84 | are tried to be loaded via modprobe same as passing | |
85 | rd.driver.pre=DRIVER kernel parameter. | |
fcbcb252 | 86 | --omit-drivers [LIST] Specify a space-separated list of kernel |
ea3c4e82 | 87 | modules not to add to the initramfs. |
8fa510d4 | 88 | --filesystems [LIST] Specify a space-separated list of kernel filesystem |
ea3c4e82 HH |
89 | modules to exclusively include in the generic |
90 | initramfs. | |
3b403b32 | 91 | -k, --kmoddir [DIR] Specify the directory, where to look for kernel |
ea3c4e82 | 92 | modules |
3b403b32 | 93 | --fwdir [DIR] Specify additional directories, where to look for |
ea3c4e82 | 94 | firmwares, separated by : |
33ee031c HH |
95 | --kernel-only Only install kernel drivers and firmware files |
96 | --no-kernel Do not install kernel drivers and firmware files | |
1743473b | 97 | --print-cmdline Print the kernel command line for the given disk layout |
5bbfd484 | 98 | --early-microcode Combine early microcode with ramdisk |
5f2c30d9 | 99 | --no-early-microcode Do not combine early microcode with ramdisk |
d20fb951 | 100 | --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters |
54e7d7c3 | 101 | --strip Strip binaries in the initramfs |
6c128565 | 102 | --nostrip Do not strip binaries in the initramfs |
f4a94278 HH |
103 | --prelink Prelink binaries in the initramfs |
104 | --noprelink Do not prelink binaries in the initramfs | |
54e7d7c3 | 105 | --hardlink Hardlink files in the initramfs |
04d18f55 | 106 | --nohardlink Do not hardlink files in the initramfs |
fd786adc | 107 | --prefix [DIR] Prefix initramfs files with [DIR] |
54e7d7c3 | 108 | --noprefix Do not prefix initramfs files |
2f02ae9d HH |
109 | --mdadmconf Include local /etc/mdadm.conf |
110 | --nomdadmconf Do not include local /etc/mdadm.conf | |
7a34efa5 | 111 | --lvmconf Include local /etc/lvm/lvm.conf |
cc02093d | 112 | --nolvmconf Do not include local /etc/lvm/lvm.conf |
25b45979 MS |
113 | --fscks [LIST] Add a space-separated list of fsck helpers. |
114 | --nofscks Inhibit installation of any fsck helpers. | |
ff3953ef | 115 | --ro-mnt Mount / and /usr read-only by default. |
5616feb0 | 116 | -h, --help This message |
00531568 | 117 | --debug Output debug information of the build process |
57258a2c | 118 | --profile Output profile information of the build process |
e103615b AŻ |
119 | -L, --stdlog [0-6] Specify logging level (to standard error) |
120 | 0 - suppress any messages | |
121 | 1 - only fatal errors | |
122 | 2 - all errors | |
123 | 3 - warnings | |
54e7d7c3 | 124 | 4 - info |
e103615b AŻ |
125 | 5 - debug info (here starts lots of output) |
126 | 6 - trace info (and even more) | |
54e7d7c3 HH |
127 | -v, --verbose Increase verbosity level |
128 | -q, --quiet Decrease verbosity level | |
5616feb0 AT |
129 | -c, --conf [FILE] Specify configuration file to use. |
130 | Default: /etc/dracut.conf | |
3b403b32 | 131 | --confdir [DIR] Specify configuration directory to use *.conf files |
cc02093d | 132 | from. Default: /etc/dracut.conf.d |
882c4c5a AŻ |
133 | --tmpdir [DIR] Temporary directory to be used instead of default |
134 | /var/tmp. | |
5616feb0 AT |
135 | -l, --local Local mode. Use modules from the current working |
136 | directory instead of the system-wide installed in | |
c5a65990 | 137 | /usr/lib/dracut/modules.d. |
5616feb0 | 138 | Useful when running dracut from a git checkout. |
7c179686 | 139 | -H, --hostonly Host-Only mode: Install only what is needed for |
324ea606 | 140 | booting the local host instead of a generic host. |
472189da | 141 | -N, --no-hostonly Disables Host-Only mode |
ab9457ef HH |
142 | --hostonly-cmdline Store kernel command line arguments needed |
143 | in the initramfs | |
144 | --no-hostonly-cmdline Do not store kernel command line arguments needed | |
145 | in the initramfs | |
324ea606 HH |
146 | --persistent-policy [POLICY] |
147 | Use [POLICY] to address disks and partitions. | |
148 | POLICY can be any directory name found in /dev/disk. | |
149 | E.g. "by-uuid", "by-label" | |
7c179686 | 150 | --fstab Use /etc/fstab to determine the root device. |
70cb8a68 HH |
151 | --add-fstab [FILE] Add file to the initramfs fstab |
152 | --mount "[DEV] [MP] [FSTYPE] [FSOPTS]" | |
153 | Mount device [DEV] on mountpoint [MP] with filesystem | |
154 | [FSTYPE] and options [FSOPTS] in the initramfs | |
c586b033 | 155 | --add-device "[DEV]" Bring up [DEV] in initramfs |
5616feb0 | 156 | -i, --include [SOURCE] [TARGET] |
39ff0682 AT |
157 | Include the files in the SOURCE directory into the |
158 | Target directory in the final initramfs. | |
3b403b32 | 159 | If SOURCE is a file, it will be installed to TARGET |
4fea3ea6 | 160 | in the final initramfs. |
39ff0682 AT |
161 | -I, --install [LIST] Install the space separated list of files into the |
162 | initramfs. | |
54b68829 HH |
163 | --install-optional [LIST] Install the space separated list of files into the |
164 | initramfs, if they exist. | |
5b158ad3 | 165 | --gzip Compress the generated initramfs using gzip. |
cc02093d HH |
166 | This will be done by default, unless another |
167 | compression option or --no-compress is passed. | |
5b158ad3 | 168 | --bzip2 Compress the generated initramfs using bzip2. |
cc02093d HH |
169 | Make sure your kernel has bzip2 decompression support |
170 | compiled in, otherwise you will not be able to boot. | |
171 | --lzma Compress the generated initramfs using lzma. | |
3b403b32 | 172 | Make sure your kernel has lzma support compiled in, |
cc02093d | 173 | otherwise you will not be able to boot. |
5e6c3b03 VL |
174 | --xz Compress the generated initramfs using xz. |
175 | Make sure that your kernel has xz support compiled | |
176 | in, otherwise you will not be able to boot. | |
37383f71 | 177 | --lzo Compress the generated initramfs using lzop. |
871c8e40 | 178 | Make sure that your kernel has lzo support compiled |
179 | in, otherwise you will not be able to boot. | |
37383f71 | 180 | --lz4 Compress the generated initramfs using lz4. |
871c8e40 | 181 | Make sure that your kernel has lz4 support compiled |
182 | in, otherwise you will not be able to boot. | |
5e6c3b03 VL |
183 | --compress [COMPRESSION] Compress the generated initramfs with the |
184 | passed compression program. Make sure your kernel | |
3b403b32 | 185 | knows how to decompress the generated initramfs, |
5e6c3b03 | 186 | otherwise you will not be able to boot. |
5b158ad3 | 187 | --no-compress Do not compress the generated initramfs. This will |
cc02093d | 188 | override any other compression options. |
5b11bb73 | 189 | --list-modules List all available dracut modules. |
956af8f2 AŻ |
190 | -M, --show-modules Print included module's name to standard output during |
191 | build. | |
5fe5c7d0 | 192 | --keep Keep the temporary initramfs for debugging purposes |
ec3c5951 | 193 | --printsize Print out the module install size |
cdfeb278 | 194 | --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module) |
ee54b840 | 195 | --logfile [FILE] Logfile to use (overrides configuration setting) |
80626ded | 196 | --reproducible Create reproducible images |
37383f71 | 197 | --loginstall [DIR] Log all files installed from the host to [DIR] |
ccaa9bee HH |
198 | |
199 | If [LIST] has multiple arguments, then you have to put these in quotes. | |
ffa71b4a | 200 | |
ccaa9bee | 201 | For example: |
ffa71b4a HH |
202 | |
203 | # dracut --add-drivers "module1 module2" ... | |
204 | ||
cc02093d | 205 | EOF |
5616feb0 AT |
206 | } |
207 | ||
8466db96 HH |
208 | # function push() |
209 | # push values to a stack | |
210 | # $1 = stack variable | |
211 | # $2.. values | |
212 | # example: | |
213 | # push stack 1 2 "3 4" | |
214 | push() { | |
ffa71b4a | 215 | local _i |
8466db96 | 216 | local __stack=$1; shift |
ffa71b4a HH |
217 | for _i in "$@"; do |
218 | eval ${__stack}'[${#'${__stack}'[@]}]="$_i"' | |
8466db96 HH |
219 | done |
220 | } | |
221 | ||
118ca9ec TR |
222 | # Fills up host_devs stack variable and makes sure there are no duplicates |
223 | push_host_devs() { | |
224 | local _dev | |
225 | for _dev in ${host_devs[@]}; do | |
226 | [ "$_dev" = "$1" ] && return | |
227 | done | |
228 | push host_devs "$1" | |
229 | } | |
230 | ||
231 | ||
8466db96 HH |
232 | # function pop() |
233 | # pops the last value from a stack | |
234 | # assigns value to second argument variable | |
235 | # or echo to stdout, if no second argument | |
236 | # $1 = stack variable | |
237 | # $2 = optional variable to store the value | |
238 | # example: | |
239 | # pop stack val | |
240 | # val=$(pop stack) | |
241 | pop() { | |
242 | local __stack=$1; shift | |
3b403b32 | 243 | local __resultvar=$1 |
ffa71b4a | 244 | local _value; |
8466db96 HH |
245 | # check for empty stack |
246 | eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1' | |
247 | ||
ffa71b4a | 248 | eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}' |
8466db96 HH |
249 | |
250 | if [[ "$__resultvar" ]]; then | |
ffa71b4a | 251 | eval $__resultvar="'$_value'" |
8466db96 | 252 | else |
b093aa2d | 253 | printf "%s" "$_value" |
8466db96 HH |
254 | fi |
255 | eval unset ${__stack}'[${#'${__stack}'[@]}-1]' | |
256 | return 0 | |
257 | } | |
258 | ||
5bc545ed VL |
259 | # Little helper function for reading args from the commandline. |
260 | # it automatically handles -a b and -a=b variants, and returns 1 if | |
261 | # we need to shift $3. | |
262 | read_arg() { | |
263 | # $1 = arg name | |
264 | # $2 = arg value | |
265 | # $3 = arg parameter | |
266 | local rematch='^[^=]*=(.*)$' | |
267 | if [[ $2 =~ $rematch ]]; then | |
cc02093d | 268 | read "$1" <<< "${BASH_REMATCH[1]}" |
5bc545ed | 269 | else |
cc02093d HH |
270 | read "$1" <<< "$3" |
271 | # There is no way to shift our callers args, so | |
272 | # return 1 to indicate they should do it instead. | |
273 | return 1 | |
5bc545ed VL |
274 | fi |
275 | } | |
276 | ||
335bc217 | 277 | dropindirs_sort() |
a42b2b81 | 278 | { |
b093aa2d HH |
279 | local suffix=$1; shift |
280 | local -a files | |
281 | local f d | |
282 | ||
dba20559 HH |
283 | for d in "$@"; do |
284 | for i in "$d/"*"$suffix"; do | |
285 | if [[ -e "$i" ]]; then | |
286 | printf "%s\n" "${i##*/}" | |
287 | fi | |
288 | done | |
289 | done | sort -Vu | { | |
290 | readarray -t files | |
291 | ||
292 | for f in "${files[@]}"; do | |
293 | for d in "$@"; do | |
294 | if [[ -e "$d/$f" ]]; then | |
295 | printf "%s\n" "$d/$f" | |
296 | continue 2 | |
b093aa2d | 297 | fi |
a42b2b81 | 298 | done |
a42b2b81 | 299 | done |
dba20559 | 300 | } |
a42b2b81 HH |
301 | } |
302 | ||
659dc319 HB |
303 | rearrange_params() |
304 | { | |
305 | # Workaround -i, --include taking 2 arguments | |
306 | set -- "${@/--include/++include}" | |
307 | ||
308 | # This prevents any long argument ending with "-i" | |
309 | # -i, like --opt-i but I think we can just prevent that | |
310 | set -- "${@/%-i/++include}" | |
311 | ||
312 | TEMP=$(unset POSIXLY_CORRECT; getopt \ | |
313 | -o "a:m:o:d:I:k:c:L:fvqlHhMN" \ | |
314 | --long kver: \ | |
315 | --long add: \ | |
316 | --long force-add: \ | |
317 | --long add-drivers: \ | |
cea907f6 | 318 | --long force-drivers: \ |
659dc319 HB |
319 | --long omit-drivers: \ |
320 | --long modules: \ | |
321 | --long omit: \ | |
322 | --long drivers: \ | |
323 | --long filesystems: \ | |
324 | --long install: \ | |
54b68829 | 325 | --long install-optional: \ |
659dc319 HB |
326 | --long fwdir: \ |
327 | --long libdirs: \ | |
328 | --long fscks: \ | |
329 | --long add-fstab: \ | |
330 | --long mount: \ | |
331 | --long device: \ | |
332 | --long add-device: \ | |
333 | --long nofscks: \ | |
334 | --long ro-mnt \ | |
335 | --long kmoddir: \ | |
336 | --long conf: \ | |
337 | --long confdir: \ | |
338 | --long tmpdir: \ | |
339 | --long stdlog: \ | |
340 | --long compress: \ | |
341 | --long prefix: \ | |
342 | --long rebuild: \ | |
343 | --long force \ | |
344 | --long kernel-only \ | |
345 | --long no-kernel \ | |
346 | --long print-cmdline \ | |
347 | --long kernel-cmdline: \ | |
348 | --long strip \ | |
349 | --long nostrip \ | |
350 | --long prelink \ | |
351 | --long noprelink \ | |
352 | --long hardlink \ | |
353 | --long nohardlink \ | |
354 | --long noprefix \ | |
355 | --long mdadmconf \ | |
356 | --long nomdadmconf \ | |
357 | --long lvmconf \ | |
358 | --long nolvmconf \ | |
359 | --long debug \ | |
360 | --long profile \ | |
361 | --long sshkey: \ | |
362 | --long logfile: \ | |
363 | --long verbose \ | |
364 | --long quiet \ | |
365 | --long local \ | |
366 | --long hostonly \ | |
367 | --long host-only \ | |
368 | --long no-hostonly \ | |
369 | --long no-host-only \ | |
646e0506 WC |
370 | --long hostonly-cmdline \ |
371 | --long no-hostonly-cmdline \ | |
659dc319 HB |
372 | --long persistent-policy: \ |
373 | --long fstab \ | |
374 | --long help \ | |
375 | --long bzip2 \ | |
376 | --long lzma \ | |
377 | --long xz \ | |
378 | --long lzo \ | |
379 | --long lz4 \ | |
380 | --long no-compress \ | |
381 | --long gzip \ | |
382 | --long list-modules \ | |
383 | --long show-modules \ | |
384 | --long keep \ | |
385 | --long printsize \ | |
386 | --long regenerate-all \ | |
387 | --long noimageifnotneeded \ | |
388 | --long early-microcode \ | |
389 | --long no-early-microcode \ | |
80626ded | 390 | --long reproducible \ |
37383f71 | 391 | --long loginstall: \ |
659dc319 HB |
392 | -- "$@") |
393 | ||
394 | if (( $? != 0 )); then | |
395 | usage | |
396 | exit 1 | |
397 | fi | |
398 | } | |
399 | ||
432196ae | 400 | verbosity_mod_l=0 |
f79e587c HH |
401 | unset kernel |
402 | unset outfile | |
486a1b93 | 403 | |
659dc319 HB |
404 | rearrange_params "$@" |
405 | eval set -- "$TEMP" | |
406 | ||
407 | # parse command line args to check if '--rebuild' option is present | |
408 | unset append_args_l | |
409 | unset rebuild_file | |
410 | while : | |
411 | do | |
412 | if [ "$1" == "--" ]; then | |
413 | shift; break | |
414 | fi | |
415 | if [ "$1" == "--rebuild" ]; then | |
416 | append_args_l="yes" | |
417 | rebuild_file=$2 | |
418 | if [ ! -e $rebuild_file ]; then | |
419 | echo "Image file '$rebuild_file', for rebuild, does not exist!" | |
420 | exit 1 | |
421 | fi | |
422 | abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file" | |
423 | shift; continue | |
424 | fi | |
425 | shift | |
426 | done | |
427 | ||
428 | # get output file name and kernel version from command line arguments | |
429 | while (($# > 0)); do | |
430 | case ${1%%=*} in | |
431 | ++include) | |
432 | shift 2;; | |
433 | *) | |
434 | if ! [[ ${outfile+x} ]]; then | |
435 | outfile=$1 | |
436 | elif ! [[ ${kernel+x} ]]; then | |
437 | kernel=$1 | |
438 | else | |
439 | printf "\nUnknown arguments: %s\n\n" "$*" >&2 | |
440 | usage; exit 1; | |
441 | fi | |
442 | ;; | |
443 | esac | |
444 | shift | |
445 | done | |
446 | ||
447 | # extract input image file provided with rebuild option to get previous parameters, if any | |
448 | if [[ $append_args_l == "yes" ]]; then | |
449 | unset rebuild_param | |
450 | ||
451 | # determine resultant file | |
452 | if ! [[ $outfile ]]; then | |
453 | outfile=$rebuild_file | |
454 | fi | |
455 | ||
456 | if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then | |
457 | echo "Image '$rebuild_file' has no rebuild information stored" | |
458 | exit 1 | |
459 | fi | |
460 | ||
461 | # prepend previous parameters to current command line args | |
462 | if [[ $rebuild_param ]]; then | |
463 | TEMP="$rebuild_param $TEMP" | |
464 | eval set -- "$TEMP" | |
465 | rearrange_params "$@" | |
466 | fi | |
467 | ||
468 | # clean the temporarily used scratch-pad directory | |
469 | rm -rf $scratch_dir | |
ffa71b4a HH |
470 | fi |
471 | ||
659dc319 HB |
472 | unset PARMS_TO_STORE |
473 | PARMS_TO_STORE="" | |
474 | ||
ffa71b4a HH |
475 | eval set -- "$TEMP" |
476 | ||
477 | while :; do | |
659dc319 HB |
478 | if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then |
479 | PARMS_TO_STORE+=" $1"; | |
480 | fi | |
ffa71b4a | 481 | case $1 in |
659dc319 HB |
482 | --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
483 | -a|--add) push add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
484 | --force-add) push force_add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
485 | --add-drivers) push add_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
cea907f6 | 486 | --force-drivers) push force_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
659dc319 HB |
487 | --omit-drivers) push omit_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
488 | -m|--modules) push dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
489 | -o|--omit) push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
490 | -d|--drivers) push drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
491 | --filesystems) push filesystems_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
492 | -I|--install) push install_items_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
54b68829 HH |
493 | --install-optional) |
494 | push install_optional_items_l \ | |
495 | "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
659dc319 HB |
496 | --fwdir) push fw_dir_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
497 | --libdirs) push libdirs_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
498 | --fscks) push fscks_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
499 | --add-fstab) push add_fstab_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
500 | --mount) push fstab_lines "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
c586b033 | 501 | --add-device|--device) |
659dc319 HB |
502 | push add_device_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
503 | --kernel-cmdline) push kernel_cmdline_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
25b45979 | 504 | --nofscks) nofscks_l="yes";; |
ff3953ef | 505 | --ro-mnt) ro_mnt_l="yes";; |
659dc319 HB |
506 | -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
507 | -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
508 | --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
509 | --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
510 | -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
511 | --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
512 | --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; | |
37383f71 | 513 | --loginstall) loginstall_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
659dc319 HB |
514 | --rebuild) if [ $rebuild_file == $outfile ]; then |
515 | force=yes | |
516 | fi | |
517 | shift | |
518 | ;; | |
cc02093d HH |
519 | -f|--force) force=yes;; |
520 | --kernel-only) kernel_only="yes"; no_kernel="no";; | |
521 | --no-kernel) kernel_only="no"; no_kernel="yes";; | |
ab9457ef HH |
522 | --print-cmdline) |
523 | print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";; | |
524 | --early-microcode) | |
525 | early_microcode_l="yes";; | |
526 | --no-early-microcode) | |
527 | early_microcode_l="no";; | |
cc02093d HH |
528 | --strip) do_strip_l="yes";; |
529 | --nostrip) do_strip_l="no";; | |
f4a94278 HH |
530 | --prelink) do_prelink_l="yes";; |
531 | --noprelink) do_prelink_l="no";; | |
04d18f55 HH |
532 | --hardlink) do_hardlink_l="yes";; |
533 | --nohardlink) do_hardlink_l="no";; | |
fd786adc | 534 | --noprefix) prefix_l="/";; |
690396a5 VL |
535 | --mdadmconf) mdadmconf_l="yes";; |
536 | --nomdadmconf) mdadmconf_l="no";; | |
537 | --lvmconf) lvmconf_l="yes";; | |
538 | --nolvmconf) lvmconf_l="no";; | |
cc02093d | 539 | --debug) debug="yes";; |
57258a2c | 540 | --profile) profile="yes";; |
659dc319 | 541 | --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
ee54b840 | 542 | --logfile) logfile_l="$2"; shift;; |
432196ae AŻ |
543 | -v|--verbose) ((verbosity_mod_l++));; |
544 | -q|--quiet) ((verbosity_mod_l--));; | |
dbf8f6ba HH |
545 | -l|--local) |
546 | allowlocal="yes" | |
b093aa2d HH |
547 | [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \ |
548 | && dracutbasedir="$(readlink -f "${0%/*}")" | |
dbf8f6ba | 549 | ;; |
ea3c4e82 HH |
550 | -H|--hostonly|--host-only) |
551 | hostonly_l="yes" ;; | |
552 | -N|--no-hostonly|--no-host-only) | |
553 | hostonly_l="no" ;; | |
ab9457ef HH |
554 | --hostonly-cmdline) |
555 | hostonly_cmdline_l="yes" ;; | |
556 | --no-hostonly-cmdline) | |
557 | hostonly_cmdline_l="no" ;; | |
324ea606 | 558 | --persistent-policy) |
659dc319 | 559 | persistent_policy_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; |
cc02093d | 560 | --fstab) use_fstab_l="yes" ;; |
ffa71b4a | 561 | -h|--help) long_usage; exit 1 ;; |
659dc319 | 562 | -i|--include) push include_src "$2"; PARMS_TO_STORE+=" '$2'"; |
ffa71b4a | 563 | shift;; |
3a714439 VL |
564 | --bzip2) compress_l="bzip2";; |
565 | --lzma) compress_l="lzma";; | |
566 | --xz) compress_l="xz";; | |
871c8e40 | 567 | --lzo) compress_l="lzo";; |
568 | --lz4) compress_l="lz4";; | |
3a714439 VL |
569 | --no-compress) _no_compress_l="cat";; |
570 | --gzip) compress_l="gzip";; | |
ffa71b4a | 571 | --list-modules) do_list="yes";; |
956af8f2 AŻ |
572 | -M|--show-modules) |
573 | show_modules_l="yes" | |
574 | ;; | |
5fe5c7d0 | 575 | --keep) keep="yes";; |
ec3c5951 | 576 | --printsize) printsize="yes";; |
7d848c55 | 577 | --regenerate-all) regenerate_all="yes";; |
83bb0893 | 578 | --noimageifnotneeded) noimageifnotneeded="yes";; |
80626ded | 579 | --reproducible) reproducible_l="yes";; |
ffa71b4a HH |
580 | --) shift; break;; |
581 | ||
582 | *) # should not even reach this point | |
583 | printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;; | |
584 | esac | |
585 | shift | |
586 | done | |
587 | ||
588 | # getopt cannot handle multiple arguments, so just handle "-I,--include" | |
589 | # the old fashioned way | |
590 | ||
591 | while (($# > 0)); do | |
4eec1a22 | 592 | if [ "${1%%=*}" == "++include" ]; then |
659dc319 HB |
593 | push include_src "$2" |
594 | push include_target "$3" | |
595 | PARMS_TO_STORE+=" --include '$2' '$3'" | |
596 | shift 2 | |
597 | fi | |
b368a5f3 | 598 | shift |
641cc356 | 599 | done |
ffa71b4a | 600 | |
7d848c55 HH |
601 | if [[ $regenerate_all == "yes" ]]; then |
602 | ret=0 | |
603 | if [[ $kernel ]]; then | |
b093aa2d | 604 | printf -- "--regenerate-all cannot be called with a kernel version\n" >&2 |
7d848c55 HH |
605 | exit 1 |
606 | fi | |
607 | ||
608 | if [[ $outfile ]]; then | |
b093aa2d | 609 | printf -- "--regenerate-all cannot be called with a image file\n" >&2 |
7d848c55 HH |
610 | exit 1 |
611 | fi | |
612 | ||
613 | ((len=${#dracut_args[@]})) | |
614 | for ((i=0; i < len; i++)); do | |
615 | [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \ | |
616 | unset dracut_args[$i] | |
617 | done | |
618 | ||
619 | cd /lib/modules | |
620 | for i in *; do | |
b29cb516 | 621 | [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue |
b093aa2d | 622 | dracut --kver="$i" "${dracut_args[@]}" |
7d848c55 HH |
623 | ((ret+=$?)) |
624 | done | |
625 | exit $ret | |
626 | fi | |
627 | ||
8a5354a9 | 628 | if ! [[ $kernel ]]; then |
486a1b93 HH |
629 | kernel=$(uname -r) |
630 | fi | |
ffa71b4a | 631 | |
05214a0b HH |
632 | if [[ $kernel ]]; then |
633 | if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then | |
634 | printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2 | |
635 | fi | |
636 | fi | |
637 | ||
ffa71b4a | 638 | if ! [[ $outfile ]]; then |
cc230300 HH |
639 | [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id |
640 | ||
641 | if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then | |
642 | outfile="/boot/${MACHINE_ID}/$kernel/initrd" | |
643 | else | |
644 | outfile="/boot/initramfs-$kernel.img" | |
645 | fi | |
ffa71b4a | 646 | fi |
4cba351e | 647 | |
02b5c8e3 HH |
648 | unset LC_MESSAGES |
649 | unset LC_CTYPE | |
650 | export LC_ALL=C | |
651 | export LANG=C | |
d619fb5e | 652 | unset LD_LIBRARY_PATH |
45404a2a | 653 | unset LD_PRELOAD |
1fcf2d2f | 654 | unset GREP_OPTIONS |
a55711cd | 655 | |
89d44e72 | 656 | export DRACUT_LOG_LEVEL=warning |
3b403b32 | 657 | [[ $debug ]] && { |
89d44e72 | 658 | export DRACUT_LOG_LEVEL=debug |
c36ce334 VL |
659 | export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '; |
660 | set -x | |
661 | } | |
662 | ||
57258a2c HH |
663 | [[ $profile ]] && { |
664 | export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '; | |
665 | set -x | |
666 | debug=yes | |
667 | } | |
668 | ||
c5a65990 | 669 | [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut |
5d791c0e | 670 | |
f1336ac7 | 671 | # if we were not passed a config file, try the default one |
42c71947 | 672 | if [[ ! -f $conffile ]]; then |
b093aa2d HH |
673 | if [[ $allowlocal ]]; then |
674 | conffile="$dracutbasedir/dracut.conf" | |
675 | else | |
eebc929a | 676 | conffile="/etc/dracut.conf" |
b093aa2d | 677 | fi |
42c71947 | 678 | fi |
f1336ac7 | 679 | |
2c2c4580 | 680 | if [[ ! -d $confdir ]]; then |
b093aa2d HH |
681 | if [[ $allowlocal ]]; then |
682 | confdir="$dracutbasedir/dracut.conf.d" | |
683 | else | |
eebc929a | 684 | confdir="/etc/dracut.conf.d" |
b093aa2d | 685 | fi |
2c2c4580 HH |
686 | fi |
687 | ||
2245f372 AB |
688 | # source our config file |
689 | [[ -f $conffile ]] && . "$conffile" | |
690 | ||
2c2c4580 | 691 | # source our config dir |
335bc217 | 692 | for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do |
a42b2b81 HH |
693 | [[ -e $f ]] && . "$f" |
694 | done | |
2c2c4580 | 695 | |
5f2baf7d | 696 | DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin} |
eab9b75c HH |
697 | |
698 | for i in $DRACUT_PATH; do | |
699 | rl=$i | |
700 | if [ -L "$i" ]; then | |
701 | rl=$(readlink -f $i) | |
702 | fi | |
703 | if [[ "$NPATH" != *:$rl* ]] ; then | |
704 | NPATH+=":$rl" | |
705 | fi | |
706 | done | |
707 | export PATH="${NPATH#:}" | |
708 | unset NPATH | |
709 | ||
d87c2708 | 710 | # these optins add to the stuff in the config file |
e5e5c895 | 711 | if (( ${#add_dracutmodules_l[@]} )); then |
661f9a34 HH |
712 | while pop add_dracutmodules_l val; do |
713 | add_dracutmodules+=" $val " | |
714 | done | |
715 | fi | |
716 | ||
31f1c02d AW |
717 | if (( ${#force_add_dracutmodules_l[@]} )); then |
718 | while pop force_add_dracutmodules_l val; do | |
719 | force_add_dracutmodules+=" $val " | |
720 | done | |
721 | fi | |
722 | ||
25b45979 MS |
723 | if (( ${#fscks_l[@]} )); then |
724 | while pop fscks_l val; do | |
725 | fscks+=" $val " | |
726 | done | |
727 | fi | |
728 | ||
70cb8a68 HH |
729 | if (( ${#add_fstab_l[@]} )); then |
730 | while pop add_fstab_l val; do | |
731 | add_fstab+=" $val " | |
732 | done | |
733 | fi | |
734 | ||
735 | if (( ${#fstab_lines_l[@]} )); then | |
736 | while pop fstab_lines_l val; do | |
737 | push fstab_lines $val | |
738 | done | |
739 | fi | |
740 | ||
0ec40e08 HH |
741 | if (( ${#install_items_l[@]} )); then |
742 | while pop install_items_l val; do | |
c6c6a088 | 743 | install_items+=" $val " |
0ec40e08 HH |
744 | done |
745 | fi | |
746 | ||
54b68829 HH |
747 | if (( ${#install_optional_items_l[@]} )); then |
748 | while pop install_optional_items_l val; do | |
749 | install_optional_items+=" $val " | |
750 | done | |
751 | fi | |
752 | ||
f1336ac7 | 753 | # these options override the stuff in the config file |
e5e5c895 | 754 | if (( ${#dracutmodules_l[@]} )); then |
661f9a34 HH |
755 | dracutmodules='' |
756 | while pop dracutmodules_l val; do | |
757 | dracutmodules+="$val " | |
758 | done | |
759 | fi | |
760 | ||
e5e5c895 | 761 | if (( ${#omit_dracutmodules_l[@]} )); then |
661f9a34 HH |
762 | omit_dracutmodules='' |
763 | while pop omit_dracutmodules_l val; do | |
764 | omit_dracutmodules+="$val " | |
765 | done | |
766 | fi | |
767 | ||
e5e5c895 | 768 | if (( ${#filesystems_l[@]} )); then |
661f9a34 HH |
769 | filesystems='' |
770 | while pop filesystems_l val; do | |
771 | filesystems+="$val " | |
772 | done | |
773 | fi | |
774 | ||
e5e5c895 | 775 | if (( ${#fw_dir_l[@]} )); then |
661f9a34 HH |
776 | fw_dir='' |
777 | while pop fw_dir_l val; do | |
778 | fw_dir+="$val " | |
779 | done | |
780 | fi | |
781 | ||
c9143a63 JAH |
782 | if (( ${#libdirs_l[@]} )); then |
783 | libdirs='' | |
784 | while pop libdirs_l val; do | |
785 | libdirs+="$val " | |
786 | done | |
787 | fi | |
788 | ||
e103615b | 789 | [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l |
b991617f | 790 | [[ ! $stdloglvl ]] && stdloglvl=4 |
432196ae AŻ |
791 | stdloglvl=$((stdloglvl + verbosity_mod_l)) |
792 | ((stdloglvl > 6)) && stdloglvl=6 | |
793 | ((stdloglvl < 0)) && stdloglvl=0 | |
794 | ||
26537a5b | 795 | [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l |
31f7db66 | 796 | [[ $do_strip_l ]] && do_strip=$do_strip_l |
6c128565 | 797 | [[ $do_strip ]] || do_strip=yes |
f4a94278 HH |
798 | [[ $do_prelink_l ]] && do_prelink=$do_prelink_l |
799 | [[ $do_prelink ]] || do_prelink=yes | |
04d18f55 HH |
800 | [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l |
801 | [[ $do_hardlink ]] || do_hardlink=yes | |
fd786adc HH |
802 | [[ $prefix_l ]] && prefix=$prefix_l |
803 | [[ $prefix = "/" ]] && unset prefix | |
ba726310 | 804 | [[ $hostonly_l ]] && hostonly=$hostonly_l |
ab9457ef | 805 | [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l |
30f6c80d | 806 | [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes" |
3411ad66 | 807 | [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l |
7c179686 | 808 | [[ $use_fstab_l ]] && use_fstab=$use_fstab_l |
2f02ae9d | 809 | [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l |
7a34efa5 | 810 | [[ $lvmconf_l ]] && lvmconf=$lvmconf_l |
c5a65990 | 811 | [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut |
8bc650d9 | 812 | [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware" |
882c4c5a AŻ |
813 | [[ $tmpdir_l ]] && tmpdir="$tmpdir_l" |
814 | [[ $tmpdir ]] || tmpdir=/var/tmp | |
871c8e40 | 815 | [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS |
3a714439 | 816 | [[ $compress_l ]] && compress=$compress_l |
956af8f2 | 817 | [[ $show_modules_l ]] && show_modules=$show_modules_l |
25b45979 | 818 | [[ $nofscks_l ]] && nofscks="yes" |
ff3953ef | 819 | [[ $ro_mnt_l ]] && ro_mnt="yes" |
b7c770e1 DS |
820 | [[ $early_microcode_l ]] && early_microcode=$early_microcode_l |
821 | [[ $early_microcode ]] || early_microcode=no | |
ee54b840 | 822 | [[ $logfile_l ]] && logfile="$logfile_l" |
80626ded | 823 | [[ $reproducible_l ]] && reproducible="$reproducible_l" |
37383f71 | 824 | [[ $loginstall_l ]] && loginstall="$loginstall_l" |
80626ded | 825 | |
ddfd1d10 VL |
826 | # eliminate IFS hackery when messing with fw_dir |
827 | fw_dir=${fw_dir//:/ } | |
9a8a00cf | 828 | |
3838dc47 | 829 | # check for logfile and try to create one if it doesn't exist |
830 | if [[ -n "$logfile" ]];then | |
831 | if [[ ! -f "$logfile" ]];then | |
832 | touch "$logfile" | |
833 | if [ ! $? -eq 0 ] ;then | |
834 | printf "%s\n" "dracut: touch $logfile failed." >&2 | |
835 | fi | |
836 | fi | |
837 | fi | |
838 | ||
3a714439 | 839 | # handle compression options. |
55468fb9 | 840 | [[ $compress ]] || compress="gzip" |
3a714439 | 841 | case $compress in |
6f223367 | 842 | bzip2) compress="bzip2 -9";; |
a76a22b7 KK |
843 | lzma) compress="lzma -9 -T0";; |
844 | xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";; | |
66fd7e43 HH |
845 | gzip) compress="gzip -n -9"; |
846 | if command -v pigz > /dev/null 2>&1; then | |
847 | compress="pigz -9 -n -T -R" | |
848 | elif command -v gzip --help 2>&1 | grep -q rsyncable; then | |
849 | compress="gzip -n -9 --rsyncable" | |
850 | fi | |
851 | ;; | |
871c8e40 | 852 | lzo) compress="lzop -9";; |
8a2db478 | 853 | lz4) compress="lz4 -l -9";; |
3a714439 VL |
854 | esac |
855 | if [[ $_no_compress_l = "cat" ]]; then | |
856 | compress="cat" | |
857 | fi | |
858 | ||
ba726310 | 859 | [[ $hostonly = yes ]] && hostonly="-h" |
ba67b923 | 860 | [[ $hostonly != "-h" ]] && unset hostonly |
ba726310 | 861 | |
80626ded HH |
862 | [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1 |
863 | ||
26c231f1 | 864 | readonly TMPDIR="$tmpdir" |
b093aa2d | 865 | readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)" |
26c231f1 | 866 | [ -d "$initdir" ] || { |
f49ec88a | 867 | printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2 |
26c231f1 HH |
868 | exit 1 |
869 | } | |
870 | ||
cd08059f | 871 | if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then |
b5b608e4 TR |
872 | readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)" |
873 | [ -d "$early_cpio_dir" ] || { | |
f49ec88a | 874 | printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2 |
5f2c30d9 KRW |
875 | exit 1 |
876 | } | |
877 | fi | |
d008b6b8 | 878 | # clean up after ourselves no matter how we die. |
bbaa0d59 HH |
879 | trap ' |
880 | ret=$?; | |
bbaa0d59 | 881 | [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; }; |
b5b608e4 | 882 | [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; }; |
bbaa0d59 HH |
883 | [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir"; |
884 | exit $ret; | |
885 | ' EXIT | |
886 | ||
d008b6b8 HH |
887 | # clean up after ourselves no matter how we die. |
888 | trap 'exit 1;' SIGINT | |
889 | ||
89d44e72 HH |
890 | export DRACUT_KERNEL_LAZY="1" |
891 | export DRACUT_RESOLVE_LAZY="1" | |
892 | ||
535f61ca HH |
893 | if [[ $print_cmdline ]]; then |
894 | stdloglvl=0 | |
895 | sysloglvl=0 | |
896 | fileloglvl=0 | |
897 | kmsgloglvl=0 | |
898 | fi | |
899 | ||
e27ecc9a HH |
900 | if [[ -f $dracutbasedir/dracut-version.sh ]]; then |
901 | . $dracutbasedir/dracut-version.sh | |
902 | fi | |
903 | ||
552ecca6 HH |
904 | if [[ -f $dracutbasedir/dracut-functions.sh ]]; then |
905 | . $dracutbasedir/dracut-functions.sh | |
adbc8a42 | 906 | else |
b093aa2d HH |
907 | printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2 |
908 | printf "%s\n" "dracut: Are you running from a git checkout?" >&2 | |
909 | printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2 | |
cc02093d | 910 | exit 1 |
adbc8a42 | 911 | fi |
22fd1627 | 912 | |
1743473b HH |
913 | if ! [[ $print_cmdline ]]; then |
914 | inst /bin/sh | |
ffc68f35 | 915 | if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then |
1743473b HH |
916 | unset DRACUT_RESOLVE_LAZY |
917 | export DRACUT_RESOLVE_DEPS=1 | |
918 | fi | |
919 | rm -fr -- ${initdir}/* | |
bfd2e8c2 | 920 | fi |
bfd2e8c2 | 921 | |
bfd2e8c2 | 922 | # Verify bash version, current minimum is 3.1 |
b093aa2d HH |
923 | if (( BASH_VERSINFO[0] < 4 )); then |
924 | dfatal 'You need at least Bash 4 to use dracut, sorry.' | |
d239b550 MS |
925 | exit 1 |
926 | fi | |
927 | ||
552ecca6 | 928 | dracutfunctions=$dracutbasedir/dracut-functions.sh |
5cad5bb5 | 929 | export dracutfunctions |
9a8a00cf | 930 | |
fcbcb252 HH |
931 | if (( ${#drivers_l[@]} )); then |
932 | drivers='' | |
933 | while pop drivers_l val; do | |
934 | drivers+="$val " | |
935 | done | |
936 | fi | |
937 | drivers=${drivers/-/_} | |
938 | ||
939 | if (( ${#add_drivers_l[@]} )); then | |
940 | while pop add_drivers_l val; do | |
941 | add_drivers+=" $val " | |
942 | done | |
943 | fi | |
944 | add_drivers=${add_drivers/-/_} | |
945 | ||
cea907f6 TR |
946 | if (( ${#force_drivers_l[@]} )); then |
947 | while pop force_drivers_l val; do | |
948 | force_drivers+=" $val " | |
949 | done | |
950 | fi | |
951 | force_drivers=${force_drivers/-/_} | |
952 | ||
fcbcb252 HH |
953 | if (( ${#omit_drivers_l[@]} )); then |
954 | while pop omit_drivers_l val; do | |
955 | omit_drivers+=" $val " | |
956 | done | |
957 | fi | |
958 | omit_drivers=${omit_drivers/-/_} | |
959 | ||
d20fb951 HH |
960 | if (( ${#kernel_cmdline_l[@]} )); then |
961 | while pop kernel_cmdline_l val; do | |
962 | kernel_cmdline+=" $val " | |
963 | done | |
964 | fi | |
965 | ||
34248c92 | 966 | omit_drivers_corrected="" |
fcbcb252 | 967 | for d in $omit_drivers; do |
b093aa2d | 968 | [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue |
cea907f6 | 969 | [[ " $drivers $force_drivers " == *\ $d\ * ]] && continue |
34248c92 | 970 | omit_drivers_corrected+="$d|" |
fcbcb252 | 971 | done |
34248c92 | 972 | omit_drivers="${omit_drivers_corrected%|}" |
fcbcb252 HH |
973 | unset omit_drivers_corrected |
974 | ||
ffa71b4a HH |
975 | # prepare args for logging |
976 | for ((i=0; i < ${#dracut_args[@]}; i++)); do | |
b093aa2d | 977 | [[ "${dracut_args[$i]}" == *\ * ]] && \ |
ffa71b4a | 978 | dracut_args[$i]="\"${dracut_args[$i]}\"" |
a4210166 | 979 | #" keep vim happy |
ffa71b4a | 980 | done |
535f61ca | 981 | |
bbaa0d59 | 982 | dinfo "Executing: $0 ${dracut_args[@]}" |
58dad702 | 983 | |
5b11bb73 HH |
984 | [[ $do_list = yes ]] && { |
985 | for mod in $dracutbasedir/modules.d/*; do | |
986 | [[ -d $mod ]] || continue; | |
d8e8e14e AŻ |
987 | [[ -e $mod/install || -e $mod/installkernel || \ |
988 | -e $mod/module-setup.sh ]] || continue | |
b093aa2d | 989 | printf "%s\n" "${mod##*/??}" |
5b11bb73 HH |
990 | done |
991 | exit 0 | |
992 | } | |
993 | ||
66ac3cd1 | 994 | # This is kinda legacy -- eventually it should go away. |
f1336ac7 | 995 | case $dracutmodules in |
66ac3cd1 | 996 | ""|auto) dracutmodules="all" ;; |
f1336ac7 | 997 | esac |
e12aac5e | 998 | |
454771cd | 999 | abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile" |
ec9315e5 | 1000 | |
5db6ca5a HH |
1001 | if [[ -d $srcmods ]]; then |
1002 | [[ -f $srcmods/modules.dep ]] || { | |
1003 | dwarn "$srcmods/modules.dep is missing. Did you run depmod?" | |
1004 | } | |
1005 | fi | |
fe1484f3 | 1006 | |
96cf7270 HH |
1007 | if [[ ! $print_cmdline ]]; then |
1008 | if [[ -f $outfile && ! $force ]]; then | |
1009 | dfatal "Will not override existing initramfs ($outfile) without --force" | |
1010 | exit 1 | |
1011 | fi | |
1012 | ||
1013 | outdir=${outfile%/*} | |
1014 | [[ $outdir ]] || outdir="/" | |
1015 | ||
1016 | if [[ ! -d "$outdir" ]]; then | |
1017 | dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible." | |
1018 | exit 1 | |
1019 | elif [[ ! -w "$outdir" ]]; then | |
1020 | dfatal "No permission to write to $outdir." | |
1021 | exit 1 | |
1022 | elif [[ -f "$outfile" && ! -w "$outfile" ]]; then | |
1023 | dfatal "No permission to write $outfile." | |
1024 | exit 1 | |
1025 | fi | |
37383f71 HH |
1026 | |
1027 | if [[ $loginstall ]]; then | |
1028 | if ! mkdir -p "$loginstall"; then | |
1029 | dfatal "Could not create directory to log installed files to '$loginstall'." | |
1030 | exit 1 | |
1031 | fi | |
1032 | loginstall=$(readlink -f "$loginstall") | |
1033 | fi | |
ec9315e5 JK |
1034 | fi |
1035 | ||
8e3f6537 HH |
1036 | if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE; then |
1037 | dwarn "Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y" | |
1038 | unset acpi_override | |
1039 | fi | |
1040 | ||
1041 | if [[ $early_microcode = yes ]]; then | |
1042 | if [[ $hostonly ]]; then | |
1043 | [[ $(get_cpu_vendor) == "AMD" ]] \ | |
1044 | && ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \ | |
1045 | && unset early_microcode | |
1046 | [[ $(get_cpu_vendor) == "Intel" ]] \ | |
1047 | && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \ | |
1048 | && unset early_microcode | |
1049 | else | |
1050 | ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \ | |
1051 | && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \ | |
1052 | && unset early_microcode | |
1053 | fi | |
1054 | [[ $early_microcode != yes ]] \ | |
1055 | && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]_EARLY!=y" | |
1056 | fi | |
1057 | ||
f6f74096 DD |
1058 | # Need to be able to have non-root users read stuff (rpcbind etc) |
1059 | chmod 755 "$initdir" | |
1060 | ||
5bfa3b36 HH |
1061 | if [[ $hostonly ]]; then |
1062 | for i in /sys /proc /run /dev; do | |
5e601454 | 1063 | if ! findmnt --target "$i" &>/dev/null; then |
5bfa3b36 HH |
1064 | dwarning "Turning off host-only mode: '$i' is not mounted!" |
1065 | unset hostonly | |
1066 | fi | |
1067 | done | |
1068 | fi | |
1069 | ||
d351541e HH |
1070 | declare -A host_fs_types |
1071 | ||
cd7ff122 AW |
1072 | for line in "${fstab_lines[@]}"; do |
1073 | set -- $line | |
6df52351 | 1074 | dev="$1" |
cd7ff122 | 1075 | #dev mp fs fsopts |
6df52351 TR |
1076 | case "$dev" in |
1077 | UUID=*) | |
1078 | dev=$(blkid -l -t UUID=${dev#UUID=} -o device) | |
1079 | ;; | |
1080 | LABEL=*) | |
1081 | dev=$(blkid -l -t LABEL=${dev#LABEL=} -o device) | |
1082 | ;; | |
1083 | PARTUUID=*) | |
1084 | dev=$(blkid -l -t PARTUUID=${dev#PARTUUID=} -o device) | |
1085 | ;; | |
1086 | PARTLABEL=*) | |
1087 | dev=$(blkid -l -t PARTLABEL=${dev#PARTLABEL=} -o device) | |
1088 | ;; | |
1089 | esac | |
1090 | [ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue | |
1091 | push_host_devs "$dev" | |
1092 | host_fs_types["$dev"]="$3" | |
cd7ff122 AW |
1093 | done |
1094 | ||
1095 | for f in $add_fstab; do | |
b093aa2d | 1096 | [[ -e $f ]] || continue |
cd7ff122 | 1097 | while read dev rest; do |
118ca9ec | 1098 | push_host_devs "$dev" |
b093aa2d HH |
1099 | done < "$f" |
1100 | done | |
1101 | ||
1102 | for dev in $add_device; do | |
118ca9ec | 1103 | push_host_devs "$dev" |
cd7ff122 AW |
1104 | done |
1105 | ||
c586b033 CG |
1106 | if (( ${#add_device_l[@]} )); then |
1107 | while pop add_device_l val; do | |
1108 | add_device+=" $val " | |
118ca9ec | 1109 | push_host_devs "$val" |
c586b033 CG |
1110 | done |
1111 | fi | |
1112 | ||
7ae5d9d1 | 1113 | if [[ $hostonly ]]; then |
480d772f HH |
1114 | # in hostonly mode, determine all devices, which have to be accessed |
1115 | # and examine them for filesystem types | |
1116 | ||
bcfbddef | 1117 | for mp in \ |
7ae5d9d1 HH |
1118 | "/" \ |
1119 | "/etc" \ | |
d624f606 HH |
1120 | "/bin" \ |
1121 | "/sbin" \ | |
1122 | "/lib" \ | |
1123 | "/lib64" \ | |
af75a298 | 1124 | "/usr" \ |
9fc14445 HH |
1125 | "/usr/bin" \ |
1126 | "/usr/sbin" \ | |
1127 | "/usr/lib" \ | |
1128 | "/usr/lib64" \ | |
a956a464 HH |
1129 | "/boot" \ |
1130 | "/boot/efi" \ | |
1131 | ; | |
bcfbddef | 1132 | do |
d624f606 | 1133 | mp=$(readlink -f "$mp") |
7ae5d9d1 | 1134 | mountpoint "$mp" >/dev/null 2>&1 || continue |
a4f7b504 | 1135 | _dev=$(find_block_device "$mp") |
e95b6723 | 1136 | _bdev=$(readlink -f "/dev/block/$_dev") |
a4f7b504 | 1137 | [[ -b $_bdev ]] && _dev=$_bdev |
118ca9ec | 1138 | push_host_devs $_dev |
8da51857 | 1139 | [[ "$mp" == "/" ]] && root_dev="$_dev" |
118ca9ec | 1140 | push_host_devs "$_dev" |
7ae5d9d1 | 1141 | done |
dd587549 | 1142 | |
7fd850d5 HH |
1143 | if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then |
1144 | while read dev type rest; do | |
1145 | [[ -b $dev ]] || continue | |
1146 | [[ "$type" == "partition" ]] || continue | |
1147 | ||
1148 | while read _d _m _t _o _r; do | |
1149 | [[ "$_d" == \#* ]] && continue | |
1150 | [[ $_d ]] || continue | |
546d5dac HH |
1151 | [[ $_t != "swap" ]] && continue |
1152 | [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue | |
7fd850d5 | 1153 | [[ "$_o" == *noauto* ]] && continue |
c82a1133 | 1154 | _d=$(expand_persistent_dev "$_d") |
7fd850d5 HH |
1155 | [[ "$_d" -ef "$dev" ]] || continue |
1156 | ||
1157 | if [[ -f /etc/crypttab ]]; then | |
1158 | while read _mapper _a _p _o; do | |
1159 | [[ $_mapper = \#* ]] && continue | |
1160 | [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue | |
1161 | [[ "$_o" ]] || _o="$_p" | |
64ae4e07 HH |
1162 | # skip entries with password files |
1163 | [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2 | |
1743473b | 1164 | # skip mkswap swap |
7fd850d5 HH |
1165 | [[ $_o == *swap* ]] && continue 2 |
1166 | done < /etc/crypttab | |
1167 | fi | |
bcfbddef | 1168 | |
118ca9ec | 1169 | push_host_devs "$(readlink -f "$dev")" |
7fd850d5 HH |
1170 | break |
1171 | done < /etc/fstab | |
1172 | done < /proc/swaps | |
1173 | fi | |
36b2e5e2 CW |
1174 | # record all host modaliases |
1175 | declare -A host_modalias | |
fc68c87a HH |
1176 | find /sys/devices/ -name uevent -print > "$initdir/.modalias" |
1177 | while read m; do | |
1178 | while read line; do | |
1179 | [[ "$line" != MODALIAS\=* ]] && continue | |
1180 | modalias="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias["$modalias"]=1 | |
3b9aaaab | 1181 | break |
fc68c87a HH |
1182 | done < "$m" |
1183 | done < "$initdir/.modalias" | |
1184 | ||
36b2e5e2 CW |
1185 | rm -f -- "$initdir/.modalias" |
1186 | ||
4d7c18c7 HH |
1187 | while read _k _s _v; do |
1188 | [ "$_k" != "name" -a "$_k" != "driver" ] && continue | |
1189 | host_modalias["$_v"]=1 | |
1190 | done </proc/crypto | |
1191 | ||
36b2e5e2 CW |
1192 | # check /proc/modules |
1193 | declare -A host_modules | |
1194 | while read m rest; do | |
1195 | host_modules["$m"]=1 | |
1196 | done </proc/modules | |
7ae5d9d1 | 1197 | fi |
7ae5d9d1 | 1198 | |
3c4315fa HH |
1199 | unset m |
1200 | unset rest | |
1201 | ||
dba20559 | 1202 | _get_fs_type() { |
19bab59c | 1203 | [[ $1 ]] || return |
e41f3f90 HH |
1204 | if [[ -b /dev/block/$1 ]]; then |
1205 | ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE" | |
19bab59c | 1206 | return 1 |
cd7ff122 | 1207 | fi |
e41f3f90 HH |
1208 | if [[ -b $1 ]]; then |
1209 | ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE" | |
19bab59c | 1210 | return 1 |
4f10ae2b | 1211 | fi |
b093aa2d | 1212 | if fstype=$(find_dev_fstype "$1"); then |
dba20559 | 1213 | host_fs_types["$1"]="$fstype" |
19bab59c | 1214 | return 1 |
cd7ff122 AW |
1215 | fi |
1216 | return 1 | |
dba20559 HH |
1217 | } |
1218 | ||
1219 | for dev in ${host_devs[@]}; do | |
1220 | _get_fs_type "$dev" | |
1221 | check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")" | |
cd7ff122 AW |
1222 | done |
1223 | ||
8df0b654 HH |
1224 | for dev in "${!host_fs_types[@]}"; do |
1225 | [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue | |
1226 | rootopts=$(find_dev_fsopts "$dev") | |
1227 | if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then | |
1228 | journaldev=$(fs_get_option $rootopts "jdev") | |
1229 | elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then | |
1230 | journaldev=$(fs_get_option $rootopts "logdev") | |
1231 | fi | |
1232 | if [[ $journaldev ]]; then | |
1233 | dev="$(readlink -f "$dev")" | |
118ca9ec | 1234 | push_host_devs "$dev" |
8df0b654 HH |
1235 | _get_fs_type "$dev" |
1236 | check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")" | |
1237 | fi | |
1238 | done | |
1239 | ||
d1615612 | 1240 | [[ -d $udevdir ]] \ |
b093aa2d | 1241 | || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)" |
d1615612 HH |
1242 | if ! [[ -d "$udevdir" ]]; then |
1243 | [[ -d /lib/udev ]] && udevdir=/lib/udev | |
1244 | [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev | |
1245 | fi | |
1246 | ||
1247 | [[ -d $systemdutildir ]] \ | |
1248 | || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null) | |
d1615612 HH |
1249 | |
1250 | if ! [[ -d "$systemdutildir" ]]; then | |
1251 | [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd | |
1252 | [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd | |
1253 | fi | |
cb8def95 HH |
1254 | |
1255 | [[ -d $systemdsystemunitdir ]] \ | |
1256 | || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null) | |
1257 | ||
d1615612 HH |
1258 | [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system |
1259 | ||
cb8def95 HH |
1260 | [[ -d $systemdsystemconfdir ]] \ |
1261 | || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null) | |
1262 | ||
1263 | [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system | |
1264 | ||
3a04bdde HH |
1265 | [[ -d $tmpfilesdir ]] \ |
1266 | || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null) | |
1267 | ||
1268 | if ! [[ -d "$tmpfilesdir" ]]; then | |
1269 | [[ -f /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d | |
1270 | [[ -f /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d | |
1271 | fi | |
1272 | ||
ab2f95e4 HH |
1273 | export initdir dracutbasedir \ |
1274 | dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \ | |
1275 | mods_to_load \ | |
e103615b | 1276 | fw_dir drivers_dir debug no_kernel kernel_only \ |
5a6a98f8 | 1277 | omit_drivers mdadmconf lvmconf root_dev \ |
ff3953ef | 1278 | use_fstab fstab_lines libdirs fscks nofscks ro_mnt \ |
1e64e493 | 1279 | stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \ |
dbf8f6ba | 1280 | debug host_fs_types host_devs sshkey add_fstab \ |
cb8def95 | 1281 | DRACUT_VERSION udevdir prefix filesystems drivers \ |
3c4315fa | 1282 | systemdutildir systemdsystemunitdir systemdsystemconfdir \ |
3a04bdde HH |
1283 | host_modalias host_modules hostonly_cmdline loginstall \ |
1284 | tmpfilesdir | |
f4fff04e | 1285 | |
1743473b HH |
1286 | mods_to_load="" |
1287 | # check all our modules to see if they should be sourced. | |
1288 | # This builds a list of modules that we will install next. | |
1289 | for_each_module_dir check_module | |
1290 | for_each_module_dir check_mount | |
1291 | ||
88c86ac7 | 1292 | dracut_module_included "fips" && export DRACUT_FIPS_MODE=1 |
1743473b HH |
1293 | |
1294 | if [[ $print_cmdline ]]; then | |
1295 | modules_loaded=" " | |
1296 | # source our modules. | |
1297 | for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do | |
1298 | _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]} | |
1299 | module_cmdline "$_d_mod" | |
1300 | done | |
1301 | unset moddir | |
1743473b HH |
1302 | exit 0 |
1303 | fi | |
1304 | ||
dbad9f46 | 1305 | # Create some directory structure first |
fd786adc | 1306 | [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}" |
dbad9f46 | 1307 | |
785a6cd2 | 1308 | [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib" |
fd786adc | 1309 | [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib" |
dbad9f46 | 1310 | |
785a6cd2 | 1311 | if [[ $prefix ]]; then |
d2a9c4a8 | 1312 | for d in bin etc lib sbin tmp usr var $libdirs; do |
b093aa2d | 1313 | [[ "$d" == */* ]] && continue |
785a6cd2 HH |
1314 | ln -sfn "${prefix#/}/${d#/}" "$initdir/$d" |
1315 | done | |
1316 | fi | |
1317 | ||
1318 | if [[ $kernel_only != yes ]]; then | |
3f54a83c | 1319 | for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do |
fd786adc | 1320 | [[ -e "${initdir}${prefix}/$d" ]] && continue |
d433da44 HH |
1321 | if [ -L "/$d" ]; then |
1322 | inst_symlink "/$d" "${prefix}/$d" | |
785a6cd2 HH |
1323 | else |
1324 | mkdir -m 0755 -p "${initdir}${prefix}/$d" | |
1325 | fi | |
3b403b32 | 1326 | done |
dbad9f46 | 1327 | |
8d89fc6b | 1328 | for d in dev proc sys sysroot root run; do |
d433da44 HH |
1329 | if [ -L "/$d" ]; then |
1330 | inst_symlink "/$d" | |
785a6cd2 HH |
1331 | else |
1332 | mkdir -m 0755 -p "$initdir/$d" | |
1333 | fi | |
33ee031c | 1334 | done |
dbad9f46 | 1335 | |
506b2192 HH |
1336 | ln -sfn ../run "$initdir/var/run" |
1337 | ln -sfn ../run/lock "$initdir/var/lock" | |
6f09acf8 HH |
1338 | else |
1339 | for d in lib "$libdir"; do | |
1340 | [[ -e "${initdir}${prefix}/$d" ]] && continue | |
1341 | if [ -h "/$d" ]; then | |
1342 | inst "/$d" "${prefix}/$d" | |
1343 | else | |
1344 | mkdir -m 0755 -p "${initdir}${prefix}/$d" | |
1345 | fi | |
1346 | done | |
33ee031c | 1347 | fi |
0f86847d | 1348 | |
14c47b0e HH |
1349 | if [[ $kernel_only != yes ]]; then |
1350 | mkdir -p "${initdir}/etc/cmdline.d" | |
4fed3ddf HH |
1351 | for _d in $hookdirs; do |
1352 | mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d | |
1353 | done | |
26144216 | 1354 | if [[ "$UID" = "0" ]]; then |
ad200fbc HH |
1355 | [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3 |
1356 | [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11 | |
1357 | [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1 | |
26144216 | 1358 | fi |
14c47b0e | 1359 | fi |
96b8d60a | 1360 | |
ec3c5951 | 1361 | _isize=0 #initramfs size |
979c4a93 | 1362 | modules_loaded=" " |
95bde758 | 1363 | # source our modules. |
5d791c0e | 1364 | for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do |
979c4a93 | 1365 | _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]} |
b093aa2d HH |
1366 | if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then |
1367 | if [[ $show_modules = yes ]]; then | |
1368 | printf "%s\n" "$_d_mod" | |
1369 | else | |
979c4a93 | 1370 | dinfo "*** Including module: $_d_mod ***" |
b093aa2d HH |
1371 | fi |
1372 | if [[ $kernel_only == yes ]]; then | |
1373 | module_installkernel "$_d_mod" || { | |
a6d3be9d AW |
1374 | dfatal "installkernel failed in module $_d_mod" |
1375 | exit 1 | |
1376 | } | |
cc02093d | 1377 | else |
b093aa2d | 1378 | module_install "$_d_mod" |
95d2dabc | 1379 | if [[ $no_kernel != yes ]]; then |
b093aa2d | 1380 | module_installkernel "$_d_mod" || { |
a6d3be9d AW |
1381 | dfatal "installkernel failed in module $_d_mod" |
1382 | exit 1 | |
1383 | } | |
cc02093d HH |
1384 | fi |
1385 | fi | |
979c4a93 HH |
1386 | mods_to_load=${mods_to_load// $_d_mod /} |
1387 | modules_loaded+="$_d_mod " | |
ec3c5951 DY |
1388 | |
1389 | #print the module install size | |
1390 | if [ -n "$printsize" ]; then | |
1391 | _isize_new=$(du -sk ${initdir}|cut -f1) | |
b093aa2d HH |
1392 | _isize_delta=$((_isize_new - _isize)) |
1393 | printf "%s\n" "$_d_mod install size: ${_isize_delta}k" | |
ec3c5951 DY |
1394 | _isize=$_isize_new |
1395 | fi | |
66ac3cd1 | 1396 | fi |
15136762 | 1397 | done |
20abd914 | 1398 | unset moddir |
0a35a80b HH |
1399 | |
1400 | for i in $modules_loaded; do | |
43fed151 | 1401 | mkdir -p $initdir/lib/dracut |
b093aa2d | 1402 | printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt |
0a35a80b HH |
1403 | done |
1404 | ||
ea216a65 | 1405 | dinfo "*** Including modules done ***" |
aabc0553 | 1406 | |
0f86847d | 1407 | ## final stuff that has to happen |
89d44e72 | 1408 | if [[ $no_kernel != yes ]]; then |
aec9f902 HH |
1409 | |
1410 | if [[ $drivers ]]; then | |
1411 | hostonly='' instmods $drivers | |
1412 | fi | |
1413 | ||
1414 | if [[ $add_drivers ]]; then | |
1415 | hostonly='' instmods -c $add_drivers | |
1416 | fi | |
cea907f6 TR |
1417 | if [[ $force_drivers ]]; then |
1418 | hostonly='' instmods -c $force_drivers | |
1419 | rm -f $initdir/etc/cmdline.d/20-force_driver.conf | |
1420 | for mod in $force_drivers; do | |
1421 | echo "rd.driver.pre=$mod" >>$initdir/etc/cmdline.d/20-force_drivers.conf | |
1422 | done | |
1423 | fi | |
aec9f902 HH |
1424 | if [[ $filesystems ]]; then |
1425 | hostonly='' instmods -c $filesystems | |
1426 | fi | |
1427 | ||
89d44e72 HH |
1428 | dinfo "*** Installing kernel module dependencies and firmware ***" |
1429 | dracut_kernel_post | |
1430 | dinfo "*** Installing kernel module dependencies and firmware done ***" | |
83bb0893 HH |
1431 | |
1432 | if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then | |
1433 | if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \ | |
1434 | [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then | |
1435 | for i in ${initdir}/etc/cmdline.d/*.conf; do | |
1436 | # We need no initramfs image and do not generate one. | |
1437 | [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0 | |
1438 | done | |
1439 | fi | |
1440 | fi | |
89d44e72 | 1441 | fi |
d8aeb3a7 | 1442 | |
998bf6e0 | 1443 | if [[ $kernel_only != yes ]]; then |
af119460 | 1444 | (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]} |
54b68829 | 1445 | (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]} |
998bf6e0 | 1446 | |
b093aa2d | 1447 | [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf" |
d20fb951 | 1448 | |
998bf6e0 | 1449 | while pop fstab_lines line; do |
5f6a495b DY |
1450 | line=($line) |
1451 | [ -z "${line[3]}" ] && line[3]="defaults" | |
1452 | [ -z "${line[4]}" ] && line[4]="0" | |
1453 | [ -z "${line[5]}" ] && line[5]="2" | |
1454 | echo "${line[@]}" >> "${initdir}/etc/fstab" | |
998bf6e0 HH |
1455 | done |
1456 | ||
1457 | for f in $add_fstab; do | |
b093aa2d | 1458 | cat "$f" >> "${initdir}/etc/fstab" |
998bf6e0 HH |
1459 | done |
1460 | ||
6c6d8057 HH |
1461 | if [ -d ${initdir}/$systemdutildir ]; then |
1462 | mkdir -p ${initdir}/etc/conf.d | |
1463 | { | |
b093aa2d HH |
1464 | printf "%s\n" "systemdutildir=\"$systemdutildir\"" |
1465 | printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\"" | |
1466 | printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\"" | |
6c6d8057 HH |
1467 | } > ${initdir}/etc/conf.d/systemd.conf |
1468 | fi | |
1469 | ||
998bf6e0 HH |
1470 | if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then |
1471 | dinfo "*** Resolving executable dependencies ***" | |
1472 | find "$initdir" -type f \ | |
1473 | '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \ | |
1474 | -not -path '*.ko' -print0 \ | |
ffc68f35 | 1475 | | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} -- |
998bf6e0 HH |
1476 | dinfo "*** Resolving executable dependencies done***" |
1477 | fi | |
8dcc4830 HH |
1478 | |
1479 | # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so | |
1480 | for _dir in $libdirs; do | |
1481 | for _f in "$_dir/libpthread.so"*; do | |
1482 | [[ -e "$_f" ]] || continue | |
1483 | inst_libdir_file "libgcc_s.so*" | |
1484 | break 2 | |
1485 | done | |
1486 | done | |
998bf6e0 HH |
1487 | fi |
1488 | ||
661f9a34 HH |
1489 | while pop include_src src && pop include_target tgt; do |
1490 | if [[ $src && $tgt ]]; then | |
1491 | if [[ -f $src ]]; then | |
1492 | inst $src $tgt | |
1493 | else | |
3b403b32 | 1494 | ddebug "Including directory: $src" |
661f9a34 | 1495 | mkdir -p "${initdir}/${tgt}" |
dbad9f46 | 1496 | # check for preexisting symlinks, so we can cope with the |
fd786adc | 1497 | # symlinks to $prefix |
dbad9f46 HH |
1498 | for i in "$src"/*; do |
1499 | [[ -e "$i" || -h "$i" ]] || continue | |
1500 | s=${initdir}/${tgt}/${i#$src/} | |
1501 | if [[ -d "$i" ]]; then | |
1502 | if ! [[ -e "$s" ]]; then | |
1503 | mkdir -m 0755 -p "$s" | |
1504 | chmod --reference="$i" "$s" | |
1505 | fi | |
98eb6d57 | 1506 | cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/* |
dbad9f46 | 1507 | else |
98eb6d57 | 1508 | cp --reflink=auto --sparse=auto -fa -t "$s" "$i" |
3b403b32 | 1509 | fi |
dbad9f46 | 1510 | done |
661f9a34 | 1511 | fi |
4fea3ea6 | 1512 | fi |
661f9a34 | 1513 | done |
88ffd2df | 1514 | |
14c47b0e | 1515 | if [[ $kernel_only != yes ]]; then |
1254925f HH |
1516 | # make sure that library links are correct and up to date |
1517 | for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do | |
482c573d | 1518 | [[ -f $f ]] && inst_simple "$f" |
1254925f HH |
1519 | done |
1520 | if ! ldconfig -r "$initdir"; then | |
1521 | if [[ $UID = 0 ]]; then | |
1522 | derror "ldconfig exited ungracefully" | |
1523 | else | |
1524 | derror "ldconfig might need uid=0 (root) for chroot()" | |
1525 | fi | |
432196ae AŻ |
1526 | fi |
1527 | fi | |
fdc421db | 1528 | |
6cd7001b HH |
1529 | PRELINK_BIN="$(command -v prelink)" |
1530 | if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then | |
1531 | if [[ $DRACUT_FIPS_MODE ]]; then | |
1532 | dinfo "*** Installing prelink files ***" | |
1533 | inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache | |
1534 | elif [[ $do_prelink == yes ]]; then | |
1535 | dinfo "*** Pre-linking files ***" | |
1536 | inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf | |
1537 | chroot "$initdir" "$PRELINK_BIN" -a | |
1538 | rm -f -- "$initdir/$PRELINK_BIN" | |
1539 | rm -fr -- "$initdir"/etc/prelink.* | |
1540 | dinfo "*** Pre-linking files done ***" | |
404815ea HH |
1541 | fi |
1542 | fi | |
1543 | ||
1544 | if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then | |
1545 | dinfo "*** Hardlinking files ***" | |
1546 | hardlink "$initdir" 2>&1 | |
1547 | dinfo "*** Hardlinking files done ***" | |
1548 | fi | |
1549 | ||
3b403b32 | 1550 | # strip binaries |
98adb06e | 1551 | if [[ $do_strip = yes ]] ; then |
69b35075 | 1552 | for p in strip xargs find; do |
cc02093d | 1553 | if ! type -P $p >/dev/null; then |
fefd3f66 | 1554 | dinfo "Could not find '$p'. Not stripping the initramfs." |
cc02093d HH |
1555 | do_strip=no |
1556 | fi | |
31f7db66 HH |
1557 | done |
1558 | fi | |
1559 | ||
5ae33613 | 1560 | if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then |
89d44e72 | 1561 | dinfo "*** Stripping files ***" |
5ae33613 HH |
1562 | find "$initdir" -type f \ |
1563 | -executable -not -path '*/lib/modules/*.ko' -print0 \ | |
1564 | | xargs -r -0 strip -g 2>/dev/null | |
2d9b156e HH |
1565 | |
1566 | # strip kernel modules, but do not touch signed modules | |
1567 | find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \ | |
1568 | | while read -r -d $'\0' f; do | |
1569 | SIG=$(tail -c 28 "$f") | |
b093aa2d | 1570 | [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; } |
2d9b156e HH |
1571 | done | xargs -r -0 strip -g |
1572 | ||
89d44e72 | 1573 | dinfo "*** Stripping files done ***" |
979c4a93 | 1574 | fi |
5f2c30d9 KRW |
1575 | if [[ $early_microcode = yes ]]; then |
1576 | dinfo "*** Generating early-microcode cpio image ***" | |
1577 | ucode_dir=(amd-ucode intel-ucode) | |
1578 | ucode_dest=(AuthenticAMD.bin GenuineIntel.bin) | |
b5b608e4 | 1579 | _dest_dir="$early_cpio_dir/d/kernel/x86/microcode" |
5f2c30d9 KRW |
1580 | _dest_idx="0 1" |
1581 | mkdir -p $_dest_dir | |
1582 | if [[ $hostonly ]]; then | |
1583 | [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0" | |
1584 | [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1" | |
1585 | fi | |
1586 | for idx in $_dest_idx; do | |
1587 | _fw=${ucode_dir[$idx]} | |
1588 | for _fwdir in $fw_dir; do | |
1589 | if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then | |
1590 | _src="*" | |
1591 | dinfo "*** Constructing ${ucode_dest[$idx]} ****" | |
1592 | if [[ $hostonly ]]; then | |
1593 | _src=$(get_ucode_file) | |
d8b04dc1 TR |
1594 | if ! [[ -r $_fwdir/$_fw/$_src ]];then |
1595 | break; | |
1596 | fi | |
5f2c30d9 KRW |
1597 | fi |
1598 | cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]} | |
d8b04dc1 | 1599 | create_early_cpio="yes" |
5f2c30d9 KRW |
1600 | fi |
1601 | done | |
1602 | done | |
5f2c30d9 | 1603 | fi |
bbaa0d59 | 1604 | |
f3b14c2b TR |
1605 | if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then |
1606 | dinfo "*** Packaging ACPI tables to override BIOS provided ones ***" | |
1607 | _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi" | |
1608 | mkdir -p $_dest_dir | |
1609 | for table in $acpi_table_dir/*.aml; do | |
1610 | dinfo " Adding ACPI table: $table" | |
80626ded | 1611 | cp -a $table $_dest_dir |
f3b14c2b TR |
1612 | create_early_cpio="yes" |
1613 | done | |
1614 | fi | |
1615 | ||
659dc319 HB |
1616 | dinfo "*** Store current command line parameters ***" |
1617 | if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then | |
1618 | dfatal "Could not store the current command line parameters" | |
1619 | exit 1 | |
1620 | fi | |
1621 | ||
fe273e39 HR |
1622 | if [[ $hostonly_cmdline ]] ; then |
1623 | if [ -d $initdir/etc/cmdline.d ];then | |
1624 | dinfo "Stored kernel commandline:" | |
1625 | for conf in $initdir/etc/cmdline.d/*.conf ; do | |
1626 | dinfo "$(< $conf)" | |
1627 | done | |
1628 | else | |
1629 | dinfo "No dracut internal kernel commandline stored in initrd" | |
1630 | fi | |
1631 | fi | |
32bd2fbb | 1632 | rm -f -- "$outfile" |
89d44e72 | 1633 | dinfo "*** Creating image file ***" |
c8a9a6b4 | 1634 | |
80626ded HH |
1635 | if [[ $DRACUT_REPRODUCIBLE ]]; then |
1636 | find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \ | |
1637 | | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh" | |
1638 | ||
1639 | [[ "$(cpio --help)" == *--reproducible* ]] && CPIO_REPRODUCIBLE=1 | |
1640 | fi | |
1641 | ||
c8a9a6b4 HH |
1642 | [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0" |
1643 | ||
b5b608e4 | 1644 | if [[ $create_early_cpio = yes ]]; then |
b9909e33 | 1645 | echo 1 > "$early_cpio_dir/d/early_cpio" |
80626ded HH |
1646 | |
1647 | if [[ $DRACUT_REPRODUCIBLE ]]; then | |
1648 | find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \ | |
1649 | | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh" | |
1650 | fi | |
1651 | ||
5f2c30d9 | 1652 | # The microcode blob is _before_ the initramfs blob, not after |
80626ded HH |
1653 | ( |
1654 | cd "$early_cpio_dir/d" | |
1655 | find . -print0 | sort -z \ | |
1656 | | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet > $outfile | |
1657 | ) | |
5f2c30d9 | 1658 | fi |
80626ded HH |
1659 | |
1660 | if ! ( | |
1661 | umask 077; cd "$initdir" | |
1662 | find . -print0 | sort -z \ | |
1663 | | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet \ | |
1664 | | $compress >> "$outfile" | |
1665 | ); then | |
dc4c1ee3 | 1666 | dfatal "dracut: creation of $outfile failed" |
734a0d9e | 1667 | exit 1 |
3b403b32 | 1668 | fi |
89d44e72 | 1669 | dinfo "*** Creating image file done ***" |
432196ae | 1670 | |
bbaa0d59 | 1671 | if (( maxloglvl >= 5 )); then |
dadd2b69 HH |
1672 | if [[ $allowlocal ]]; then |
1673 | "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug | |
1674 | else | |
1675 | lsinitrd "$outfile"| ddebug | |
1676 | fi | |
bbaa0d59 | 1677 | fi |
1faecdc1 | 1678 | |
3da58569 | 1679 | exit 0 |