[RFC PATCH 5/5] Documentation: bootconfig: Document multiple bootconfigs and selection

From: Masami Hiramatsu (Google)

Date: Fri Nov 27 2026 - 09:51:29 EST


Document stacked initrd bootconfigs, #BOOTCONFIG-ID naming rules,
index 0 default semantics, XBC_CONFIG_MAX (32) limits, backward
compatibility and single-image requirements, bootconfig= command-line
selection syntax, updated CONFIG_CMDLINE_FROM_BOOTCONFIG selection
rules, and tools/bootconfig -i usage in
Documentation/admin-guide/bootconfig.rst.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
Documentation/admin-guide/bootconfig.rst | 82 ++++++++++++++++++++++--
1 file changed, 76 insertions(+), 6 deletions(-)

diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index 3d6412458c8b..72be0df4cb3d 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -199,11 +199,11 @@ to/from initrd image. You can build it by the following command::
# make -C tools/bootconfig

To add your boot config file to initrd image, run bootconfig as below
-(Old data is removed automatically if exists)::
+(Old default data is replaced if it exists)::

# tools/bootconfig/bootconfig -a your-config /boot/initrd.img-X.Y.Z

-To remove the config from the image, you can use -d option as below::
+To remove all boot config files from the image, use the -d option as below::

# tools/bootconfig/bootconfig -d /boot/initrd.img-X.Y.Z

@@ -212,6 +212,69 @@ kernel to look for the bootconfig at the end of the initrd file.
Alternatively, build your kernel with the ``CONFIG_BOOT_CONFIG_FORCE``
Kconfig option selected.

+Attaching Multiple Boot Configs to Initrd
+-----------------------------------------
+
+Multiple bootconfig files (up to 32) can be stacked at the end of an initrd
+image, which is useful for Unified Kernel Images (UKIs) that bundle a base
+configuration alongside scenario-specific or debug overlays::
+
+ [initrd][block 0 (default)][block 1 (id1)][block 2 (id2)]...
+
+Each block has its own ``#BOOTCONFIG\n`` footer. Named blocks carry an
+in-band comment header on their first line (``#BOOTCONFIG-ID: <id>\n``).
+Identifiers must be 1 to 31 characters long, start with an ASCII letter or
+underscore (``[A-Za-z_]`` -- leading digits are reserved for 0-based indices),
+and contain only ASCII letters, digits, ``_``, ``-``, or ``.``.
+
+To attach or replace a named bootconfig, pass ``-i <id>`` to ``bootconfig``::
+
+ # tools/bootconfig/bootconfig -a base.bconf /boot/initrd.img-X.Y.Z
+ # tools/bootconfig/bootconfig -i debug -a debug.bconf /boot/initrd.img-X.Y.Z
+ # tools/bootconfig/bootconfig -i trace -a trace.bconf /boot/initrd.img-X.Y.Z
+
+To inspect or preview the merged result on the host, or selectively delete
+configs::
+
+ # tools/bootconfig/bootconfig /boot/initrd.img-X.Y.Z
+ # tools/bootconfig/bootconfig -l -i ,debug /boot/initrd.img-X.Y.Z
+ # tools/bootconfig/bootconfig -d -i debug /boot/initrd.img-X.Y.Z
+
+The block at index ``0`` is the default bootconfig. ``bootconfig -a`` without
+``-i`` always places the unnamed block at index ``0``; deleting index ``0``
+(``bootconfig -d -i 0``) promotes the next block to index ``0`` (making it the
+new default). At boot time, ``bootconfig`` parameters before ``--`` are
+evaluated left-to-right:
+
+- ``bootconfig`` (bare): selects only the default config (index ``0``).
+- ``bootconfig=id1,id2`` (or ``bootconfig=0,2``): selects and merges the
+ listed IDs or 0-based indices in initrd stack order. An empty entry such as
+ ``bootconfig=,debug`` is shorthand for ``0,debug``.
+- ``bootconfig=+debug``: appends ``debug`` onto an earlier ``bootconfig=...``
+ selection on the command line (or onto index ``0`` if no prior
+ ``bootconfig`` parameter appeared).
+- ``bootconfig=`` (empty value): clears earlier selections and loads no
+ bootconfig (unless ``CONFIG_BOOT_CONFIG_FORCE=y`` is set, which forces
+ index ``0`` when no config is selected).
+
+Selected configs are merged in stack order (index ``0`` first, later overlays
+after), so overlays can use ``:=`` and ``+=`` to override or extend base keys.
+
+.. warning::
+
+ - **Older kernels**: A kernel without multi-bootconfig support strips and
+ loads only the outermost trailer (the last overlay) as the sole
+ bootconfig, leaving earlier trailers inside the initrd where
+ ``unpack_to_rootfs()`` will fail with ``Initramfs unpacking failed`` (or
+ fall back to ``CONFIG_BLK_DEV_RAM``).
+ - **Older tools**: An older ``tools/bootconfig -a/-d`` operates only on the
+ outermost trailer and leaves earlier stacked blocks behind.
+ - **Single contiguous trailer stack**: Inner trailers must end at the exact
+ start of the next trailer with no inter-image padding. All stacked
+ bootconfig blocks must therefore be attached at the tail of a single
+ initrd image via ``tools/bootconfig -i`` rather than split across
+ separately padded initrd images or UKI initrd addons.
+
Embedding a Boot Config into Kernel
-----------------------------------

@@ -254,10 +317,12 @@ an architecture that selects ``CONFIG_ARCH_SUPPORTS_CMDLINE_FROM_BOOTCONFIG``.
Currently only x86 selects it; on other architectures the embedded
bootconfig still works, but only through the late runtime parser.

-The same ``bootconfig`` opt-in applies as elsewhere: the rendered keys
-are prepended only when ``bootconfig`` (in any form) appears on the
-kernel command line, or when ``CONFIG_BOOT_CONFIG_FORCE`` is set, which
-defaults to ``y`` when ``CONFIG_BOOT_CONFIG_EMBED`` is set.
+The same ``bootconfig`` selection rules apply as elsewhere: the rendered
+keys are prepended only when index 0 (or the embedded bootconfig's ID) is
+selected via ``bootconfig`` on the kernel command line, or when
+``CONFIG_BOOT_CONFIG_FORCE`` is set (which defaults to ``y`` when
+``CONFIG_BOOT_CONFIG_EMBED`` is set) and no active ``bootconfig=...``
+selection overrides it.

For example, given::

@@ -367,6 +432,11 @@ the padding null characters.)
Anyway, since bootconfig command verifies it when appending a boot config
to initrd image, user can notice it before boot.

+When stacking multiple bootconfig files in an initrd, up to 32 files can be
+attached. Each individual file must fit within 32KB, while the combined size
+of all stacked files in the initrd may exceed 32KB as long as the subset
+selected at boot fits within 32KB and the node limit.
+

Bootconfig APIs
===============
--
2.43.0