Skip to content
Fuse
Esc
↑↓navigate↵open⌘Jpreview
On this page

Firecracker host setup

Turn a Linux box with KVM into a Fuse host, from a fresh server to your first environment

This page takes a fresh Linux server to a running Fuse environment. One command installs everything on the box: the Firecracker host agent, the orchestrator and a Postgres for it. You then drive it from your laptop with the CLI.

1. Check the server

Firecracker needs hardware virtualization, so the server must expose /dev/kvm:

ls -l /dev/kvm
[ -r /dev/kvm ] && [ -w /dev/kvm ] && echo ok

If /dev/kvm is missing, the box can’t run Fuse. Ordinary cloud VMs and containers don’t expose it. Use one of these:

  • bare metal: Hetzner dedicated, Equinix, OVH, AWS *.metal
  • a cloud VM with nested virtualization enabled: for example a GCP instance with nested virtualization turned on

The server also needs:

  • Linux on x86_64 (the baked rootfs pulls amd64 podman and iptables)
  • apt (Debian/Ubuntu) or dnf (Fedora/RHEL), so the scripts can install their own dependencies
  • sudo, and git to clone the repo
  • docker, which runs restate-server for the orchestrator. fc-deps.sh installs it if missing (docker.io on apt, moby-engine on Fedora) and makes sure the daemon is running. On RHEL, Rocky or Alma, install docker-ce from Docker’s repo first

2. Run bootstrap

git clone https://github.com/folsomintel/fuse ~/fuse
cd ~/fuse/host-agent/firecracker
sudo ./scripts/fc-agent.sh bootstrap

Keep the checkout where it is. The services run from it, and the updater pulls into it.

bootstrap runs eight stages and prints each one as [bootstrap] N/8:

Stage What it does
1. host dependencies fc-deps.sh installs podman, docker, python3, iptables, e2fsprogs and the rest, then checks KVM
2. firecracker fc-install.sh fetches the Firecracker binary, a guest kernel, a base rootfs and an SSH key
3. host agent installs and starts fc-agent.service on :8090, generating its token
4. postgres fc-postgres.sh installs Postgres and creates a loopback-only fuse_orchestrator database
5. orchestrator installs and starts orchestrator.service on :8080, with auth on and a generated token
6. auto-update installs a weekly timer that pulls the latest release (skip with --no-updater)
7. guest agent + bake downloads fused and bakes it into rootfs-fused.ext4
8. register registers this box with the orchestrator as host local-fc (skip with --no-register)

It’s safe to re-run. If a stage fails, fix the cause and run it again. When it finishes it prints the address and token to use from your laptop:

======================================================================
 fuse host ready
   orchestrator : http://203.0.113.10:8080
   token        : 3f9c...

   drive it from your laptop:
     fuse connect http://203.0.113.10:8080 --token 3f9c...
======================================================================

3. Open the orchestrator port

With everything on one box, your laptop only talks to the orchestrator. Allow 8080/tcp from wherever you run the CLI, or put a TLS proxy or a tailnet in front of it. Leave 8090 (the host agent) closed to the outside: the orchestrator reaches it over loopback.

4. Connect from your laptop

Install the CLI (see Quickstart), then run the line bootstrap printed:

fuse connect http://203.0.113.10:8080 --token <token>
fuse host get local-fc

fuse host get should show the server’s CPUs, RAM and disk. If you lose the token, it’s ORCH_AUTH_TOKEN in /etc/default/orchestrator on the server.

5. Boot an environment

In any directory on your laptop:

cat > Fusefile <<'EOF'
version: 1
resources:
  cpus: 2
  memory: 2GB
run: echo "hello from $(hostname)" > hello.txt
EOF

fuse up
fuse environment exec <id> -- cat /workspace/hello.txt

If that prints hello from ..., the host is done. See Your first Fusefile for what each line does.

Where things live

What Where
Host agent service fc-agent.service, log at host-agent/firecracker/fc-agent.log
Host agent token FC_AGENT_TOKEN in host-agent/firecracker/.env
Orchestrator service orchestrator.service, logs via journalctl -u orchestrator
Orchestrator config and token /etc/default/orchestrator (ORCH_AUTH_TOKEN, DATABASE_URL)
Postgres password /etc/fuse/postgres.pass
Auto-update timer fc-update.timer, Mondays 04 UTC
VM state host-agent/firecracker/agent-state/vms/<vm_id>/

Adding more hosts

bootstrap puts an orchestrator on every box it runs on. For a second host that should join an existing orchestrator, install only the host agent:

