Firecracker snapshots: from cold boot to resumed VM
By Origin Clouds Engineering, Platform team
For function runtimes, boot time is only half the story. The language runtime, dependencies and application still have to initialize. Snapshots let you do that work once, save the VM's memory and device state, and resume copies of it on demand.
Take a snapshot
Pause the VM, then ask Firecracker to write its state and memory to disk.
curl --unix-socket /tmp/fc.sock -X PATCH http://localhost/vm \
-H 'Content-Type: application/json' -d '{"state":"Paused"}'
curl --unix-socket /tmp/fc.sock -X PUT http://localhost/snapshot/create \
-H 'Content-Type: application/json' \
-d '{"snapshot_type":"Full","snapshot_path":"./vm.snap","mem_file_path":"./vm.mem"}'Restore it
A fresh Firecracker process loads the snapshot instead of booting. Guest memory is mapped from the file and paged in as it's touched, which is why restores are so quick.
curl --unix-socket /tmp/fc2.sock -X PUT http://localhost/snapshot/load \
-H 'Content-Type: application/json' \
-d '{"snapshot_path":"./vm.snap","mem_backend":{"backend_type":"File","backend_path":"./vm.mem"},"resume_vm":true}'The hard part: clones are identical
Every VM restored from one snapshot starts with the same memory, which means the same random number generator state, the same in-memory secrets and the same network identity. That's fine for one restore and dangerous for a thousand.
- Reseed randomness in the guest after restore, and make sure your kernel and runtime support VM generation ID notifications
- Never bake long-lived secrets into a snapshot; fetch them after resume
- Reassign IPs and MACs, and reset connections the guest thought were open
- Snapshot files are tied to the Firecracker version and host CPU family; rebuild them when either changes
Snapshot pools are one of the most common things we build for clients. The API calls are the easy part; the lifecycle around them is where the engineering is.
Running this in production?
We help teams design, harden and tune platforms like this one.
Talk to an engineer
Origin Clouds