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