What it is
A Firecracker “drive” is avirtio-block device: an emulated block device the guest kernel sees and can mount exactly like a real disk, backed by an ordinary file on the host. There’s no virtualization magic beyond that. The guest issues block reads and writes, Firecracker translates them into reads and writes against the backing file, and whatever filesystem the guest formats it with (ext4, in every case here) is the guest’s own concern. A drive is durable and reattachable specifically because “the backing file” is just a file sandkiln keeps around after the sandbox that used it stops. Nothing about it is tied to any one VM process.
Why sandkiln uses it here
The per-sandbox rootfs a VM boots from is deliberately ephemeral, cloned fresh at boot time and torn down when the sandbox is destroyed, the same way a container’s own filesystem layer normally is. A drive exists for the opposite case: state a caller explicitly wants to survive past one sandbox’s lifetime and reattach to a different one later, such as a persistent cache, a shared dataset, or a working directory that should outlive whichever sandbox is currently using it.Key terms
How it works in sandkiln
sandkiln_vmm::drive::DriveStore (core/crates/vmm/src/drive.rs) manages a directory of drive image files, one per drive, named <id>.ext4. Creating one is genuinely simple: allocate a sparse file of the requested size (file.set_len, so actual disk usage grows with what the guest writes rather than being reserved up front, the same “let the filesystem do the work” approach the per-sandbox rootfs clone uses), then run mkfs.ext4 against it. DriveStore itself has no idea which sandbox, if any, currently has a drive attached. That tracking lives entirely on the daemon side, in sandkiln-daemon::state, because only the daemon has the concept of a running sandbox at all.
The actual exclusivity rule is one small, pure function, can_attach_read_only (core/crates/daemon/src/state.rs):
drive_holders(drive_id) walks both the live sandbox map and the held-snapshot map to build the list this function checks against, and describe_drive_holders renders it into the human-readable 409 message a caller actually sees ("sandbox a (read-only), sandbox b").
See it in action
Create a drive, attach it read-write, then try attaching it read-write again while it’s still held:attached_to is exactly can_attach_read_only’s input, rendered back out. The same data the exclusivity check reasons over is what GET /drives shows you.