Skip to content

feat(orch): move reserved blocks setting from in-guest to host-side pre-boot hook#2199

Merged
arkamar merged 7 commits intomainfrom
feat/host-side-reserved-blocks
Mar 23, 2026
Merged

feat(orch): move reserved blocks setting from in-guest to host-side pre-boot hook#2199
arkamar merged 7 commits intomainfrom
feat/host-side-reserved-blocks

Conversation

@arkamar
Copy link
Copy Markdown
Contributor

@arkamar arkamar commented Mar 22, 2026

Narrows the issue introduced in #2082 where setting reserved disk space required running tune2fs inside the guest VM. This approach failed when the guest image didn't have e2fsprogs installed (e.g. from_template builds inheriting from older parents) or when the guest e2fsprogs version was incompatible with the host's ext4 features.

Obsoletes #2194, which tried to fix this by adding e2fsprogs to provision.sh. This would force cache invalidation for all existing templates but still didn't cover the from_template path where provisioning is skipped entirely.

Instead, a PreBootFn hook is added to Factory.CreateSandbox() that runs after the rootfs device is ready but before Firecracker boots. The finalize phase uses this hook to call SetReservedBlocksOnHost using the host's tune2fs, which is always available and compatible. The in-guest SetReservedBlocksInGuest is removed.

Close: #2194


Note

Medium Risk
Touches sandbox creation by adding a pre-boot callback that can mutate the rootfs before Firecracker starts, which could affect boot behavior or disk state if misused. Risk is limited to template build sandboxes and is gated by a feature flag for reserved disk space.

Overview
Adds an optional PreBootFn hook to sandbox creation that runs after the rootfs device is prepared but before Firecracker boots, enabling host-side filesystem adjustments. Template builds now use this hook (behind BuildReservedDiskSpaceMB) to set ext4 reserved blocks via host tune2fs instead of running tune2fs inside the guest, and the in-guest reserved-blocks command path is removed while feature-flag plumbing is threaded through the build step/user builders.

Written by Cursor Bugbot for commit 21cd01a. This will update automatically on new commits. Configure here.

arkamar added 2 commits March 22, 2026 01:13
… rootfs modifications

Add a PreBootFn callback parameter to Factory.CreateSandbox() that runs
after the rootfs device is ready but before Firecracker boots the VM.
This enables host-side filesystem metadata changes (e.g. tune2fs) on the
rootfs path without depending on guest-side tooling.

Thread the hook through the layer CreateSandbox builder via a new
WithPreBootFn option.
…re-boot hook

Replace SetReservedBlocksInGuest (tune2fs inside the VM) with a host-side
PreBootFn that calls SetReservedBlocksOnHost on the rootfs device path
before the guest kernel boots. This eliminates the dependency on e2fsprogs
being installed and compatible inside the guest image.

The previous in-guest approach was fragile across different build paths:
- fromImage builds: provisioning could install e2fsprogs, but older guest
  versions were incompatible with host-created ext4 features.
- fromTemplate builds: provisioning is skipped entirely, so e2fsprogs
  was only present if the parent template happened to have it.
- Cached builds: the base phase SetReservedBlocksOnHost was skipped on
  cache hits, leaving only the in-guest call which could fail.

Reserved blocks are now set at two points:
- Base phase: on the host rootfs file after provisioning, so root has
  protected disk space during user build steps.
- Finalize phase: via PreBootFn before every VM boot, regardless of
  build path or cache state, using the host's own tune2fs.
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Review of pre-boot hook changes

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88394c8df9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

arkamar added 2 commits March 22, 2026 08:37
Gather CreateSandbox options up front and spread them, rather than
always passing WithPreBootFn which could be nil.
…ootFn

Apply the host-side SetReservedBlocksOnHost pre-boot hook to the steps
phase as well, not just finalize. When the first uncached layer creates
a new sandbox, the PreBootFn sets reserved blocks before the guest boots.
This protects intermediate build sandboxes from disk-full conditions
during user RUN commands, not just the final template.
@jakubno jakubno assigned dobrac and unassigned jakubno Mar 23, 2026
Move the inline SetReservedBlocksOnHost call in buildLayerFromOCI to use
the same WithPreBootFn mechanism as the steps and finalize phases. This
is a pure refactor — same file, same timing (before VM boot), just
consistent with the rest of the pipeline.
Copy link
Copy Markdown
Contributor

@dobrac dobrac left a comment

Choose a reason for hiding this comment

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

This is great! It would be better to run the reserve for the first uncached layer (like envd) instead, but this is enough to fix the behavior for now.

…reBootFn setup

Consolidate the identical reserved blocks PreBootFn setup from base,
steps, and finalize phases into a single ReservedBlocksOptions() helper
in the layer package. Each call site now collapses from 5 lines to 1.
@arkamar
Copy link
Copy Markdown
Contributor Author

arkamar commented Mar 23, 2026

This is great! It would be better to run the reserve for the first uncached layer (like envd) instead, but this is enough to fix the behavior for now.

I think this should be addressed now in the latest push.

@arkamar arkamar requested a review from dobrac March 23, 2026 10:04
Copy link
Copy Markdown
Contributor

@dobrac dobrac left a comment

Choose a reason for hiding this comment

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

one nit

Only set reserved blocks in finalize when the source layer was cached,
since otherwise a prior step phase already set them via its own
CreateSandbox PreBootFn.
@arkamar arkamar merged commit e2abd1d into main Mar 23, 2026
36 checks passed
@arkamar arkamar deleted the feat/host-side-reserved-blocks branch March 23, 2026 12:37
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.

4 participants