Introducing a new way to review your PRs.

Read the announcement

superradcompany / microsandbox

🧱 easy, fast, programmable and local-first microVM runtime and library

View on GitHub

27 documents · Updated Nov 23, 2026

docs / storage-migration-execution

Storage migration execution and compatibility

Storage migration turns a stopped sandbox's legacy disk view into protected storage that the current runtime can trust. It discovers only host-authorized disk roles, checks related writers and artifacts, captures a stable group, and publishes new journals without deleting the original inputs. The wider recovery model is described in Storage migration and recovery, while Checkpoint and restore covers the disk and artifact model that migration preserves.

Migration authority

Host storage roles

The migration authority comes from the saved host configuration. It defines the root disk and each named owned disk, including its expected path, capacity, and read-only policy. A legacy journal can describe a chain inside one of these roles, but it cannot grant access to another path or disk. This keeps guest-controlled metadata from becoming host authority.

The host also binds a plan to the sandbox incarnation and the saved configuration revision. Deleting and recreating a sandbox with the same name therefore cannot reuse an old plan.

References: sdk/…/protected_state.rs• L34-70 crates/…/types.rs• L13-50

Legacy source discovery

Discovery reads the configured roles and their legacy journals to find complete disk chains. It checks that each layer has a supported format, a valid capacity, and an explicit predecessor when one is required. Missing journals are accepted only for simple fresh storage; advanced files without an active-head record require recovery instead of a guessed head.

The discovery result is an inspection, not permission to migrate. It reports whether the storage is ready, eligible, in progress, or requires recovery. Recovery candidates use opaque IDs that bind the disk role, ordered layers, and current host identity.

References: crates/…/source.rs• L84-264 crates/…/source.rs• L1125-1334 crates/…/types.rs• L53-96

Migration must account for every known name that can write to a selected disk. The alias pass checks related sandboxes, owned volumes, checkpoint layers, and snapshot ancestry. These records extend writer exclusion only when they point to an already selected host-authorized object; they never add a new source.

The process retains lifecycle, storage, snapshot, and related-writer guards until capture and publication finish. This prevents a peer sandbox or snapshot operation from changing the source group between inspection and execution. See Checkpoint and restore for how checkpoint lineage and disk generations create these related artifacts.

References: sdk/…/storage_aliases.rs• L76-118 sdk/…/storage_aliases.rs• L139-239 sdk/…/storage_aliases.rs• L330-462

Migration execution

Frozen migration plan

A migration plan is a pinned choice of one complete view for every configured disk role. The caller records the plan and keeps the storage and lifecycle ownership for the whole synchronous operation. A later retry resumes the recorded choice; it cannot silently choose a different journal head.

The execution moves through a forward-only sequence. The barrier makes old readers reject the layout before new journals become visible, and the durable operation record lets a later process continue from the last completed step.

This diagram shows how a selected legacy view becomes protected storage.

flowchart LR
    A[Inspect host-authorized roles] --> B[Pin complete disk view]
    B --> C[Record migration intent]
    C --> D[Publish layout barrier and guards]
    D --> E[Capture one protected disk group]
    E --> F[Validate captures and journals]
    F --> G[Publish all disk journals]
    G --> H[Publish protected ready state]

References: crates/…/engine.rs• L30-60 crates/…/engine.rs• L67-181 sdk/…/protected_state.rs• L215-246

Capture and journal publication

Internal legacy layers are copied into a private operation area. Source and metadata access uses bounded, no-follow reads, and each capture is checked as an independent file. Embedded QCOW dependencies are changed to point to the private ordered layers. External write-through root disks remain at their configured paths and stay protected by their original authority.

The operation records each completed capture, then certifies the whole group after the final source audit. It validates the private layers again before it writes the new root and owned-disk journals. New directories and files are hardened before publication, and publication uses a durable replacement step. All journals are published behind the rejecting barrier so a ready consumer cannot observe only part of a multi-disk migration.

Original disks, checkpoints, and recovery records remain available after success. The retained records support later alias accounting and verification; migration is not a destructive cleanup step.

References: crates/…/io.rs• L157-185 crates/…/io.rs• L339-370 crates/…/io.rs• L420-487 crates/…/engine.rs• L140-181 crates/…/engine.rs• L301-454 crates/…/engine.rs• L457-512

Crash resume

An interrupted operation is identified by its durable operation record and layout marker. Resume verifies the stored host bindings, source identities, capture identities, writer protection, and any already certified group before it does more work. It never mixes layers from different source epochs.

