Volumes
A volume is an ext4 disk that belongs to an app, not to a machine. Every deploy makes a new machine with a new root disk and deletes the old one, so anything that must survive a deploy (a database, uploads, a cache worth keeping) goes on a volume. This page covers the manifest, what a redeploy does, backups, repair and removal. Key syntax is in manifest; flags are in cli.
Example
A PostgreSQL app, where the data must outlive every deploy:
app = "notes"
image = "docker.io/library/postgres:17-alpine"
env_file = "db.env" # POSTGRES_PASSWORD=...
[env]
PGDATA = "/var/lib/postgresql/data/pgdata" # a subdirectory of the mount
[[mounts]]
source = "pgdata" # the volume's name
destination = "/var/lib/postgresql/data" # where the guest sees it
initial_size = "2gib" # only when first created; default 1gib
[[services]]
internal_port = 5432
[[services.ports]]
port = 5432The same keys work for any image. Here is a small nginx app with one volume, and the output cairn printed when it was deployed, redeployed and listed:
app = "web"
image = "docker.io/library/nginx:1.27"
[[mounts]]
source = "site"
destination = "/usr/share/nginx/html/data"
initial_size = "256mib"
[[services]]
internal_port = 80
[[services.ports]]
port = 8080$ cairn deploy
volume site — new and empty, 256.0 MiB, owner 0:0 (the image's initial user), at /usr/share/nginx/html/data
creating volume site as QZLCYYNUDM
this app has volumes: the running machine is stopped before the new one starts, so the app does not answer until the new machine starts listening
ready port 80 accept, 1.1s after the workload started; accepted
volume site QZLCYYNUDM — new and empty, 256.0 MiB, 764.0 KiB allocated, at /usr/share/nginx/html/data
from starting the stop: 2.0 s to the new machine's readinessA second cairn deploy prints stopping the previous machine NG7ZBL57E9 (SIGQUIT, up to 10 s) and the new machine mounts the same volume: the data written before is still there.
$ cairn volume list web
NAME ID SIZE HOST ALLOCATION ATTACHED TO HELD DESTINATION STATE
site QZLCYYNUDM 256.0 MiB 800.0 KiB Y4LNK2Y9AQ yes (machine Y4LNK2Y9AQ, pid 985172) /usr/share/nginx/html/dataHELD says whether a VMM cairn let at the volume is still running, and which machine's. STATE names unfinished work (a growth, repair, restore or destroy), and the command's pid while that command still runs.
Rules for [[mounts]]
- Name and path.
sourceis[a-z][a-z0-9_]{0,29}.destinationis an absolute, normalised path. It cannot be/,/etc,/bin,/sbin,/lib,/lib64or/usr, nor inside/proc,/sys,/dev,/runor/tmp. Two mounts cannot nest. No directory on the way may be a symlink in the image (/var/run/xis refused where/var/runlinks to/run). Cairn checks this against the built image before it stops the running machine, so a bad path costs no outage. - Count and size. At most 4 mounts per app, each 64 MiB to 1 TiB.
- A mount hides what the image has at that path and is not seeded from it. The image's files there are not copied in. Mount where your program writes data, not over files it ships with.
lost+found. Every new ext4 filesystem has one in its root. PostgreSQL'sinitdbrefuses a directory that contains it, so pointPGDATAone level down, as above. Other databases that want an empty directory need the same.- Ownership. A new volume's root belongs to the image's initial user (its OCI
User; root when empty), not to a user an entrypoint switches to later. The officialpostgresimage starts as root andchowns its own data directory. An image built withUSER 1000gets a root owned by 1000. - The jail is required.
--jail offis refused for an app with mounts, since an unjailed VMM gives cairn no way to keep a second writer off the disk. - Filesystem.
CAIRN_HOME/volumes/must be on the same filesystem asCAIRN_HOME/apps/(volumes are hard-linked into each machine), and one that root can read. A FUSE mount made by your user withoutallow_otheris refused when the machine starts.cairn doctorchecks the first. The host needsmkfs.ext4,e2fsckandresize2fs(package e2fsprogs).
What a manifest change does
| Change | Result |
|---|---|
A new [[mounts]] entry | A new, empty volume is created. |
| An entry removed | The volume is detached and kept. |
source renamed | A new, empty volume; the old one is detached. The deploy says so before it stops anything. |
destination changed | The same volume mounts at the new path. |
Larger initial_size on an existing volume | Nothing. The deploy prints the cairn volume extend command instead. |
Redeploy and failed deploys
A volume has one writer, and an app has one machine at a time in any case. A deploy builds the new machine while the old one serves, then stops the old one, then starts the new one. The app does not answer in between. That time is mostly your workload's own shutdown and startup, so cairn does not promise a number. It prints the time from the start of the stop to the new machine's readiness. That is not a measurement of a client's outage: the new machine serves its ports as soon as its workload listens, before it is ready.
By the time a volume deploy fails, the old machine is already stopped, and the new one may have changed the data (a schema migration, say). Starting the old code on that data can do more damage. So the rollback decides from evidence, while it holds the app's start fence, so that nothing can boot the old machine before the decision is made:
- Each volume's record names the machine it is attached to and, until that VMM's ending is recorded, the VMM, written before that VMM can open the disk; and whether that machine's workload may have run.
- If none of the new release's VMMs got that far, or each one ended in a boot or exec failure before the workload ran, the old release is restarted.
- Otherwise the app is held. Nothing boots it: not
cairn start, a crash restart, systemd, or the next host boot.
$ cairn start notes
cairn: notes is held: its last deploy failed after the new release may have changed its volumes (pgdata). `cairn start notes --release` starts the previous release on them as they are; or deploy a fixed release
$ cairn start notes --release # you decided the old release is safe on this datacairn ps and cairn status show held. If your data changes are always backward compatible, let cairn restore the old release every time:
[deploy]
restore_previous = "always" # default "before-start"A volume created by a failed deploy is kept, because the new release may have written to it.
The same rule applies when a deploy was killed while its new machine was starting and the next cairn deploy, start, stop or destroy settles it: the settlement rolls back with the same decision, so a held app stays held and the old release never boots on data the new one may have changed. A settlement never starts the old machine itself; cairn start (or start --release for a held app) does. Every cairn volume command that works on a volume (extend, repair, backup, restore, destroy) refuses while a deploy of the app did not finish, and says to run cairn stop <app>, which settles it.
Listing and size
cairn volume list # every app's volumes
cairn volume list notesA volume is a sparse file, so a new 2 GiB volume takes a few MiB on the host. SIZE is the filesystem's size. HOST ALLOCATION is what the host has allocated. Neither is the guest's usage. For that, run:
cairn exec notes -- df -h /var/lib/postgresql/datacairn doctor warns when free space under CAIRN_HOME runs low, and how far volumes and root disks could grow past it. If the host disk fills, guest writes fail with I/O errors and the machine can still be stopped.
Extend
Volumes grow and never shrink, and grow only while the app is stopped. The maximum is 1 TiB.
cairn stop notes
cairn volume extend notes pgdata 4gib # an interrupted growth is finished by running it again
cairn start notes # the guest sees 4 GiBBackup, verify, restore
Cairn has no snapshots and no scheduled backups. While the app runs, use the application's own tool (pg_dump, SQLite's .backup) through cairn exec. cairn volume backup refuses while the app runs:
cairn: machine 7KQ2MXW9PD of notes is running or restarting (supervisor pid 985376); `cairn stop notes` firstFor a copy of the whole disk, stop the app:
cairn stop notes
cairn volume backup notes pgdata ~/backups/notes-2026-11-03 # a new directory, mode 0700
cairn volume verify ~/backups/notes-2026-11-03 # reads only; checks the digest
cairn start notes
# later, to go back:
cairn stop notes && cairn volume restore notes pgdata ~/backups/notes-2026-11-03 && cairn start notesThe backup reports backed up 732.0 KiB of data (256.0 MiB logical) to <dir>, and verify ends with filesystem: usable.
A backup is a directory with a sparse image.ext4 and a manifest.json holding a sha256 digest over the volume's identity, its state and every byte of data. Copy it with cp -r or rsync. Verification does not depend on how the copy is stored. The digest detects corruption and mistakes. It does not prove who made the backup, since anyone who can rewrite both files can make a matching one.
A restore replaces the whole volume and keeps its UUID. An interrupted restore blocks every boot, and every other volume command, until you run it again with the same backup.
cairn volume list --backups <dir> lists the backups in a directory and the unfinished ones a crash left. Cairn never deletes those, because one may be the only copy of something.
The backup directory must be on a filesystem that can name a directory without replacing one (ext4, xfs, btrfs, tmpfs). NFS and FUSE cannot, so a backup there is refused before anything is copied. Write to a local disk, then copy.
Damage and repair
Cairn checks a volume before every boot. It never lets e2fsck make repairs that e2fsck -p would not. A volume whose file is shorter than its filesystem, an unreadable superblock, or an interrupted growth, restore or repair refuses to boot, and the refusal names the command that fixes it.
cairn volume repair is the one command that runs e2fsck -y, and it needs a copy first or your explicit acceptance:
cairn volume repair notes pgdata --keep ~/backups/notes-before-repair # a copy as it is
cairn volume repair notes pgdata --accept-data-loss # no copyA repaired volume boots with a damaged note in status and volume list. --clear-damage removes the note once you have checked the data, and changes nothing else. A truncated file needs --accept-data-loss either way: the bytes past its end are gone and e2fsck may not notice. An interrupted repair blocks every boot; run the command again to resume.
One writer
Cairn never starts a second VMM on a volume, whether from a deploy, a restart, cairn start, systemd, or a VMM whose supervisor died. One record says who has the volume: a machine and the VMM cairn let at it, or a command's unfinished work. A boot or a command that finds that VMM still running refuses and names its pid.
A cairn volume command holds the app while it runs: cairn start and another volume command wait for it, for up to 30 seconds, and then give up. The tools it starts (e2fsck, resize2fs) hold the volume's lock too, so a command killed while one runs leaves the volume held by that tool: another command refuses until the tool exits. A boot refuses because the record names the command whose work did not finish, and keeps refusing after the tool exits, until that command is run again. The commands also refuse while the supervisor of a machine that mounts the volume runs, even while it waits to restart the machine.
Cairn knows only the programs it started. It cannot see or stop another one, so do not open CAIRN_HOME/volumes/<app>/<id>.ext4 yourself while the app could start.
Destroy
cairn destroy web keeps the app's volumes and prints the commands that delete them:
kept 1 volume: site (QZLCYYNUDM, 256.0 MiB); `cairn deploy` of web attaches it again; `cairn volume destroy web site` or `cairn destroy web --volumes` deletes itA later cairn deploy of the app attaches them again. cairn destroy web --volumes deletes them too.
cairn volume destroy notes pgdata deletes one. It asks for the app's name to be typed back (--yes skips this, and is needed when not on a terminal). Without a terminal and without --yes it refuses:
cairn: deleting volume site loses its data for good, and there is no terminal to ask on; run `cairn volume destroy web site --yes` if that is what you want
destroyed volume site (QZLCYYNUDM), freeing 800.0 KiB(The second line is what a confirmed deletion prints.) It needs the app stopped, even when no machine mounts the volume. It refuses a volume the current machine still mounts. An interrupted destroy blocks every boot of a machine that mounts the volume; run cairn volume destroy <app> <name> --yes again to finish it, whether or not a machine still mounts it. To delete one the app still uses:
# 1. remove the volume's [[mounts]] entry from cairn.toml, then:
cairn deploy # the new machine no longer mounts pgdata
cairn stop notes # the outage starts
cairn volume destroy notes pgdata
cairn start notes # the outage endsHow it works
A volume is two files in CAIRN_HOME/volumes/<app>/: <id>.ext4 (the sparse filesystem) and <id>.json (the record: identity, size, known damage, and one state: free, attached to a machine, or a command's unfinished work). If the record and the file disagree about size, the file wins. At each boot cairn hard-links the volume into the new machine's directory as volume-<name>.ext4 and attaches it to the guest, which mounts it at destination. The one-writer rule is the record's state plus an flock on the volume (CAIRN_HOME/run/volumes/<app>/<id>.lock): a command holds it for as long as it and its tools run, and a supervisor only while it writes the record, before the VMM is let at the disk and after it has exited. No history of earlier VMMs is kept. Growth, restore and repair write down what they are about to do first, so a crash leaves a state a later command can finish. What a compromised guest can and cannot do to a volume is in security.