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