If a source, journal, namespace, or completed private capture changed, execution stops and preserves the migration state for investigation. A plan that has reached the protected ready state is not reinterpreted as legacy storage.

References: crates/…/engine.rs• L233-299 crates/…/engine.rs• L519-713 sdk/…/protected_state.rs• L257-285

Budgets and protection

Work and metadata budgets

Migration uses shared bounds so one disk role cannot pass alone while the complete storage group exceeds safe work limits. Inspection estimates capture space before execution, while execution applies the same limits to source handles, entries, metadata, and parser state.

QCOW metadata has a conservative 256 MiB parser budget. The budget covers all selected roles together and rejects malformed or unbounded headers before the full image parser reads them. These limits are admission guards for migration work; they are not guest RAM or disk-capacity limits.

References: crates/…/budget.rs• L12-16 crates/…/budget.rs• L22-39 crates/…/source.rs• L455-472 crates/…/io.rs• L17-20

Namespace protection

The destination namespace must be controlled by the host before migration can publish authoritative state. The checks cover the sandbox, runtime, operation area, owned-disk paths, and their ancestors. They inspect both the path spelling and its resolved ancestry, so a trusted final directory cannot hide an unsafe alias. Symlinks, reparse points, unsafe ownership, and untrusted replacement paths are refused.

Execution retains platform-specific namespace guards while it admits the catalog and publishes files. New capture directories are created and hardened while private, then become visible through one durable replacement step. Inspection keeps shared handles, while execution retains stronger publication guards where the platform supports them. This keeps another account or path alias from substituting a disk or journal during migration.

References: crates/…/namespace.rs• L27-76 crates/…/namespace.rs• L128-215 crates/…/io.rs• L339-410

Writer exclusion

Inspection can run without stopping writers because it reads bounded metadata and records provisional identities. Execution is different: it must exclude existing and new writers for the entire capture epoch. Linux and Windows use file-level protection, while macOS requires an explicit maintenance window because the needed per-file lease is not available to this application.

If protection breaks or a related writer appears, the whole capture epoch is invalid. Migration does not certify a partial mixture and does not retry with a new source under the same operation record.

References: crates/…/writer.rs• L20-89 sdk/…/protected_state.rs• L194-253 sdk/…/storage_aliases.rs• L465-489

Preview and compatibility

Read-only diagnosis

Storage diagnosis gives the operator a bounded view of local sandbox readiness without starting a backend or changing catalog records, permissions, guards, or disks. It reads the existing catalog and reports per-sandbox status, running state, guest mount paths, candidate views, reasons, and estimated capture space.

The report is advisory. A later locked operation repeats catalog, namespace, source, and writer checks before it can migrate. The CLI exposes this distinction through statuses such as Ready, Eligible, MaintenanceRequired, RecoveryRequired, and InProgress.

References: sdk/…/storage.rs• L29-99 sdk/…/storage.rs• L147-241 crates/…/storage_doctor.rs• L43-78

Private recovery preview

When legacy metadata is ambiguous or damaged, the system can capture every complete authorized alternative into private staging. The preview uses copies, not original layers, so browsing cannot write through to the sandbox or external disk. It can materialize a disposable raw image and expose bounded directory and file reads through an isolated read-only guest reader.

The operator selects one complete view for every disk role. Confirmation checks that the catalog, journals, source identities, and reviewed bytes still match the preview session before it enters normal migration. A selected view may omit later writes, so explicit selection requires that the operator acknowledge this risk.

References: crates/…/preview.rs• L23-133 crates/…/preview.rs• L173-301 sdk/…/storage_preview.rs• L64-169 sdk/…/storage_preview.rs• L321-447

Compatibility boundary

The protected layout is the compatibility boundary between old and new storage behavior. The ready marker, protected disk journals, host bindings, and retained migration record must agree before normal launch or recovery can use the storage. Old readers are blocked once migration enters its protected transition.

Preview and recovery also require a compatible embedded storage reader. The reader has a fixed private protocol, bounded replies, restricted mounts, no network, and no ability to change the target. Recovery does not restore pending guest memory or device state; it prepares disk storage for a later start. For that distinction, see Checkpoint and restore.

References: crates/…/engine.rs• L619-713 crates/…/mod.rs• L16-25 crates/…/storage_preview.rs• L5-30 sdk/…/storage_recovery.rs• L24-70 sdk/…/storage_preview.rs• L397-418

