|
| 1 | +# Package manager integration |
| 2 | + |
| 3 | +A toplevel goal of bootc is to encourage a default model |
| 4 | +where Linux systems are built and delivered as (container) images. |
| 5 | +In this model, the default usage of package managers such as `apt` and `dnf` |
| 6 | +will be at container build time. |
| 7 | + |
| 8 | +However, one may end up shipping the package manager tooling onto |
| 9 | +the end system. In some cases this may be desirable even, to allow |
| 10 | +workflows with transient overlays using e.g. `bootc usroverlay`. |
| 11 | + |
| 12 | +## Detecting image-based systems |
| 13 | + |
| 14 | +bootc is not the only image based system; there are many. A common |
| 15 | +emphasis is on having the operating system content in `/usr`, |
| 16 | +and for that filesystem to be mounted read-only at runtime. |
| 17 | + |
| 18 | +A first recommendation here is that package managers should |
| 19 | +detect if `/usr` is read-only, and provide a useful error |
| 20 | +message referring users to documentation guidance. |
| 21 | + |
| 22 | +An example of a non-bootc case is "Live CD" environments, |
| 23 | +where the *physical media* is readonly. Some Live operating system environments end |
| 24 | +up mounting a transient writable overlay (whether via e.g. devicemapper or overlayfs) |
| 25 | +that make the system appear writable, but it's arguably clearer not to do so by |
| 26 | +default. Detecting `/usr` as read-only here and providing the same information |
| 27 | +would make sense. |
| 28 | + |
| 29 | +### Running a read-only system via podman/docker |
| 30 | + |
| 31 | +The historical default for docker (inherited into podman) is that |
| 32 | +the `/` is a writable (but transient) overlayfs. However, e.g. `podman` |
| 33 | +supports a `--read-only` flag, and [Kubernetes pods](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/) offer a |
| 34 | +`securityContext.readOnlyRootFilesystem` flag. |
| 35 | + |
| 36 | +Running containers in production in this way is a good idea, |
| 37 | +for exactly the same reasons that bootc defaults to mounting |
| 38 | +the system read-only. |
| 39 | + |
| 40 | +Ensure that your package manager offers a useful error message |
| 41 | +in this mode. Today for example: |
| 42 | + |
| 43 | +``` |
| 44 | +$ podman run --read-only --rm -ti debian apt update |
| 45 | +Reading package lists... Done |
| 46 | +E: List directory /var/lib/apt/lists/partial is missing. - Acquire (30: Read-only file system) |
| 47 | +$ podman run --read-only --rm -ti quay.io/fedora/fedora:40 dnf -y install strace |
| 48 | +Config error: [Errno 30] Read-only file system: '/var/log/dnf.log': '/var/log/dnf.log' |
| 49 | +``` |
| 50 | + |
| 51 | +However note that both of these fail on `/var` being read-only; in a default bootc |
| 52 | +model, it won't be. A more accurate check is thus closer to: |
| 53 | + |
| 54 | +``` |
| 55 | +$ podman run --read-only --rm -ti --tmpfs /var quay.io/fedora/fedora:40 dnf -y install strace |
| 56 | +... |
| 57 | +Error: Transaction test error: |
| 58 | + installing package strace-6.9-1.fc40.x86_64 needs 2MB more space on the / filesystem |
| 59 | +``` |
| 60 | + |
| 61 | +``` |
| 62 | +$ podman run --read-only --rm --tmpfs /var -ti debian /bin/sh -c 'apt update && apt -y install strace' |
| 63 | +... |
| 64 | +dpkg: error processing archive /var/cache/apt/archives/libunwind8_1.6.2-3_amd64.deb (--unpack): |
| 65 | + unable to clean up mess surrounding './usr/lib/x86_64-linux-gnu/libunwind-coredump.so.0.0.0' before installing another version: Read-only file system |
| 66 | +``` |
| 67 | + |
| 68 | +These errors message are misleading and confusing for the user. A more useful error may look like e.g.: |
| 69 | + |
| 70 | +``` |
| 71 | +$ podman run --read-only --rm --tmpfs /var -ti debian /bin/sh -c 'apt update && apt -y install strace' |
| 72 | +error: read-only /usr detected, refusing to operate. See `man apt-image-based` for more information. |
| 73 | +``` |
| 74 | + |
| 75 | +### Detecting bootc specifically |
| 76 | + |
| 77 | +You may also reasonably want to detect that the operating system is specifically |
| 78 | +using `bootc`. This can be done via e.g.: |
| 79 | + |
| 80 | +`bootc status --format=json | jq -r .spec.image` |
| 81 | + |
| 82 | +If the output of that field is non-`null`, then the system is a bootc system |
| 83 | +tracking the specified image. |
| 84 | + |
| 85 | +## Transient overlays |
| 86 | + |
| 87 | +Today there is a simple `bootc usroverlay` command that adds a transient writable overlayfs for `/usr`. |
| 88 | +This makes many package manager operations work; conceptually it is similar |
| 89 | +to the writable overlay that many "Live CDs" use. However, one cannot change the kernel |
| 90 | +this way for example. |
| 91 | + |
| 92 | +An optional integration that package managers can do is to detect this transient overlay |
| 93 | +situation and inform the user that the changes will be ephemeral. |
| 94 | + |
| 95 | +## Persistent changes |
| 96 | + |
| 97 | +A bootc system by default *does* have a writable, persistent data store that holds |
| 98 | +multiple container image versions (more in [filesystem](filesystem.md)). |
| 99 | + |
| 100 | +Systems such as [rpm-ostree](https://github.com/coreos/rpm-ostree/) implement |
| 101 | +a "hybrid" mechanism where packages can be persistently layered and re-applied; |
| 102 | +the system effectively does a "local build", unioning the intermediate filesystems. |
| 103 | + |
| 104 | +One aspect of how rpm-ostree implements this is by caching individual unpacked RPMs as ostree commits |
| 105 | +in the ostree repo. |
| 106 | + |
| 107 | +This section will be expanded later; you may also be able to find more information in [booting local builds](booting-local-builds.md). |
| 108 | + |
| 109 | + |
0 commit comments