git clone https://github.com/folsomintel/fuse ~/fuse
cd ~/fuse/host-agent/firecracker
sudo ./scripts/fc-deps.sh
sudo ./scripts/fc-install.sh
sudo ./scripts/fc-update.sh                  # download fused and bake the rootfs
sudo ./scripts/fc-agent.sh install-service   # starts the agent, prints its URL and token

Then register it from your laptop, using the agent token it printed (not the orchestrator token):

fuse host register fc-east-2 \
  --url http://<host>:8090 \
  --token "$FC_AGENT_TOKEN" \
  --max-vms 20

Here the orchestrator reaches the agent over the network, so open 8090/tcp and the per-VM range 19551-<19550 + max VMs>/tcp from the orchestrator to this host (slots are handed out lowest first, so --max-vms 20 needs 19551-19570). See Deploying the orchestrator for the token and port reference.

Manual, step-by-step setup

To run or skip individual stages, this is what the host side of bootstrap does:

git clone https://github.com/folsomintel/fuse ~/fuse
cd ~/fuse/host-agent/firecracker

# 0. Install host dependencies (podman, docker, python3, e2fsprogs, ...) and verify them.
./scripts/fc-deps.sh

# 1. Fetch firecracker binary + CI kernel + base rootfs + SSH key. The guest kernel
#    is 6.1, which reseeds its random number generator when a vm is resumed from a
#    snapshot; FC_GUEST_KERNEL=5.10 installs the older one. An existing vmlinux.bin
#    is kept, so delete it first to switch.
./scripts/fc-install.sh

# 2. Build the reference in-guest agent (produces host-agent/firecracker/fused). Needs Go
#    (./scripts/fc-deps.sh --with-go installs it). To run your own agent instead, drop
#    your binary here as `fused` and skip this.
../shared/fc-build-agent.sh

# 3. Bake the guest rootfs (rootfs-fused.ext4). Bakes in `fused` + fused.service.
#    Re-run whenever the agent binary changes -- the agent is baked into the image.
./scripts/fc-bake-rootfs.sh

# 4. Start the agent. Prints FIRECRACKER_BASE_URL + FIRECRACKER_TOKEN.
./scripts/fc-agent.sh start

# 5. Smoke-test the contract end to end.
./tests/fc-agent-test.sh

Point Fuse at the printed values:

FIRECRACKER_BASE_URL=http://<host>:8090
FIRECRACKER_TOKEN=<generated>

See Deploying the orchestrator to wire these into an orchestrator instance, or register the agent with an existing one as in Adding more hosts.

Operating

./scripts/fc-agent.sh start               # launch agent on :8090, print env
./scripts/fc-agent.sh stop                 # stop
./scripts/fc-agent.sh restart              # stop+start; re-attaches to running VMs
./scripts/fc-agent.sh log                  # tail agent log
./scripts/fc-agent.sh env                  # print env keys for an already-running agent
./tests/fc-agent-test.sh                 # contract smoke test

# systemd integration (optional, for long-lived hosts)
./scripts/fc-agent.sh install-service      # enable fc-agent.service (survives reboot)
./scripts/fc-agent.sh uninstall-service

To pick up a new agent binary: re-run ./scripts/fc-bake-rootfs.sh then ./scripts/fc-agent.sh restart.

On startup, the agent walks its state directory and for each VM either reuses it (if the process and socket are alive) or transparently recreates the TAP/DNAT and relaunches Firecracker with the same config. That means systemctl restart fc-agent and host reboots don’t lose VMs, as long as the systemd unit is installed.

Auto-update

fc-update.sh keeps a self-hosted box on the latest GitHub release. It pulls the checkout first, resolves the latest release tag, then compares that tag against the .fc-version marker file next to the script. If they differ it downloads the new fused, re-bakes the rootfs, and restarts the agent. The comparison is string equality, not a version ordering, so re-tagging or rolling back to an older release also triggers an update, and FC_FORCE=1 re-applies the current one. It never shells out to fused --version to make that decision:

./scripts/fc-update.sh                 # one-shot: update if the marker != the latest tag
./scripts/fc-agent.sh install-updater  # weekly systemd timer (Mon 04:00 UTC +/- 30m)
./scripts/fc-agent.sh uninstall-updater

No token needed (public repo). Optional host-agent/firecracker/.fc-updater.env can set GH_TOKEN=... to dodge API rate limits, or FUSE_ORCH_SERVICE/FUSE_ORCH_BIN to also update a co-located orchestrator. Override the source repo with FUSE_REPO=owner/name.

Upgrade every fc-agent before live-migrating or checkpointing across hosts. An upgraded agent hashes a live snapshot’s memory in a format older agents cannot check, so an older target refuses it with a 422 and the move fails.

