Skip to content

kerf: Record load provenance and show it in kerf show - #15

Merged
congwang-mk merged 5 commits into
mainfrom
kimage-metadata
Aug 14, 2026
Merged

kerf: Record load provenance and show it in kerf show#15
congwang-mk merged 5 commits into
mainfrom
kimage-metadata

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Summary

The Kernel Image section of kerf show only displays what the kernel exposes in /proc/kimage (id, type, start address, segments, mode, cmdline). The source image file is unknown to the kernel, since kexec_file_load takes a bare fd, so nothing identified which kernel, initrd, or rootfs an instance is actually running.

This PR records that provenance in userspace at load time and displays it in kerf show. Stacked on #14 (base branch bzimage-support) because it reuses the vmlinuz module for bzImage parsing; it retargets to main automatically when #14 merges.

What gets recorded

On a successful load, kerf load writes /var/lib/kerf/instances/<name>.json (consistent with the existing /var/lib/kerf/rootfs and /var/lib/kerf/daxfs state directories):

  • Kernel: path, format (bzImage/vmlinux), compression, version string, size, sha256. The version comes from the kernel_version setup header field for a bzImage, or the Linux version banner for a vmlinux.
  • Initrd (optional): path, size, sha256, compression format, including recognition of a leading uncompressed cpio (early microcode). Purely informational: kexec treats the initrd as an opaque blob and the spawn kernel decompresses it at boot, so no extraction is needed.
  • Rootfs (optional, for --image / --rootfs-dir): source kind, image reference or directory path, resolved entrypoint, and daxfs physical address and size.

kerf show

The recorded fields merge into the Kernel Image section, with a new Rootfs section when applicable:

  Kernel Image:
    ...existing /proc/kimage rows...
    Image           /boot/vmlinuz-7.0.11-generic
    Format          bzImage (zstd compressed, vmlinux extracted at load)
    Version         7.0.11-generic #1 SMP
    Initrd          /boot/initrd.img (zstd compressed)
    Loaded At       2026-08-13T10:00:00+00:00

  Rootfs:
    Image           nginx:latest
    Entrypoint      /docker-entrypoint.sh
    Daxfs           phys=0xf80000000, size=536870912

--verbose adds sha256 rows and the Docker extraction path. A metadata write failure only warns and never fails the load. kerf unload and kerf delete remove the record so it cannot go stale.

Testing

30 tests in tests/test_metadata.py cover the store round-trip, corrupt-file handling, kernel/initrd inspection across formats, and the kerf show rendering including optional-field omission and verbose-only rows. Full suite: 119 passed.

🤖 Generated with Claude Code

Base automatically changed from bzimage-support to main August 14, 2026 16:23
The Kernel Image section of kerf show only displays what the kernel
exposes in /proc/kimage (id, type, start address, segments, mode,
cmdline). The source image file is unknown to the kernel, since
kexec_file_load takes a bare fd, so nothing identified which kernel an
instance is actually running.

Record the provenance in userspace instead. On a successful load, kerf
load writes /var/lib/kerf/instances/<name>.json with the kernel path,
image format, compression, version string, size, sha256, initrd path,
and load time. The version comes from the kernel_version setup header
field for a bzImage, or from the "Linux version" banner for a vmlinux.
kerf show merges these fields into the Kernel Image section, and both
kerf unload and kerf delete remove the record.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Inspect the optional initrd the same way as the kernel image and store
its path, size, sha256, and compression format in the instance record.
Unlike the kernel image, a compressed initrd needs no extraction: kexec
treats it as an opaque blob and the spawn kernel decompresses it at
boot, so this is purely informational for kerf show.

The initrd field changes from a bare path string to an object; kerf
show still renders records written in the old form.

Signed-off-by: Cong Wang <cwang@multikernel.io>
An instance loaded with a Docker image or rootfs directory records
which image or directory it is running, the resolved entrypoint, and
the daxfs physical placement, all known at load time but visible
nowhere afterwards. kerf show renders them in a new Rootfs section,
with the Docker extraction path shown under --verbose. Instances
loaded without a rootfs are unaffected.

Signed-off-by: Cong Wang <cwang@multikernel.io>
Taking the instances_dir fixture as a test parameter shadows the
fixture function name and trips pylint W0621. The fixture already
redirects the store to tmp_path, so use tmp_path directly.

Signed-off-by: Cong Wang <cwang@multikernel.io>
A tag like nginx:latest names different bytes over time, so the
reference alone cannot tell which image an instance is actually
running. Have extract_image() also return the image ID, the sha256
digest of the config blob it already parses for the entrypoint, and
record it as rootfs.image_id. kerf show displays it under --verbose.

Pin the layer extraction to the fully_trusted tar filter it relies on
today: a rootfs needs setuid bits, device nodes, and absolute
symlinks, which the restrictive default coming in Python 3.14 rejects.

Signed-off-by: Cong Wang <cwang@multikernel.io>
@congwang-mk
congwang-mk merged commit 1cde6cc into main Aug 14, 2026
4 checks passed
@congwang-mk
congwang-mk deleted the kimage-metadata branch August 14, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant