Skip to content

Add WithRootFSShare to boot from the cached rootfs without copying it - #160

Merged
jhrozek merged 3 commits into
stacklok:mainfrom
thejoeejoee:feat/rootfs-share
Nov 6, 2026
Merged

jhrozek merged 3 commits into
stacklok:mainfrom
thejoeejoee:feat/rootfs-share

Conversation

@thejoeejoee

Copy link
Copy Markdown
Contributor

Closes #159.

Adds WithRootFSShare(tag): instead of cloning the cached rootfs on every start, Run boots from an empty root directory in the data dir (hooks, guest VM config and .krun_config.json land there) and shares the cache entry read-only over virtio-fs under tag. The guest init assembles its root, e.g. as an overlay. The cached image's OCI config still drives the init config.

  • Requires an image from the cache (FromCache); errors otherwise.
  • Rejected together with WithRootFSPath, and when tag collides with a WithVirtioFS mount.
  • VM.Remove keeps the cache entry, as before.

Testing

  • TestRun_RootFSShare_SharesCachedRootfsReadOnly: hooks see an empty root with the OCI config, nothing is written into the cache entry, the backend gets the read-only mount of the cache path.
  • TestRun_RootFSShare_Validation: pre-built rootfs path and tag collision are rejected before the backend starts.
  • go test ./..., golangci-lint run ./....
  • End to end with jailoc on a Linux/KVM host (overlay of the boot root over the idmapped image share, tmpfs upper): microvm.Run 3.8–4.2 s → 7 ms, jailoc restart ~6 s → 1.0–1.6 s.

jhrozek and others added 2 commits November 6, 2026 10:53
Co-authored-by: Mecatl <noreply@mecatl.dev>
Co-authored-by: Mecatl <noreply@mecatl.dev>
@jhrozek

jhrozek commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Pushed two follow-up fixes on top of this PR:

  • 134ece2 — Preserve existing rootfs work storage. The share path now exclusively creates rootfs-work and rejects existing entries instead of recursively deleting them. The previous behavior could remove a stopped or running VM's writable root, an attached disk, or a custom cache beneath that directory without WithCleanDataDir. Intentional removal stays on the explicit cleanup path with its existing safeguards. Initialization-failure cleanup only removes the newly created empty directory and preserves cleanup errors.
  • cd68b95 — Restore private rootfs storage validation. Share mode now validates the raw data-directory path before cleanup/normalization and applies the existing private-parent checks before creating the writable root. This restores the non-root Linux protection provided by the clone path: an existing publicly traversable data directory with a separate private cache could otherwise expose environment values in .krun_config.json. The fix preserves the existing platform gates, valid private effective-path ancestry, and guest-root 0755 permissions.

Both commits include regression tests. An independent sol-6.1 worker statically reviewed the actual fixes and found no blocking regressions. Tests, lint, and vet were not run, as requested; runtime/compiler verification remains outstanding.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after independent static review of the implementation and the two follow-up fixes. The fixes preserve existing working-root storage and restore share-mode private-parent validation while retaining guest-root permissions and existing platform behavior. No blocking regressions identified in the reviewed changes.

@jhrozek
jhrozek merged commit f6464c7 into stacklok:main Nov 6, 2026
8 checks passed
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.

Boot from the cached rootfs without copying it

2 participants