forked from dracutdevs/dracut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dracut.sh
executable file
·2625 lines (2393 loc) · 91.6 KB
/
dracut.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -p
#
# Generator script for a dracut initramfs
# Copyright 2005-2013 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# store for logging
unset BASH_ENV
unset GZIP
# Verify bash version, current minimum is 4
if ((BASH_VERSINFO[0] < 4)); then
printf "%s\n" "dracut[F]: dracut requires at least Bash 4." >&2
exit 1
fi
dracut_args=("$@")
# shellcheck disable=SC2155
readonly dracut_cmd=$(readlink -f "$0")
set -o pipefail
usage() {
[[ $sysroot_l ]] && dracutsysrootdir="$sysroot_l"
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi
# 80x25 linebreak here ^
cat << EOF
Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Version: $DRACUT_VERSION
Creates initial ramdisk images for preloading modules
-h, --help Display all options
If a [LIST] has multiple arguments, then you have to put these in quotes.
For example:
# dracut --add-drivers "module1 module2" ...
EOF
}
long_usage() {
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi
# 80x25 linebreak here ^
cat << EOF
Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Version: $DRACUT_VERSION
Creates initial ramdisk images for preloading modules
--kver [VERSION] Set kernel version to [VERSION].
-f, --force Overwrite existing initramfs file.
[OUTPUT_FILE] --rebuild
Append the current arguments to those with which the
input initramfs image was built. This option helps in
incrementally building the initramfs for testing.
If optional [OUTPUT_FILE] is not provided, the input
initramfs provided to rebuild will be used as output
file.
-a, --add [LIST] Add a space-separated list of dracut modules.
--force-add [LIST] Force to add a space-separated list of dracut modules
to the default set of modules, when -H is specified.
-o, --omit [LIST] Omit a space-separated list of dracut modules.
-m, --modules [LIST] Specify a space-separated list of dracut modules to
call when building the initramfs. Modules are located
in /usr/lib/dracut/modules.d.
This option forces dracut to only include the specified
dracut modules.
In most cases the --add option is what you want to use.
--add-drivers [LIST] Specify a space-separated list of kernel
modules to add to the initramfs.
--force-drivers [LIST]
Specify a space-separated list of kernel
modules to add to the initramfs and make sure they
are tried to be loaded via modprobe same as passing
rd.driver.pre=DRIVER kernel parameter.
--omit-drivers [LIST] Specify a space-separated list of kernel
modules not to add to the initramfs.
-d, --drivers [LIST] Specify a space-separated list of kernel modules to
exclusively include in the initramfs.
--filesystems [LIST] Specify a space-separated list of kernel filesystem
modules to exclusively include in the generic
initramfs.
-k, --kmoddir [DIR] Specify the directory where to look for kernel
modules.
--fwdir [DIR] Specify additional colon-separated list of directories
where to look for firmware files.
--libdirs [LIST] Specify a space-separated list of directories
where to look for libraries.
--kernel-only Only install kernel drivers and firmware files.
--no-kernel Do not install kernel drivers and firmware files.
--print-cmdline Print the kernel command line for the given disk layout.
--early-microcode Combine early microcode with ramdisk.
--no-early-microcode Do not combine early microcode with ramdisk.
--kernel-cmdline [PARAMETERS]
Specify default kernel command line parameters.
--strip Strip binaries in the initramfs.
--aggressive-strip Strip more than just debug symbol and sections,
for a smaller initramfs build. The --strip option must
also be specified.
--nostrip Do not strip binaries in the initramfs.
--hardlink Hardlink files in the initramfs.
--nohardlink Do not hardlink files in the initramfs.
--prefix [DIR] Prefix initramfs files with [DIR].
--noprefix Do not prefix initramfs files.
--mdadmconf Include local /etc/mdadm.conf file.
--nomdadmconf Do not include local /etc/mdadm.conf file.
--lvmconf Include local /etc/lvm/lvm.conf file.
--nolvmconf Do not include local /etc/lvm/lvm.conf file.
--fscks [LIST] Add a space-separated list of fsck helpers.
--nofscks Inhibit installation of any fsck helpers.
--ro-mnt Mount / and /usr read-only by default.
-h, --help This message.
--debug Output debug information of the build process.
--profile Output profile information of the build process.
-L, --stdlog [0-6] Specify logging level (to standard error)
0 - suppress any messages
1 - only fatal errors
2 - all errors
3 - warnings
4 - info
5 - debug info (here starts lots of output)
6 - trace info (and even more)
-v, --verbose Increase verbosity level.
-q, --quiet Decrease verbosity level.
-c, --conf [FILE] Specify configuration file to use.
Default: /etc/dracut.conf
--confdir [DIR] Specify configuration directory to use *.conf files
from. Default: /etc/dracut.conf.d
--tmpdir [DIR] Temporary directory to be used instead of default
${TMPDIR:-/var/tmp}.
-r, --sysroot [DIR] Specify sysroot directory to collect files from.
-l, --local Local mode. Use modules from the current working
directory instead of the system-wide installed in
/usr/lib/dracut/modules.d.
Useful when running dracut from a git checkout.
-H, --hostonly Host-only mode: Install only what is needed for
booting the local host instead of a generic host.
-N, --no-hostonly Disables host-only mode.
--hostonly-mode [MODE]
Specify the host-only mode to use. [MODE] could be
one of "sloppy" or "strict". "sloppy" mode is used
by default.
In "sloppy" host-only mode, extra drivers and modules
will be installed, so minor hardware change won't make
the image unbootable (e.g. changed keyboard), and the
image is still portable among similar hosts.
With "strict" mode enabled, anything not necessary
for booting the local host in its current state will
not be included, and modules may do some extra job
to save more space. Minor change of hardware or
environment could make the image unbootable.
DO NOT use "strict" mode unless you know what you
are doing.
--hostonly-cmdline Store kernel command line arguments needed
in the initramfs.
--no-hostonly-cmdline Do not store kernel command line arguments needed
in the initramfs.
--no-hostonly-default-device
Do not generate implicit host devices like root,
swap, fstab, etc. Use "--mount" or "--add-device"
to explicitly add devices as needed.
--hostonly-i18n Install only needed keyboard and font files according
to the host configuration (default).
--no-hostonly-i18n Install all keyboard and font files available.
--hostonly-nics [LIST]
Only enable listed NICs in the initramfs. The list can
be empty, so other modules can install only the
necessary network drivers.
--persistent-policy [POLICY]
Use [POLICY] to address disks and partitions.
POLICY can be any directory name found in /dev/disk
(e.g. "by-uuid", "by-label"), or "mapper" to use
/dev/mapper device names (default).
--fstab Use /etc/fstab to determine the root device.
--add-fstab [FILE] Add file to the initramfs fstab.
--mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
Mount device [DEV] on mountpoint [MP] with filesystem
[FSTYPE] and options [FSOPTS] in the initramfs.
--mount "[MP]" Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
determined by looking at the current mounts.
--add-device "[DEV]" Bring up [DEV] in initramfs.
-i, --include [SOURCE] [TARGET]
Include the files in the SOURCE directory into the
Target directory in the final initramfs.
If SOURCE is a file, it will be installed to TARGET
in the final initramfs.
-I, --install [LIST] Install the space separated list of files into the
initramfs.
--install-optional [LIST]
Install the space separated list of files into the
initramfs, if they exist.
--gzip Compress the generated initramfs using gzip.
This will be done by default, unless another
compression option or --no-compress is passed.
--bzip2 Compress the generated initramfs using bzip2.
Make sure your kernel has bzip2 decompression support
compiled in, otherwise you will not be able to boot.
--lzma Compress the generated initramfs using lzma.
Make sure your kernel has lzma support compiled in,
otherwise you will not be able to boot.
--xz Compress the generated initramfs using xz.
Make sure that your kernel has xz support compiled
in, otherwise you will not be able to boot.
--lzo Compress the generated initramfs using lzop.
Make sure that your kernel has lzo support compiled
in, otherwise you will not be able to boot.
--lz4 Compress the generated initramfs using lz4.
Make sure that your kernel has lz4 support compiled
in, otherwise you will not be able to boot.
--zstd Compress the generated initramfs using Zstandard.
Make sure that your kernel has zstd support compiled
in, otherwise you will not be able to boot.
--compress [COMPRESSION]
Compress the generated initramfs with the
passed compression program. Make sure your kernel
knows how to decompress the generated initramfs,
otherwise you will not be able to boot.
--no-compress Do not compress the generated initramfs. This will
override any other compression options.
--squash-compressor [COMPRESSION]
Specify the compressor and compressor specific options
used by mksquashfs if squash module is called when
building the initramfs.
--enhanced-cpio Attempt to reflink cpio file data using dracut-cpio.
--list-modules List all available dracut modules.
-M, --show-modules Print included module's name to standard output during
build.
--keep Keep the temporary initramfs for debugging purposes.
--printsize Print out the module install size.
--sshkey [SSHKEY] Add SSH key to initramfs (use with ssh-client module).
--logfile [FILE] Logfile to use (overrides configuration setting).
--reproducible Create reproducible images.
--no-reproducible Do not create reproducible images.
--loginstall [DIR] Log all files installed from the host to [DIR].
--uefi Create an UEFI executable with the kernel cmdline and
kernel combined.
--no-uefi Disables UEFI mode.
--no-machineid Affects the default output filename of the UEFI
executable, discarding the <MACHINE_ID> part.
--uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable.
--uefi-splash-image [FILE]
Use [FILE] as a splash image when creating an UEFI
executable. Requires bitmap (.bmp) image format.
--kernel-image [FILE] Location of the kernel image.
--regenerate-all Regenerate all initramfs images at the default location
for the kernel versions found on the system.
-p, --parallel Use parallel processing if possible (currently only
supported --regenerate-all)
images simultaneously.
--version Display version.
If [LIST] has multiple arguments, then you have to put these in quotes.
For example:
# dracut --add-drivers "module1 module2" ...
EOF
}
long_version() {
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
if [[ -f $dracutbasedir/dracut-version.sh ]]; then
# shellcheck source=./dracut-version.sh
. "$dracutbasedir"/dracut-version.sh
fi
echo "dracut $DRACUT_VERSION"
}
# Fills up host_devs stack variable and makes sure there are no duplicates
push_host_devs() {
local _dev
for _dev in "$@"; do
[[ " ${host_devs[*]} " == *" $_dev "* ]] && return
host_devs+=("$_dev")
done
}
# Little helper function for reading args from the commandline.
# it automatically handles -a b and -a=b variants, and returns 1 if
# we need to shift $3.
read_arg() {
# $1 = arg name
# $2 = arg value
# $3 = arg parameter
local rematch='^[^=]*=(.*)$'
if [[ $2 =~ $rematch ]]; then
read -r "$1" <<< "${BASH_REMATCH[1]}"
else
read -r "$1" <<< "$3"
# There is no way to shift our callers args, so
# return 1 to indicate they should do it instead.
return 1
fi
}
check_conf_file() {
if grep -H -e '^[^#]*[+]=\("[^ ]\|.*[^ ]"\)' "$@"; then
printf '\ndracut[W]: <key>+=" <values> ": <values> should have surrounding white spaces!\n' >&2
printf 'dracut[W]: This will lead to unwanted side effects! Please fix the configuration file.\n\n' >&2
fi
}
dropindirs_sort() {
local suffix=$1
shift
local -a files
local f d
for d in "$@"; do
for i in "$d/"*"$suffix"; do
if [[ -e $i ]]; then
printf "%s\n" "${i##*/}"
fi
done
done | sort -Vu | {
readarray -t files
for f in "${files[@]}"; do
for d in "$@"; do
if [[ -e "$d/$f" ]]; then
printf "%s\n" "$d/$f"
continue 2
fi
done
done
}
}
rearrange_params() {
# Workaround -i, --include taking 2 arguments
newat=()
for i in "$@"; do
if [[ $i == "-i" ]] || [[ $i == "--include" ]]; then
newat+=("++include") # Replace --include by ++include
else
newat+=("$i")
fi
done
set -- "${newat[@]}" # Set new $@
TEMP=$(
unset POSIXLY_CORRECT
getopt \
-o "a:m:o:d:I:k:c:r:L:fvqlHhMNp" \
--long kver: \
--long add: \
--long force-add: \
--long add-drivers: \
--long force-drivers: \
--long omit-drivers: \
--long modules: \
--long omit: \
--long drivers: \
--long filesystems: \
--long install: \
--long install-optional: \
--long fwdir: \
--long libdirs: \
--long fscks: \
--long add-fstab: \
--long mount: \
--long device: \
--long add-device: \
--long nofscks \
--long ro-mnt \
--long kmoddir: \
--long conf: \
--long confdir: \
--long tmpdir: \
--long sysroot: \
--long stdlog: \
--long compress: \
--long squash-compressor: \
--long prefix: \
--long rebuild: \
--long force \
--long kernel-only \
--long no-kernel \
--long print-cmdline \
--long kernel-cmdline: \
--long strip \
--long aggressive-strip \
--long nostrip \
--long hardlink \
--long nohardlink \
--long noprefix \
--long mdadmconf \
--long nomdadmconf \
--long lvmconf \
--long nolvmconf \
--long debug \
--long profile \
--long sshkey: \
--long logfile: \
--long verbose \
--long quiet \
--long local \
--long hostonly \
--long host-only \
--long no-hostonly \
--long no-host-only \
--long hostonly-mode: \
--long hostonly-cmdline \
--long no-hostonly-cmdline \
--long no-hostonly-default-device \
--long persistent-policy: \
--long fstab \
--long help \
--long bzip2 \
--long lzma \
--long xz \
--long lzo \
--long lz4 \
--long zstd \
--long no-compress \
--long gzip \
--long enhanced-cpio \
--long list-modules \
--long show-modules \
--long keep \
--long printsize \
--long regenerate-all \
--long parallel \
--long noimageifnotneeded \
--long early-microcode \
--long no-early-microcode \
--long reproducible \
--long no-reproducible \
--long loginstall: \
--long uefi \
--long no-uefi \
--long uefi-stub: \
--long uefi-splash-image: \
--long kernel-image: \
--long no-hostonly-i18n \
--long hostonly-i18n \
--long hostonly-nics: \
--long no-machineid \
--long version \
-- "$@"
)
# shellcheck disable=SC2181
if (($? != 0)); then
usage
exit 1
fi
}
verbosity_mod_l=0
unset kernel
unset outfile
rearrange_params "$@"
eval set -- "$TEMP"
# parse command line args to check if '--rebuild' option is present
unset append_args_l
unset rebuild_file
while :; do
if [ "$1" == "--" ]; then
shift
break
fi
if [ "$1" == "--rebuild" ]; then
append_args_l="yes"
rebuild_file="$2"
if [ ! -e "$rebuild_file" ]; then
echo "Image file '$rebuild_file', for rebuild, does not exist!"
exit 1
fi
abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
shift
continue
fi
shift
done
# get output file name and kernel version from command line arguments
while (($# > 0)); do
case ${1%%=*} in
++include)
shift 2
;;
*)
if ! [[ ${outfile+x} ]]; then
outfile=$1
elif ! [[ ${kernel+x} ]]; then
kernel=$1
else
printf "\nUnknown arguments: %s\n\n" "$*" >&2
usage
exit 1
fi
;;
esac
shift
done
# extract input image file provided with rebuild option to get previous parameters, if any
if [[ $append_args_l == "yes" ]]; then
unset rebuild_param
# determine resultant file
if ! [[ $outfile ]]; then
outfile=$rebuild_file
fi
if ! rebuild_param=$(lsinitrd "$rebuild_file" '*lib/dracut/build-parameter.txt'); then
echo "Image '$rebuild_file' has no rebuild information stored"
exit 1
fi
# prepend previous parameters to current command line args
if [[ $rebuild_param ]]; then
TEMP="$rebuild_param $TEMP"
eval set -- "$TEMP"
rearrange_params "$@"
fi
fi
unset PARMS_TO_STORE
PARMS_TO_STORE=""
eval set -- "$TEMP"
while :; do
if [[ $1 != "--" ]] && [[ $1 != "--rebuild" ]]; then
PARMS_TO_STORE+=" $1"
fi
case $1 in
--kver)
kernel="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
-a | --add)
add_dracutmodules_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--force-add)
force_add_dracutmodules_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--add-drivers)
add_drivers_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--force-drivers)
force_drivers_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--omit-drivers)
omit_drivers_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
-m | --modules)
dracutmodules_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
-o | --omit)
omit_dracutmodules_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
-d | --drivers)
drivers_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--filesystems)
filesystems_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
-I | --install)
install_items_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--install-optional)
install_optional_items_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--fwdir)
fw_dir_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--libdirs)
libdirs_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--fscks)
fscks_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--add-fstab)
add_fstab_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--mount)
fstab_lines+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--add-device | --device)
add_device_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--kernel-cmdline)
kernel_cmdline_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--nofscks) nofscks_l="yes" ;;
--ro-mnt) ro_mnt_l="yes" ;;
-k | --kmoddir)
drivers_dir_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
-c | --conf)
conffile="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--confdir)
confdir="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--tmpdir)
tmpdir_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
-r | --sysroot)
sysroot_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
-L | --stdlog)
stdloglvl_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--compress)
compress_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--squash-compressor)
squash_compress_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--prefix)
prefix_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--loginstall)
loginstall_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--rebuild)
if [[ $rebuild_file == "$outfile" ]]; then
force=yes
fi
shift
;;
-f | --force) force=yes ;;
--kernel-only)
kernel_only="yes"
no_kernel="no"
;;
--no-kernel)
kernel_only="no"
no_kernel="yes"
;;
--print-cmdline)
print_cmdline="yes"
hostonly_l="yes"
kernel_only="yes"
no_kernel="yes"
;;
--early-microcode)
early_microcode_l="yes"
;;
--no-early-microcode)
early_microcode_l="no"
;;
--strip) do_strip_l="yes" ;;
--aggressive-strip) aggressive_strip_l="yes" ;;
--nostrip) do_strip_l="no" ;;
--hardlink) do_hardlink_l="yes" ;;
--nohardlink) do_hardlink_l="no" ;;
--noprefix) prefix_l="/" ;;
--mdadmconf) mdadmconf_l="yes" ;;
--nomdadmconf) mdadmconf_l="no" ;;
--lvmconf) lvmconf_l="yes" ;;
--nolvmconf) lvmconf_l="no" ;;
--debug) debug="yes" ;;
--profile) profile="yes" ;;
--sshkey)
sshkey="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--logfile)
logfile_l="$2"
shift
;;
-v | --verbose) ((verbosity_mod_l++)) ;;
-q | --quiet) ((verbosity_mod_l--)) ;;
-l | --local)
allowlocal="yes"
[[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
&& dracutbasedir="$(readlink -f "${0%/*}")"
;;
-H | --hostonly | --host-only)
hostonly_l="yes"
;;
-N | --no-hostonly | --no-host-only)
hostonly_l="no"
;;
--hostonly-mode)
hostonly_mode_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--hostonly-cmdline)
hostonly_cmdline_l="yes"
;;
--hostonly-i18n)
i18n_install_all_l="no"
;;
--hostonly-nics)
hostonly_nics_l+=("$2")
PARMS_TO_STORE+=" '$2'"
shift
;;
--no-hostonly-i18n)
i18n_install_all_l="yes"
;;
--no-hostonly-cmdline)
hostonly_cmdline_l="no"
;;
--no-hostonly-default-device)
hostonly_default_device="no"
;;
--persistent-policy)
persistent_policy_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--fstab) use_fstab_l="yes" ;;
-h | --help)
long_usage
exit 0
;;
--bzip2) compress_l="bzip2" ;;
--lzma) compress_l="lzma" ;;
--xz) compress_l="xz" ;;
--lzo) compress_l="lzop" ;;
--lz4) compress_l="lz4" ;;
--zstd) compress_l="zstd" ;;
--no-compress) _no_compress_l="cat" ;;
--gzip) compress_l="gzip" ;;
--enhanced-cpio) enhanced_cpio_l="yes" ;;
--list-modules) do_list="yes" ;;
-M | --show-modules)
show_modules_l="yes"
;;
--keep) keep="yes" ;;
--printsize) printsize="yes" ;;
--regenerate-all) regenerate_all_l="yes" ;;
-p | --parallel) parallel_l="yes" ;;
--noimageifnotneeded) noimageifnotneeded="yes" ;;
--reproducible) reproducible_l="yes" ;;
--no-reproducible) reproducible_l="no" ;;
--uefi) uefi_l="yes" ;;
--no-uefi) uefi_l="no" ;;
--uefi-stub)
uefi_stub_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--uefi-splash-image)
uefi_splash_image_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--kernel-image)
kernel_image_l="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--no-machineid)
machine_id_l="no"
;;
--version)
long_version
exit 0
;;
--)
shift
break
;;
*) # should not even reach this point
printf "\n!Unknown option: '%s'\n\n" "$1" >&2
usage
exit 1
;;
esac
shift
done
# getopt cannot handle multiple arguments, so just handle "-I,--include"
# the old fashioned way
while (($# > 0)); do
if [ "${1%%=*}" == "++include" ]; then
include_src+=("$2")
include_target+=("$3")
PARMS_TO_STORE+=" --include '$2' '$3'"
shift 2
fi
shift
done
[[ $sysroot_l ]] && dracutsysrootdir="$sysroot_l"
export LC_ALL=C
export LANG=C
unset LC_MESSAGES
unset LC_CTYPE
unset LD_LIBRARY_PATH
unset LD_PRELOAD
unset GREP_OPTIONS
export DRACUT_LOG_LEVEL=warning
[[ $debug ]] && {
export DRACUT_LOG_LEVEL=debug
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
set -x
}
[[ $profile ]] && {
export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '
set -x
debug=yes
}
[[ $dracutbasedir ]] || dracutbasedir="$dracutsysrootdir"/usr/lib/dracut
# if we were not passed a config file, try the default one
if [[ -z $conffile ]]; then
if [[ $allowlocal ]]; then
conffile="$dracutbasedir/dracut.conf"
else
conffile="$dracutsysrootdir/etc/dracut.conf"
fi
elif [[ ! -e $conffile ]]; then
printf "%s\n" "dracut[F]: Configuration file '$conffile' not found." >&2
exit 1
fi
if [[ -z $confdir ]]; then
if [[ $allowlocal ]]; then
confdir="$dracutbasedir/dracut.conf.d"
else
confdir="$dracutsysrootdir/etc/dracut.conf.d"
fi
elif [[ ! -d $confdir ]]; then
printf "%s\n" "dracut[F]: Configuration directory '$confdir' not found." >&2
exit 1
fi
# source our config file
if [[ -f $conffile ]]; then
check_conf_file "$conffile"
# shellcheck disable=SC1090
. "$conffile"
fi
# source our config dir
for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
check_conf_file "$f"
# shellcheck disable=SC1090
[[ -e $f ]] && . "$f"
done
# regenerate_all shouldn't be set in conf files
regenerate_all=$regenerate_all_l
if [[ $parallel_l == "yes" ]]; then
parallel=yes
fi
if [[ $regenerate_all == "yes" ]]; then
ret=0
if [[ $kernel ]]; then
printf "%s\n" "dracut[F]: --regenerate-all cannot be called with a kernel version." >&2
exit 1
fi
if [[ $outfile ]]; then
printf "%s\n" "dracut[F]: --regenerate-all cannot be called with an image file." >&2
exit 1
fi
((len = ${#dracut_args[@]}))
for ((i = 0; i < len; i++)); do
case ${dracut_args[$i]} in
--regenerate-all | --parallel)
# shellcheck disable=SC2184
unset dracut_args["$i"]
;;
esac
done
cd "$dracutsysrootdir"/lib/modules || exit 1
if [[ $parallel != "yes" ]]; then
for i in *; do
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
"$dracut_cmd" --kver="$i" "${dracut_args[@]}"
((ret += $?))
done
else
for i in *; do
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
"$dracut_cmd" --kver="$i" "${dracut_args[@]}" &
done
while true; do
wait -n
wst=$?
if [[ $wst == 127 ]]; then
break
else
((ret += wst))
fi
done
fi
exit "$ret"
fi
if ! [[ $kernel ]]; then
kernel=$(uname -r)
fi
DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
for i in $DRACUT_PATH; do
rl=$i
if [ -L "$dracutsysrootdir$i" ]; then