Snapshots Guide
Save and restore VM state — crash recovery, fast boot, debugging.
Overview
Section titled “Overview”SwarmCracker can snapshot a running Firecracker microVM and restore it later.
A snapshot captures the full VM state: guest memory plus CPU/device state
(Firecracker snapshot_type: Full). This requires Firecracker v1.14.0+ — the
version installed by swarmcracker setup install.
Calling create pauses the VM, writes the snapshot, and the VM can then resume.
Use Cases
Section titled “Use Cases”| Use Case | Benefit |
|---|---|
| Crash recovery | Restore a VM to a known-good state |
| Fast boot | Resume from a snapshot faster than a cold boot |
| Debugging | Capture exact VM state at a point in time |
| Pre-update safety | Roll back a workload after a bad update |
CLI Commands
Section titled “CLI Commands”Snapshots live under swarmcracker vm snapshot:
# Create a snapshot of a running VM (task)swarmcracker vm snapshot create <task-id>
# With metadata (all optional)swarmcracker vm snapshot create <task-id> \ --service <service-id> \ --node <node-id> \ --rootfs /var/lib/firecracker/rootfs/<image>.ext4 \ --vcpus 2 \ --memory 512
# List snapshots (optionally filtered)swarmcracker vm snapshot listswarmcracker vm snapshot list --task <task-id>swarmcracker vm snapshot list --service <service-id>swarmcracker vm snapshot list --node <node-id>
# Restore a VM from a snapshotswarmcracker vm snapshot restore <snapshot-id>
# Delete a snapshotswarmcracker vm snapshot delete <snapshot-id>
# Remove snapshots older than a durationswarmcracker vm snapshot cleanup --max-age 168hcreate determines the Firecracker API socket from --socket (default:
<socket-dir>/<task-id>.sock). restore can set a new socket with --socket.
Configuration
Section titled “Configuration”snapshot: enabled: true snapshot_dir: "/var/lib/firecracker/snapshots" max_snapshots: 3 # per service (0 = unlimited) max_age: 168h # cleanup threshold (0 = unlimited) auto_snapshot: false # snapshot automatically on start compress: false| Option | Default | Description |
|---|---|---|
enabled |
true |
Enable the snapshot feature |
snapshot_dir |
/var/lib/firecracker/snapshots |
Snapshot storage directory |
max_snapshots |
3 |
Max snapshots per service |
max_age |
168h (7 days) |
Age threshold used by cleanup |
auto_snapshot |
false |
Snapshot automatically on VM start |
compress |
false |
Compress snapshot files |
Snapshot Storage
Section titled “Snapshot Storage”Each snapshot gets its own ID and directory:
/var/lib/firecracker/snapshots/└── snap-a1b2c3d4e5f67890/ ├── vm.state # VM state (~15 KB) ├── vm.mem # Memory image (≈ VM RAM size) └── … # metadata (JSON)The metadata records the snapshot ID, task/service/node IDs, creation time, vCPU count, memory size, rootfs path, and a SHA-256 checksum of the state file.
Workflow Examples
Section titled “Workflow Examples”Pre-Update Snapshot
Section titled “Pre-Update Snapshot”# Find the task behind the serviceswarmcracker service ps <service>
# Snapshot before updatingswarmcracker vm snapshot create <task-id>
# Update the serviceswarmcracker service update <service> --image nginx:1.25-alpine
# If something breaks, restoreswarmcracker vm snapshot restore <snapshot-id>Crash Recovery
Section titled “Crash Recovery”# Snapshot before a risky operationswarmcracker vm snapshot create <task-id>
# If the VM dies, restore itswarmcracker vm snapshot restore <snapshot-id>swarmctl Alternative
Section titled “swarmctl Alternative”The lightweight swarmctl debug client (manager node only) can also manage
snapshots. Note the name is a positional argument:
swarmctl snapshot create <task-id> <snapshot-name>swarmctl snapshot listswarmctl snapshot restore <snapshot-name>swarmctl snapshot rm <snapshot-name>Limitations
Section titled “Limitations”- VM must be paused before snapshot (handled automatically by
create). - Snapshots are node-local — they are not replicated across the cluster.
- Size — the memory file is roughly the VM’s RAM size.
- Rootfs path — the rootfs must be accessible at the same path on restore.
- Firecracker version — requires v1.14.0+ for the current snapshot API.
- Network state — active network connections may not survive a restore.
Troubleshooting
Section titled “Troubleshooting”Snapshot Fails
Section titled “Snapshot Fails”# Check the VM/task is runningswarmcracker task lsswarmcracker vm list
# Check the snapshot directory is writable and has spacels -la /var/lib/firecracker/snapshotsdf -h /var/lib/firecracker/snapshotsRestore Fails
Section titled “Restore Fails”# Verify the snapshot existsswarmcracker vm snapshot list
# Confirm the files are presentls /var/lib/firecracker/snapshots/<snapshot-id>/Snapshots Too Large
Section titled “Snapshots Too Large”# Create VMs with less memoryswarmcracker vm create --memory 256 alpine:latest
# Or reclaim spaceswarmcracker vm snapshot cleanup --max-age 24hSee Also: Configuration | CLI Reference | Operations