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