# Design

> The decisions behind Barn — one inventory, explicit destruction, native acceleration, two NICs, layered disks, and verified process identity.

---

LLMS index: [llms.txt](/v1.5/llms.txt)

---

Barn's behavior follows from a handful of decisions. Each one answers a concrete problem that comes up when you run multi-node labs on a workstation. Knowing them makes the rest of the documentation predictable: why `barn up` never deletes anything, why every node has two network interfaces, why there is no "project" to switch between.

Barn has two workflows that share a CLI and nothing else:

| | Linux labs (`barn …`) | macOS VMs (`barn mac …`) |
|---|---|---|
| Hypervisor | QEMU with HVF or KVM; TCG emulation for a foreign architecture | Apple `Virtualization.framework` |
| Configuration | One Ansible inventory (`barn.yml` or `pigsty.yml`) | Named VMs set up with command-line flags |
| State | `$BARN_HOME` (default `~/.barn`) | `$BARN_HOME/mac` (default `~/.barn/mac`) |
| Network | NAT management interface plus a shared fixed-IP `/24` | One private `/24` NAT subnet per VM, guest at `.10` |
| Typical use | Database clusters, Ansible playbooks, multi-node testing | macOS builds, GUI testing, a clean desktop to reproduce bugs |
{.wide .expand}

The rest of this page covers Linux labs. The macOS side is explained in [native Mac lifecycle](/v1.5/blog/design/native-mac-lifecycle/).

## One inventory, one lab per user {#one-linux-lab-per-user}

**Problem.** A Pigsty or Ansible inventory already names every node and its IP address. A per-directory "project" layer on top of it raises questions with no good answers: which file owns a node's address, whether moving a checkout creates a second lab, and which project owns the single host bridge.

**Decision.** The inventory *is* Barn's configuration, and each user has exactly one Linux lab, stored under `BARN_HOME`. Barn reads only the host addresses, a few identity fields (`nodename`, `admin_ip`, `pg_cluster`, `pg_seq`, …), and the `vm_*` variables. It validates `vm_*` strictly and ignores everything else, so a typo in `vm_mem` fails `barn validate` while PostgreSQL settings in the same file change freely.

**What you notice.** `barn status`, `barn ssh`, and `barn stop` work from any directory, and `barn up` in a directory without an inventory resumes the same lab instead of starting a second one. [Why Barn has no projects](/v1.5/blog/design/one-deployment-no-projects/)

## Creation is declarative, destruction is explicit {#node-level-convergence}

**Problem.** An inventory gets edited for debugging, switched with a git branch, or loses a group in a bad merge. If a missing node meant "delete this VM", one typo would wipe a database node.

**Decision.** The inventory authorizes creation, never deletion. Barn hashes each node's resolved specification and compares it with what was applied:

- `barn up` creates new nodes, starts stopped ones, and finishes interrupted guest setup without restarting healthy VMs.
- In 1.5.0, new labs inherit Debian 13 from the embedded catalog. Each lab records its default image in the applied specification. Upgrading Barn keeps that default, so starting the lab or adding a node preserves its distribution unless the inventory or a command selects another. [Upgrade acceptance](../../../blog/design/release-1-5-0-readiness/#checks)
- A changed node is reported as drift and left alone. CPU and memory changes apply with `barn resize`; other changes need `barn recreate`.
- A node removed from the file keeps running until you run `barn destroy` on it, and a whole-lab `recreate` refuses an inventory that omits an existing node.

**What you notice.** `barn plan` always tells you what `up` would do, and the commands that delete data are the ones named after it. [Declarative does not mean destructive](/v1.5/blog/design/convergence-without-surprise/)

## Native speed, or a clear failure {#runtime-selection}

**Problem.** QEMU can silently fall back to software emulation when hardware acceleration is unavailable. The VM still boots, but runs far slower, and nothing tells you why.

**Decision.** When guest and host architectures match, Barn uses HVF on macOS or KVM on Linux, and fails if that accelerator does not work. It uses TCG emulation only when you ask for a different architecture, or when the image catalog marks a guest as incompatible with the host accelerator (Rocky Linux 8 on Apple Silicon, whose 64 KiB page kernel HVF cannot run).

**What you notice.**

- The guest architecture is one setting for the whole lab (`vm_arch`, or `-A` for one command). It defaults to the host's. An architecture-suffixed image alias such as `el10a` or `d13x` also selects it. [Precedence rules](../../reference/configuration/#image-and-architecture)
- `barn status` shows each node's architecture and accelerator.
- Before `recreate` deletes a working VM, Barn checks that the QEMU binary, network backend, base image, and firmware for the replacement are all present.

## Two network interfaces per node {#two-nics-one-fixed-subnet}

**Problem.** Cluster software identifies peers by IP address: replication, consensus, load-balancer backends, a keepalived VIP, and Prometheus targets all expect `10.10.10.11` to be the same machine across reboots and reachable from the other nodes. Port forwarding to the host gives *you* a way in, but nodes cannot form a cluster through it. At the same time, a freshly booted VM needs internet access to install packages, ideally without you editing host firewall rules.

**Decision.** Every Linux VM gets two NICs with separate jobs:

| Interface | Provided by | Used for |
|---|---|---|
| Management | QEMU user-mode NAT with DHCP | Internet access, DNS, and the SSH port forwarded to `127.0.0.1` on the host |
| Lab | A host bridge, static address from the inventory | Host-to-node and node-to-node traffic, Ansible, cluster services, VIPs |
{.wide}

The bridge lets QEMU run as your user: macOS hosts use a pinned `socket_vmnet` daemon; Linux hosts use a `barn0` bridge managed by NetworkManager or systemd-networkd, with the distribution's `qemu-bridge-helper`. Creating it is a one-time `sudo` step during `barn setup`.

**What you notice.** Nodes reach each other and your host at the inventory addresses, and they reach the internet without any NAT rules on your machine. [Why every node has two NICs](/v1.5/blog/design/fixed-ip-two-nics/)

## Images, disks, and configuration change independently {#storage-and-configuration-lifetimes}

**Problem.** A base image download is large, a lab's root disks are disposable, and test data on a data disk can take an hour to regenerate. Tying their lifetimes together means either redownloading constantly or losing data by accident.

**Decision.** Each layer has its own lifetime:

- Verified base images are cached read-only under `$BARN_HOME/images` and shared by all nodes; each node's root disk is a thin copy-on-write overlay on top.
- `barn update` refreshes the image catalog without touching existing root disks. New and recreated nodes get the newer images.
- Data disks marked `persistent: true` survive `destroy` and `recreate`.
- `barn image prune` removes only images that nothing references.

**What you notice.** Creating a node is fast and nearly free in disk space, and you choose when a node moves to a new image. [What survives each operation](../../start/storage/#what-survives-each-operation)

## Check identity before acting {#safety-boundary}

**Problem.** A PID file records a number. After a crash or a reboot, that number may belong to an unrelated process, and a path in a damaged state file may point somewhere it should not. Trusting either can kill the wrong process or delete a disk still in use.

**Decision.** QEMU and image downloads run as your user; root is used only by `setup`, `network install/uninstall`, and `hosts install/uninstall`. Before Barn signals a process or deletes a node's files, it checks file ownership, that the path is inside the deployment, the VM's name and UUID over QEMU's control socket (QMP), and the process start time and command line. If any check is ambiguous, it stops and reports instead of guessing.

**What you notice.** An interrupted command can be rerun safely, and an occasional "identity mismatch" error means Barn refused to act on something it could not prove was its own. [A PID is not a virtual machine](/v1.5/blog/design/identity-before-pid/) · [Security and trust](../security/)
