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