Skip to content

Commit

Permalink
feat(dracut): add option to disable automatic guessing of output file
Browse files Browse the repository at this point in the history
This patch allows forcing the input of the file path for the generated initramfs
image (disabling automatic guessing of the location) using a new command line
option `--force-output-file`, or setting `force_output_file=yes` via
configuration file.
  • Loading branch information
aafeijoo-suse committed Jul 26, 2023
1 parent 6c9f403 commit 16c1f5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ Creates initial ramdisk images for preloading modules
--kver [VERSION] Set kernel version to [VERSION].
-f, --force Overwrite existing initramfs file.
--force-output-file Require to specify a file path for the generated
initramfs image, disabling automatic guessing of the
location.
[OUTPUT_FILE] --rebuild
Append the current arguments to those with which the
input initramfs image was built. This option helps in
Expand Down Expand Up @@ -405,6 +408,7 @@ rearrange_params() {
--long prefix: \
--long rebuild: \
--long force \
--long force-output-file \
--long kernel-only \
--long no-kernel \
--long print-cmdline \
Expand Down Expand Up @@ -714,6 +718,9 @@ while :; do
shift
;;
-f | --force) force=yes ;;
--force-output-file)
force_output_file_l="yes"
;;
--kernel-only)
kernel_only="yes"
no_kernel="no"
Expand Down Expand Up @@ -936,6 +943,15 @@ for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); d
[[ -e $f ]] && . "$f"
done

# check if automatic guessing of the output file is disabled.
[[ $force_output_file_l ]] && force_output_file=$force_output_file_l
[[ $force_output_file ]] || force_output_file=no
if [[ $force_output_file == "yes" && -z $outfile ]]; then
printf "%s\n" "dracut[F]: dracut is called with --force-output-file or configured with force_output_file=yes" >&2
printf "%s\n" "dracut[F]: so it is required to specify the file path of the generated initramfs image." >&2
exit 1
fi

# regenerate_all shouldn't be set in conf files
regenerate_all=$regenerate_all_l
if [[ $parallel_l == "yes" ]]; then
Expand Down
4 changes: 4 additions & 0 deletions man/dracut.8.asc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ OPTIONS
**-f, --force**::
Overwrite existing initramfs file.

**--force-output-file**::
Require to specify a file path for the generated initramfs image, disabling
automatic guessing of the location.

_<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
Expand Down
4 changes: 4 additions & 0 deletions man/dracut.conf.5.asc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ Logging levels:
If set to _yes_, try to execute tasks in parallel (currently only supported
for _--regenerate-all_).

*force_output_file=*"__{yes|no}__"::
If set to _yes_, require to specify a file path for the generated initramfs
image, disabling automatic guessing of the location (default=no).

Files
-----
_/etc/dracut.conf_::
Expand Down
2 changes: 1 addition & 1 deletion shell-completion/bash/dracut
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _dracut() {
--enhanced-cpio --rebuild --aggressive-strip --hostonly-cmdline
--no-hostonly-cmdline --no-hostonly-default-device --nofscks
--hostonly-i18n --no-hostonly-i18n --lzo --lz4 --no-reproducible
--no-uefi --no-machineid --version --parallel
--no-uefi --no-machineid --version --parallel --force-output-file
'
[ARG]='-a -m -o -d -I -k -c -L -r -i
--kver --add --force-add --add-drivers --force-drivers
Expand Down

0 comments on commit 16c1f5d

Please sign in to comment.