Skip to main content
This setup was tested with Firecracker v1.18.0 and a 6.1 guest kernel. You need a Linux host with read-write access to /dev/kvm, Docker, curl, python3 and mkfs.ext4, the firecracker binary from a Firecracker release, and an uncompressed guest kernel (vmlinux), such as one of the 6.1 kernels Firecracker publishes for its own testing.

Build the root filesystem

The guest needs the static binaries, a shell for the commands you run, and an init that mounts the kernel filesystems and execs axed so it becomes PID 1. This example uses static busybox:
Write rootfs/init:
Then make it executable and build an ext4 image:
What the axed flags do:
  • --listen 'vsock://any:1024?auth=none' listens on vsock port 1024 without a token. Outside the guest, only the host reaches the vsock channel through the VMM, so the channel is the trust boundary. Inside the guest, any process could connect over the loopback CID, so an auth=none vsock listener refuses connections from the guest itself and accepts only the host. Passing --listen replaces the default TCP gRPC listener.
  • --agent-sandbox=false turns off the sandboxd API. Without it, axed also opens the REST API on TCP port 8080.
  • The init mounts /dev/pts so terminal sessions work, and /sys/fs/cgroup so axed can use cgroups.

Boot the VM

Start Firecracker, wait for its API socket to appear, then point the boot source at your kernel with init=/init, attach the rootfs, and add a vsock device:

Connect from the host

Firecracker exposes the guest’s vsock as a Unix socket on the host (uds_path). A host client connects to it, writes CONNECT 1024\n, reads OK <n>\n, and then the stream reaches the guest listener. axectl dials plain Unix sockets, so put a small proxy in between that performs the handshake for each connection. The repository has one you can use or adapt, tests/firecracker/vsock_proxy.py:
Use the axectl binary you copied into rootfs/usr/local/bin, or put a copy on your PATH. axectl info shows pid1 true and the guest’s cgroup. In your own platform, perform the same handshake in your host agent’s dialer.

Cgroups in the guest

As PID 1 with the cgroup v2 hierarchy mounted, axed takes over the guest’s cgroups with --cgroups auto. Each process gets its own cgroup, so whole-tree kill works, and memory limits are enforced when the kernel has the memory controller (an over-limit process is reported oom-killed). CPU limits need the cpu controller. axed enables whichever of cpu, memory and pids the guest kernel provides; check /sys/fs/cgroup/cgroup.subtree_control in the guest to see which ones yours has.

Snapshot and restore

Pause the VM, take a full snapshot, and later load it into a new Firecracker process:
After restore, detached processes are still running and their output replays intact from any retained offset. Client connections die with the old VMM, so clients reconnect through the restored vsock socket and continue from the last offset they saw. The instance_id stays the same, because the process table survived.

Call axectl resumed after every restore

Firecracker freezes the guest clocks across the snapshot, so timeouts stay correct without help. But the clocks do not show the gap, so axed does not detect the resume on its own, and the guest’s wall clock falls behind. After every restore, report the restore with System.Configure:
It sends the host’s wall time and 64 bytes of fresh entropy, and prints the new generation, how far the clock was stepped, and whether the entropy was added, in the form generation N, clock stepped S.SSSs, entropy added. axed checks the request, then handles it in this order:
  1. Steps the guest’s wall clock to the host’s time if it is more than 50 ms off. This needs CAP_SYS_TIME; without it the call fails here and nothing else happens.
  2. Adds the entropy to the guest’s random pool, so clones of one snapshot stop sharing random state. This needs CAP_SYS_ADMIN. It is best effort: without the capability the entropy is skipped and the output says entropy not added.
  3. Records the resume, which increments the generation.
axed has both capabilities as root PID 1, as in this setup. --no-entropy skips step 2. To quiesce processes before the snapshot, run axectl freeze first and axectl freeze --thaw after restore. Freezing needs cgroups. See Snapshots.

What was tested

With Firecracker v1.18.0 and a 6.1 guest kernel, using the setup on this page:
  • axed runs as PID 1 and takes the guest’s cgroup v2 hierarchy.
  • Offset replay, PTYs, memory limits (oom-killed) and whole-tree kill work inside the microVM.
  • After pause, snapshot, 15 seconds stopped and restore: the instance id is unchanged, the detached process is still running and producing output, replay from offset 0 is intact, and axectl resumed records the resume.
  • A 20-second timeout fires after about 20 seconds of running time, not counting the 15 seconds stopped.