]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(dracut): add a DRACUT_EXTRA_ARGS environment variable
authorJo Zzsi <jozzsicsataban@gmail.com>
Fri, 10 Apr 2026 13:21:51 +0000 (09:21 -0400)
committerBenjamin Drung <bdrung@ubuntu.com>
Mon, 13 Apr 2026 13:03:50 +0000 (15:03 +0200)
Some build tools (e.g. autopkgtest-build-qemu) invoke dracut indirectly
through update-initramfs via dpkg triggers, making it impossible to pass
extra flags directly on the command line.

Add a DRACUT_EXTRA_ARGS environment variable whose contents are
word-split and prepended to the dracut argument list before option
parsing.  This allows callers to inject arbitrary flags without modifying
the configuration on disk:

  DRACUT_EXTRA_ARGS=--no-hostonly autopkgtest-build-qemu ...

The variable is intentionally word-split (like MAKEFLAGS), so arguments
that themselves contain spaces must be shell-quoted within the value:

  DRACUT_EXTRA_ARGS='--add "mod1 mod2"' dracut

Changed test 13 to provide test coverage for DRACUT_EXTRA_ARGS variable.

dracut.sh
man/dracut.8.adoc
test/TEST-13-SYSROOT/test.sh

index 9b299a3860ff68ae71b9676ed8b8f03ef85031a4..18edc521419c8dc9bfda8a90e263af22294444ca 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -601,6 +601,13 @@ PARMS_TO_STORE=""
 
 eval set -- "$TEMP"
 
+if [[ -n ${DRACUT_EXTRA_ARGS-} ]]; then
+    mapfile -d '' _extra_args < <(xargs printf '%s\0' <<< "$DRACUT_EXTRA_ARGS" 2> /dev/null \
+        || printf "%s\n" "dracut[W]: Ignoring malformed DRACUT_EXTRA_ARGS: $DRACUT_EXTRA_ARGS" >&2)
+    set -- "${_extra_args[@]}" "$@"
+    unset _extra_args
+fi
+
 while :; do
     case $1 in
         -h | --help)
index 8397e5860d9eca84bad54e8c922dfc7cb5ebb7a4..6c46e072aeffb9ee3e7b3e8bcee54362f317e96f 100644 (file)
@@ -734,6 +734,18 @@ _DRACUT_ARCH_::
 Default:
     _empty_ (the value of **uname -m** on the host system)
 
+_DRACUT_EXTRA_ARGS_::
+    A string of additional _dracut_ command-line arguments.  The value is
+    word-split and prepended to the argument list before option parsing, so
+    explicit flags supplied directly on the command line will override the
+    values set here.
++
+Arguments that contain spaces must be shell-quoted within the value:
++
+----
+DRACUT_EXTRA_ARGS='--add "module1 module2"' dracut
+----
+
 _SYSTEMD_VERSION_::
     overrides systemd version. Used for **--sysroot**.
 
index 3002ade46a0d880130ffc0729ee8eebdd7380bdd..a8fab1895ea529411d1e06824f56548d897f86b5 100755 (executable)
@@ -23,7 +23,10 @@ test_setup() {
     build_ext4_image "$TESTDIR/rootfs" "$TESTDIR"/root.img dracut
 
     ln -s / "$TESTDIR"/sysroot
-    test_dracut --keep --hostonly --sysroot "$TESTDIR"/sysroot
+    # test DRACUT_EXTRA_ARGS
+    DRACUT_EXTRA_ARGS="--keep --hostonly --sysroot '$TESTDIR/sysroot'" test_dracut
+
+    grep 'hostonly' "$TESTDIR"/initrd/dracut.*/initramfs/usr/lib/dracut/build-parameter.txt
 
     if grep -q '^root:' /etc/shadow; then
         if ! grep -q '^root:' "$TESTDIR"/initrd/dracut.*/initramfs/etc/shadow; then