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