]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install(uki): filter comments from cmdline
authorCynthia <cynthia@cynthia.dev>
Tue, 17 Mar 2026 22:30:31 +0000 (23:30 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 26 Mar 2026 13:28:22 +0000 (14:28 +0100)
This change aligns the behaviour of UKI generation with the behaviour
of BLS. The latter filters out lines starting with a #, allowing users
to add comments and/or temporarily remove some flags from the kernel
command line.

The kernel-install test have been adjusted to use a multiline cmdline
with a comment in it. Without this patch, the test fails.

man/kernel-install.xml
src/kernel-install/60-ukify.install.in
src/kernel-install/test-kernel-install.sh

index 38c183be243e3715b359df993ecbc14612b3eff2..0bf57b4d5341ece4422a66711185147373662282 100644 (file)
         <term><filename>/proc/cmdline</filename></term>
         <listitem>
           <para>Specifies the kernel command line to use. The first of the files that is found will be used.
-          When running in a container, <filename>/proc/cmdline</filename> is ignored.
-          <varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be used to override the search path; see below for
-          details.</para>
+          Lines starting with the <literal>#</literal> character are ignored. When running in a container,
+          <filename>/proc/cmdline</filename> is ignored. <varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be
+          used to override the search path; see below for details.</para>
 
           <xi:include href="version-info.xml" xpointer="v198"/>
         </listitem>
index 076390dd0475e2bc6d75348b3869fca7d03c5fff..310b6f26cafc088ecdcbd50fc6015baf4aee67a2 100755 (executable)
@@ -185,7 +185,12 @@ def devicetree_file_location(opts) -> Optional[Path]:
 def kernel_cmdline_base() -> list[str]:
     path = input_file_location('cmdline')
     if path:
-        return path.read_text().split()
+        # Filter out commented out lines from cmdline.
+        lines = path.read_text().splitlines()
+        return [opt
+                for line in lines
+                if not line.startswith('#')
+                for opt in line.split()]
 
     # If we read /proc/cmdline, we need to do some additional filtering.
     options = Path('/proc/cmdline').read_text().split()
index e2add8ba80b5c21e03cd0a78b9891e572b5b2477..399979a0260e2822addfb59e964aa4b5c266155b 100755 (executable)
@@ -29,7 +29,12 @@ mkdir -p "$D/sources"
 echo 'buzy image' >"$D/sources/linux"
 echo 'the initrd' >"$D/sources/initrd"
 echo 'the-token' >"$D/sources/entry-token"
-echo 'opt1 opt2' >"$D/sources/cmdline"
+
+cat >"$D/sources/cmdline" <<EOF
+opt1
+# commented line
+opt2
+EOF
 
 cat >"$D/sources/install.conf" <<EOF
 layout=bls