kernel-install(uki): filter comments from cmdline

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.

(cherry picked from commit 0c2747e789)
(cherry picked from commit 3c5046c43f)
This commit is contained in:
Cynthia
2026-03-17 23:30:31 +01:00
committed by Luca Boccassi
parent 5ad0cd4e2d
commit 2f251d725c
3 changed files with 15 additions and 5 deletions

View File

@@ -616,9 +616,9 @@
<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>

View File

@@ -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()

View File

@@ -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