State

State lives under agent-state/vms/<vm_id>/, safe to rm -rf if the agent is stopped and you want a clean slate.

Hit an issue baking or booting? See Troubleshooting.

What gets baked into the rootfs

See Artifacts for the conceptual explanation. Concretely, fc-bake-rootfs.sh builds rootfs-fused.ext4 on top of the Firecracker CI Ubuntu 22.04 rootfs, injecting /usr/local/bin/fused, podman-static and its runtime dependencies, iptables (symlinked to xtables-legacy-multi, the CI kernel has no nftables), the host’s CA bundle, and a fused.service systemd unit. Re-run it whenever the agent binary changes.

Known limitations of this rootfs: apt is unusable (the CI rootfs ships an empty /var/lib/dpkg/status, customize via the mounted ext4 from the host instead). podman run without --network=host falls back to host netns anyway (bridged per-container networking isn’t supported). The kernel lacks fuse and nftables support.

Distro images

fc-bake-distro-rootfs.sh <oci-ref> <name> bakes an apt or dnf based OCI image into $IMAGES_DIR/<name>.ext4 (default images/), which a Fusefile then boots with image: <name>. It pulls the image with podman, installs systemd, sshd, iptables (legacy backend) and ca-certificates with the image’s own package manager, injects the same fused, podman-static, docker-compose and containers config as the base bake, puts the public half of ubuntu.id_rsa in root’s authorized_keys, and writes the image with mkfs.ext4 -d. Alpine and other distros without apt-get or dnf are refused. It needs fused and ubuntu.id_rsa in host-agent/firecracker/, passwordless sudo, and e2fsprogs 1.43 or newer.

cd host-agent/firecracker
./scripts/fc-bake-distro-catalogue.sh               # debian-12, ubuntu-24.04, fedora-40
./scripts/fc-bake-distro-catalogue.sh fedora-40     # just one
./scripts/fc-bake-distro-rootfs.sh docker.io/library/debian@sha256:<digest> my-debian

The script never prompts and is safe to re-run. The image is built in a temp file and moved into place at the end, so a failed bake never leaves a partial <name>.ext4. On failure it exits nonzero with the reason as the last line on stderr. FC_BAKE_WORK overrides the work dir (default /tmp/fcbake-distro-<name>) and FC_ROOTFS_SIZE the image size (default 4G, sparse). Re-run it after the agent binary changes, as with the base bake.

Images converted through POST /v1/images (a Fusefile’s from:) land in the same directory as oci-<digest>.ext4, under a per-host cap: FC_IMAGE_CACHE_GB on the agent (default 50) bounds the disk they allocate. Before a new conversion that could pass it, counted at FC_ROOTFS_SIZE since a bake never allocates more, the agent evicts the least recently booted converted images that no vm or snapshot on the host was booted from. When nothing can be evicted the convert answers 507. Baked catalogue images and anything else in IMAGES_DIR are never counted or evicted.

The host agent’s HTTP contract

VM routes are under /v1/vm, bearer auth (Authorization: Bearer $TOKEN), JSON in/out. Auth applies to every route including the health and capacity probes, there is no unauthenticated path on this agent:

Method Path Purpose
POST /v1/vm Create a microVM. Body: {name,cpus,memory_mb,storage_gb,region,image}. Returns {vm_id,url}.
GET /v1/vm/{id} {vm_id,url}
GET /v1/vm?prefix= {vms:[{vm_id,url}]}, prefix match on name.
DELETE /v1/vm/{id} Tear down, free TAP + DNAT.
POST /v1/vm/{id}/upload {path, content_b64}, writes into the guest.
POST /v1/vm/{id}/exec {cmd:[...], timeout_ms}, returns {exit_code, stdout, stderr} (base64).
POST /v1/vm/{id}/start-agent Preferred. Optionally fetches the agent binary via download_url, writes a systemd drop-in, starts it.
POST /v1/vm/{id}/start-surfd Frozen legacy wire, same as start-agent with fused defaults. Fuse falls back to this on a 404 from start-agent.
POST /v1/vm/{id}/snapshot {comment, live}. live defaults to false (rootfs copy only); true pauses the VM and writes guest memory and vCPU state alongside it. Returns {snapshot_id, digest, kind, size_bytes}, where digest covers the rootfs only.
GET /v1/vm/{id}/snapshots {snapshots:[...]}
POST /v1/vm/{id}/restore {snapshot_id}. Stops fc and swaps the rootfs, then branches on the snapshot’s recorded kind: disk reboots the VM, live loads the memory image into a fresh fc process, resumes, and pushes the host clock into the guest. There is no flag, the recorded kind decides.
POST /v1/vm/{id}/fork Seeds a brand-new VM from this VM’s snapshot. Returns the new VM’s {vm_id,url}.
GET /v1/vm/{id}/attach Hijacks the connection for an interactive pty session, fuse-attach/1 framing.
GET /v1/capacity Host CPU count, total RAM, and free disk. Probed once at host registration, not polled.
GET /healthz {ok:true, app_name:"fc-agent"}. GET / is the same handler.