Change checklist

When these files or sections are changed, remember to consider these:

  • When host disk roles or saved configuration change, update binding derivation, candidate identity, journal validation, and related-writer discovery together.
  • When legacy journal or layer naming changes, update source discovery, QCOW dependency checks, capture normalization, journal publication, and protected-layout admission together.
  • When alias or snapshot lineage rules change, check both source authority and the guards that keep related writers stopped through publication.
  • When capture or parser limits change, update inspection estimates, whole-group admission, preview capture, and materialization bounds together.
  • When the migration record or barrier changes, check crash resume, old-reader refusal, ready publication, and downgrade or recovery behavior.
  • When preview protocol or reader policy changes, update candidate binding, content verification, guest mount paths, reply limits, and runtime capability checks together.
  • When platform writer or namespace protection changes, check Linux, Windows, and macOS maintenance paths before changing migration eligibility.
  • When bounded storage I/O or publication rules change, check no-follow acquisition, source identity checks, private staging, hardlink handling, and durable replacement together.

Important failure modes

TriggerConsequenceGuard
A journal names a disk outside the saved host role or has an incomplete chainMigration refuses to choose a source and preserves the legacy storageHost bindings define authority; source discovery validates complete explicit chains.
A related sandbox, snapshot, or alias can still write to a selected objectCapture is blocked before it can publish a mixed disk groupAlias discovery acquires related guards and the execution plan audits writer protection.
QCOW metadata exceeds the shared parser budget or has an unbounded headerInspection or migration stops before full image parsingThe bounded header budget is applied across all selected disk roles.
A source or completed private capture changes during executionThe operation remains recoverable but does not publish the changed bytesPinned file identities and durable capture identities are rechecked at each resume and publication step.
A source path uses a link, hardlink alias, or unsafe path componentMigration refuses the source rather than reading through an ambiguous objectDescriptor-relative no-follow access, link checks, hardlink checks, and bounded components are applied before reads.
A destination or one of its lexical or canonical ancestors is not host controlledMigration stops before it can publish or replace authoritative stateNamespace acquisition checks both path forms and retains execution guards.
The migration barrier or operation record is only partly writtenOld readers refuse the transition and the next supported process resumes or reports recoveryIntent and layout markers use atomic publication, and journals publish only behind the barrier.
A preview source, catalog revision, or reviewed byte changes before confirmationThe selected view is rejected and the operator must inspect againPreview confirmation compares current views and verifies content roots under fresh locks.
macOS legacy writers are not stopped across all homesMigration cannot prove that an unlinked writer is absentExplicit maintenance confirmation is required; protected or new storage is exempt.
The embedded reader lacks the required private protocol or policyPreview browsing stops without reading the targetRuntime capability and handshake checks run before capture or reader launch.

Key files

FileWhy to read it
crates/…/engine.rsDefines the frozen plan, durable intent, capture order, crash resume, validation, and journal publication.
crates/…/source.rsDefines legacy disk discovery, complete candidate views, source roles, aliases, and group limits.
crates/…/io.rsDefines bounded no-follow storage access, source identity checks, private capture, QCOW header checks, and durable publication.
crates/…/preview.rsDefines private alternative capture, disposable materialization, content review, and preview-to-plan binding.
crates/…/types.rsDefines migration status, host bindings, candidate summaries, and recovery selections.
crates/…/budget.rsDefines the shared parser metadata admission budget.
crates/…/writer.rsDefines source writer exclusion and epoch auditing across supported platforms.
crates/…/namespace.rsDefines destination namespace authority, alias ancestry checks, and private staging protection.
crates/…/mod.rsDefines the migration module's public plan, preview, source, and status surface.
sdk/…/protected_state.rsConnects saved configuration, lifecycle locks, catalog admission, migration, and normal startup.
sdk/…/storage_aliases.rsExplains related sandbox, snapshot, alias, and writer discovery.
sdk/…/storage.rsDefines read-only diagnosis and its compatibility-aware status report.
sdk/…/storage_preview.rsExposes private browse and confirmation behavior to the SDK.
sdk/…/storage_recovery.rsDefines stopped-sandbox recovery choices and the promise that originals remain retained.
crates/…/storage_preview.rsDefines the bounded contract for the isolated recovery reader.
crates/…/storage_doctor.rsShows how diagnosis statuses, candidate views, and recovery guidance reach the CLI.