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