Skip to content

Commit 6fcca68

Browse files
jmarrerocgwalters
authored andcommitted
docs: Add guidance for machine-local initramfs content
Admins might need to add machine-specific initramfs content after install (a udev rule to unlock local storage is the classic case) and reach for editing /boot, which bootc overwrites on update. Document the supported path: build a machine-local derived image that regenerates the initramfs, so the image stays the source of truth. Also record why rpm-ostree's client-side initramfs is incompatible with bootc upgrade, and the UKI-addon direction. Assisted-by: AI Signed-off-by: Joseph Marrero Corchado <jmarrero@redhat.com>
1 parent 5c3d1e5 commit 6fcca68

3 files changed

Lines changed: 161 additions & 0 deletions

File tree

‎docs/src/SUMMARY.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Accessing registries and offline updates](registries-and-offline.md)
2424
- [Logically bound images](logically-bound-images.md)
2525
- [Booting local builds](booting-local-builds.md)
26+
- [Managing the initramfs after installation](initramfs.md)
2627
- [`man bootc`](man/bootc.8.md)
2728
- [`man bootc-status`](man/bootc-status.8.md)
2829
- [`man bootc-upgrade`](man/bootc-upgrade.8.md)

‎docs/src/booting-local-builds.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,53 @@ From there, the new image will be queued for the next boot
3939
and a `reboot` will apply it.
4040

