Skip to content

Commit 6d92326

Browse files
mwilckjohannbg
authored andcommitted
feat(dracut): support parallel execution with --parallel
Add an option --parallel which can currently be used with --regenerate-all. With --regenerate-all --parallel, dracut will be run in parallel for all kernels found. Also introduce a config file equivalent setting: parallel="yes". Making this work requires moving the code block that handles --regenerate-all behind the code block for reading the config files. Signed-off-by: Martin Wilck <[email protected]>
1 parent d9812fc commit 6d92326

File tree

3 files changed

+73
-35
lines changed

3 files changed

+73
-35
lines changed

dracut.sh

+64-35
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ Creates initial ramdisk images for preloading modules
273273
--kernel-image [FILE] Location of the kernel image.
274274
--regenerate-all Regenerate all initramfs images at the default location
275275
for the kernel versions found on the system.
276+
-p, --parallel Use parallel processing if possible (currently only
277+
supported --regenerate-all)
278+
images simultaneously.
276279
--version Display version.
277280
278281
If [LIST] has multiple arguments, then you have to put these in quotes.
@@ -368,7 +371,7 @@ rearrange_params() {
368371
TEMP=$(
369372
unset POSIXLY_CORRECT
370373
getopt \
371-
-o "a:m:o:d:I:k:c:r:L:fvqlHhMN" \
374+
-o "a:m:o:d:I:k:c:r:L:fvqlHhMNp" \
372375
--long kver: \
373376
--long add: \
374377
--long force-add: \
@@ -447,6 +450,7 @@ rearrange_params() {
447450
--long keep \
448451
--long printsize \
449452
--long regenerate-all \
453+
--long parallel \
450454
--long noimageifnotneeded \
451455
--long early-microcode \
452456
--long no-early-microcode \
@@ -813,7 +817,8 @@ while :; do
813817
;;
814818
--keep) keep="yes" ;;
815819
--printsize) printsize="yes" ;;
816-
--regenerate-all) regenerate_all="yes" ;;
820+
--regenerate-all) regenerate_all_l="yes" ;;
821+
-p | --parallel) parallel_l="yes" ;;
817822
--noimageifnotneeded) noimageifnotneeded="yes" ;;
818823
--reproducible) reproducible_l="yes" ;;
819824
--no-reproducible) reproducible_l="no" ;;
@@ -870,37 +875,6 @@ done
870875

871876
[[ $sysroot_l ]] && dracutsysrootdir="$sysroot_l"
872877

873-
if [[ $regenerate_all == "yes" ]]; then
874-
ret=0
875-
if [[ $kernel ]]; then
876-
printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
877-
exit 1
878-
fi
879-
880-
if [[ $outfile ]]; then
881-
printf -- "--regenerate-all cannot be called with a image file\n" >&2
882-
exit 1
883-
fi
884-
885-
((len = ${#dracut_args[@]}))
886-
for ((i = 0; i < len; i++)); do
887-
[[ ${dracut_args[$i]} == "--regenerate-all" ]] \
888-
&& unset dracut_args["$i"]
889-
done
890-
891-
cd "$dracutsysrootdir"/lib/modules || exit 1
892-
for i in *; do
893-
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
894-
"$dracut_cmd" --kver="$i" "${dracut_args[@]}"
895-
((ret += $?))
896-
done
897-
exit "$ret"
898-
fi
899-
900-
if ! [[ $kernel ]]; then
901-
kernel=$(uname -r)
902-
fi
903-
904878
export LC_ALL=C
905879
export LANG=C
906880
unset LC_MESSAGES
@@ -961,6 +935,62 @@ for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); d
961935
[[ -e $f ]] && . "$f"
962936
done
963937

938+
# regenerate_all shouldn't be set in conf files
939+
regenerate_all=$regenerate_all_l
940+
if [[ $parallel_l == "yes" ]]; then
941+
parallel=yes
942+
fi
943+
944+
if [[ $regenerate_all == "yes" ]]; then
945+
ret=0
946+
if [[ $kernel ]]; then
947+
printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
948+
exit 1
949+
fi
950+
951+
if [[ $outfile ]]; then
952+
printf -- "--regenerate-all cannot be called with a image file\n" >&2
953+
exit 1
954+
fi
955+
956+
((len = ${#dracut_args[@]}))
957+
for ((i = 0; i < len; i++)); do
958+
case ${dracut_args[$i]} in
959+
--regenerate-all | --parallel)
960+
unset dracut_args["$i"]
961+
;;
962+
esac
963+
done
964+
965+
cd "$dracutsysrootdir"/lib/modules || exit 1
966+
if [[ $parallel != "yes" ]]; then
967+
for i in *; do
968+
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
969+
"$dracut_cmd" --kver="$i" "${dracut_args[@]}"
970+
((ret += $?))
971+
done
972+
else
973+
for i in *; do
974+
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
975+
"$dracut_cmd" --kver="$i" "${dracut_args[@]}" &
976+
done
977+
while true; do
978+
wait -n
979+
wst=$?
980+
if [[ $wst == 127 ]]; then
981+
break
982+
else
983+
((ret += wst))
984+
fi
985+
done
986+
fi
987+
exit "$ret"
988+
fi
989+
990+
if ! [[ $kernel ]]; then
991+
kernel=$(uname -r)
992+
fi
993+
964994
DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
965995

966996
for i in $DRACUT_PATH; do
@@ -1332,8 +1362,7 @@ dinfo "Executing: $dracut_cmd ${dracut_args[*]}"
13321362
[[ $do_list == yes ]] && {
13331363
for mod in "$dracutbasedir"/modules.d/*; do
13341364
[[ -d $mod ]] || continue
1335-
[[ -e $mod/install || -e $mod/installkernel || -e \
1336-
$mod/module-setup.sh ]] || continue
1365+
[[ -e $mod/install || -e $mod/installkernel || -e $mod/module-setup.sh ]] || continue
13371366
printf "%s\n" "${mod##*/??}"
13381367
done
13391368
exit 0

man/dracut.8.asc

+5
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ will not be able to boot. Equivalent to "--compress=zstd -15 -q -T0".
558558
Regenerate all initramfs images at the default location with the kernel
559559
versions found on the system. Additional parameters are passed through.
560560
561+
**-p, --parallel**::
562+
Try to execute tasks in parallel. Currently only supported with
563+
**--regenerate-all** (build initramfs images for all kernel
564+
versions simultaneously).
565+
561566
**--noimageifnotneeded**::
562567
Do not create an image in host-only mode, if no kernel driver is needed
563568
and no /etc/cmdline/*.conf will be generated into the initramfs.

man/dracut.conf.5.asc

+4
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ Logging levels:
308308
parameters, with initramfs source files, **tmpdir** staging area and
309309
destination all on the same copy-on-write capable filesystem.
310310

311+
*parallel=*"__{yes|no}__"::
312+
If set to _yes_, try to execute tasks in parallel (currently only supported
313+
for _--regenerate-all_).
314+
311315
Files
312316
-----
313317
_/etc/dracut.conf_::

0 commit comments

Comments
 (0)