Spinbox / field notes

Spinbox· 5 min read

A disk is a chain

Why Spinbox runs on QEMU: a workspace disk is a chain of qcow2 files, which gives snapshots of a running machine, forks that share their ancestors, and no registry at all.

3.1s, in large type: the time to clone a running workspace and have the clone running, with spin workspace clone --wait. Under it: A fork is one new file on top of layers that already exist.

I wanted three things from a workspace’s disk. A stopped workspace should cost object-store prices. The layers of an image, and every ancestor of a snapshot, should exist once, however many workspaces grow from them. And a snapshot should be cheap enough to be a habit, not an event: fork a running machine, let an agent try something, throw the fork away.

A chain of qcow2 files was the base for all three. It’s QEMU’s own disk format, and the reason QEMU stayed.

Before: layers as files

The first prototype kept containerd. A snapshotter turned each image layer into an EROFS file, and a VMDK descriptor stitched them into one disk the guest mounted. The host mounted nothing, and every workspace shared its image’s layers. I liked that part.

The price was paid inside the guest. The writable layer was a separate ext4 disk, so the host attached disks in some order and told the guest which name was which, and the guest’s init waited for every disk to appear, mounted them, and laid an overlay on top to build the root. Two programs, on two sides of a virtual machine, had to agree on the order, with a timeout in the middle. And it still didn’t answer the hard questions: where the disk you write to lives when the machine stops, how you snapshot it while it runs, how it follows you to another host. In January, a snapshot was still a nerdctl commit to an image in a registry.

A chain of files

The answer was an old idea of QEMU’s. A qcow2 file can name another qcow2 file as its backing file. A read that finds nothing in the file goes to the one it names, and from there down the chain. A write only ever goes to the file on top, the tip.

It’s overlayfs’s trick, used to assemble container filesystems, with whole disks where overlayfs has files: the image’s layers at the bottom, the workspace’s sealed layers above them, and one writable tip.

files 2bytes copied 0

Write something, take a snapshot, fork it.

Each slab is a file, each square a block it holds. The guest reads every block from the highest file that has it.

Our code decides four things: which layers make a disk, in what order, who may write, and how the layers get to a bucket. QEMU handles the reads and writes. Before handing it the disk, our machine library opens the backing layers read-only and refuses a writable tip that is a shared image or has a second name through a hard link.

What the chain gives you

A snapshot of a running machine. The runner creates a new, empty tip that names the current one as its backing file, hands it to QEMU, and switches the disk onto it. The old tip is now a sealed layer. The guest never stops; its disk waits only for the switch. Since November the runner first asks the guest to write out what it still holds in memory, and waits up to three seconds; a guest that doesn’t answer still gets its snapshot, as a crash would have left the disk.

A fork that shares its history. A fork is a new tip on top of a sealed layer of another disk. It doesn’t duplicate the ancestors in the bucket. On a host that already has them, the new disk needs only its tip; another host must download the layers missing from its cache. In this run, a clone of a running workspace was booted and running in three seconds.

$ time spin workspace clone blog-captures --name blog-captures-b --wait
…
Network:  web, ping
Created:  2026-11-18 16:10
spin workspace clone …  0.02s user 0.01s system 1% cpu 3.134 total
A clone of a running workspace's disk, booted and running, three seconds later.
$ spin snapshot list blog-captures
ID                                    STATE      MEMORY  CREATED           DESCRIPTION
01a1ef6d-4831-7ebb-92ca-c7fc0950dc9d  published  false   2026-11-18 16:11  after
01a1ef6d-2911-7227-902e-e88f2309ccf6  published  false   2026-11-18 16:11  before
01a1ef6c-72b1-7e15-ac88-12c6c30c926e  published  false   2026-11-18 16:10  clone → blog-captures-b
A clone leaves a snapshot behind: the floor its new tip stands on. On the installation, in November.

No registry. An image is a snapshot with a name. Pulling an image and cloning a snapshot are the same operation, and the difference between a base image and your committed workspace is which snapshot a clone points at.

A chain that doesn’t grow forever. Every layer is one more file a read may have to cross, so at 32 layers the runner starts folding its published layers into a new root. It tries to switch the running machine onto that root; if QEMU refuses, the switch waits until the disk is detached. A test holds it to that: it writes a file and takes a snapshot 33 times, reads every file back, then restarts the machine and checks it reads through a shorter chain.

The bucket remembers

The object store holds every published layer. A host holds the tip and a cache of the rest, and the cache can be rebuilt from the bucket. Publishing a layer takes three steps, always in this order: upload the layer, compressed and sealed; upload the manifest that names it; then move HEAD with a compare-and-swap. A crash between any two leaves the last published state intact, and every HEAD is signed by the host that wrote it.

Each disk has its own key. A fork gets a new one, and reads each layer it inherited with the key of the disk that sealed it. Those descendants still need their ancestor’s key, so a delete is refused while anything descends from the disk. Deletion removes its key material from the current records; older versions in the bucket remain until its retention policy expires them. That isn’t an immediate erasure of every copy.

Sharing has a catch, too. A hundred clones of one disk, each with 20 GiB of history, would have taken 2 TB on a single host, because each kept its own copy of the ancestors. Now every host has one directory of layers that every disk reads from, so clones share what they have in common, on the host as much as in the bucket.

The chain gave things up, too. A layer on a host’s disk is cleartext: the host is the security boundary. And our storage code no longer sits in the path of each guest write. If publishing falls behind while writes keep coming, the host can run out of disk space. Cheap storage in a bucket doesn’t give the host an unlimited disk.

I looked at what already existed. Archil offered a file system backed by your own S3 bucket, with a fast cache in front. JuiceFS offered something similar in the open, though I found it hard to try. Both worked at the file level; I wanted a disk QEMU could open.

For that, Ceph meant a storage cluster to run. ZeroFS could serve a disk over NBD, but that put another process between the machine and its bytes. When that process has a bad day, the machine has one too. I’d been there already: over the summer I decided qcow2 wasn’t enough and wrote a storage engine of our own. That went badly.

Now QEMU reads the chain itself, and our code gets its sealed layers to the bucket.

Found something wrong, or out of date? Tell me, with this post already named, and I'll fix it here. New posts come by RSS.