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