]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
dracut.sh: Support --mount with just mountpoint as parameter
[thirdparty/dracut.git] / dracut.sh
1 #!/bin/bash --norc
2 #
3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
6 #
7
8 # Copyright 2005-2013 Red Hat, Inc. All rights reserved.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 # store for logging
25
26 # Verify bash version, current minimum is 4
27 if (( BASH_VERSINFO[0] < 4 )); then
28 printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
29 exit 1
30 fi
31
32 dracut_args=( "$@" )
33 readonly dracut_cmd="$(readlink -f $0)"
34
35 set -o pipefail
36
37 usage() {
38 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
39 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
40 . $dracutbasedir/dracut-version.sh
41 fi
42
43 # 80x25 linebreak here ^
44 cat << EOF
45 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
46
47 Version: $DRACUT_VERSION
48
49 Creates initial ramdisk images for preloading modules
50
51 -h, --help Display all options
52
53 If a [LIST] has multiple arguments, then you have to put these in quotes.
54
55 For example:
56
57 # dracut --add-drivers "module1 module2" ...
58
59 EOF
60 }
61
62 long_usage() {
63 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
64 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
65 . $dracutbasedir/dracut-version.sh
66 fi
67
68 # 80x25 linebreak here ^
69 cat << EOF
70 Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
71
72 Version: $DRACUT_VERSION
73
74 Creates initial ramdisk images for preloading modules
75
76 --kver [VERSION] Set kernel version to [VERSION].
77 -f, --force Overwrite existing initramfs file.
78 -a, --add [LIST] Add a space-separated list of dracut modules.
79 --rebuild Append arguments to those of existing image and rebuild
80 -m, --modules [LIST] Specify a space-separated list of dracut modules to
81 call when building the initramfs. Modules are located
82 in /usr/lib/dracut/modules.d.
83 -o, --omit [LIST] Omit a space-separated list of dracut modules.
84 --force-add [LIST] Force to add a space-separated list of dracut modules
85 to the default set of modules, when -H is specified.
86 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
87 exclusively include in the initramfs.
88 --add-drivers [LIST] Specify a space-separated list of kernel
89 modules to add to the initramfs.
90 --force-drivers [LIST] Specify a space-separated list of kernel
91 modules to add to the initramfs and make sure they
92 are tried to be loaded via modprobe same as passing
93 rd.driver.pre=DRIVER kernel parameter.
94 --omit-drivers [LIST] Specify a space-separated list of kernel
95 modules not to add to the initramfs.
96 --filesystems [LIST] Specify a space-separated list of kernel filesystem
97 modules to exclusively include in the generic
98 initramfs.
99 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
100 modules
101 --fwdir [DIR] Specify additional directories, where to look for
102 firmwares, separated by :
103 --kernel-only Only install kernel drivers and firmware files
104 --no-kernel Do not install kernel drivers and firmware files
105 --print-cmdline Print the kernel command line for the given disk layout
106 --early-microcode Combine early microcode with ramdisk
107 --no-early-microcode Do not combine early microcode with ramdisk
108 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
109 --strip Strip binaries in the initramfs
110 --nostrip Do not strip binaries in the initramfs
111 --prelink Prelink binaries in the initramfs
112 --noprelink Do not prelink binaries in the initramfs
113 --hardlink Hardlink files in the initramfs
114 --nohardlink Do not hardlink files in the initramfs
115 --prefix [DIR] Prefix initramfs files with [DIR]
116 --noprefix Do not prefix initramfs files
117 --mdadmconf Include local /etc/mdadm.conf
118 --nomdadmconf Do not include local /etc/mdadm.conf
119 --lvmconf Include local /etc/lvm/lvm.conf
120 --nolvmconf Do not include local /etc/lvm/lvm.conf
121 --fscks [LIST] Add a space-separated list of fsck helpers.
122 --nofscks Inhibit installation of any fsck helpers.
123 --ro-mnt Mount / and /usr read-only by default.
124 -h, --help This message
125 --debug Output debug information of the build process
126 --profile Output profile information of the build process
127 -L, --stdlog [0-6] Specify logging level (to standard error)
128 0 - suppress any messages
129 1 - only fatal errors
130 2 - all errors
131 3 - warnings
132 4 - info
133 5 - debug info (here starts lots of output)
134 6 - trace info (and even more)
135 -v, --verbose Increase verbosity level
136 -q, --quiet Decrease verbosity level
137 -c, --conf [FILE] Specify configuration file to use.
138 Default: /etc/dracut.conf
139 --confdir [DIR] Specify configuration directory to use *.conf files
140 from. Default: /etc/dracut.conf.d
141 --tmpdir [DIR] Temporary directory to be used instead of default
142 /var/tmp.
143 -l, --local Local mode. Use modules from the current working
144 directory instead of the system-wide installed in
145 /usr/lib/dracut/modules.d.
146 Useful when running dracut from a git checkout.
147 -H, --hostonly Host-Only mode: Install only what is needed for
148 booting the local host instead of a generic host.
149 -N, --no-hostonly Disables Host-Only mode
150 --hostonly-cmdline Store kernel command line arguments needed
151 in the initramfs
152 --no-hostonly-cmdline Do not store kernel command line arguments needed
153 in the initramfs
154 --persistent-policy [POLICY]
155 Use [POLICY] to address disks and partitions.
156 POLICY can be any directory name found in /dev/disk.
157 E.g. "by-uuid", "by-label"
158 --fstab Use /etc/fstab to determine the root device.
159 --add-fstab [FILE] Add file to the initramfs fstab
160 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
161 Mount device [DEV] on mountpoint [MP] with filesystem
162 [FSTYPE] and options [FSOPTS] in the initramfs
163 --mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
164 determined by looking at the current mounts.
165 --add-device "[DEV]" Bring up [DEV] in initramfs
166 -i, --include [SOURCE] [TARGET]
167 Include the files in the SOURCE directory into the
168 Target directory in the final initramfs.
169 If SOURCE is a file, it will be installed to TARGET
170 in the final initramfs.
171 -I, --install [LIST] Install the space separated list of files into the
172 initramfs.
173 --install-optional [LIST] Install the space separated list of files into the
174 initramfs, if they exist.
175 --gzip Compress the generated initramfs using gzip.
176 This will be done by default, unless another
177 compression option or --no-compress is passed.
178 --bzip2 Compress the generated initramfs using bzip2.
179 Make sure your kernel has bzip2 decompression support
180 compiled in, otherwise you will not be able to boot.
181 --lzma Compress the generated initramfs using lzma.
182 Make sure your kernel has lzma support compiled in,
183 otherwise you will not be able to boot.
184 --xz Compress the generated initramfs using xz.
185 Make sure that your kernel has xz support compiled
186 in, otherwise you will not be able to boot.
187 --lzo Compress the generated initramfs using lzop.
188 Make sure that your kernel has lzo support compiled
189 in, otherwise you will not be able to boot.
190 --lz4 Compress the generated initramfs using lz4.
191 Make sure that your kernel has lz4 support compiled
192 in, otherwise you will not be able to boot.
193 --compress [COMPRESSION] Compress the generated initramfs with the
194 passed compression program. Make sure your kernel
195 knows how to decompress the generated initramfs,
196 otherwise you will not be able to boot.
197 --no-compress Do not compress the generated initramfs. This will
198 override any other compression options.
199 --list-modules List all available dracut modules.
200 -M, --show-modules Print included module's name to standard output during
201 build.
202 --keep Keep the temporary initramfs for debugging purposes
203 --printsize Print out the module install size
204 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
205 --logfile [FILE] Logfile to use (overrides configuration setting)
206 --reproducible Create reproducible images
207 --no-reproducible Do not create reproducible images
208 --loginstall [DIR] Log all files installed from the host to [DIR]
209 --uefi Create an UEFI executable with the kernel cmdline and
210 kernel combined
211 --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
212 --kernel-image [FILE] location of the kernel image
213
214 If [LIST] has multiple arguments, then you have to put these in quotes.
215
216 For example:
217
218 # dracut --add-drivers "module1 module2" ...
219
220 EOF
221 }
222
223 # Fills up host_devs stack variable and makes sure there are no duplicates
224 push_host_devs() {
225 local _dev
226 for _dev in "$@"; do
227 [[ " ${host_devs[@]} " == *" $_dev "* ]] && return
228 host_devs+=( "$_dev" )
229 done
230 }
231
232 # Little helper function for reading args from the commandline.
233 # it automatically handles -a b and -a=b variants, and returns 1 if
234 # we need to shift $3.
235 read_arg() {
236 # $1 = arg name
237 # $2 = arg value
238 # $3 = arg parameter
239 local rematch='^[^=]*=(.*)$'
240 if [[ $2 =~ $rematch ]]; then
241 read "$1" <<< "${BASH_REMATCH[1]}"
242 else
243 read "$1" <<< "$3"
244 # There is no way to shift our callers args, so
245 # return 1 to indicate they should do it instead.
246 return 1
247 fi
248 }
249
250 dropindirs_sort()
251 {
252 local suffix=$1; shift
253 local -a files
254 local f d
255
256 for d in "$@"; do
257 for i in "$d/"*"$suffix"; do
258 if [[ -e "$i" ]]; then
259 printf "%s\n" "${i##*/}"
260 fi
261 done
262 done | sort -Vu | {
263 readarray -t files
264
265 for f in "${files[@]}"; do
266 for d in "$@"; do
267 if [[ -e "$d/$f" ]]; then
268 printf "%s\n" "$d/$f"
269 continue 2
270 fi
271 done
272 done
273 }
274 }
275
276 rearrange_params()
277 {
278 # Workaround -i, --include taking 2 arguments
279 set -- "${@/--include/++include}"
280
281 # This prevents any long argument ending with "-i"
282 # -i, like --opt-i but I think we can just prevent that
283 set -- "${@/%-i/++include}"
284
285 TEMP=$(unset POSIXLY_CORRECT; getopt \
286 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
287 --long kver: \
288 --long add: \
289 --long force-add: \
290 --long add-drivers: \
291 --long force-drivers: \
292 --long omit-drivers: \
293 --long modules: \
294 --long omit: \
295 --long drivers: \
296 --long filesystems: \
297 --long install: \
298 --long install-optional: \
299 --long fwdir: \
300 --long libdirs: \
301 --long fscks: \
302 --long add-fstab: \
303 --long mount: \
304 --long device: \
305 --long add-device: \
306 --long nofscks: \
307 --long ro-mnt \
308 --long kmoddir: \
309 --long conf: \
310 --long confdir: \
311 --long tmpdir: \
312 --long stdlog: \
313 --long compress: \
314 --long prefix: \
315 --long rebuild: \
316 --long force \
317 --long kernel-only \
318 --long no-kernel \
319 --long print-cmdline \
320 --long kernel-cmdline: \
321 --long strip \
322 --long nostrip \
323 --long prelink \
324 --long noprelink \
325 --long hardlink \
326 --long nohardlink \
327 --long noprefix \
328 --long mdadmconf \
329 --long nomdadmconf \
330 --long lvmconf \
331 --long nolvmconf \
332 --long debug \
333 --long profile \
334 --long sshkey: \
335 --long logfile: \
336 --long verbose \
337 --long quiet \
338 --long local \
339 --long hostonly \
340 --long host-only \
341 --long no-hostonly \
342 --long no-host-only \
343 --long hostonly-cmdline \
344 --long no-hostonly-cmdline \
345 --long persistent-policy: \
346 --long fstab \
347 --long help \
348 --long bzip2 \
349 --long lzma \
350 --long xz \
351 --long lzo \
352 --long lz4 \
353 --long no-compress \
354 --long gzip \
355 --long list-modules \
356 --long show-modules \
357 --long keep \
358 --long printsize \
359 --long regenerate-all \
360 --long noimageifnotneeded \
361 --long early-microcode \
362 --long no-early-microcode \
363 --long reproducible \
364 --long no-reproducible \
365 --long loginstall: \
366 --long uefi \
367 --long uefi-stub: \
368 --long kernel-image: \
369 --long no-hostonly-i18n \
370 --long hostonly-i18n \
371 -- "$@")
372
373 if (( $? != 0 )); then
374 usage
375 exit 1
376 fi
377 }
378
379 verbosity_mod_l=0
380 unset kernel
381 unset outfile
382
383 rearrange_params "$@"
384 eval set -- "$TEMP"
385
386 # parse command line args to check if '--rebuild' option is present
387 unset append_args_l
388 unset rebuild_file
389 while :
390 do
391 if [ "$1" == "--" ]; then
392 shift; break
393 fi
394 if [ "$1" == "--rebuild" ]; then
395 append_args_l="yes"
396 rebuild_file=$2
397 if [ ! -e $rebuild_file ]; then
398 echo "Image file '$rebuild_file', for rebuild, does not exist!"
399 exit 1
400 fi
401 abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
402 shift; continue
403 fi
404 shift
405 done
406
407 # get output file name and kernel version from command line arguments
408 while (($# > 0)); do
409 case ${1%%=*} in
410 ++include)
411 shift 2;;
412 *)
413 if ! [[ ${outfile+x} ]]; then
414 outfile=$1
415 elif ! [[ ${kernel+x} ]]; then
416 kernel=$1
417 else
418 printf "\nUnknown arguments: %s\n\n" "$*" >&2
419 usage; exit 1;
420 fi
421 ;;
422 esac
423 shift
424 done
425
426 # extract input image file provided with rebuild option to get previous parameters, if any
427 if [[ $append_args_l == "yes" ]]; then
428 unset rebuild_param
429
430 # determine resultant file
431 if ! [[ $outfile ]]; then
432 outfile=$rebuild_file
433 fi
434
435 if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
436 echo "Image '$rebuild_file' has no rebuild information stored"
437 exit 1
438 fi
439
440 # prepend previous parameters to current command line args
441 if [[ $rebuild_param ]]; then
442 TEMP="$rebuild_param $TEMP"
443 eval set -- "$TEMP"
444 rearrange_params "$@"
445 fi
446
447 # clean the temporarily used scratch-pad directory
448 rm -rf $scratch_dir
449 fi
450
451 unset PARMS_TO_STORE
452 PARMS_TO_STORE=""
453
454 eval set -- "$TEMP"
455
456 while :; do
457 if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
458 PARMS_TO_STORE+=" $1";
459 fi
460 case $1 in
461 --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
462 -a|--add) add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
463 --force-add) force_add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
464 --add-drivers) add_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
465 --force-drivers) force_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
466 --omit-drivers) omit_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
467 -m|--modules) dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
468 -o|--omit) omit_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
469 -d|--drivers) drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
470 --filesystems) filesystems_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
471 -I|--install) install_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
472 --install-optional) install_optional_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
473 --fwdir) fw_dir_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
474 --libdirs) libdirs_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
475 --fscks) fscks_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
476 --add-fstab) add_fstab_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
477 --mount) fstab_lines+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
478 --add-device|--device) add_device_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
479 --kernel-cmdline) kernel_cmdline_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
480 --nofscks) nofscks_l="yes";;
481 --ro-mnt) ro_mnt_l="yes";;
482 -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
483 -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
484 --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
485 --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
486 -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
487 --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
488 --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
489 --loginstall) loginstall_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
490 --rebuild) if [ $rebuild_file == $outfile ]; then
491 force=yes
492 fi
493 shift
494 ;;
495 -f|--force) force=yes;;
496 --kernel-only) kernel_only="yes"; no_kernel="no";;
497 --no-kernel) kernel_only="no"; no_kernel="yes";;
498 --print-cmdline)
499 print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";;
500 --early-microcode)
501 early_microcode_l="yes";;
502 --no-early-microcode)
503 early_microcode_l="no";;
504 --strip) do_strip_l="yes";;
505 --nostrip) do_strip_l="no";;
506 --prelink) do_prelink_l="yes";;
507 --noprelink) do_prelink_l="no";;
508 --hardlink) do_hardlink_l="yes";;
509 --nohardlink) do_hardlink_l="no";;
510 --noprefix) prefix_l="/";;
511 --mdadmconf) mdadmconf_l="yes";;
512 --nomdadmconf) mdadmconf_l="no";;
513 --lvmconf) lvmconf_l="yes";;
514 --nolvmconf) lvmconf_l="no";;
515 --debug) debug="yes";;
516 --profile) profile="yes";;
517 --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
518 --logfile) logfile_l="$2"; shift;;
519 -v|--verbose) ((verbosity_mod_l++));;
520 -q|--quiet) ((verbosity_mod_l--));;
521 -l|--local)
522 allowlocal="yes"
523 [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
524 && dracutbasedir="$(readlink -f "${0%/*}")"
525 ;;
526 -H|--hostonly|--host-only)
527 hostonly_l="yes" ;;
528 -N|--no-hostonly|--no-host-only)
529 hostonly_l="no" ;;
530 --hostonly-cmdline)
531 hostonly_cmdline_l="yes" ;;
532 --hostonly-i18n)
533 i18n_install_all_l="no" ;;
534 --no-hostonly-i18n)
535 i18n_install_all_l="yes" ;;
536 --no-hostonly-cmdline)
537 hostonly_cmdline_l="no" ;;
538 --persistent-policy)
539 persistent_policy_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
540 --fstab) use_fstab_l="yes" ;;
541 -h|--help) long_usage; exit 1 ;;
542 -i|--include) include_src+=("$2"); PARMS_TO_STORE+=" '$2'";
543 shift;;
544 --bzip2) compress_l="bzip2";;
545 --lzma) compress_l="lzma";;
546 --xz) compress_l="xz";;
547 --lzo) compress_l="lzo";;
548 --lz4) compress_l="lz4";;
549 --no-compress) _no_compress_l="cat";;
550 --gzip) compress_l="gzip";;
551 --list-modules) do_list="yes";;
552 -M|--show-modules)
553 show_modules_l="yes"
554 ;;
555 --keep) keep="yes";;
556 --printsize) printsize="yes";;
557 --regenerate-all) regenerate_all="yes";;
558 --noimageifnotneeded) noimageifnotneeded="yes";;
559 --reproducible) reproducible_l="yes";;
560 --no-reproducible) reproducible_l="no";;
561 --uefi) uefi="yes";;
562 --uefi-stub)
563 uefi_stub_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
564 --kernel-image)
565 kernel_image_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
566 --) shift; break;;
567
568 *) # should not even reach this point
569 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
570 esac
571 shift
572 done
573
574 # getopt cannot handle multiple arguments, so just handle "-I,--include"
575 # the old fashioned way
576
577 while (($# > 0)); do
578 if [ "${1%%=*}" == "++include" ]; then
579 include_src+=("$2")
580 include_target+=("$3")
581 PARMS_TO_STORE+=" --include '$2' '$3'"
582 shift 2
583 fi
584 shift
585 done
586
587 if [[ $regenerate_all == "yes" ]]; then
588 ret=0
589 if [[ $kernel ]]; then
590 printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
591 exit 1
592 fi
593
594 if [[ $outfile ]]; then
595 printf -- "--regenerate-all cannot be called with a image file\n" >&2
596 exit 1
597 fi
598
599 ((len=${#dracut_args[@]}))
600 for ((i=0; i < len; i++)); do
601 [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
602 unset dracut_args[$i]
603 done
604
605 cd /lib/modules
606 for i in *; do
607 [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
608 "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
609 ((ret+=$?))
610 done
611 exit $ret
612 fi
613
614 if ! [[ $kernel ]]; then
615 kernel=$(uname -r)
616 fi
617
618 if [[ $kernel ]]; then
619 if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then
620 printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2
621 fi
622 fi
623
624 if ! [[ $outfile ]]; then
625 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
626
627 if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
628 outfile="/boot/${MACHINE_ID}/$kernel/initrd"
629 else
630 outfile="/boot/initramfs-$kernel.img"
631 fi
632 fi
633
634 unset LC_MESSAGES
635 unset LC_CTYPE
636 export LC_ALL=C
637 export LANG=C
638 unset LD_LIBRARY_PATH
639 unset LD_PRELOAD
640 unset GREP_OPTIONS
641
642 export DRACUT_LOG_LEVEL=warning
643 [[ $debug ]] && {
644 export DRACUT_LOG_LEVEL=debug
645 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
646 set -x
647 }
648
649 [[ $profile ]] && {
650 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
651 set -x
652 debug=yes
653 }
654
655 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
656
657 # if we were not passed a config file, try the default one
658 if [[ ! -f $conffile ]]; then
659 if [[ $allowlocal ]]; then
660 conffile="$dracutbasedir/dracut.conf"
661 else
662 conffile="/etc/dracut.conf"
663 fi
664 fi
665
666 if [[ ! -d $confdir ]]; then
667 if [[ $allowlocal ]]; then
668 confdir="$dracutbasedir/dracut.conf.d"
669 else
670 confdir="/etc/dracut.conf.d"
671 fi
672 fi
673
674 # source our config file
675 [[ -f $conffile ]] && . "$conffile"
676
677 # source our config dir
678 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
679 [[ -e $f ]] && . "$f"
680 done
681
682 DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
683
684 for i in $DRACUT_PATH; do
685 rl=$i
686 if [ -L "$i" ]; then
687 rl=$(readlink -f $i)
688 fi
689 if [[ "$NPATH" != *:$rl* ]] ; then
690 NPATH+=":$rl"
691 fi
692 done
693 export PATH="${NPATH#:}"
694 unset NPATH
695
696 # these options add to the stuff in the config file
697 (( ${#add_dracutmodules_l[@]} )) && add_dracutmodules+=" ${add_dracutmodules_l[@]} "
698 (( ${#force_add_dracutmodules_l[@]} )) && force_add_dracutmodules+=" ${force_add_dracutmodules_l[@]} "
699 (( ${#fscks_l[@]} )) && fscks+=" ${fscks_l[@]} "
700 (( ${#add_fstab_l[@]} )) && add_fstab+=" ${add_fstab_l[@]} "
701 (( ${#fstab_lines_l[@]} )) && fstab_lines+=( "${fstab_lines_l[@]}" )
702 (( ${#install_items_l[@]} )) && install_items+=" ${install_items_l[@]} "
703 (( ${#install_optional_items_l[@]} )) && install_optional_items+=" ${install_optional_items_l[@]} "
704
705 # these options override the stuff in the config file
706 (( ${#dracutmodules_l[@]} )) && dracutmodules="${dracutmodules_l[@]}"
707 (( ${#omit_dracutmodules_l[@]} )) && omit_dracutmodules="${omit_dracutmodules_l[@]}"
708 (( ${#filesystems_l[@]} )) && filesystems="${filesystems_l[@]}"
709 (( ${#fw_dir_l[@]} )) && fw_dir="${fw_dir_l[@]}"
710 (( ${#libdirs_l[@]} ))&& libdirs="${libdirs_l[@]}"
711
712 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
713 [[ ! $stdloglvl ]] && stdloglvl=4
714 stdloglvl=$((stdloglvl + verbosity_mod_l))
715 ((stdloglvl > 6)) && stdloglvl=6
716 ((stdloglvl < 0)) && stdloglvl=0
717
718 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
719 [[ $do_strip_l ]] && do_strip=$do_strip_l
720 [[ $do_strip ]] || do_strip=yes
721 [[ $do_prelink_l ]] && do_prelink=$do_prelink_l
722 [[ $do_prelink ]] || do_prelink=yes
723 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
724 [[ $do_hardlink ]] || do_hardlink=yes
725 [[ $prefix_l ]] && prefix=$prefix_l
726 [[ $prefix = "/" ]] && unset prefix
727 [[ $hostonly_l ]] && hostonly=$hostonly_l
728 [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
729 [[ "$hostonly" == "yes" ]] && ! [[ $hostonly_cmdline ]] && hostonly_cmdline="yes"
730 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
731 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
732 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
733 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
734 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
735 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
736 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware /lib/firmware/$kernel"
737 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
738 [[ $tmpdir ]] || tmpdir=/var/tmp
739 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
740 [[ $compress_l ]] && compress=$compress_l
741 [[ $show_modules_l ]] && show_modules=$show_modules_l
742 [[ $nofscks_l ]] && nofscks="yes"
743 [[ $ro_mnt_l ]] && ro_mnt="yes"
744 [[ $early_microcode_l ]] && early_microcode=$early_microcode_l
745 [[ $early_microcode ]] || early_microcode=no
746 [[ $logfile_l ]] && logfile="$logfile_l"
747 [[ $reproducible_l ]] && reproducible="$reproducible_l"
748 [[ $loginstall_l ]] && loginstall="$loginstall_l"
749 [[ $uefi_stub_l ]] && uefi_stub="$uefi_stub_l"
750 [[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
751
752 # eliminate IFS hackery when messing with fw_dir
753 fw_dir=${fw_dir//:/ }
754
755 # check for logfile and try to create one if it doesn't exist
756 if [[ -n "$logfile" ]];then
757 if [[ ! -f "$logfile" ]];then
758 touch "$logfile"
759 if [ ! $? -eq 0 ] ;then
760 printf "%s\n" "dracut: touch $logfile failed." >&2
761 fi
762 fi
763 fi
764
765 # handle compression options.
766 if [[ $_no_compress_l = "cat" ]]; then
767 compress="cat"
768 fi
769
770 if ! [[ $compress ]]; then
771 # check all known compressors, if none specified
772 for i in pigz gzip lz4 lzop lzma xz lbzip2 bzip2 cat; do
773 command -v "$i" &>/dev/null || continue
774 compress="$i"
775 break
776 done
777 if [[ $compress = cat ]]; then
778 printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
779 fi
780 fi
781
782 # choose the right arguments for the compressor
783 case $compress in
784 bzip2|lbzip2)
785 if [[ "$compress" = lbzip2 ]] || command -v lbzip2 &>/dev/null; then
786 compress="lbzip2 -9"
787 else
788 compress="bzip2 -9"
789 fi
790 ;;
791 lzma)
792 compress="lzma -9 -T0"
793 ;;
794 xz)
795 compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
796 ;;
797 gzip|pigz)
798 if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
799 compress="pigz -9 -n -T -R"
800 elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
801 compress="gzip -n -9 --rsyncable"
802 else
803 compress="gzip -n -9"
804 fi
805 ;;
806 lzo|lzop)
807 compress="lzop -9"
808 ;;
809 lz4)
810 compress="lz4 -l -9"
811 ;;
812 esac
813
814 [[ $hostonly = yes ]] && hostonly="-h"
815 [[ $hostonly != "-h" ]] && unset hostonly
816
817 [[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
818
819 readonly TMPDIR="$tmpdir"
820 readonly initdir="$(mktemp -p "$TMPDIR/" -d -t initramfs.XXXXXX)"
821 [ -d "$initdir" ] || {
822 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
823 exit 1
824 }
825
826 if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
827 readonly early_cpio_dir="$(mktemp -p "$TMPDIR/" -d -t early_cpio.XXXXXX)"
828 [ -d "$early_cpio_dir" ] || {
829 printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
830 exit 1
831 }
832 fi
833 # clean up after ourselves no matter how we die.
834 trap '
835 ret=$?;
836 [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
837 [[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
838 [[ $keep ]] && echo "Not removing $uefi_outdir." >&2 || { [[ $uefi_outdir ]] && rm -Rf -- "$uefi_outdir"; };
839 [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
840 exit $ret;
841 ' EXIT
842
843 # clean up after ourselves no matter how we die.
844 trap 'exit 1;' SIGINT
845
846 export DRACUT_KERNEL_LAZY="1"
847 export DRACUT_RESOLVE_LAZY="1"
848
849 if [[ $print_cmdline ]]; then
850 stdloglvl=0
851 sysloglvl=0
852 fileloglvl=0
853 kmsgloglvl=0
854 fi
855
856 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
857 . $dracutbasedir/dracut-version.sh
858 fi
859
860 if [[ -f $dracutbasedir/dracut-init.sh ]]; then
861 . $dracutbasedir/dracut-init.sh
862 else
863 printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
864 printf "%s\n" "dracut: Are you running from a git checkout?" >&2
865 printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
866 exit 1
867 fi
868
869 if ! [[ $print_cmdline ]]; then
870 inst /bin/sh
871 if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
872 unset DRACUT_RESOLVE_LAZY
873 export DRACUT_RESOLVE_DEPS=1
874 fi
875 rm -fr -- ${initdir}/*
876 fi
877
878 dracutfunctions=$dracutbasedir/dracut-functions.sh
879 export dracutfunctions
880
881 (( ${#drivers_l[@]} )) && drivers="${drivers_l[@]}"
882 drivers=${drivers/-/_}
883
884 (( ${#add_drivers_l[@]} )) && add_drivers+=" ${add_drivers_l[@]} "
885 add_drivers=${add_drivers/-/_}
886
887 (( ${#force_drivers_l[@]} )) && force_drivers+=" ${force_drivers_l[@]} "
888 force_drivers=${force_drivers/-/_}
889
890 (( ${#omit_drivers_l[@]} )) && omit_drivers+=" ${omit_drivers_l[@]} "
891 omit_drivers=${omit_drivers/-/_}
892
893 (( ${#kernel_cmdline_l[@]} )) && kernel_cmdline+=" ${kernel_cmdline_l[@]} "
894
895 omit_drivers_corrected=""
896 for d in $omit_drivers; do
897 [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
898 [[ " $drivers $force_drivers " == *\ $d\ * ]] && continue
899 omit_drivers_corrected+="$d|"
900 done
901 omit_drivers="${omit_drivers_corrected%|}"
902 unset omit_drivers_corrected
903
904 # prepare args for logging
905 for ((i=0; i < ${#dracut_args[@]}; i++)); do
906 [[ "${dracut_args[$i]}" == *\ * ]] && \
907 dracut_args[$i]="\"${dracut_args[$i]}\""
908 #" keep vim happy
909 done
910
911 dinfo "Executing: $dracut_cmd ${dracut_args[@]}"
912
913 [[ $do_list = yes ]] && {
914 for mod in $dracutbasedir/modules.d/*; do
915 [[ -d $mod ]] || continue;
916 [[ -e $mod/install || -e $mod/installkernel || \
917 -e $mod/module-setup.sh ]] || continue
918 printf "%s\n" "${mod##*/??}"
919 done
920 exit 0
921 }
922
923 # This is kinda legacy -- eventually it should go away.
924 case $dracutmodules in
925 ""|auto) dracutmodules="all" ;;
926 esac
927
928 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
929
930 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
931 if ! [[ -f $srcmods/modules.dep ]]; then
932 dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
933 elif ! ( command -v gzip &>/dev/null && command -v xz &>/dev/null); then
934 read _mod < $srcmods/modules.dep
935 _mod=${_mod%%:*}
936 if [[ -f $srcmods/"$_mod" ]]; then
937 # Check, if kernel modules are compressed, and if we can uncompress them
938 case "$_mod" in
939 *.ko.gz) kcompress=gzip;;
940 *.ko.xz) kcompress=xz;;
941 esac
942 if [[ $kcompress ]]; then
943 if ! command -v "$kcompress" &>/dev/null; then
944 dfatal "Kernel modules are compressed with $kcompress, but $kcompress is not available."
945 exit 1
946 fi
947 fi
948 fi
949 fi
950 fi
951
952 if [[ ! $print_cmdline ]]; then
953 if [[ -f $outfile && ! $force ]]; then
954 dfatal "Will not override existing initramfs ($outfile) without --force"
955 exit 1
956 fi
957
958 outdir=${outfile%/*}
959 [[ $outdir ]] || outdir="/"
960
961 if [[ ! -d "$outdir" ]]; then
962 dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
963 exit 1
964 elif [[ ! -w "$outdir" ]]; then
965 dfatal "No permission to write to $outdir."
966 exit 1
967 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
968 dfatal "No permission to write $outfile."
969 exit 1
970 fi
971
972 if [[ $loginstall ]]; then
973 if ! mkdir -p "$loginstall"; then
974 dfatal "Could not create directory to log installed files to '$loginstall'."
975 exit 1
976 fi
977 loginstall=$(readlink -f "$loginstall")
978 fi
979
980 if [[ $uefi = yes ]]; then
981 if ! command -v objcopy &>/dev/null; then
982 dfatal "Need 'objcopy' to create a UEFI executable"
983 exit 1
984 fi
985 unset EFI_MACHINE_TYPE_NAME
986 case $(arch) in
987 x86_64)
988 EFI_MACHINE_TYPE_NAME=x64;;
989 ia32)
990 EFI_MACHINE_TYPE_NAME=ia32;;
991 *)
992 dfatal "Architecture '$(arch)' not supported to create a UEFI executable"
993 exit 1
994 ;;
995 esac
996
997 if ! [[ -s $uefi_stub ]]; then
998 for uefi_stub in \
999 "/lib/systemd/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
1000 "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
1001 [[ -s $uefi_stub ]] || continue
1002 break
1003 done
1004 fi
1005 if ! [[ -s $uefi_stub ]]; then
1006 dfatal "Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
1007 exit 1
1008 fi
1009
1010 if ! [[ $kernel_image ]]; then
1011 for kernel_image in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
1012 [[ -s "$kernel_image" ]] || continue
1013 break
1014 done
1015 fi
1016 if ! [[ -s $kernel_image ]]; then
1017 dfatal "Can't find a kernel image '$kernel_image' to create a UEFI executable"
1018 exit 1
1019 fi
1020 fi
1021 fi
1022
1023 if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE; then
1024 dwarn "Disabling ACPI override, because kernel does not support it. CONFIG_ACPI_INITRD_TABLE_OVERRIDE!=y"
1025 unset acpi_override
1026 fi
1027
1028 if [[ $early_microcode = yes ]]; then
1029 if [[ $hostonly ]]; then
1030 [[ $(get_cpu_vendor) == "AMD" ]] \
1031 && ! check_kernel_config CONFIG_MICROCODE_AMD \
1032 && unset early_microcode
1033 [[ $(get_cpu_vendor) == "Intel" ]] \
1034 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1035 && unset early_microcode
1036 else
1037 ! check_kernel_config CONFIG_MICROCODE_AMD \
1038 && ! check_kernel_config CONFIG_MICROCODE_INTEL \
1039 && unset early_microcode
1040 fi
1041 [[ $early_microcode != yes ]] \
1042 && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
1043 fi
1044
1045 # Need to be able to have non-root users read stuff (rpcbind etc)
1046 chmod 755 "$initdir"
1047
1048 if [[ $hostonly ]]; then
1049 for i in /sys /proc /run /dev; do
1050 if ! findmnt --target "$i" &>/dev/null; then
1051 dwarning "Turning off host-only mode: '$i' is not mounted!"
1052 unset hostonly
1053 fi
1054 done
1055 fi
1056
1057 declare -A host_fs_types
1058
1059 for line in "${fstab_lines[@]}"; do
1060 set -- $line
1061 dev="$1"
1062 #dev mp fs fsopts
1063 case "$dev" in
1064 UUID=*)
1065 dev=$(blkid -l -t UUID=${dev#UUID=} -o device)
1066 ;;
1067 LABEL=*)
1068 dev=$(blkid -l -t LABEL=${dev#LABEL=} -o device)
1069 ;;
1070 PARTUUID=*)
1071 dev=$(blkid -l -t PARTUUID=${dev#PARTUUID=} -o device)
1072 ;;
1073 PARTLABEL=*)
1074 dev=$(blkid -l -t PARTLABEL=${dev#PARTLABEL=} -o device)
1075 ;;
1076 esac
1077 [ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue
1078 if [[ "$3" == btrfs ]]; then
1079 for i in $(btrfs_devs "$2"); do
1080 push_host_devs "$i"
1081 done
1082 fi
1083 push_host_devs "$dev"
1084 host_fs_types["$dev"]="$3"
1085 done
1086
1087 for f in $add_fstab; do
1088 [[ -e $f ]] || continue
1089 while read dev rest || [ -n "$dev" ]; do
1090 push_host_devs "$dev"
1091 done < "$f"
1092 done
1093
1094 for dev in $add_device; do
1095 push_host_devs "$dev"
1096 done
1097
1098 if (( ${#add_device_l[@]} )); then
1099 add_device+=" ${add_device_l[@]} "
1100 push_host_devs "${add_device_l[@]}"
1101 fi
1102
1103 if [[ $hostonly ]]; then
1104 # in hostonly mode, determine all devices, which have to be accessed
1105 # and examine them for filesystem types
1106
1107 for mp in \
1108 "/" \
1109 "/etc" \
1110 "/bin" \
1111 "/sbin" \
1112 "/lib" \
1113 "/lib64" \
1114 "/usr" \
1115 "/usr/bin" \
1116 "/usr/sbin" \
1117 "/usr/lib" \
1118 "/usr/lib64" \
1119 "/boot" \
1120 "/boot/efi" \
1121 ;
1122 do
1123 mp=$(readlink -f "$mp")
1124 mountpoint "$mp" >/dev/null 2>&1 || continue
1125 _dev=$(find_block_device "$mp")
1126 _bdev=$(readlink -f "/dev/block/$_dev")
1127 [[ -b $_bdev ]] && _dev=$_bdev
1128 [[ "$mp" == "/" ]] && root_devs+=("$_dev")
1129 push_host_devs "$_dev"
1130 if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
1131 for i in $(btrfs_devs "$mp"); do
1132 [[ "$mp" == "/" ]] && root_devs+=("$i")
1133 push_host_devs "$i"
1134 done
1135 fi
1136 done
1137
1138 if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
1139 while read dev type rest || [ -n "$dev" ]; do
1140 [[ -b $dev ]] || continue
1141 [[ "$type" == "partition" ]] || continue
1142
1143 while read _d _m _t _o _r || [ -n "$_d" ]; do
1144 [[ "$_d" == \#* ]] && continue
1145 [[ $_d ]] || continue
1146 [[ $_t != "swap" ]] && continue
1147 [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue
1148 [[ "$_o" == *noauto* ]] && continue
1149 _d=$(expand_persistent_dev "$_d")
1150 [[ "$_d" -ef "$dev" ]] || continue
1151
1152 if [[ -f /etc/crypttab ]]; then
1153 while read _mapper _a _p _o || [ -n "$_mapper" ]; do
1154 [[ $_mapper = \#* ]] && continue
1155 [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
1156 [[ "$_o" ]] || _o="$_p"
1157 # skip entries with password files
1158 [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
1159 # skip mkswap swap
1160 [[ $_o == *swap* ]] && continue 2
1161 done < /etc/crypttab
1162 fi
1163
1164 _dev="$(readlink -f "$dev")"
1165 push_host_devs "$_dev"
1166 swap_devs+=("$_dev")
1167 break
1168 done < /etc/fstab
1169 done < /proc/swaps
1170 fi
1171
1172 # collect all "x-initrd.mount" entries from /etc/fstab
1173 if [[ -f /etc/fstab ]]; then
1174 while read _d _m _t _o _r || [ -n "$_d" ]; do
1175 [[ "$_d" == \#* ]] && continue
1176 [[ $_d ]] || continue
1177 [[ "$_o" != *x-initrd.mount* ]] && continue
1178 _dev=$(expand_persistent_dev "$_d")
1179 _dev="$(readlink -f "$_dev")"
1180 [[ -b $_dev ]] || continue
1181
1182 push_host_devs "$_dev"
1183 if [[ "$_t" == btrfs ]]; then
1184 for i in $(find_btrfs_devs "$_m"); do
1185 push_host_devs "$i"
1186 done
1187 fi
1188 done < /etc/fstab
1189 fi
1190
1191 # record all host modaliases
1192 declare -A host_modalias
1193 find /sys/devices -name modalias -exec cat '{}' \; > "$initdir/.modalias"
1194 while read -r modalias || [ -n "$modalias" ]; do
1195 [[ $modalias ]] && host_modalias["$modalias"]=1
1196 done < "$initdir/.modalias"
1197
1198 rm -f -- "$initdir/.modalias"
1199
1200 while read _k _s _v || [ -n "$_k" ]; do
1201 [ "$_k" != "name" -a "$_k" != "driver" ] && continue
1202 host_modalias["$_v"]=1
1203 done </proc/crypto
1204
1205 # check /proc/modules
1206 declare -A host_modules
1207 while read m rest || [ -n "$m" ]; do
1208 host_modules["$m"]=1
1209 done </proc/modules
1210 fi
1211
1212 unset m
1213 unset rest
1214
1215 _get_fs_type() {
1216 [[ $1 ]] || return
1217 if [[ -b /dev/block/$1 ]]; then
1218 ID_FS_TYPE=$(get_fs_env "/dev/block/$1") && host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
1219 return 1
1220 fi
1221 if [[ -b $1 ]]; then
1222 ID_FS_TYPE=$(get_fs_env "$1") && host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
1223 return 1
1224 fi
1225 if fstype=$(find_dev_fstype "$1"); then
1226 host_fs_types["$1"]="$fstype"
1227 return 1
1228 fi
1229 return 1
1230 }
1231
1232 for dev in "${host_devs[@]}"; do
1233 _get_fs_type "$dev"
1234 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1235 done
1236
1237 for dev in "${!host_fs_types[@]}"; do
1238 [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue
1239 rootopts=$(find_dev_fsopts "$dev")
1240 if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then
1241 journaldev=$(fs_get_option $rootopts "jdev")
1242 elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then
1243 journaldev=$(fs_get_option $rootopts "logdev")
1244 fi
1245 if [[ $journaldev ]]; then
1246 dev="$(readlink -f "$dev")"
1247 push_host_devs "$dev"
1248 _get_fs_type "$dev"
1249 check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
1250 fi
1251 done
1252
1253 [[ -d $udevdir ]] \
1254 || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
1255 if ! [[ -d "$udevdir" ]]; then
1256 [[ ! -h /lib ]] && [[ -d /lib/udev ]] && udevdir=/lib/udev
1257 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
1258 fi
1259
1260 [[ -d $systemdutildir ]] \
1261 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
1262
1263 if ! [[ -d "$systemdutildir" ]]; then
1264 [[ ! -h /lib ]] && [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
1265 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
1266 fi
1267
1268 [[ -d $systemdsystemunitdir ]] \
1269 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
1270
1271 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
1272
1273 [[ -d $systemdsystemconfdir ]] \
1274 || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
1275
1276 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
1277
1278 [[ -d $tmpfilesdir ]] \
1279 || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null)
1280
1281 if ! [[ -d "$tmpfilesdir" ]]; then
1282 [[ -f /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d
1283 [[ -f /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d
1284 fi
1285
1286 export initdir dracutbasedir \
1287 dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \
1288 mods_to_load \
1289 fw_dir drivers_dir debug no_kernel kernel_only \
1290 omit_drivers mdadmconf lvmconf root_dev \
1291 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
1292 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
1293 debug host_fs_types host_devs swap_devs sshkey add_fstab \
1294 DRACUT_VERSION udevdir prefix filesystems drivers \
1295 systemdutildir systemdsystemunitdir systemdsystemconfdir \
1296 host_modalias host_modules hostonly_cmdline loginstall \
1297 tmpfilesdir
1298
1299 mods_to_load=""
1300 # check all our modules to see if they should be sourced.
1301 # This builds a list of modules that we will install next.
1302 for_each_module_dir check_module
1303 for_each_module_dir check_mount
1304
1305 dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
1306
1307 do_print_cmdline()
1308 {
1309 local -A _mods_to_print
1310 for i in $modules_loaded $mods_to_load; do
1311 _mods_to_print[$i]=1
1312 done
1313
1314 # source our modules.
1315 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1316 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1317 [[ ${_mods_to_print[$_d_mod]} ]] || continue
1318 module_cmdline "$_d_mod"
1319 done
1320 unset moddir
1321 }
1322
1323 if [[ $print_cmdline ]]; then
1324 do_print_cmdline
1325 printf "\n"
1326 exit 0
1327 fi
1328
1329 # Create some directory structure first
1330 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
1331
1332 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
1333 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
1334
1335 if [[ $prefix ]]; then
1336 for d in bin etc lib sbin tmp usr var $libdirs; do
1337 [[ "$d" == */* ]] && continue
1338 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
1339 done
1340 fi
1341
1342 if [[ $kernel_only != yes ]]; then
1343 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var var/tmp $libdirs; do
1344 [[ -e "${initdir}${prefix}/$d" ]] && continue
1345 if [ -L "/$d" ]; then
1346 inst_symlink "/$d" "${prefix}/$d"
1347 else
1348 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1349 fi
1350 done
1351
1352 for d in dev proc sys sysroot root run; do
1353 if [ -L "/$d" ]; then
1354 inst_symlink "/$d"
1355 else
1356 mkdir -m 0755 -p "$initdir/$d"
1357 fi
1358 done
1359
1360 ln -sfn ../run "$initdir/var/run"
1361 ln -sfn ../run/lock "$initdir/var/lock"
1362 else
1363 for d in lib "$libdir"; do
1364 [[ -e "${initdir}${prefix}/$d" ]] && continue
1365 if [ -h "/$d" ]; then
1366 inst "/$d" "${prefix}/$d"
1367 else
1368 mkdir -m 0755 -p "${initdir}${prefix}/$d"
1369 fi
1370 done
1371 fi
1372
1373 if [[ $kernel_only != yes ]]; then
1374 mkdir -p "${initdir}/etc/cmdline.d"
1375 for _d in $hookdirs; do
1376 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1377 done
1378 if [[ "$UID" = "0" ]]; then
1379 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1380 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1381 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1382 fi
1383 fi
1384
1385 _isize=0 #initramfs size
1386 modules_loaded=" "
1387 # source our modules.
1388 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1389 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1390 [[ "$mods_to_load" == *\ $_d_mod\ * ]] || continue
1391 if [[ $show_modules = yes ]]; then
1392 printf "%s\n" "$_d_mod"
1393 else
1394 dinfo "*** Including module: $_d_mod ***"
1395 fi
1396 if [[ $kernel_only == yes ]]; then
1397 module_installkernel "$_d_mod" || {
1398 dfatal "installkernel failed in module $_d_mod"
1399 exit 1
1400 }
1401 else
1402 module_install "$_d_mod"
1403 if [[ $no_kernel != yes ]]; then
1404 module_installkernel "$_d_mod" || {
1405 dfatal "installkernel failed in module $_d_mod"
1406 exit 1
1407 }
1408 fi
1409 fi
1410 mods_to_load=${mods_to_load// $_d_mod /}
1411 modules_loaded+="$_d_mod "
1412
1413 #print the module install size
1414 if [ -n "$printsize" ]; then
1415 _isize_new=$(du -sk ${initdir}|cut -f1)
1416 _isize_delta=$((_isize_new - _isize))
1417 printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1418 _isize=$_isize_new
1419 fi
1420 done
1421 unset moddir
1422
1423 for i in $modules_loaded; do
1424 mkdir -p $initdir/lib/dracut
1425 printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1426 done
1427
1428 dinfo "*** Including modules done ***"
1429
1430 ## final stuff that has to happen
1431 if [[ $no_kernel != yes ]]; then
1432
1433 if [[ $drivers ]]; then
1434 hostonly='' instmods $drivers
1435 fi
1436
1437 if [[ $add_drivers ]]; then
1438 hostonly='' instmods -c $add_drivers
1439 fi
1440 if [[ $force_drivers ]]; then
1441 hostonly='' instmods -c $force_drivers
1442 rm -f $initdir/etc/cmdline.d/20-force_driver.conf
1443 for mod in $force_drivers; do
1444 echo "rd.driver.pre=$mod" >>$initdir/etc/cmdline.d/20-force_drivers.conf
1445 done
1446 fi
1447 if [[ $filesystems ]]; then
1448 hostonly='' instmods -c $filesystems
1449 fi
1450
1451 dinfo "*** Installing kernel module dependencies and firmware ***"
1452 dracut_kernel_post
1453 dinfo "*** Installing kernel module dependencies and firmware done ***"
1454
1455 if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1456 if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1457 [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1458 for i in ${initdir}/etc/cmdline.d/*.conf; do
1459 # We need no initramfs image and do not generate one.
1460 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1461 done
1462 fi
1463 fi
1464 fi
1465
1466 if [[ $kernel_only != yes ]]; then
1467 (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1468 (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]}
1469
1470 [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1471
1472 for line in "${fstab_lines[@]}"; do
1473 line=($line)
1474
1475 if [ -z "${line[1]}" ]; then
1476 # Determine device and mount options from current system
1477 mountpoint -q "${line[0]}" || derror "${line[0]} is not a mount point!"
1478 line=($(findmnt --raw -n --target "${line[0]}" --output=source,target,fstype,options))
1479 dinfo "Line for ${line[1]}: ${line[@]}"
1480 else
1481 # Use default options
1482 [ -z "${line[3]}" ] && line[3]="defaults"
1483 fi
1484
1485 # Default options for freq and passno
1486 [ -z "${line[4]}" ] && line[4]="0"
1487 [ -z "${line[5]}" ] && line[5]="2"
1488
1489 strstr "${line[2]}" "nfs" && line[5]="0"
1490 echo "${line[@]}" >> "${initdir}/etc/fstab"
1491 done
1492
1493 for f in $add_fstab; do
1494 cat "$f" >> "${initdir}/etc/fstab"
1495 done
1496
1497 if [ -d ${initdir}/$systemdutildir ]; then
1498 mkdir -p ${initdir}/etc/conf.d
1499 {
1500 printf "%s\n" "systemdutildir=\"$systemdutildir\""
1501 printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1502 printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1503 } > ${initdir}/etc/conf.d/systemd.conf
1504 fi
1505
1506 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1507 dinfo "*** Resolving executable dependencies ***"
1508 find "$initdir" -type f -perm /0111 -not -path '*.ko' -print0 \
1509 | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
1510 dinfo "*** Resolving executable dependencies done***"
1511 fi
1512
1513 # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
1514 for _dir in $libdirs; do
1515 for _f in "$_dir/libpthread.so"*; do
1516 [[ -e "$_f" ]] || continue
1517 inst_libdir_file "libgcc_s.so*"
1518 break 2
1519 done
1520 done
1521 fi
1522
1523 for ((i=0; i < ${#include_src[@]}; i++)); do
1524 src="${include_src[$i]}"
1525 target="${include_target[$i]}"
1526 if [[ $src && $target ]]; then
1527 if [[ -f $src ]]; then
1528 inst $src $target
1529 else
1530 ddebug "Including directory: $src"
1531 destdir="${initdir}/${target}"
1532 mkdir -p "$destdir"
1533 # check for preexisting symlinks, so we can cope with the
1534 # symlinks to $prefix
1535 # Objectname is a file or a directory
1536 for objectname in "$src"/*; do
1537 [[ -e "$objectname" || -h "$objectname" ]] || continue
1538 if [[ -d "$objectname" ]]; then
1539 # objectname is a directory, let's compute the final directory name
1540 object_destdir=${destdir}/${objectname#$src/}
1541 if ! [[ -e "$object_destdir" ]]; then
1542 mkdir -m 0755 -p "$object_destdir"
1543 chmod --reference="$objectname" "$object_destdir"
1544 fi
1545 cp --reflink=auto --sparse=auto -fa -t "$object_destdir" "$objectname"/*
1546 else
1547 cp --reflink=auto --sparse=auto -fa -t "$destdir" "$objectname"
1548 fi
1549 done
1550 fi
1551 fi
1552 done
1553
1554 if [[ $kernel_only != yes ]]; then
1555 # make sure that library links are correct and up to date
1556 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1557 [[ -f $f ]] && inst_simple "$f"
1558 done
1559 if ! ldconfig -r "$initdir"; then
1560 if [[ $UID = 0 ]]; then
1561 derror "ldconfig exited ungracefully"
1562 else
1563 derror "ldconfig might need uid=0 (root) for chroot()"
1564 fi
1565 fi
1566 fi
1567
1568 PRELINK_BIN="$(command -v prelink)"
1569 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1570 if [[ $DRACUT_FIPS_MODE ]]; then
1571 dinfo "*** Installing prelink files ***"
1572 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1573 elif [[ $do_prelink == yes ]]; then
1574 dinfo "*** Pre-linking files ***"
1575 inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1576 chroot "$initdir" "$PRELINK_BIN" -a
1577 rm -f -- "$initdir/$PRELINK_BIN"
1578 rm -fr -- "$initdir"/etc/prelink.*
1579 dinfo "*** Pre-linking files done ***"
1580 fi
1581 fi
1582
1583 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1584 dinfo "*** Hardlinking files ***"
1585 hardlink "$initdir" 2>&1
1586 dinfo "*** Hardlinking files done ***"
1587 fi
1588
1589 # strip binaries
1590 if [[ $do_strip = yes ]] ; then
1591 for p in strip xargs find; do
1592 if ! type -P $p >/dev/null; then
1593 dinfo "Could not find '$p'. Not stripping the initramfs."
1594 do_strip=no
1595 fi
1596 done
1597 fi
1598
1599 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1600 dinfo "*** Stripping files ***"
1601 find "$initdir" -type f \
1602 -executable -not -path '*/lib/modules/*.ko' -print0 \
1603 | xargs -r -0 strip -g 2>/dev/null
1604
1605 # strip kernel modules, but do not touch signed modules
1606 find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1607 | while read -r -d $'\0' f || [ -n "$f" ]; do
1608 SIG=$(tail -c 28 "$f")
1609 [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1610 done | xargs -r -0 strip -g
1611
1612 dinfo "*** Stripping files done ***"
1613 fi
1614 if [[ $early_microcode = yes ]]; then
1615 dinfo "*** Generating early-microcode cpio image ***"
1616 ucode_dir=(amd-ucode intel-ucode)
1617 ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1618 _dest_dir="$early_cpio_dir/d/kernel/x86/microcode"
1619 _dest_idx="0 1"
1620 mkdir -p $_dest_dir
1621 if [[ $hostonly ]]; then
1622 [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1623 [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1624 fi
1625 for idx in $_dest_idx; do
1626 _fw=${ucode_dir[$idx]}
1627 for _fwdir in $fw_dir; do
1628 if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1629 _src="*"
1630 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1631 if [[ $hostonly ]]; then
1632 _src=$(get_ucode_file)
1633 [[ $_src ]] || break
1634 [[ -r $_fwdir/$_fw/$_src ]] || break
1635 fi
1636
1637 for i in $_fwdir/$_fw/$_src; do
1638 [ -e "$i" ] && break
1639 break 2
1640 done
1641 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1642 create_early_cpio="yes"
1643 fi
1644 done
1645 done
1646 fi
1647
1648 if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
1649 dinfo "*** Packaging ACPI tables to override BIOS provided ones ***"
1650 _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi"
1651 mkdir -p $_dest_dir
1652 for table in $acpi_table_dir/*.aml; do
1653 dinfo " Adding ACPI table: $table"
1654 cp -a $table $_dest_dir
1655 create_early_cpio="yes"
1656 done
1657 fi
1658
1659 dinfo "*** Store current command line parameters ***"
1660 if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
1661 dfatal "Could not store the current command line parameters"
1662 exit 1
1663 fi
1664
1665 if [[ $hostonly_cmdline ]] ; then
1666 unset _stored_cmdline
1667 if [ -d $initdir/etc/cmdline.d ];then
1668 dinfo "Stored kernel commandline:"
1669 for conf in $initdir/etc/cmdline.d/*.conf ; do
1670 [ -e "$conf" ] || continue
1671 dinfo "$(< $conf)"
1672 _stored_cmdline=1
1673 done
1674 fi
1675 if ! [[ $_stored_cmdline ]]; then
1676 dinfo "No dracut internal kernel commandline stored in initrd"
1677 fi
1678 fi
1679 rm -f -- "$outfile"
1680 dinfo "*** Creating image file '$outfile' ***"
1681
1682 if [[ $uefi = yes ]]; then
1683 uefi_outfile="$outfile"
1684 readonly uefi_outdir="$(mktemp -p "$TMPDIR/" -d -t initrd.XXXXXX)"
1685 # redirect initrd output
1686 outfile="$uefi_outdir/initrd"
1687 fi
1688
1689 if [[ $DRACUT_REPRODUCIBLE ]]; then
1690 find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1691 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1692
1693 if [[ "$(cpio --help)" == *--reproducible* ]]; then
1694 CPIO_REPRODUCIBLE=1
1695 else
1696 dinfo "cpio does not support '--reproducible'. Resulting image will not be reproducible."
1697 fi
1698 fi
1699
1700 [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0"
1701
1702 if [[ $create_early_cpio = yes ]]; then
1703 echo 1 > "$early_cpio_dir/d/early_cpio"
1704
1705 if [[ $DRACUT_REPRODUCIBLE ]]; then
1706 find "$early_cpio_dir/d" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
1707 | xargs -r -0 touch -h -m -c -r "$dracutbasedir/dracut-functions.sh"
1708 fi
1709
1710 # The microcode blob is _before_ the initramfs blob, not after
1711 (
1712 cd "$early_cpio_dir/d"
1713 find . -print0 | sort -z \
1714 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet > $outfile
1715 )
1716 fi
1717
1718 if ! (
1719 umask 077; cd "$initdir"
1720 find . -print0 | sort -z \
1721 | cpio ${CPIO_REPRODUCIBLE:+--reproducible} --null $cpio_owner_root -H newc -o --quiet \
1722 | $compress >> "$outfile"
1723 ); then
1724 dfatal "dracut: creation of $outfile failed"
1725 rm -f "$outfile"
1726 exit 1
1727 fi
1728
1729 dinfo "*** Creating initrd image file '$outfile' done ***"
1730
1731 if (( maxloglvl >= 5 )); then
1732 if [[ $allowlocal ]]; then
1733 "$dracutbasedir/lsinitrd.sh" "$outfile"| ddebug
1734 else
1735 lsinitrd "$outfile"| ddebug
1736 fi
1737 fi
1738
1739 if [[ $uefi = yes ]]; then
1740 if [[ $kernel_cmdline ]]; then
1741 echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
1742 elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc/cmdline.d ];then
1743 for conf in $initdir/etc/cmdline.d/*.conf ; do
1744 [ -e "$conf" ] || continue
1745 printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
1746 done
1747 else
1748 do_print_cmdline > "$uefi_outdir/cmdline.txt"
1749 fi
1750 echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
1751
1752 dinfo "Using UEFI kernel cmdline:"
1753 dinfo $(< "$uefi_outdir/cmdline.txt")
1754
1755 [[ -s /usr/lib/os-release ]] && uefi_osrelease="/usr/lib/os-release"
1756 [[ -s /etc/os-release ]] && uefi_osrelease="/etc/os-release"
1757
1758 objcopy \
1759 ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
1760 --add-section .cmdline="$uefi_outdir/cmdline.txt" --change-section-vma .cmdline=0x30000 \
1761 --add-section .linux="$kernel_image" --change-section-vma .linux=0x40000 \
1762 --add-section .initrd="$outfile" --change-section-vma .initrd=0x3000000 \
1763 "$uefi_stub" "$uefi_outfile"
1764 dinfo "*** Creating UEFI image file '$uefi_outfile' done ***"
1765 fi
1766
1767 exit 0