Skip to content

systemd: Add bootc-log-boot.service to journal the booted image - #2681

Merged
Johan-Liebert1 merged 2 commits into
bootc-dev:mainfrom
fcuny:log-boot-journal
Nov 25, 2026
Merged

Johan-Liebert1 merged 2 commits into
bootc-dev:mainfrom
fcuny:log-boot-journal

Conversation

@fcuny

@fcuny fcuny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

On systems that are installed once and never updated, nothing records which image the system booted: nothing is ever staged, and bootc install logs to the installer's journal, not the target's. This adds bootc-log-boot.service, which writes one structured journal entry on every boot. It implements the proposal in #452 (comment), for the composefs backend only.

journalctl MESSAGE_ID=66797517e29842bfa048064146ec92c2

The entry carries BOOTC_BACKEND, BOOTC_DEPLOYMENT (the composefs verity digest), BOOTC_IMAGE, BOOTC_TRANSPORT, BOOTC_MANIFEST_DIGEST, BOOTC_ARCHITECTURE, and BOOTC_VERSION and BOOTC_TIMESTAMP when the image has them. The first boot of a deployment is the oldest entry with its BOOTC_DEPLOYMENT. bootc-log-boot.service(5) documents the fields.

Two choices differ from what the issue comment suggested:

  • No bootc status path. On composefs, BootedStorage::new mounts the ESP and runs prepend_custom_prefix on every invocation. A logging unit that runs unattended at every boot shouldn't do that, and a failure there would lose the audit record. log-boot reads only the deployment's origin file and the image in the composefs repository. The first commit is a prep refactor that lets get_imginfo work without a full Storage. So the command is not backend-agnostic after all, and the ostree follow-up needs its own small reader.
  • libsystemd instead of tracing. The tracing journald layer in bootc_utils::initialize_tracing keeps tracing-journald's default F field prefix. So every existing message_id = ... entry is stored as F_MESSAGE_ID, and journalctl MESSAGE_ID=... doesn't match it (the tmt tests already query F_MESSAGE_ID). This entry uses libsystemd::logging::journal_send to get a real MESSAGE_ID. Fixing the layer would rename every existing field, so I left that for a separate issue.

Out of scope: the ostree backend, and the finalize-time entry from the original issue.

Testing

  • cargo fmt --check, cargo test -p bootc-lib --lib (345 passed), cargo clippy with the CI lint config, and cargo doc -D warnings, on Fedora 43 aarch64.
  • The prep commit passes the same checks on its own.
  • Booted tests on a GCE VM with nested KVM, on Ubuntu 26.04 like the CI runners and set up with bootc-dev/actions/bootc-host-setup. The base was CentOS Stream 10, and SELinux was enforcing in both runs. Both runs passed all 26 readonly tests, including 014 (no failed units) and the new 056:
    • composefs (systemd-boot, BLS, ext4, unsealed): just test-tmt-nobuild --filesystem=ext4 --seal-state=unsealed --boot-type=bls readonly passed.
    • ostree (grub, xfs) as a control: just test-tmt readonly passed. The unit isn't enabled there, and 056 finds no entry.

Test 056 output from the composefs run:

verify booted image journal entry
# MESSAGE: Booted localhost/bootc:latest version devel (sha256:2349ef69646225839fe17f9781945925f14e26e06df237ba2965c5f9af1fd047) from composefs deployment 3ee688487c9460cc9e37bd7a24d3217374be5ae4a98dd9f7fc9e1dd40516b174749d6059d283a44f02cc66b98825a91e2ca06a1d28708452f0b92eaa69023e88
{
  "BOOTC_BACKEND": "composefs",
  "BOOTC_DEPLOYMENT": "3ee688487c9460cc9e37bd7a24d3217374be5ae4a98dd9f7fc9e1dd40516b174749d6059d283a44f02cc66b98825a91e2ca06a1d28708452f0b92eaa69023e88",
  "BOOTC_IMAGE": "localhost/bootc:latest",
  "BOOTC_TRANSPORT": "registry",
  "BOOTC_MANIFEST_DIGEST": "sha256:2349ef69646225839fe17f9781945925f14e26e06df237ba2965c5f9af1fd047",
  "BOOTC_ARCHITECTURE": "amd64",
  "BOOTC_VERSION": "devel",
  "BOOTC_TIMESTAMP": "2026-11-23T19:01:08.350280219+00:00"
}
ok

The test also asserts that each field matches bootc status --json and that the unit exited 0 during this boot. It passing with SELinux enforcing shows that bootc_t can read /sysroot/state and /sysroot/composefs at boot without the install_t transition bootc status uses. I did not run the other composefs cells: grub, UKI, sealed, and btrfs/xfs.

AI disclosure

Generated-by: AI

I don't have particular experience with Rust, so please review the Rust code with extra care. I reviewed the design and the behavior, and the tests above pass.

Related: #452

@Johan-Liebert1 Johan-Liebert1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

Comment thread crates/lib/src/boot_journal.rs Resolved
Comment thread systemd/bootc-log-boot.service Resolved
Comment thread crates/lib/src/boot_journal.rs Resolved
Prep for logging the booted image at boot without going through
`bootc status`. On composefs that path remounts `/sysroot` read-write,
mounts the ESP and may migrate boot entries. The new caller only needs
the image metadata of the booted deployment, which this function builds
from the origin file and the composefs repository.

No behavior change intended.

Generated-by: AI
Signed-off-by: Franck Cuny <[email protected]>
On systems that are installed once and never updated, nothing records
which image the system booted: nothing is ever staged, and `bootc
install` logs to the installer's journal, not the target's. Write one
structured journal entry on every boot, so the journal always holds a
recent record whatever its retention. The first boot of a deployment is
the oldest entry with its `BOOTC_DEPLOYMENT`.

The generator enables the unit on native composefs boots only for now,
and the unit carries a matching kernel command line condition.
`bootc internals log-boot` opens the deployment state and the composefs
repository read-only, through a new `Storage` constructor. Unlike the
`bootc status` path, it doesn't remount `/sysroot`, mount the ESP or
touch boot entries, so it needs no private mount namespace.

The entry goes through libsystemd directly rather than `tracing`. The
tracing journald layer prefixes custom fields with `F_`, so a
`message_id` field would be stored as `F_MESSAGE_ID` and
`journalctl MESSAGE_ID=...` would not match it.

Related: bootc-dev#452
Generated-by: AI
Signed-off-by: Franck Cuny <[email protected]>

@Johan-Liebert1 Johan-Liebert1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Johan-Liebert1
Johan-Liebert1 merged commit deb6220 into bootc-dev:main Nov 25, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/documentation Updates to the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants