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