4141
For more on valid transports, see [containers-transports](https://github.com/containers/image/blob/main/docs/containers-transports.5.md).
42+
43+
## Automating local rebuilds
44+
45+
The build and switch above can be automated with a systemd service and timer.
46+
For example, keep the build context in `/var/lib/machine-bootc` and build the
47+
image on a schedule:
48+
49+
```systemd
50+
# /etc/systemd/system/machine-bootc-build.service
51+
[Unit]
52+
Description=Build the machine-local bootc image
53+
After=network-online.target
54+
Wants=network-online.target
55+
56+
[Service]
57+
Type=oneshot
58+
WorkingDirectory=/var/lib/machine-bootc
59+
ExecStart=/usr/bin/podman build --security-opt=label=disable --pull=newer --tag localhost/machine-bootc:latest .
60+
```
61+
62+
```systemd
63+
# /etc/systemd/system/machine-bootc-build.timer
64+
[Unit]
65+
Description=Build the machine-local bootc image daily
66+
67+
[Timer]
68+
OnCalendar=*-*-* 06:00:00
69+
Persistent=true
70+
71+
[Install]
72+
WantedBy=timers.target
73+
```
74+
75+
```console
76+
$ sudo systemctl daemon-reload
77+
$ sudo systemctl enable --now machine-bootc-build.timer
78+
```
79+
80+
This automates only the build. Staging the new image with `bootc switch` and
81+
rebooting are intentionally left as explicit operations; automate them only
82+
with a reboot policy appropriate for the machine.
83+
84+
Automating the rebuild is only worthwhile if the build reliably produces a new
85+
image *when, and only when, an input changed*. With `--pull=newer` an identical
86+
rebuild is a full cache hit and yields the same image, so nothing new is
87+
deployed. But that relies on the build cache, not on reproducible output: a
88+
step whose result is not deterministic (regenerating an initramfs is a common
89+
example) can produce a different image on a cache-busted rebuild even when
90+
nothing meaningful changed, causing needless reboots. Prefer reproducible build
91+
steps for anything driven on a timer.

‎docs/src/initramfs.md‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Managing the initramfs after installation
2+
3+
The initramfs is part of the container image and is updated together with the
4+
image. On systems using the OSTree backend with a split kernel and initramfs,
5+
the canonical path is `/usr/lib/modules/$kver/initramfs.img`. Editing the copy
6+
in `/boot` is not supported because `bootc` replaces it from the container
7+
image during an update.
8+
9+
For how to modify and regenerate the initramfs *inside* an image build,
10+
including dracut drop-in configuration, see your operating system's
11+
documentation, for example Fedora's
12+
[bootc initramfs guide](https://docs.fedoraproject.org/en-US/bootc/initramfs/).
13+
14+
## Prefer generic configuration
15+
16+
Content that at first looks machine-specific often does not need to be. A
17+
single generic image can carry configuration that dispatches on a
18+
machine-specific identifier at runtime — a hardware MAC address, a DMI
19+
property, a disk serial, and so on. A udev rule that matches particular
20+
hardware, for instance, can ship in the base or a shared derived image and
21+
still only act on the machine that has that hardware.
22+
23+
Reach for a machine-local image only when the content genuinely cannot be
24+
expressed generically. Keeping configuration in shared images means fewer
25+
distinct images to build, test, and update.
26+
27+
## Machine-local initramfs content
28+
29+
When machine-specific initramfs content really is required — such as a udev
30+
rule needed to unlock local storage that cannot be selected generically — and
31+
until `bootc` has a dedicated interface for this use case, build a
32+
machine-local derived image containing the configuration and its regenerated
33+
initramfs. This keeps the image, rather than mutable files in `/boot`, as the
34+
source of truth.
35+
36+
> This procedure applies to the OSTree backend with a split kernel and
37+
> initramfs. It does not apply to sealed composefs/UKI images.
38+
39+
Create a build context containing the machine-specific files. For example:
40+
41+
```text
42+
.
43+
├── Containerfile
44+
└── 98-storage.rules
45+
```
46+
47+
The `Containerfile` derives from the image shown by `bootc status`, adds the
48+
files, and regenerates the initramfs. Configure dracut with a drop-in under
49+
`/usr/lib/dracut/dracut.conf.d` and regenerate for the image's kernel, per your
50+
OS's initramfs documentation:
51+
52+
```Dockerfile
53+
FROM quay.io/example/example-bootc:latest
54+
55+
COPY 98-storage.rules /etc/udev/rules.d/98-storage.rules
56+
RUN echo 'install_items+=" /etc/udev/rules.d/98-storage.rules "' \
57+
> /usr/lib/dracut/dracut.conf.d/50-storage.conf
58+
59+
RUN set -xe; kver=$(ls /usr/lib/modules); \
60+
env DRACUT_NO_XATTR=1 dracut -vf "/usr/lib/modules/${kver}/initramfs.img" "$kver"; \
61+
bootc container lint
62+
```
63+
64+
A bootc image must contain exactly one kernel, so `ls /usr/lib/modules` must
65+
resolve to a single directory; `bootc container lint` checks this image
66+
invariant. Dracut must be told the kernel version explicitly, because its
67+
default targets the *running* kernel, which is not what a build should use. The
68+
exact dracut modules and arguments depend on the base image and the content
69+
being added.
70+
71+
Build the image locally and deploy it exactly as any other local build; see
72+
[Booting local builds](booting-local-builds.md) for building against the booted
73+
image, the `containers-storage` transport, and automating the rebuild. Rebuild
74+
and switch to this derived image whenever either the base image or the
75+
machine-specific configuration changes.
76+
77+
## The rpm-ostree client-side initramfs mechanism
78+
79+
On rpm-ostree-managed systems, `rpm-ostree initramfs --enable` enables
80+
client-side initramfs regeneration and accepts additional dracut arguments.
81+
However, this mechanism predates bootc and records the regenerated initramfs as
82+
a local rpm-ostree modification in the deployment origin (a
83+
`regenerate-initramfs` key under `[rpmostree]`).
84+
85+
Bootc does not currently know how to reproduce or carry that configuration
86+
onto a new container-image deployment. It marks a deployment with rpm-ostree
87+
local modifications as incompatible, and `bootc upgrade` refuses to update it
88+
with an error such as "Deployment contains local rpm-ostree modifications".
89+
Running `rpm-ostree reset` removes the local modifications and allows bootc to
90+
manage the deployment again, but also removes the client-side initramfs
91+
configuration. It may remove other rpm-ostree package layering and overrides as
92+
well, so inspect the pending changes before running it. Therefore, do not use
93+
`rpm-ostree initramfs --enable` for this workflow if the system is intended to
94+
continue receiving updates through bootc; use a derived container image
95+
instead. See also
96+
[Relationship with rpm-ostree](relationships.md#relationship-with-rpm-ostree).
97+
98+
## Future direction
99+
100+
[UKI add-ons](https://uapi-group.org/specifications/specs/unified_kernel_image/#addon-uki-format)
101+
are the intended mechanism for adding machine-specific kernel arguments or
102+
initrd content without rebuilding a Unified Kernel Image. The bootc project is
103+
working toward this model for composefs/UKI systems.
104+
105+
For OSTree environments that do not use composefs with sealed UKIs, support for
106+
supplementary initrds has been requested in
107+
[ostree#3634](https://github.com/ostreedev/ostree/issues/3634), and a general
108+
bootc interface is being designed in
109+
[bootc#2414](https://github.com/bootc-dev/bootc/issues/2414). Until that design
110+
is implemented, use the machine-local derived-image workflow above.

0 commit comments

Comments
 (0)