This is the multi-page printable view of this section.
Guides
- 1: Download and Install Barn
- 2: Linux Quick Start
- 3: macOS Virtual Machines
- 4: Daily Operations
- 5: Storage, Files, and Service Access
- 6: Image Repositories
- 7: Automation and Guest Scripts
- 8: Use Barn with an AI Agent
- 9: Troubleshooting
- 10: Build from Source
- 11: Uninstall and Clean Up
Task-by-task guides, roughly in the order you will need them. Linux labs and macOS VMs can run side by side on the same Apple Silicon Mac; each is managed on its own.
Get started
- Install Barn — Homebrew, installer script, or DEB/RPM; host requirements and upgrades.
- Linux Quick Start — Boot a Debian 13 VM, log in, and grow it into a four-node fixed-IP lab.
- macOS VMs — Create a macOS machine on Apple Silicon with a desktop, SSH, shared folders, and clipboard.
Run a Linux lab
- Daily Operations — Check status, stop and start nodes, and apply inventory changes safely.
- Storage and Access — Add data disks that survive rebuilds, copy files, and reach guest services.
- Images — Choose Ubuntu, Debian, or Rocky Linux, use the China mirror, or bring your own
qcow2. - Automation — Drive Barn from scripts, CI, or AI agents, and pair it with Pigsty.
- Use Barn with an AI agent — Give a coding agent the Barn skill and specify the lab you need.
Fix, build, and remove
- Troubleshooting — Symptoms, checks, and fixes for setup, networking, SSH, and images.
- Build from Source — Build the CLI and
Barn.appyourself to try unreleased changes. - Uninstall — Remove VMs, cached images, the host network, and Barn itself.
1 - Download and Install Barn
Barn is one command-line tool, barn, with a small companion binary for editing /etc/hosts. On Apple Silicon it also ships Barn.app, the native component that runs macOS guests. Install it as your normal user: Barn asks for sudo itself when a host setup step needs it.
Install Barn 1.5.0 with Homebrew or the installer, or choose an archive or package below. Run barn version to verify the installed version. Build from source
Install
Install with Homebrew. This also installs QEMU, which Linux guests need:
On Apple Silicon the formula also installs Barn.app, signed with Developer ID and notarized by Apple; the CLI finds it automatically. To run macOS guests, continue with barn mac doctor in the macOS guide. Intel Macs run Linux guests only.
The installer script picks the amd64 or arm64 archive, verifies its SHA-256 against the release’s checksums.txt, and installs into ~/.local/bin without sudo:
Add the export PATH=… line to ~/.bashrc or ~/.zshrc. The script works on macOS too if you prefer not to use Homebrew. It installs versioned copies under ~/.local/bin/.barn-releases/; leave that layout as it is.
There is nothing else to set up now. The first interactive barn up checks for QEMU, firmware, and the host network, shows what it will install, and asks once before doing it. For a script or CI job, prepare the host up front with barn setup --yes, or preview the changes with barn setup --dry-run (details).
System requirements
| Guest | Host | Needs |
|---|---|---|
| Linux | macOS on Apple Silicon or Intel | QEMU 8.2.1 or later (HVF acceleration) |
| Linux | Linux on amd64 or arm64 | QEMU 6.2 or later, a usable /dev/kvm, and NetworkManager or systemd-networkd |
| macOS 27 | Apple Silicon running macOS 27 or later, with a logged-in desktop session | Barn.app; no QEMU |
A Linux VM defaults to 1 vCPU, 2 GiB of memory, a 64 GiB root disk, and a 128 GiB data disk. Disks are thin-provisioned and grow only as the guest writes data.
A new macOS VM defaults to 4 vCPUs and 8 GiB of memory. Its disk inherits the prepared base’s capacity. The first base defaults to 100 GiB. Allow about 65 GiB of free space to download Apple’s macOS 27.2.1 restore image and install the base. Later VMs share the base’s disk blocks through APFS cloning. See macOS requirements.
Download Barn 1.5.0
Released on 2026-12-03. Pick your host operating system and CPU architecture:
| Host OS | Architecture | Archive | Debian / Ubuntu | RHEL / Fedora |
|---|---|---|---|---|
| macOS | Apple Silicon (arm64) | tar.gz | — | — |
| macOS | Intel (amd64) | tar.gz | — | — |
| Linux | x86-64 (amd64) | tar.gz | DEB | RPM |
| Linux | ARM64 (arm64) | tar.gz | DEB | RPM |
SHA-256 checksums · Detached signature · Release metadata · Installer script
Every archive and package has a matching .spdx.json software bill of materials on the GitHub release page.
| File | What it is | Shipped in |
|---|---|---|
barn | The CLI for Linux labs and macOS VMs | Every archive and package |
barn-hosts-helper | Companion that edits /etc/hosts for barn hosts install | Every archive and package, paired with its CLI |
Barn.app | Native runner and desktop window for macOS guests | The macOS arm64 archive and the Apple Silicon Homebrew install |
Other installation methods
Linux packages
The DEB and RPM packages pull in QEMU, UEFI firmware, and OpenSSH as dependencies. On ARM64 hosts, replace amd64 with arm64:
Manual archives
Download barn_1.5.0_<os>_<arch>.tar.gz and checksums.txt, and verify the digest before extracting:
Extract the archive and add its bin/ directory to PATH. Keep the files together: the CLI checks the helper’s embedded SHA-256 before running it, and looks for bin/Barn.app next to itself.
Build from source
To try unreleased changes or build Barn.app yourself, see Build from Source.
Upgrade Barn
In 1.5.0, the release owner signs checksums.txt. Use the public key from a trusted source to verify checksums.txt.sig before checking individual downloads. Verification command
When upgrading from 1.3.0 or earlier, update the CLI and check barn version before running barn update. Catalog 2026112601 uses a new Minisign key. Version 1.3.0 rejects that signature and keeps its previously active catalog.
Upgrade through the channel you installed with. With Homebrew:
On Linux, run install.sh again or install the newer DEB/RPM package, then check command -v barn and barn version. If you have both a ~/.local/bin copy and a packaged one, PATH decides which runs; upgrade that one or remove the other.
Upgrades keep everything under ~/.barn: VM disks, SSH keys, state, and configuration. Before upgrading on a Mac, stop running macOS VMs (barn mac stop NAME), because the CLI, helper, and Barn.app are replaced together.
Some releases change defaults. Check these before running barn up on an existing lab, and run barn plan to see the effect:
| Upgrading from | What changed | To keep the old behavior |
|---|---|---|
| 1.4.0 to 1.5.0 | New labs default to Debian 13. Existing labs retain their saved image default for new peers. | Use barn init -I u24 to start a new Ubuntu 24.04 lab. |
| 1.2.x | vm_image: rocky now means Rocky Linux 10 (el10) and vm_image: ubuntu means Ubuntu 26.04 (u26) | Set vm_image: el9 or vm_image: u24 |
| 1.1.x | New nodes default to 1 vCPU / 2 GiB instead of 2 vCPU / 4 GiB; existing VMs keep their size until you change it | Set vm_cpu: 2 and vm_mem: 4GiB |
Upgrading Barn never changes the OS inside existing VMs. Guest images update separately:
| To update | Run | Effect on existing VMs |
|---|---|---|
| Barn itself | brew upgrade, install.sh, or a newer package | None; disks and state are kept |
| The Linux image catalog | barn update (or barn update --mirror) | None; new and recreated nodes use the newer images |
| Cached Linux base images | Preview with barn image update --dry-run, then run barn image update | Existing nodes keep their backing images |
| The macOS base image | barn mac image update | None; apply it to a VM with barn mac recreate NAME --update |
The 1.5.0 release notes cover mirror upgrades and image defaults. For proxy or PATH issues, see Troubleshooting. To remove Barn, see Uninstall.
2 - Linux Quick Start
You will boot a Debian 13 VM, log in to it, then grow it into a four-node lab by editing one YAML file. Every command runs on your host as your normal user. For macOS guests, see macOS VMs.
Before you start
- Install Barn.
- Keep about 2 GiB of free memory per VM; each node defaults to 1 vCPU and 2 GiB.
- Use an interactive terminal. The first run prepares the host and asks once before changing anything;
sudomay then ask for your password. For CI and other unattended runs, see Automation. - In mainland China, add
--mirrorto the firstbarn upto download images fromrepo.pigsty.cc.
Start a VM
In 1.5.0, barn up selects Debian 13 for a new lab. With Barn 1.4.0, use barn up -I d13 on the first run to follow this tutorial.
On a fresh host, barn up first shows what it will set up and asks you to confirm. Only the rows that apply appear: dependencies (QEMU, UEFI firmware, OpenSSH), network (the lab subnet), config (the one-node barn.yml it writes here), and sudo (which of those steps need root). On a host that already has QEMU:
Barn then downloads and verifies the Debian image, boots the VM, and waits until SSH answers:
If 10.10.10.0/24 is already routed on your machine, Barn picks a free private /24 for this first lab instead; barn status shows the address it chose.
If barn up stops with an error, run barn doctor to check the host and barn logs meta to read the guest console, fix what they report, and run barn up again. It continues from where it stopped and leaves healthy VMs running. Troubleshooting covers the common cases.
Log in and look around
You are now user dba on meta, with key-based SSH and passwordless sudo. barn up also installed SSH aliases, so plain ssh meta works from any terminal. Type exit to return to the host.
From the host, list the lab and run commands inside a guest. Everything after -- runs in the VM:
The image version in the status output depends on your active catalog.
| What you just created | Value |
|---|---|
| Node and address | meta at 10.10.10.10 |
| Image | Debian 13 (d13), same CPU architecture as the host |
| CPU and memory | 1 vCPU, 2 GiB |
| Disks | 64 GiB root disk, 128 GiB data disk mounted at /data |
Both disks are thin-provisioned, so they take host space only as the guest writes data. Treat /data as test storage, not a home for files you care about: if barn up finds its filesystem corrupted while recovering a node, it reformats it. Storage and Access shows what each command keeps.
The lab’s state lives in ~/.barn, not in ~/barn-lab, so barn status, barn ssh, and barn stop work from any directory. Each user has one Linux lab at a time; barn up in another directory without an inventory resumes it rather than starting a second one (why).
Grow it into a four-node lab
Open ~/barn-lab/barn.yml, which the first run wrote, and add three hosts under nodes. Use addresses in the same /24 as meta:
Preview the change, then apply it:
barn plan reports create: node-1, node-2, node-3, and barn up creates the three VMs without restarting meta. All four nodes now reach each other at these addresses, which is what a database cluster or an Ansible playbook expects. At the default size, the lab uses 8 GiB of guest memory.
Every later change follows the same loop: edit barn.yml, run barn plan, then apply. The command that applies it depends on what changed, because barn up never replaces an existing VM’s disks:
Change in barn.yml | Apply with | Result |
|---|---|---|
| Add a node | barn up | Creates the new VM |
| CPU or memory | barn resize <node> | Same VM, same disks, new size |
| Image or disk layout | barn recreate <node> | New root and non-persistent data disks; persistent data disks are kept |
| Remove a node | barn destroy <node> | Deletes the VM; until then it stays on disk |
Pick the image, size, or subnet
The defaults suit a first run. To start from something else, generate barn.yml yourself in an empty directory before the first barn up:
| To get | Run |
|---|---|
| Two, three, or four nodes | barn init dual -I d13, barn init trio -I d13, or barn init full -I d13 |
| Another OS for every node | barn init -I el9 — see Images for the names |
| Another subnet | barn init -c 10.20.30.0/24 -I d13 |
| amd64 guests on an Apple Silicon Mac | barn init -A amd64 -I d13 — emulated, so slower |
The options combine, for example barn init full -I el9. barn init writes the result to barn.yml; edit it for anything else, such as the size of every node:
Check the file before booting anything:
validate and plan need neither QEMU nor the host network, so you can check an inventory on any machine. Linux Configuration lists every variable, and image and architecture settings explains how -I and -A interact with the file.
Stop, start, and clean up
barn destroy deletes the VMs with their root disks and non-persistent data disks, the deployment state, and the SSH aliases it installed. It keeps persistent data disks, the deployment’s SSH keys, downloaded images, and the host network, so running barn up in ~/barn-lab later rebuilds the lab from barn.yml without downloading again. To remove everything, see Uninstall.
Next steps
- Daily Operations — Restart nodes, read logs, and apply inventory changes safely.
- Storage and Access — Add persistent disks, copy files, and reach services in the guest.
- Images — Run Ubuntu, Rocky Linux, other Debian releases, or your own
qcow2. - Automation — Drive Barn from scripts, CI, or Pigsty.
3 - macOS Virtual Machines
Use barn mac when you need a clean macOS machine to build, test, or reproduce a macOS-specific bug, and want to throw it away afterwards. Each VM gets an administrator account with passwordless sudo, SSH with pinned keys, a desktop window, shared host folders, and clipboard sharing. VMs run under your own user account through Apple’s Virtualization framework, so nothing needs sudo.
Mac VMs are separate from the Linux lab: they don’t read barn.yml, their state lives in $BARN_HOME/mac (default ~/.barn/mac), and Linux barn destroy or barn purge never touches them.
Requirements
- An Apple Silicon Mac running macOS 27 or later, with a logged-in desktop session. Guests also run macOS 27.
- About 65 GiB of free disk space for the first VM: the IPSW download (23.8 GiB for macOS 27.2.1) plus 40 GiB that Barn requires for the restore. Each VM is an APFS clone of the base image and uses more space as the guest writes to disk. The first base defaults to 100 GiB of capacity.
Barn.app, the native app bundle that runs the VMs, from the same release as the CLI. Homebrew and the Apple Silicon release archive include it.
Apple’s Virtualization framework runs at most two macOS VMs at a time on one Mac, counting VMs from every virtualization tool and an in-progress base-image install. You can keep more stopped VMs on disk and start any two of them, subject to the Apple software license.
Install
Homebrew installs the signed, notarized Barn.app together with the matching CLI and helper; you don’t need Go or Xcode. The installer and manual archive include the app on Apple Silicon too. Stop running Mac VMs before upgrading or replacing the app.
To develop Barn itself, see Build the Mac component.
Create your first machine
On a Mac with no prepared base, Barn 1.4.0 selects macOS 27.2.1 (26B131) and asks before downloading it:
After you confirm, Barn:
- Downloads the restore image from Apple (
updates.cdn-apple.com), resuming any partial transfer and checking Apple’s published SHA-256. - Installs macOS once into an unbooted base image. The install uses one of the two VM slots while it runs.
- Clones
mac1from the base with APFS copy-on-write, boots it, creates your account, and waits until SSH and passwordlesssudowork.
Later VMs clone the same base in seconds. If an earlier release prepared this Mac, run barn mac image update to prepare 27.2.1 for new VMs; existing VMs keep their current base.
If you already have Apple’s restore image, pass it with --ipsw to skip the download. On the same APFS volume Barn clones the file instead of copying it:
In scripts, pass --yes to allow the download, or run barn mac setup beforehand to prepare the base without creating a VM. A new VM started with --no-wait returns as soon as its process runs; run barn mac up NAME without --no-wait to finish SSH and sudo setup before using ssh or exec.
Work in the machine
Shell and commands
The guest administrator account has your host username unless you set --user at creation. Put -- before the remote command. ssh passes a command string to the guest shell; exec runs the program with its arguments directly, so wrap pipelines and redirection in sh -c (see the SSH/exec contract). Both return the remote exit status, and --json captures stdout, stderr, and exit_code:
The full schema is in the Mac reference.
Desktop
barn mac open shows the guest desktop in a native window; the guest display follows the window size (View → Enter Full Screen for full screen). Closing the window leaves the VM running. Run barn mac open again to reopen it, or to boot a stopped VM and show its display.
While the guest window has focus, keyboard shortcuts go to the guest, so use the menu bar for host actions:
| Menu item | Action |
|---|---|
| Machine → Share Clipboard | Toggle plain-text clipboard sync for this session |
| Machine → Restart… | Restart macOS inside the guest |
| Machine → Shut Down… | Shut the guest down cleanly (same as barn mac stop) |
| Window → Keep Running in Background | Hide the window and keep the VM running |
| Barn → Quit Barn… | Choose whether to keep the VM running in the background or shut it down |
When you log out of or shut down the host, Barn asks the guest to shut down and powers it off if it misses the timeout.
Each VM has a random password for the lock screen and GUI administrator prompts. Copy it to the host clipboard without printing it:
Clipboard
Clipboard sharing moves plain text over the VM’s SSH channel, so the guest needs no extra agent. Focusing the guest window brings in text copied on the host; switching back to a host app brings out text copied in the guest. Password-manager items marked concealed, images, and files are never transferred.
To turn clipboard sharing off for a VM from its next start, run barn mac configure mac1 --clipboard off.
Shared folders
Pass --share when creating a VM to mount host directories in the guest under /Volumes/My Shared Files/<name>:
The share name defaults to the directory’s basename; append :ro for read-only. Each path must resolve to an existing directory (symlinks are fine), and Barn never creates or deletes the host directory. To change shares on an existing VM, stop it and use configure:
VirtioFS in macOS guests can briefly serve cached contents after a host-side edit. When a build needs the exact bytes immediately, copy files onto the guest disk with scp or rsync.
SSH from other tools
When the first Mac VM becomes ready, Barn adds a marked Include line to ~/.ssh/config, so ssh mac1, scp, rsync, and IDE Remote-SSH work with each VM’s own key and pinned host key:
If ~/.ssh/config is a symlink managed by a dotfile tool, Barn leaves it alone and prints the Include line for you to add. If your own config already has a Host alias with a VM’s name, Barn keeps yours and writes its entry by IP address only.
Multiple machines
VM names are lowercase letters and digits, start with a letter, and may contain inner hyphens. Creation flags (--cpu, --memory, --disk, --user, --share) apply when creating a VM. CPU and memory default to 4 vCPUs and 8 GiB. Without --disk, the VM inherits the default base’s capacity, or uses 100 GiB for the first base.
Without a name, commands act on the only VM, or on mac1; when several exist, Barn asks you to name one. A --disk size different from the prepared base’s capacity makes Barn install a new base at that size first.
Each VM gets its own private /24, starting at 10.10.20.0/24 with the guest at .10. Barn skips subnets that overlap your LAN, VPNs, the Linux lab, or other Mac VMs.
Everyday lifecycle
barn mac stop --force powers off at once; barn mac start --recovery boots macOS Recovery with the desktop window open.
barn mac up never changes an existing VM. Passing a different creation flag points you to configure:
Stop the VM before changing CPUs, memory, shared folders, or subnet (clipboard sharing can change while it runs):
barn mac recreate replaces the disk with a fresh clone of the base and keeps the name, account, hardware settings, shares, and IP. barn mac destroy deletes the VM. Both ask for typed confirmation on a terminal; pass --yes in scripts.
| Operation | Guest disk and installed apps | Hardware settings, IP, and account |
|---|---|---|
stop / start, restart, repeated up | Kept | Kept |
configure | Kept | Updated as requested |
recreate | Replaced with a fresh macOS clone | Kept; new login password and SSH keys |
destroy | Deleted | Deleted; the base image stays |
macOS versions and disk space
APFS clones share blocks with their base, so ON DISK and the per-VM disk figures overlap and don’t add up.
barn mac image update prepares the newest macOS 27 build Barn supports and makes it the default for new VMs. Existing VMs keep their disks and bases. To move a VM to the new base, back up its files and run barn mac recreate NAME --update. For a VM with a custom disk size such as 200G, first prepare a base of that size with barn mac setup --disk 200G.
barn mac image prune lists base images that no VM uses and aren’t the default; --installers adds downloaded .ipsw files, and --yes deletes them:
Clean up
Destroying the last Mac VM removes its ~/.ssh/config entries and keeps the default base image. To remove all Mac VM state:
- Destroy every Mac VM (
barn mac destroy ...) and runbarn mac ssh-config --remove. - Delete
$BARN_HOME/mac(default~/.barn/mac). - Optionally delete
~/Library/Preferences/com.pgsty.barn.plist(io.pgsty.barn.mac-runner.plistin0.9.0), which stores the desktop window geometry.
Troubleshooting
Start with barn mac doctor. It checks the host, Barn.app, base images, free space, and every VM, and exits 3 if any check fails. barn mac logs [name] shows startup, network, and Virtualization framework logs.
| Symptom | Fix |
|---|---|
dev and mac1 are running; macOS allows 2 macOS virtual machines at a time | Run the suggested barn mac stop NAME, or quit another tool’s macOS VM. See Requirements. |
preparing macOS needs … GiB free on this volume | Free space, or run barn mac image prune --installers --yes. |
… has a 200 GiB disk, but macOS … is prepared only at 100 GiB | Run the printed barn mac setup --disk 200G, then barn mac recreate NAME --update. |
network … overlaps route … on start | A VPN or new route now covers the VM’s subnet. Run barn mac configure NAME --subnet auto. |
ssh mac1 from another SSH client fails with No route to host | Allow your terminal or IDE in System Settings → Privacy & Security → Local Network, or use /usr/bin/ssh (barn mac ssh and exec use it). |
mac_runner_missing or mac_runner_protocol | The CLI and Barn.app come from different builds. Reinstall Barn so they match; for a source build, use the bin/mac/barn from one make mac-build. |
| Starting a VM fails from a remote SSH session | Run barn mac in a terminal on the Mac’s logged-in desktop session, with the login keychain unlocked. |
Every error reason and exit code is listed in the Mac reference.
Apple Account sign-in is unreliable in macOS guests under Apple’s Virtualization framework. USB passthrough, snapshots, and suspend/resume aren’t supported.
4 - Daily Operations
Once a lab is running, day-to-day work comes down to a few commands: check it, log in, stop it overnight, apply an inventory edit, and tear it down. This page covers them for the Linux lab; macOS VMs have their own lifecycle.
Inspect and access
These commands read the deployment stored in BARN_HOME (default ~/.barn), so they work from any directory; if you set BARN_HOME yourself, use an absolute path. barn status shows each node’s image and resources and flags software emulation (tcg); barn status --verbose adds guest architecture, accelerator, loopback SSH port, and QEMU PID.
Every barn up, including one for a subset of nodes, refreshes the ~/.ssh/barn_config aliases for the whole deployment, so ssh meta keeps working. Run barn ssh-config --install to refresh them at any other time.
Commands that read an inventory (plan, up, reload, resize, recreate) use -f, else the first of barn.yml, barn.yaml, pigsty.yml, pigsty.yaml in the current directory, else the applied specification (Discovery). Pass -f pigsty.yml when a directory has both barn.yml and pigsty.yml.
Running barn up again on a healthy lab is safe: it retries unfinished guest setup and updates guest helper scripts without restarting running VMs. Anything it could not set up is listed under nodes[].warnings, and anything it repaired, such as a reset data disk, under nodes[].repairs.
Stop and start
| Command | Reads the inventory | What it does |
|---|---|---|
stop | No | Stops running nodes |
start | No | Boots stopped nodes, re-checks running ones, and updates SSH aliases if a loopback port had to move |
restart | No | Stops and boots nodes with their applied definitions |
reload | Yes | Validates the inventory, stops the selected nodes, then runs up; can add new nodes |
Before stopping anything, reload refuses changes to an existing node’s definition (CPU, memory, image, disks, shares, addresses); apply those with resize or recreate.
--no-wait returns as soon as QEMU starts and skips readiness checks, guest recovery, the startup clock check, and /etc/hosts and control-node SSH updates until the next barn up.
Startup corrects guest clocks that drifted while the host slept. For a lab that keeps running, use barn time status, barn time sync, or the opt-in timer barn time auto enable (time reference).
Change the deployment
Editing the inventory never changes a VM on its own. barn plan shows what the edit means, and you apply it with the command the plan names:
| Plan reports | Meaning | Apply with |
|---|---|---|
create | Node is in the inventory but not provisioned yet | barn up |
resize | Node CPU or memory changed | barn resize <node> |
recreate | Node image, disks, shares, or other VM definition changed | barn recreate <node> |
missing | Provisioned node is no longer in the inventory | Restore the YAML entry, or barn destroy <node> |
With --json, start, create, resize, recreate, and missing are node lists, and action summarizes the plan as create, start, converge, resize, recreate, blocked-removal, repair, or none. blocked, when present, is a string explaining what blocks the plan, and whole_deployment: true means every node has to be recreated together; run the command the plan suggests so new nodes are included. Pigsty service variables that Barn does not read produce action: none. The full schema is in Planning.
Resize CPU, memory, or the root disk
Edit vm_cpu or vm_mem and run barn resize. Increases are hot-plugged where the backend supports it; decreases and other backends stop and start the VM, keeping its identity and disks. barn resize -D grows the root disk in place (root growth).
If an online resize is interrupted after hot-plugging, barn status reports reason: resize_incomplete. Run barn resize NODE again to finish, or barn restart NODE to return to the committed resources.
Recreate a node
recreate is the explicit way to replace a VM. Barn first validates the new image, network, shares, and persistent-disk layout, then destroys the selected VMs and boots fresh ones from the inventory. Root disks and non-persistent data disks are replaced, compatible persistent disks are reattached (what survives), and each new VM gets a new identity and refreshed SSH host-key state.
On a terminal, recreate and destroy list the affected nodes and ask you to type the command name; scripts pass --yes (or --force).
Without node names, recreate replaces every node. If the inventory no longer lists an existing node, it stops before touching any VM (exit 4, reason: nodes_removed): run barn destroy <node> or add the node back.
Apply changes to selected nodes
You can edit several nodes and roll the changes out one at a time:
With explicit node names, plan, up, reload, recreate, and resize keep every unselected node’s applied definition, even if its YAML entry was edited or removed, and do not resolve images for unselected nodes that do not exist yet. The whole inventory must still parse, and the selected changes must not conflict with applied addresses, aliases, control-node roles, or deployment-wide settings.
Without node names, Barn evaluates the whole inventory: CPU and memory changes need resize, other changes to existing VMs need recreate, and missing nodes need their entry restored or an explicit destroy.
Concurrent commands
Within one command, --parallel/-p sets how many nodes are handled at once (default max(1, logical CPUs - 2); see lifecycle concurrency).
Commands that change the deployment (up, start, stop, restart, reload, resize, recreate, destroy, purge, provision) take a lock in BARN_HOME, so only one runs at a time. Another waits up to 10 minutes (or its shorter provision --timeout), showing the holder’s command, PID, and start time, then exits 4 with reason: deployment_busy. The lock is released when its process exits; never delete lock files by hand.
Read-only and access commands (status, ssh, exec, ssh-config, hosts) don’t wait. barn status shows the last committed state, with a note naming any operation in progress. For a command that was killed midway, see Troubleshooting.
Destroy
barn purge and barn destroy --yes --purge immediately power off running Linux VMs before deleting their disks. Run barn stop first to give databases and other guest services time to shut down.
Pick the scope to remove:
barn destroy <node>removes one node and refreshes SSH aliases for the rest. If it removes the control node, the first remaining node takes over, sossh-config,hosts,exec, andprovisionkeep working. Setadmin_ipin the inventory to the new control node (and delete the old entry unless you wantupto recreate it), then runbarn upto install its control SSH access.barn destroyremoves every VM with its root disk and non-persistent data disks, plus the deployment state and Barn’s SSH aliases. It keeps persistent disks, deployment keys, cached images, and the host network, sobarn uprebuilds the lab from the inventory.barn destroy --delete-persistentalso deletes persistent disks;--purgealso deletes keys and deployment state. Both apply to the whole deployment only.barn purgedeletes the whole lab, persistent disks, keys, and deployment state immediately, keeping the image cache and host network.barn purge --askshows the nodes and scope first and acceptsy/yes;n/no, an empty line, or EOF cancels.purgeaccepts no--yes,-y, or--force.
Each command’s effect on data disks is summarized in What survives each operation. Once no Linux VM remains, you can remove the host network:
To clear cached images, see Image Repositories; to remove Barn completely, see Uninstall.
5 - Storage, Files, and Service Access
Each Linux node has a disposable root disk and separate data disks. The root disk is a copy-on-write layer over the base image, and recreate replaces it whenever the image or node definition changes. Data disks keep test data on their own devices, so the system can be rebuilt underneath them; with persistent: true, a data disk also survives recreate and destroy. This page covers disk layout and retention, then file transfer and service access, using the meta node at 10.10.10.10 from the Linux Quick Start.
Configure disks before creating the VM
By default each node gets a 64 GiB root disk and one 128 GiB non-persistent data disk mounted at /data. vm_disk sets the root size in GiB (64 or 64GiB); vm_disks replaces the whole data-disk list, and vm_disks: [] creates no data disks.
This single-node inventory keeps /data across rebuilds and adds a throwaway /scratch:
Create the VM and check the mounts:
Sizes (size: 64 or size: 64GiB) are thin-provisioned: the host file grows only as the guest writes. With fs: auto, Barn formats a new disk as XFS when the guest has mkfs.xfs and as ext4 otherwise. If findmnt shows nothing, the reason is in the barn up warnings.
If meta already exists with a different disk layout, barn up reports drift instead of changing it. Check barn plan, copy out anything you need, then run barn recreate meta, which replaces the root disk and non-persistent data disks.
What survives each operation
| Operation | Root and non-persistent data disks | Persistent data disks (persistent: true) |
|---|---|---|
stop then start, restart, or reload | Kept | Kept |
resize, including root growth | Kept | Kept |
Repeated up on a healthy node | Kept | Kept |
recreate | Replaced | Kept and reattached |
destroy (one node or the whole lab) | Deleted | Kept |
destroy --delete-persistent, destroy --purge, or purge | Deleted | Deleted, including disks kept from earlier destroys |
Newly formatted data filesystems are owned by root. To see /data survive a stop and start:
Reattach a persistent disk
Barn matches a kept disk to its node by name and disk definition. To reattach it after recreate or destroy, keep the node name, mount path, size, and fs unchanged; fs: auto matches whichever filesystem the disk already has. A mismatched definition is refused rather than resized, renamed, or converted.
Removing a persistent disk from a node’s definition takes a whole-lab teardown: recreate refuses an inventory that drops an attached persistent disk, so run barn destroy --delete-persistent --yes or barn purge first. Disks kept from a node you removed stay on the host until one of those commands deletes them.
When Barn resets a data disk
Data disks are test storage, persistent: true included. Barn reformats a data disk when it finds the filesystem damaged. Keep anything valuable on the host.
Barn checks data disks when a VM first boots and whenever barn up (or reload, which runs it) finds a guest whose data disks are not mounted cleanly. --no-wait postpones the check to the next barn up.
| What Barn finds | What it does | Reported in |
|---|---|---|
| A blank disk with no signature | Formats it with fs | nodes[].repairs, unless this is the disk’s first format |
| A healthy ext4 or XFS filesystem | Mounts it unchanged | — |
An ext4 or XFS filesystem that will not mount, where e2fsck -fn or xfs_repair -n reports recognized corruption | Reformats it, erasing its contents | nodes[].repairs |
| A partition table, a signature without a filesystem UUID, another filesystem type, features the guest tools do not support, or a checker failure Barn does not recognize | Leaves the data alone | nodes[].warnings |
| A missing device, failed probe, busy mount, read-only device, or host I/O error | Leaves the data alone | nodes[].warnings |
Root disks and host shares are never formatted. After fixing the cause of a warning, run barn up again to mount the disk. barn up exits 0 in all of these cases, so scripts should check repairs and warnings.
Copy files over managed SSH
Export an OpenSSH configuration to use ssh, scp, or rsync directly:
The file points at the current loopback SSH port, the deployment key path, and a per-instance known_hosts; it does not contain the key itself. Export it again after you recreate a node or its loopback port changes, or run barn ssh-config --install so plain ssh meta and scp work without -F.
Reach services inside the guest
A service listening on the node’s fixed IP, such as PostgreSQL on 10.10.10.10:5432, is reachable from the host and from other nodes at that address, as long as the guest firewall allows it.
For a service bound to 127.0.0.1 inside the guest, forward a host port over SSH and connect host clients to 127.0.0.1:15432; Ctrl-C closes the tunnel:
Management SSH uses its own loopback port, so barn ssh and -L tunnels work even when the fixed-IP network reports a limitation. The inventory has no vm_ports or vm_forwards setting; use the fixed IP or a tunnel.
SSH aliases such as ssh meta only help OpenSSH tools. For browsers, psql, and other host programs to resolve node names and vm_alias entries, preview and then apply the /etc/hosts integration:
barn hosts install --yes edits the host’s /etc/hosts, using sudo when needed. Run it again after adding nodes or changing addresses.
Share a host directory
To edit code on the host and build it in the guest, mount a host directory with Virtio-9p (Linux and macOS hosts). Set vm_shares under all.vars or on a host before the first barn up:
host may be relative to the inventory’s real location, start with ~/, or be a directory symlink. The directory must exist, be accessible to you, and not overlap BARN_HOME; you don’t need to own it. Several guests may write the same tree; coordinating those writes is up to you.
Host QEMU and the guest kernel must support 9p. If the guest user cannot write a writable share, Barn mounts it read-only with a warning and leaves host ownership alone. Changing shares on an existing node needs barn recreate <node>. The full schema is in Shares; macOS guests share folders with VirtioFS instead (see macOS shared folders).
6 - Image Repositories
On first use of an official Linux image, Barn downloads the selected base image and verifies it against the signed catalog. New labs in 1.5.0 use d13:stable (Debian 13) for your host architecture. On Barn 1.4.0, use barn init -I d13 to start with Debian 13. Use this page to pick another distribution, download from the China mirror, bring your own qcow2, host a repository, or reclaim disk space.
Choose an image
| Family | Distribution | Short aliases | Notes |
|---|---|---|---|
d13 | Debian 13 | d, debian, trixie | Default for new labs in 1.5.0 |
d12 | Debian 12 | bookworm | |
u24 | Ubuntu 24.04 LTS | noble | |
u26 | Ubuntu 26.04 LTS | u, ubuntu, resolute | |
u22 | Ubuntu 22.04 LTS | jammy | deprecated |
el10 | Rocky Linux 10 | e, el, rocky | |
el9 | Rocky Linux 9 | rocky9 | |
el8 | Rocky Linux 8 | rocky8 | deprecated; arm64 runs under TCG on Apple Silicon |
el7 | CentOS Linux 7.9 | c7, centos7 | deprecated (EOL); amd64 only, native linux/amd64 hosts only |
Append a to a family name (or to e, el, d, u) for arm64, or x/i for amd64: d13x, el10a, da. Deprecated images still boot and print a status warning. If you upgraded from Barn 1.2.0, note that rocky and ubuntu now point to el10 and u26; see Upgrade Barn. The full alias list is in the image reference.
Set the image for the whole lab in the inventory:
A bare family such as el9 follows its stable channel; name:channel picks another channel, and name@full-version pins one build (a shorter numeric prefix can match several versions). vm_version is a numeric prefix matched on dot boundaries: "9.9" selects the newest 9.9.x build in the active catalog, "9" the newest 9.x. Quote it so YAML keeps it a string, and don’t combine it with a :channel or @version suffix.
To get the same build after future catalog updates, pin the full version that barn image info reports:
After changing vm_image or vm_version, run barn plan. Existing nodes keep their root disk until you run barn recreate <node>. barn update fetches, verifies, and activates the newest catalog; it changes only what new or recreated nodes get.
To refresh cached images, preview the downloads with barn image update --dry-run and then run barn image update. An empty cache refreshes only the catalog. Use barn image update d13i d13a for a first download of both Debian 13 architectures.
Override image or architecture for one command
-I (--image) and -A (--arch) override the inventory for one command and leave the file as it is. Guests use the host architecture unless vm_arch or -A says otherwise, and -A native follows the host again. An architecture-suffixed alias such as -I d13x selects the family and architecture together. With such an alias, an explicit -A or BARN_ARCH must name the matching architecture. A different architecture or native fails validation.
To keep an override, set vm_image and all.vars.vm_arch in the inventory (removing a superseded vm_version), or generate a new inventory with barn init -I d13 -A amd64 or barn init -I d13x. Existing nodes need recreate to change image or architecture, and an architecture change must include every existing node. Precedence rules and architecture spellings are in Image and architecture overrides.
For a bare alias, standalone barn image info and barn image pull default to the host architecture. Use an architecture-suffixed alias or pass -A to select another. These commands ignore both vm_arch and BARN_ARCH. If the image has no build for that architecture, the command fails. Barn runs only amd64 and arm64 guests. A guest whose architecture differs from the host runs under TCG emulation; on Linux, install the emulator first (see HVF, KVM, or an emulator is unavailable).
Download from the China mirror
Release builds download from https://repo.pigsty.io/barn. Add --mirror to use the China mirror, https://repo.pigsty.cc/barn:
Downloads from either official repository retry transient errors, resume partial transfers, and switch to the other official repository if an artifact is unreachable.
To use your own repository, pass --repo with a URL or local directory, or export BARN_REPO for the shell session:
The precedence is --repo → --mirror → BARN_REPO → https://repo.pigsty.io/barn. A custom --repo downloads only from that root, with no fallback. Barn reads a built local directory’s catalog.json on first use. For a custom HTTPS server, activate its catalog with barn update --repo <url> first. Use the same --repo for later commands.
The official repositories and any plain http:// repository must serve a valid ML-DSA-87 signature (catalog.json.sig); a local directory or custom https:// endpoint may serve an unsigned catalog.json. Either way, each download must match the catalog’s byte size and SHA-256 and pass qemu-img checks; see Trust and verification.
Import a local qcow2
To use one custom image without running a repository, import it under a local- alias and set vm_image: local-mybase in the inventory:
--name(must start withlocal-),--boot(uefiorbios), and--source-usergo together. Without them, Barn caches the verifiedqcow2by content digest but creates no alias.- The image must already include cloud-init, which Barn uses for first-boot provisioning.
local-*aliases are immutable. Register a new name each time you rebuild the image.- The recorded architecture defaults to the host.
-A(which requires--name) records a different one, for examplebarn image import /path/to/debian-13-generic-arm64.qcow2 --name local-arm64 --boot uefi --source-user debian -A arm64. Barn records the declaration without converting the image or detecting its guest CPU, so set the inventory’svm_archor the command’s-Ato match.
See Prune the cache to check which images Barn can reclaim.
Build a static repository
A repository lets several hosts or a team share the same images, or work offline. It is a plain directory that you can serve over HTTP or HTTPS, copy with rsync, or read from a local path:
/srv/barn
- barn/
- repo.yamlOptional metadata
- catalog.jsonGenerated catalog with SHA-256 and file sizes
- catalog.json.sigRequired for official and plain HTTP repositories
- images/
- d13-1-arm64.qcow2Verified cloud-init qcow2 base image
With images/d13-1-arm64.qcow2 in place, run barn repo build /srv/barn and barn repo verify /srv/barn. Use the directory immediately with barn image info d13 --repo /srv/barn. To specify the upstream login user and mark the image as testing, add this optional file before building:
Put the cloud-init-capable image at /srv/barn/images/d13-1-arm64.qcow2 (relative roots, directory symlinks, and shared writable directories all work). Then, on a host with qemu-img, generate and check the catalog:
barn repo scan inspects the layout. barn repo build checks the image files and records their SHA-256, size and virtual capacity. If you set revision in repo.yaml, increase it when the contents change. Publish the images before the catalog and its signatures. Signing an official mirror
To cache the local catalog and test a download, run the following commands.
Pass --repo /srv/barn (or export BARN_REPO=/srv/barn) to plan, up, and recreate, and set vm_image: d13@1 in the inventory. To switch /srv/barn back to the binary’s built-in catalog while keeping its anti-rollback high-water mark, run barn image reset --repo /srv/barn. The file formats are in Static repository format.
Prune the cache
barn image prune reclaims disk space from cached images that nothing references and from interrupted download staging files. Preview first, then delete:
Pruning needs qemu-img. It keeps every image in the selected repository’s active catalog, every base image used by a node in BARN_HOME, and every registered local-* alias. Use the same --repo for the preview and the deletion. Details are in Pruning; to build new base images from upstream cloud releases, see Image Pipeline.
7 - Automation and Guest Scripts
Barn commands print JSON with --json and return documented exit codes, so CI jobs and AI agents can drive a lab without a terminal. This page starts with a complete unattended run, then covers what a script needs to check and how to run commands inside guests. Run every command as the Unix user who owns the deployment, with the same BARN_HOME and -f <inventory> each time.
Run a lab end to end
Run this example under a dedicated CI account with one lab job at a time on the host. BARN_HOME isolates VM state. Jobs on the same host share the lab network, and jobs under the same account share its SSH aliases.
barn setup --yesaccepts the host-preparation plan without asking. It needssudothat works without a password prompt (cached credentials or aNOPASSWDrule); what it installs is described inbarn setup.barn upexits non-zero when a node fails. Barn verifies each ready marker over management SSH. Optional guest warnings can accompany a successful run, so the example checks command-levelwarningsas well as each node’swarningsandrepairs.barn execandbarn provisionrun commands and scripts in the guests; see below.barn purgedeletes the deployment in thisBARN_HOME, persistent disks and keys included, without asking. The image cache stays, so the next run does not download again. Usebarn destroy --yesinstead to keep persistent disks.
Prepare a predictable lab
Commit the inventory and pin vm_image to an exact version, such as vm_image: d13@20261123.2671.1; a channel like d13:stable can move to a new image after barn update. Always pass -f; it also stops first-run setup from moving an unedited generated template to a different subnet. With a custom image repository, run barn update --repo URL first and pass the same --repo to setup and up.
To write and check an inventory, then preview the host changes:
barn init [template] --image <reference> writes all.vars.vm_image, so every node uses the same image; the reference can be an alias (el9), a channel (d13:stable), or a version (d13@20261123.2671.1). barn init full -I d13 -A amd64 saves both image and architecture. barn setup [template] --image works the same way, but only when it generates the template.
On validate, plan, up, reload, recreate, and resize, --image/-I, --arch/-A, --cpu/-C, --mem/-M, --scale/-S, and --disk/-D override the inventory for one invocation. Values come from the flag, then a nonempty BARN_* variable, then the inventory, then the default, so give plan and the command that applies it the same flags and environment: barn plan -f barn.yml -I d13 -A arm64 --json, then barn up -f barn.yml -I d13 -A arm64. Existing VMs need recreate to change image or architecture (Image and architecture).
Without a terminal, up, start, restart, and reload never prepare the host themselves; they report what is missing and fail. Run barn setup --yes before them.
Validate JSON output alongside the exit code
Barn writes JSON or YAML results to stdout and diagnostics to stderr. With the default wait, barn up checks each selected node’s readiness marker over management SSH. It can exit 0 even if an optional stage such as a secondary data disk, a Virtio-9p share, or peer SSH configuration reported a limitation (nodes[].warnings), or Barn reformatted a damaged test disk (nodes[].repairs). A script that needs a fully working lab checks both:
Don’t pass --no-wait when a later step needs ready guests. barn status --json reports the recorded state without probing guest SSH again.
Exit codes and command-specific payloads
The full table and the JSON failure object are in Exit codes and Structured failures. The codes scripts most often branch on:
| Exit | error | Typical cause in automation |
|---|---|---|
2 | usage | Missing inventory on first run, invalid flags, unknown image alias, or destroy/recreate without --yes when stdin is not a terminal |
4 | conflict | Drift that needs an explicit command (reason: recreate_required or nodes_removed), state changed during a recreate preflight (deployment_changed), or another command held the deployment lock for 10 minutes (deployment_busy) |
5 | partial | Some nodes of a multi-node up or provision failed; read nodes[] or results[] before retrying |
7 | integrity | A digest, signature, or identity check failed, including reason: catalog_signature or catalog_equivocation |
A few commands report success differently:
barn doctor --jsonexits0when host compute checks pass, even if aclass: networkcheck reports an error. Readchecks[]andbarn network status --jsonbefore relying on the fixed-IP network.barn sshandbarn execexit with the remote command’s status (255can also mean an OpenSSH transport failure); with--jsonthey returnsuccess,exit_code,stdout, andstderr.barn networkandbarn hostsinstall/uninstallonly print their plan and exit0when--yesis missing and stdin is not a terminal or output is--json/--yaml. Pass--yes, or checkappliedin the result.
Run single commands or batch scripts
Put -- between the node and the remote command, and Barn flags such as --json before it:
barn exec passes the program and each argument separately, so use sh -c for pipes, redirection, or variables (Remote commands).
For anything longer, write a local Bash script (a regular file, or a symlink to one, up to 4 MiB):
Run it on selected nodes, or on every node when you name none; all targets must be running:
Barn streams the script to Bash over SSH, so no copy is left in the guest, and records its SHA-256 in the event log and in the result (script.sha256).
| Option or limit | Behavior |
|---|---|
--parallel | Positive integer; default 1 (serial). Workers never exceed the number of selected nodes |
--timeout | Deadline for the whole operation; default 1h, any positive duration |
--sudo | Runs the script through non-interactive sudo -n |
| Output | Up to 1 MiB each of stdout and stderr per node; stdout_truncated / stderr_truncated mark a cut |
| Exit code | 5 when some nodes succeed and others fail; a single target’s own positive exit code other than 255; 1 otherwise |
A failed run does not undo what already ran in the guests, so write scripts that are safe to run again.
Pair the lab with Pigsty
Barn reads the same Ansible inventory that Pigsty uses, so the VMs come up with the names and fixed IPs Pigsty expects to deploy to. Let Pigsty write the inventory, then create the VMs from it:
barn up creates the admin account in every guest and gives the control node at admin_ip the deployment key and an SSH configuration that reaches every peer on its fixed IP, which is what Ansible needs (Security and Trust). barn ssh logs in to that control node; run Pigsty’s playbooks from there.
8 - Use Barn with an AI Agent
Barn publishes an agent skill, Barn VMs (barn): one Markdown file that teaches a coding agent to create, use, change, and clean up Barn VMs. It gives the agent Barn’s mental model, an index of this documentation, starting points for common scenarios (one Debian machine, a multi-node lab, a Pigsty sandbox, replacing Vagrant, distribution matrices, CI, macOS VMs), and the boundaries it must respect. For command details, it sends the agent back to these pages.
Start with a prompt
Paste this prompt into the agent and replace the brackets with your requirements:
The last line carries the task, for example:
What I need: one VM to test the install script in ~/src/app.What I need: a four-node Pigsty sandbox from the full template in ~/pigsty.What I need: replace the Vagrantfile in this repository with a barn.yml that keeps the node names and IPs.What I need: a macOS VM named build with 8 CPUs and 16 GiB of memory, sharing ~/src.
Install the skill
To load the skill in every session, save it to the agent’s skill directory and start a new session:
Agents without a skill directory read the URL directly. Use skill.zh.md for the Chinese edition. Download the file again to update it; its header names the Barn version it matches.
What the agent asks first
Most Barn commands run as your user without prompts. The skill tells the agent to ask before it:
- changes an existing Linux lab, because each user has one deployment;
- prepares the host with
barn setup --yes, which installs packages, creates the private network, and usessudo; whensudoneeds a password, the agent gives you the command to run; - downloads a macOS restore image of about 24 GiB;
- runs
destroy,recreate, orpurge, or deletes VM disks in any other way.
When it finishes, the agent reports the nodes it created, how to connect, any warnings from barn up, the changes it made to the host, and how to stop or remove the VMs.
9 - Troubleshooting
Linux lab problems in the order you are likely to hit them. Each entry gives the Symptom, a Check to confirm it, and the Fix. For macOS VMs, see macOS troubleshooting.
Run barn doctor first
barn doctor probes the host without changing it: platform, QEMU and qemu-img, required QEMU devices, a short HVF or KVM boot, UEFI firmware, /dev/kvm on Linux, the OpenSSH client, deployment state and free space under BARN_HOME, and the host network. Each problem prints a detail: line and, when Barn knows one, a fix: line.
A failed compute check exits 3. Network problems show as blocked without changing the exit code, so read barn network status too. barn status also reconciles interrupted VM state when no other command holds the lock. Add --json to any of the three for scripts and bug reports.
Install fails or barn is not found
Symptom: The installer can’t reach GitHub, or after installing, the shell says barn: command not found or barn version shows an older release.
Check:
Fix:
Download fails: the installer downloads from GitHub Releases (
--mirrorchanges only the guest image repository). If you need a proxy, exportHTTPS_PROXYorALL_PROXYin the shell; CLI tools don’t pick up proxies from macOS System Settings.Not found or old version: the user-scoped installer puts binaries in
~/.local/bin. Add it toPATHand run the check again:With two installs (for example
~/.local/binand Homebrew), update the onePATHselects; see Upgrade Barn.Keep
barnandbarn-hosts-helperfrom the same release, in their packaged directory layout.
barn up finds no inventory
Symptom: plan, up, or validate fails with no inventory found in this directory (exit 2, reason: no_inventory), or barn status reports no deployment state found.
Check:
Fix: Run the command where the inventory is, pass -f /path/to/file, or create one with barn init. In a terminal, barn up writes a starter barn.yml itself; without one, run barn setup --yes and then barn up.
Without -f, plan, up, reload, resize, and recreate look for barn.yml, barn.yaml, pigsty.yml, and pigsty.yaml, in that order, and fall back to the applied inventory in BARN_HOME only when none exists. A syntax error in the first match stops the command; pass -f pigsty.yml when an old barn.yml sits beside it. no deployment state found means the active BARN_HOME is new or was purged. See Discovery.
First barn up or barn setup stops at sudo
Symptom: The first barn up or barn setup asks for your password, or fails with sudo needs a password, but stdin is not a terminal (exit 3, reason: sudo_unavailable).
Check: Preview the host changes without applying them:
Fix: Run the command in a terminal. Barn prints the exact host change, then hands the terminal to sudo; one password covers the whole command. --yes accepts Barn’s plan but can’t answer sudo, so automation needs cached sudo credentials or a NOPASSWD sudoers rule. On macOS, barn setup downloads and verifies the pinned socket_vmnet package before asking for sudo, so a failed download never prompts. All setup options are in barn setup.
barn init won’t write through a symlink
Symptom: barn init --force reports will not overwrite …: it is a symlink.
Check:
Fix: Barn never writes through an output-file symlink. Pass the link’s target instead:
Directory symlinks are fine, and barn init -o ./lab/config/barn.yml creates missing parent directories.
HVF, KVM, or an emulator is unavailable
Symptom: barn doctor reports an error for hvf-real-smoke or kvm-real-smoke, accelerator, kvm, qemu, or firmware; or a foreign-architecture guest fails with QEMU is not installed (… not found in PATH) (exit 3, reason: qemu_missing).
Check:
Fix:
- KVM on Linux: enable KVM and give your user read/write access to
/dev/kvm. - QEMU or firmware missing: run
barn setupto install the host packages. - Foreign architecture on Linux:
barn setupinstalls only the host-native emulator. Install the matchingqemu-system-*binary and UEFI firmware before running a guest with a differentvm_arch. Homebrew’sqemuon macOS includes both thearm64andamd64emulators.
Barn runs native guests only with HVF (macOS) or KVM (Linux) and never falls back to TCG software emulation when they fail. TCG is used only for a foreign vm_arch or a built-in compatibility rule such as el8 arm64 on Apple Silicon; see Runtime policy.
Host network is stopped, partial, or invalid
Symptom: barn doctor shows network-* checks as blocked and warns the Barn network is not ready; run barn setup to prepare it, or barn network status reports partial or invalid.
Check:
Fix:
Stopped but intact: in a terminal,
barn upadds the restart to its host plan and asks once. Without a terminal, runbarn setup --yes.partialorinvalid: let Barn remove what it owns instead of deleting system network files by hand. Stop the deployment first; uninstall refuses while any node is running. Then prepare the network again:Linux bridge test failed during setup: Barn rolls the network changes back automatically. Clean up by hand only when it reports
automatic rollback failed.macOS
/var/log/barn-vmnet:barn setupfixes a missing or too-restrictive directory (root:wheel 0755) but won’t touch a symlink, a directory with a foreign owner, or a group- or world-writable one. Run the exact commandbarn network statusprints.
Linux bridge helper is not usable
Symptom: barn doctor flags bridge-helper, for example … is not yet usable by this user or … the invoking user is not in group ….
Check:
Fix:
- Debian and Ubuntu: the helper should be
root:<group> 4750, with a group your user belongs to.barn setupsets this throughdpkg-statoverride, andbarn network uninstallrestores the original. If another user installed the Barn network, uninstall it as that user, then runbarn setupas yourself. - RPM-family hosts: the packaged mode is
4755and Barn doesn’t change it. If the mode differs, reinstall the distribution’s QEMU packages.
A node did not become ready
Symptom: barn up exits 5 with N of M node(s) failed: <node> (<stage>: <error>), or it exits 0 but lists warnings under nodes[].warnings.
Check:
Fix: Barn reads /var/lib/barn/ready.json over management SSH. The node name, generation, and configuration hash (spec_hash) must match the host’s expected values. Fix the cause the logs show, then run barn up again. It retries only the unfinished stages and doesn’t restart healthy VMs. Add --rollback to remove the artifacts of a failed first preparation in the same run.
Optional guest setup stages record warnings. When all selected nodes pass readiness, barn up can exit 0 with these warnings.
| Warning | Fix |
|---|---|
| Data disk unavailable | Fix the missing device, missing filesystem tool, busy mount, or host I/O error, then run barn up. A disk with a partition table, a signature without a UUID, or unsupported filesystem features keeps its data and stays unmounted; see what survives each operation. |
| Shared directory is read-only | Check write permissions on the host and in the guest, then run barn up. |
| Guest hosts or control-node SSH incomplete | Run barn up to rewrite the managed files in the guest. |
| Private interface unavailable | Check barn network status, repair the host bridge or vmnet, then run barn up. |
Linux shared folders need 9p support in both QEMU and the guest kernel, on macOS and Linux hosts alike. If the guest kernel lacks 9p, copy files with SSH, scp, or rsync instead.
SSH to a node fails
Symptom: ssh meta or barn ssh meta fails, or barn up reports a control-ssh warning.
Check:
Fix:
| What you see | Fix |
|---|---|
barn ssh meta works but ssh meta doesn’t | ~/.ssh/config is a symlink or hard link, so Barn wrote ~/.ssh/barn_config and printed an Include line instead. Add that line to your config. |
| The deployment’s private SSH key is missing | Restore it from a backup. Barn never generates a replacement key for existing VMs. A missing .pub file is rebuilt from the private key automatically. |
control-ssh warning | The control node’s copy of the private key is missing; host-to-guest SSH still works. Run barn up to restore it. |
| A remote command is parsed as Barn flags | Put -- between the node name and the command: barn exec meta -- hostname. See Remote commands. |
Two cases need no action: if another process takes a stopped VM’s loopback SSH port, the next barn start or barn up picks a free port and updates ~/.ssh/barn_config; and host keys are pinned per VM instance UUID, so a recreated node causes no stale known_hosts error.
barn plan says recreate or missing
Symptom: barn plan or barn up lists a node as recreate or missing, or barn recreate fails with exit 4 and reason: nodes_removed.
Check:
Fix:
recreate: the node’s definition changed in a way that needs a new root disk. Afterbarn update, this also happens to nodes whose image channel or version prefix now resolves to a newer build. Back up data on the root disk and any non-persistent data disks (what survives), then runbarn recreate <node>(--yesin scripts).missing: a node with a VM was removed from the inventory. Restore its entry, or delete the VM withbarn destroy <node>. While any node is missing,barn recreatewithout node names stops before touching any VM.
To rebuild one node, name it: barn plan node-1 and barn recreate node-1 keep the applied definitions of unselected peers, so their unrelated edits can wait. Conflicts in addresses, aliases, control-node roles, or deployment-wide settings must still be resolved. See Apply changes to selected nodes.
Catalog or image verification fails
Symptom: barn update, barn image pull, or barn up exits 7 (error: integrity) with reason: catalog_signature or catalog_equivocation, or an image fails its size, SHA-256, or qcow2 check.
Check:
Fix: Barn rejects unknown signers, catalog revision rollbacks, size or SHA-256 mismatches, and malformed qcow2 files. Pull from a validly signed repository, such as the default or --mirror. Register your own images with barn image import --sha256 ... rather than copying files into ~/.barn/images. A permission or I/O error while reading a cached signature exits 1 (runtime), not 7; fix the file’s permissions and retry. Trust rules are in Trust and verification.
A command was interrupted
Symptom: Ctrl-C or SIGTERM stopped a command, which exits 130 (cancelled), or the host rebooted in the middle of an operation.
Check:
If another Barn process holds the deployment lock, status shows a note; wait for that command to finish. Otherwise status checks each recorded QEMU process by PID and start time and repairs the state.
Fix:
| Interrupted state | What barn status does / what to run |
|---|---|
| Host rebooted, or an unrelated process reused the QEMU PID | Marks the VM stopped; run barn start |
barn stop was interrupted while QEMU kept running | Restores running; run barn stop again if you still want it stopped |
Online barn resize was interrupted after changing the live guest | Reports resize_incomplete; run barn resize <node> again or barn restart <node> |
First barn up failed during preparation | Fix the inventory and run barn up -f barn.yml; Barn rolls back the journaled unfinished artifacts |
barn destroy was interrupted | Run the same barn destroy or barn purge again to finish |
When cancelled, Barn sends SIGTERM to the processes it started (sudo forwards it to privileged commands) and waits at most 10 seconds. A descendant that ignores SIGTERM keeps running until you stop it.
If Barn can’t confirm that a recorded process belongs to the node, or QEMU is alive but its QMP socket is gone, it refuses further changes rather than risk killing an unrelated process. Keep the state directory and the logs (barn logs <node> --source qemu --verbose); don’t delete PID or lock files by hand.
Report a bug
Include the exact command and its exit code, barn version, the host OS and architecture, the QEMU version, and the JSON output of barn doctor, barn network status, and barn status.
10 - Build from Source
Build Barn yourself to try changes on main before they are released, or to rebuild a release from its tag. To simply use Barn, install a release instead: it needs neither Go nor Xcode, and the Apple Silicon release already includes a signed Barn.app.
Check out the source
This checks out the source for Barn 1.5.0. Omit --branch v1.5.0 to follow development on main.
Build the CLI
You need Go 1.27.4 (pinned in go.mod), Git, Make, and Bash. Compiling needs no QEMU and no host network setup.
An unstamped build reports version dev, and its commit reads uncommitted if the working tree has changes. On the release tag, use BARN_VERSION=1.5.0 make build to stamp the version.
make build writes the CLI and its matching barn-hosts-helper into bin/.barn-releases/ and links them as bin/barn and bin/barn-hosts-helper. Use it instead of go build ./cmd/barn: the CLI embeds the helper’s SHA-256 and runs only a helper that matches. If you move the build, keep bin/.barn-releases/ next to the two links.
To build all four targets (darwin_amd64, darwin_arm64, linux_amd64, and linux_arm64) into bin/<os>_<arch>/, run make cross.
Build the Mac component
On an Apple Silicon Mac running macOS 27 or later, with Xcode 27 or later selected for xcrun, stop any Mac VMs that use a previous local build, then run:
make mac-build puts a matched set in bin/mac/, namely barn, barn-hosts-helper, the standalone barn-mac-runner, and Barn.app, and also writes bin/barn-mac-darwin-arm64.tar.gz. BARN_VERSION stamps it the same way as make build. Run the CLI from bin/mac so it uses the Barn.app built with it.
The build is ad-hoc signed, which is all you need to run VMs on your own Mac. Developer ID signing and notarization are part of the release procedure. Continue with the macOS guide to create a VM.
Run the tests
Before opening a pull request, run the full make check gate with the pinned linters. Contributing lists the tools and what each target covers.
11 - Uninstall and Clean Up
Use this page to remove part of what Barn created, or all of it. Linux labs and macOS VMs are managed separately, so barn purge never touches Mac VMs. Keep the barn CLI installed until the last step, because the cleanup commands need it.
Choose what to remove
| Remove | Run | What is kept |
|---|---|---|
| Nothing yet, just stop the VMs | barn stop; barn mac stop --all | Everything, disks included |
| One Linux node | barn destroy <node> | The other nodes, that node’s persistent disks, keys, images, host network |
| The Linux lab | barn destroy | Persistent disks, deployment keys, cached images, host network |
| The Linux lab, its persistent disks, and keys | barn purge (deletes immediately; --ask to confirm first) | Cached images, host network |
| Named Mac VMs | barn mac destroy <name...> (asks you to confirm) | Other Mac VMs, cached macOS images |
Barn’s SSH, /etc/hosts, and clock-sync integrations | Step 2 | Your own ~/.ssh/config and /etc/hosts entries |
| Cached images | barn image prune --yes; barn mac image prune --installers --yes | Images a VM still uses, and the default macOS base |
| The Linux host network | barn network uninstall --yes (after all Linux VMs are gone) | — |
| Barn itself | Step 5 | ~/.barn, until you delete it |
Before destroying anything, check names with barn status (Linux) and barn mac ls (Mac), and copy files you want to keep to the host. What survives each operation has the per-command detail for data disks.
Full teardown steps
Destroy Linux and Mac virtual machines
Discard the whole Linux lab, persistent disks and deployment keys included:
It deletes immediately. To review the VM list and scope first, run
barn purge --askand answery/yesorn/no;purgeaccepts no--yes,-y, or--force. Then list and destroy any macOS VMs by name:Remove SSH,
/etc/hosts, and timer integrationsDestroying the whole Linux deployment already removes the default
~/.ssh/barn_configintegration. Remove anything else you installed: a custom-named SSH fragment,/etc/hostsentries, Mac SSH aliases, or the clock-sync user timer:Each command removes only the block Barn wrote.
Prune cached images
Preview, then delete, cached Linux and macOS images:
Uninstall Linux host networking
The shared Linux host network can be removed only while no Linux VM is running. Mac VM networks go away by themselves when each VM stops.
On hosts that use systemd-networkd, the uninstall leaves networkd’s global unit state alone when other links exist or Barn cannot confirm it is the only user; the plan reports
preserve_networkd, and the result explains the decision inchecks.networkd.Uninstall the Barn application and remaining state
If a package manager installed Barn, remove the package:
HomebrewDebian / UbuntuRHEL / Fedora- User-scoped
install.sh: removebarn,barn-hosts-helper,.barn-current,.barn-releases/, and.barn-install.lockfrom~/.local/bin, and thePATHline from your shell rc file. - Manual archive or source build: with all Mac guests stopped, remove the extracted release directory,
bin/mac, or any copiedBarn.app(Barn Mac.appin0.9.0), plus~/Library/Preferences/com.pgsty.barn.plist(io.pgsty.barn.mac-runner.plistin0.9.0). - Manually installed hosts helper: if you installed
/opt/barn/libexec/barn-hosts-helperby hand and no other user on the host uses Barn, remove it afterbarn hosts uninstall --yes.
- User-scoped
Delete ~/.barn (or your custom BARN_HOME) only after both Linux and Mac VMs are destroyed. It holds VM state, keys, persistent disks, and base images for both. If a VM is still running or a destroy failed, resolve it with barn status / barn mac ls before deleting the directory.