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