Mutating calls may carry an Idempotency-Key header, and the orchestrator sends one on every call made inside a durable step. The agent keeps each keyed answer below 500 for 24h (FC_AGENT_IDEMPOTENCY_TTL, seconds): a repeat with the same key gets that answer back with Idempotent-Replayed: true instead of running again, and a repeat that arrives mid-request waits for the first. A 5xx is not kept, so a retry runs again. Without a key, DELETE /v1/vm/{id} of a VM that is already gone returns 204, and POST /v1/vm naming an existing VM with the identical body returns that VM rather than 409.

Mutating calls also carry X-Fuse-Epoch, the incarnation of the VM they are for. A VM ID repeats when an environment is destroyed and created again under the same task_id, and the epoch keeps a late request for the old one off the new one. The agent saves the epoch a VM was created with and answers 412 to a mutating call for any other epoch. A create gets 412 when its epoch is no newer than the newest the host has created under that ID, which the agent keeps in epochs/ under its state dir for 30 days after the VM is destroyed. A create for a newer epoch while a VM with an older epoch still holds the ID gets 409 instead of that VM. The VM objects returned by the create, get and list calls carry epoch. Requests without the header, and VMs created before the agent supported it, are not checked. Reads are never checked.

image on create is optional: a base-image name resolved to $IMAGES_DIR/<image>.ext4, defaulting to the baked rootfs-fused.ext4 when unset. A name that resolves outside IMAGES_DIR and a name with no matching file both return 400, so bake and place the rootfs before referencing it.

timeout_ms on exec is clamped to a 600-second ceiling, and the ceiling applies when the field is omitted or zero.

A bring-your-own host agent has to serve fork and attach too. fuse environment fork is implemented on top of the former, and the API’s attach endpoint on top of the latter, rather than on any orchestrator-side fallback. Attach has no CLI command, it is reachable only over the HTTP API.

url is <public_host>:<host_port>, DNAT’d to the guest’s 9550. Host port is 19550 + vm_index. Public host is auto-detected; override with PUBLIC_HOST=... in the agent’s environment.

Networking model

  • One network namespace per VM (fcns<N>), where N is the VM’s slot (1 up to the port below the start of net.ipv4.ip_local_port_range, minus FUSE_HOST_PORT_BASE: 13217 with the defaults, so agent ports stay below the ephemeral range that exposed ports are drawn from). Inside it the guest network is the same for every VM: a TAP tap0 at 172.16.0.1/30, the guest at 172.16.0.2, one MAC. That is what lets a live snapshot resume into any free slot, and two VMs resume from one snapshot on the same host.
  • A veth pair joins the namespace to the host: fcv<N> on the host at 10.208.<hi>.<lo>, veth0 in the namespace at 10.209.<hi>.<lo>, where hi and lo are the slot’s two bytes. The namespace NATs between 10.209.<hi>.<lo> and the guest, so the agent reaches the guest (SSH, the guest agent, exposed ports) on 10.209.<hi>.<lo>.
  • Host iptables: MASQUERADE for egress, FORWARD accept for the veth (a DROP for proxy egress), and a per-VM PREROUTING DNAT rule <public_host>:<port> -> 10.209.<hi>.<lo>:9550. Destroying the VM removes the rules keyed on its veth and deletes the namespace, which takes the veth and TAP with it. At startup the agent deletes any fcns<N> namespace no VM holds.
  • 10.208.0.0/16 and 10.209.0.0/16 must not be in use on the host’s own networks.
  • A VM created before per-VM namespaces keeps its old layout (a TAP fcv<N> in the host namespace at 10.200.<N>.0/30) until it is destroyed, including across a restore or a relaunch after a reboot, so its guest addresses and egress proxy keep working. Its live snapshots resume into new VMs with that 10.200.<N> guest network inside the new VM’s namespace.
  • Open at your cloud / external firewall: 8090/tcp (the agent’s HTTP API) and 19551–<19550 + N>/tcp (the per-VM guest-agent DNAT range, N the most VMs the host runs; 19551-19799 covers 249).

Was this page helpful?