]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(base): support cmdline options in /run/initramfs/cmdline.d
authorBenjamin Drung <benjamin.drung@canonical.com>
Tue, 3 Feb 2026 11:22:02 +0000 (12:22 +0100)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Wed, 4 Feb 2026 09:53:00 +0000 (04:53 -0500)
The command line options can be specified in `/etc/cmdline`,
`/etc/cmdline.d`, and on the kernel command line `/proc/cmdline`.
`/proc/cmdline` is read last and overrides options from `/etc`. There is
no way to override options from `/proc/cmdline`.

To allow overriding options from `/proc/cmdline` during boot also read
`/run/initramfs/cmdline.d`.

modules.d/80base/dracut-lib.sh

index d44b05cc0bea3dd43b6f5a8111c8e41bc79b8ea4..93b774a931cbb0c94ccddaf415330678b68518af 100755 (executable)
@@ -10,6 +10,7 @@ fi
 
 if [ -z "${PREFIX-}" ]; then
     if ! [ -d /run/initramfs ]; then
+        mkdir -p -m 0755 /run/initramfs/cmdline.d
         mkdir -p -m 0755 /run/initramfs/log
         ln -sfn /run/initramfs/log /var/log
     fi
@@ -128,6 +129,7 @@ getcmdline() {
     local CMDLINE_ETC_D=''
     local CMDLINE_ETC=''
     local CMDLINE_PROC=''
+    local CMDLINE_RUN=''
     unset _line
 
     if [ -e /etc/cmdline ]; then
@@ -146,7 +148,13 @@ getcmdline() {
             CMDLINE_PROC="$CMDLINE_PROC $_line"
         done < /proc/cmdline
     fi
-    CMDLINE="$CMDLINE_ETC_D $CMDLINE_ETC $CMDLINE_PROC"
+    for _i in /run/initramfs/cmdline.d/*.conf; do
+        [ -e "$_i" ] || continue
+        while read -r _line || [ -n "$_line" ]; do
+            CMDLINE_RUN="$CMDLINE_RUN $_line"
+        done < "$_i"
+    done
+    CMDLINE="$CMDLINE_ETC_D $CMDLINE_ETC $CMDLINE_PROC $CMDLINE_RUN"
     printf "%s" "$CMDLINE"
 }