Skip to content

Commit

Permalink
feat(dracut.sh): add --add-confdir option
Browse files Browse the repository at this point in the history
When generating kdump's initrd, we want to keep [omit_]dracutmodules
empty and let kdump to handle the modules. And we don't want to
affect the first kernel's initrd, so we cannot place our conf file
to /etc/dracut.conf.d or /usr/lib/dracut/dracut.conf.d.

This patch adds a new option to allow user to add an extra configuration
directory to use *.conf files from. If the dir not exists, will look for
confdir's subdir.

After that, kdump can use "--add-confdir kdump" if
/usr/lib/dracut/dracut.conf.d/kdump exists, to apply its own dracut conf.

See also:
rhkdump/kdump-utils#11
rhkdump/kdump-utils#31

Suggested-by: Dave Young <[email protected]>
Signed-off-by: Lichen Liu <[email protected]>
  • Loading branch information
licliu authored and LaszloGombos committed Sep 11, 2024
1 parent b7b4f03 commit ae81535
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
25 changes: 24 additions & 1 deletion dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ Creates initial ramdisk images for preloading modules
Default: /etc/dracut.conf
--confdir [DIR] Specify configuration directory to use *.conf files
from. Default: /etc/dracut.conf.d
--add-confdir [DIR] Add an extra configuration directory to use *.conf
files from. If the directory is not existed, will
look for subdirectory under confdir.
--tmpdir [DIR] Temporary directory to be used instead of default
${TMPDIR:-/var/tmp}.
-r, --sysroot [DIR] Specify sysroot directory to collect files from.
Expand Down Expand Up @@ -385,6 +388,7 @@ rearrange_params() {
--long kmoddir: \
--long conf: \
--long confdir: \
--long add-confdir: \
--long tmpdir: \
--long sysroot: \
--long stdlog: \
Expand Down Expand Up @@ -661,6 +665,11 @@ while :; do
PARMS_TO_STORE+=" '$2'"
shift
;;
--add-confdir)
add_confdir="$2"
PARMS_TO_STORE+=" '$2'"
shift
;;
--tmpdir)
tmpdir_l="$2"
PARMS_TO_STORE+=" '$2'"
Expand Down Expand Up @@ -914,6 +923,20 @@ elif [[ ! -d $confdir ]]; then
exit 1
fi

if [[ -n $add_confdir ]]; then
if [[ -d $add_confdir ]]; then
:
# Check if it exists under $confdir.
elif [[ -d $confdir/$add_confdir ]]; then
add_confdir="$confdir/$add_confdir"
elif [[ -d $dracutbasdir/dracut.conf.d/$add_confdir ]]; then
add_confdir="$dracutbasdir/dracut.conf.d/$add_confdir"
else
printf "%s\n" "dracut[F]: Configuration directory '$add_confdir' not found." >&2
exit 1
fi
fi

# source our config file
if [[ -f $conffile ]]; then
check_conf_file "$conffile"
Expand All @@ -922,7 +945,7 @@ if [[ -f $conffile ]]; then
fi

# source our config dir
for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
for f in $(dropindirs_sort ".conf" "$confdir" "$add_confdir" "$dracutbasedir/dracut.conf.d"); do
check_conf_file "$f"
# shellcheck disable=SC1090
[[ -e $f ]] && . "$f"
Expand Down
8 changes: 8 additions & 0 deletions man/dracut.8.asc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ Default:
Default:
_/etc/dracut.conf.d_
**--add-confdir** _<configuration directory>_::
Add an extra configuration directory to use *.conf files from. If the
directory is not existed, will look for subdirectory under confdir.
+
Default:
_empty_
**--tmpdir** _<temporary directory>_::
Specify temporary directory to use.
+
Expand Down
4 changes: 2 additions & 2 deletions shell-completion/bash/dracut
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ _dracut() {
--kernel-cmdline --sshkey --persistent-policy --install-optional
--loginstall --uefi-stub --kernel-image --squash-compressor
--sysroot --hostonly-mode --hostonly-nics --include --logfile
--uefi-splash-image --sbat
--uefi-splash-image --sbat --add-confdir
'
)

# shellcheck disable=SC2086
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
--kmoddir | -k | --fwdir | --confdir | --tmpdir | -r | --sysroot)
--kmoddir | -k | --fwdir | --confdir | --add-confdir | --tmpdir | -r | --sysroot)
comps=$(compgen -d -- "$cur")
compopt -o filenames
;;
Expand Down

0 comments on commit ae81535

Please sign in to comment.