Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Command Reference

Every Barn command with syntax, all local options, defaults, examples, and version availability.

Find a command below for its arguments, complete local option table, examples, and effects. This reference follows the command-index and command-family organization of PIG. Barn’s CLI contracts describe structured output and exit codes; Configuration defines inventory fields.

Version baseline

This reference covers the Barn 1.5.0. Its command names and flags remain compatible with 1.4.0. Release notes

LabelAvailabilityBehavior
1.1.0Options available across 1.1.0–1.5.01.1.0 used 2 vCPUs / 4 GiB by default and accepted CPU/memory resize through the inventory
1.2.0Added in 1.2.0Resource flags and environment overrides, vm_scale, root-disk growth, lifecycle --parallel, vm_hosts, and hosts install -f; defaults are 1 vCPU / 2 GiB
1.3.0Added in 1.3.0barn time manual, startup, and scheduled guest clock synchronization; shorthand family and architecture-suffixed image aliases (el10a, d13x); embedded catalog 2026112101; macOS 27.2.1 base and macOS network setup/repair fix
1.4.0Added in 1.4.0barn image update, catalog signing key rotation, Debian 13.8 on both architectures, and immediate power-off during Linux purge
1.5.0Changed in 1.5.0New labs use d13. repo build can infer image metadata from filenames, and official catalogs use catalog.json.sig.

To preserve the 1.1.0 resource defaults when upgrading from 1.1.0, set vm_cpu: 2 and vm_mem: 4GiB explicitly and inspect barn plan. Existing applied VMs keep their resources until a resource-changing operation is requested. Use barn version and barn COMMAND --help to check an installed build. See the release notes and release acceptance.

Command index

TaskCommands and detailed reference
Preparesetup, init, validate, doctor
Plan and createplan, up
Start and stopstart, stop, restart, reload
Change and inspectresize, recreate, status
Deletedestroy, purge
Access Linux guestsssh, exec, logs, provision, ssh-config
Publish host nameshosts install, hosts uninstall
Synchronize clockstime status, sync, auto
Refresh catalogupdate, image sync, image reset
Manage Linux imagesimage list, info, pull, update (1.4.0), import, prune
Maintain a repositoryrepo scan, build, verify
Host networknetwork status, install, uninstall
Native macOS VMsmac ls, up, start, stop, restart, configure, recreate, destroy
Mac accessmac open, ssh, exec, password, ssh-config, logs
Mac preparationmac setup, doctor, image ls, image update, image prune
CLI utilitiesversion, completion, help

Global options

barn [--json|--yaml] [-v|--verbose] COMMAND [arguments] [local options]
OptionMeaning
-h, --helpHuman-readable help for the selected command; exits 0
--jsonStructured JSON on stdout; progress and diagnostics stay on stderr
--yamlStructured YAML on stdout; mutually exclusive with --json
-v, --verboseBounded diagnostics on stderr
--versionRoot-command shortcut to display build identity; use barn version --json for a structured report

Global output options can appear before or after a subcommand, but must precede the remote-command -- separator used by ssh and exec. -f, -I, -A, -p, and --yes are local options: consult the selected command’s table. -f means follow for logs; -n means line count for mac logs. Long boolean options accept =true or =false.

BARN_OUTPUT and BARN_VERBOSE set presentation defaults. BARN_HOME selects private state (default ~/.barn); use an absolute path when changing directories. Linux and Mac machines share that data root but have independent lifecycles. See environment variables and exit codes.

barn and help

barn
barn --help
barn help resize
barn image pull --help
barn --json

With no arguments, text mode prints complete help and exits 0; JSON/YAML mode returns suggested actions[]. Explicit help always prints human-readable text. Groups image, repo, network, hosts, time, time auto, and mac image require a subcommand and exit 2 without one. The mac group is the exception: it defaults to mac ls. It is hidden from root help on Linux and Intel Macs, while explicit Mac help remains available.

Short aliases are scoped to their parent. barn im ls is barn image list; barn mac st is barn mac ls. The per-command pages list each alias. There is no rm alias for purge.

1 - Preparation and Utilities

Prepare the host with barn setup, write and validate inventories, diagnose the host, and print the version or completion scripts.

barn setup prepares a host to run Linux VMs: it installs QEMU and UEFI firmware, creates the fixed-IP network the nodes share, and writes an inventory if you have none. This page also covers init, validate, doctor, version, and completion. Every command accepts the global options; Available in shows availability from the 1.1.0 baseline onward (version baseline).

barn setup

barn setup [meta|dual|trio|full] [flags]

On a terminal, the first barn up runs this preparation itself and asks once. Run barn setup directly to preview the changes, to prepare a host from a script or CI job, or to get ready before the first up. It creates no VMs and downloads no base images; barn up does that.

barn setup --dry-run              # print the plan, change nothing
barn setup                        # print the plan, ask, then apply
barn setup full -I el9 --yes      # generate a four-node EL9 lab without asking
barn setup -f pigsty.yml --yes    # prepare the host for an existing inventory
barn up

Aliases: s.

What setup changes

Setup skips steps that are already satisfied and prints the whole plan before the first change:

StepWhat it doesRoot
dependenciesInstalls missing QEMU, qemu-img, UEFI firmware, and OpenSSH: brew install qemu on macOS (Homebrew required), apt-get or dnf on LinuxLinux only
capabilitiesRuns the host checks of barn doctorNo
networkInstalls or repairs the fixed-IP network: socket_vmnet as a root service under /opt/barn on macOS, the barn0 bridge through NetworkManager or systemd-networkd on LinuxYes
verifyRe-checks the installed networkNo
configWrites the generated inventory, or uses the existing oneNo

The network step needs root because it changes host networking; in return, QEMU itself runs as you. /etc/hosts is not part of setup: the first barn hosts install installs its root-owned helper, which is why setup reports the hosts-helper step as on-demand.

On macOS, socket_vmnet comes from the first of BARN_VMNET_ARCHIVE, Barn’s cache, Homebrew, or a SHA-256-pinned download from the selected repository or github.com/lima-vm; --mirror and --repo change the download source. Behind a proxy, setup passes HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY (either case) through sudo to apt-get and dnf. On Linux, setup installs only the host-architecture emulator; for foreign-architecture guests, install the other qemu-system-* package and its UEFI firmware yourself.

sudo and confirmation

Run setup as your normal user. It asks for your password at most once, at the first root step, after printing why; Homebrew runs as you. On a terminal, setup shows the plan and asks Continue with this setup? [Y/n], unless nothing needs to change.

  • --yes skips that question and is required without a terminal, where setup otherwise exits 2. It cannot answer sudo: without a terminal, sudo must work without a password, or setup exits 3 with reason sudo_unavailable (troubleshooting).
  • --dry-run prints the plan and changes nothing; its next: line is the command that applies it. It cannot be combined with --yes.
  • barn --json setup reports ready, blocked, steps[], dependencies (with missing[] and the exact package-manager commands[]), network, and next/next_argv.

Which inventory it prepares

With no template and no -f, setup reuses the first discovered inventory or writes the meta template to ./barn.yml. A template (meta, dual, trio, or full, with 1 to 4 nodes) generates that lab; -f prepares an existing file and cannot be combined with a template. -c and the specification flags shape generated templates only: setup rejects them for an existing inventory and ignores the matching BARN_* variables when it reuses one.

If the default subnet is taken and the inventory is a fresh, unedited template, setup picks a free private /24 and keeps the original as barn.yml.before-network-change. An inventory you wrote or edited keeps its subnet, and a conflict stops setup.

Options

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-c, --cidr stringgenerated template network as a canonical RFC1918 IPv4 /241.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-d, --dry-runshow the resolved setup plan without changing anything1.1.0
-f, --file stringInventory to prepare; mutually exclusive with a template argument1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-m, --mode stringmacOS fixed-IP network backend: host or shared (default “host”)1.1.0
-r, --repo stringimage repository URL or local directory, also used for socket_vmnet; overrides --mirror and $BARN_REPO1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
-y, --yesaccept the one-time setup plan (required without a terminal)1.1.0

barn init

barn init [meta|dual|trio|full] [flags]

Write an editable, Pigsty-compatible inventory without touching the host. The default is the one-node meta template in ./barn.yml, with the control node at .10; dual, trio, and full add .11, .12, and .13. Existing files are kept unless you pass --force, and -o - prints to stdout.

In 1.5.0, all four templates write vm_image: d13 and vm_arch: native by default. On Barn 1.4.0, pass -I d13 when generating a template to select Debian 13.

Generated nodes get 1 vCPU, 2 GiB of memory, a 64 GiB root disk, and a 128 GiB /data disk, written out as all six specification fields including vm_scale (specification overrides). Barn 1.1.0 templates used 2 vCPUs and 4 GiB (upgrade notes).

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-c, --cidr stringrebase the generated template to a canonical RFC1918 IPv4 /241.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
--forceOverwrite the destination inventory; default preserves existing files1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
-o, --output stringwrite to this path instead of ./barn.yml; ‘-’ writes to stdout1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn init -I d13
barn init full -I d13 -A amd64 -o lab.yml
barn init dual -I d13 -c 10.20.30.0/24 -o -

barn validate

barn validate [flags]

Check an inventory before up. validate checks every field Barn reads and prints the resolved nodes, or the full resolved specification with --json. It requires an inventory file, either -f or the first of barn.yml, barn.yaml, pigsty.yml, and pigsty.yaml in the current directory. In 1.5.0, a readable deployment supplies the same image default as plan. It takes no node names, and overrides apply to this check only. To compare an inventory with the running deployment, use barn plan.

Aliases: v.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringInventory to validate; otherwise use local discovery, with no applied-state fallback1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
-r, --repo stringimage repository whose catalog checks the images; overrides $BARN_REPO1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn validate -f lab.yml
barn --json validate -f lab.yml -I d13 -A arm64

barn doctor

barn doctor [flags]

Check whether this host can run Linux VMs: QEMU, native acceleration, firmware, OpenSSH, a short accelerated boot, and host networking. A missing compute capability exits 3 and prints a fix: line for each problem. A missing network is only a warning, because setup installs it. For network detail, run barn network status; for macOS guests, run barn mac doctor.

Aliases: dt. No options of its own.

barn doctor
barn --json doctor
barn doctor --verbose

barn version

barn version [flags]

Print the version, source commit, build time, OS, and architecture to include in a bug report; barn --version prints the same line. --json returns name, version, commit, built, os, and arch. Source builds without a release stamp report dev.

Aliases: ver. No options of its own.

barn version
barn --json version

barn completion

barn completion [bash|zsh|fish|powershell] [flags]

Print one shell’s completion script to stdout, then install it as shown below. It completes commands, flags, templates, image aliases, and, on a best-effort basis, node names. Regenerate it after upgrading Barn. Use text mode: with --json or BARN_OUTPUT=json, the script arrives wrapped in a {shell, script} object.

No options of its own.

source <(barn completion bash)
barn completion zsh > "${fpath[1]}/_barn"
barn completion fish > ~/.config/fish/completions/barn.fish
barn completion powershell

Implementation

See cmd/barn/command_setup.go for the CLI and internal/setup/ for host preparation. cmd/barn/command_misc.go and cmd/barn/command_root.go define the diagnostic and root commands.

2 - Linux Lifecycle

Plan, create, start, resize, inspect, and explicitly remove Linux virtual machines.

These commands take a Linux lab from an inventory to running VMs, change it, and tear it down. The Available in column of each option table names the release that introduced the option (version baseline).

Choosing a command

You want toRunWhat happens to disks
See what a change would doplanNothing; read-only
Create the lab, or bring it back after a stop or rebootupKept
Boot, shut down, or reboot existing nodes as they arestart, stop, restartKept
Restart nodes and re-apply the inventory (stop, then up)reloadKept; nodes new in the inventory are created
Change CPU or memory, or grow the root diskresizeKept
Change image, architecture, data disks, network, or sharesrecreateRoot and non-persistent data disks replaced
Remove some nodes, or the whole lab but keep persistent datadestroyDeleted, except persistent data disks
Start over from nothingpurgeEverything deleted, persistent data disks included

The full retention rules are in What survives each operation.

Selecting nodes

Node arguments are resolved node names such as meta and node-1; omit them to select every node the command covers. IP addresses, groups, and vm_alias are not selectors.

plan, up, reload, resize, and recreate read the desired inventory from -f, then the current directory’s inventory, then applied state. The other lifecycle commands work from applied state only, so they run from any directory that uses the same BARN_HOME.

All commands accept the global options. Specification overrides (-I, -A, -C, -M, -S, -D) and their environment variables are defined in Configuration. --parallel appears only in the tables that list it; plan, resize, and status do not accept it. Structured results and exit codes are in CLI contracts.

barn plan

Run plan before up, resize, or recreate to see what they would change. It changes no VM and downloads nothing.

barn plan [node...] [flags]

The plan compares the effective desired inventory with applied state and reports exact images, resources, per-disk actions, and the nodes that need creation, resize, recreation, start, or explicit removal. Catalog images need only local metadata; inspecting a named local image also needs qemu-img.

Exit 0 means a plan was produced, including a plan blocked by nodes missing from the inventory, so automation must inspect action, blocked, and the change arrays (planning output). Explicit selectors keep the applied definitions of unselected peers.

Aliases: pl.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringdesired inventory; defaults to the discovered inventory, then the applied state1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
-r, --repo stringimage repository URL or directory; overrides $BARN_REPO1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn plan
barn plan -f pigsty.yml meta
barn --json plan -I d13 -A amd64

barn up

up is the everyday command: it creates missing nodes, starts stopped ones, and finishes any guest setup left undone, while healthy running VMs keep running.

barn up [node...] [flags]

Unless --no-wait is set, up verifies each guest’s readiness marker over management SSH, corrects guest clock offsets greater than two seconds against the host, and refreshes host SSH aliases and the guests’ host and control-node entries. Non-fatal guest setup or clock-sync problems appear in warnings; ready nodes still succeed.

On an interactive first run, up prepares missing host dependencies and generates meta when no inventory or applied deployment exists. Scripts run setup --yes first.

up never applies a changed node definition: use resize for CPU, memory, or root growth and recreate for anything else. Nodes removed from the inventory stay until you destroy them. --rollback removes only safe, uncommitted artifacts left by preparation failures in this run.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringdesired inventory; defaults to the discovered inventory, then the applied state1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-n, --no-waitreturn once QEMU is running, without waiting for the guest to boot1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
-r, --repo stringimage repository URL or directory; overrides --mirror and $BARN_REPO1.1.0
--rollbackremove safe artifacts from nodes that fail to prepare1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn up
barn up -f pigsty.yml meta
barn up --mirror --rollback
barn up meta --no-wait

barn start

Use start to boot nodes that already exist, from any directory: it reads applied state, not the inventory, and never creates nodes.

barn start [node...] [flags]

Unless --no-wait is set, start waits for SSH and corrects guest clock offsets greater than two seconds. It refreshes SSH access; to retry unfinished guest setup on a VM that is already running, use up. An unavailable host share fails only its node, and independent nodes continue.

OptionMeaning / defaultAvailable in
-n, --no-waitreturn once QEMU is running, without waiting for the guest to boot1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
barn start
barn start meta --no-wait

barn stop

Use stop to shut nodes down and free host CPU and memory; root disks, data disks, keys, and deployment state all stay.

barn stop [node...] [flags]

stop identifies each VM by its recorded process identity. With no names it stops the whole Linux deployment; macOS VMs and the host network keep running.

OptionMeaning / defaultAvailable in
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
barn stop meta
barn stop

barn restart

Use restart to reboot nodes exactly as they were created. Inventory edits are ignored; use reload to pick them up.

barn restart [node...] [flags]

restart stops and starts existing nodes from applied state, then waits for SSH and checks guest clocks unless --no-wait is set.

OptionMeaning / defaultAvailable in
-n, --no-waitreturn once QEMU is running, without waiting for the guest to boot1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
barn restart
barn restart meta --no-wait

barn reload

Use reload to restart nodes after editing the inventory: Barn re-reads it, stops the selected nodes, and runs up, so nodes you added are created in the same step.

barn reload [node...] [flags]

reload validates the desired specification and startup dependencies before it stops anything. Changes that need resize or recreate, and applied nodes missing from the inventory, fail this preflight while every VM keeps running. To reboot with the recorded configuration only, use restart.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringdesired inventory; defaults to the discovered inventory, then the applied state1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-n, --no-waitreturn once QEMU is running, without waiting for the guest to boot1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
-r, --repo stringimage repository URL or directory; overrides --mirror and $BARN_REPO1.1.0
--rollbackremove safe artifacts from nodes that fail to prepare1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn reload -f pigsty.yml
barn reload meta --mirror

barn resize

Use resize to change CPU or memory, or grow the root disk, without losing anything on the VM: its identity, disks, and SSH keys stay.

barn resize [node...] [flags]

Desired resources come from the inventory, environment variables, or CLI overrides; CLI overrides do not rewrite the inventory. Supported CPU and memory increases are hot-plugged; decreases and changes the VM cannot take live fall back to a stop and start. Image, architecture, data-disk, network, and share changes need recreate; new nodes need up, and removed nodes need destroy.

-D 128GiB grows the existing root to 128 GiB. Barn stops QEMU, expands the image, boots the guest to grow and verify its last plain ext4/XFS root partition, and returns a VM that was stopped to stopped. The target can only grow the disk and must align to 512 bytes. After an interruption, repeat the same target. Shrinking, LVM, encrypted roots, and roots that are not the last partition are unsupported; see root growth and recovery.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringdesired inventory; defaults to the discovered inventory, then the applied state1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
barn plan -f pigsty.yml meta
barn resize -f pigsty.yml meta
barn --json status meta

barn recreate

Use recreate for changes resize cannot make, such as a new image, architecture, data-disk layout, network, or shares: Barn rebuilds the selected VMs from the desired inventory.

Warning

recreate deletes the selected nodes’ root disks and non-persistent data disks, and everything stored on them. Only compatible persistent data disks are reattached. Run barn plan first to see which nodes it replaces; What survives each operation has the full rules.

barn recreate [node...] [flags]

On a terminal you type recreate to confirm; scripts pass --yes or --force (there is no -y).

Without selectors recreate applies the whole inventory, and fails before stopping any VM if the inventory omits an applied node: destroy that node explicitly or add it back. Selected recreation keeps unselected peers as they are. A successful recreate also refreshes SSH access.

Aliases: rc.

OptionMeaning / defaultAvailable in
-A, --arch stringoverride deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.01.1.0
-C, --cpu stringBase vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU1.2.0
-D, --disk stringAbsolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK1.2.0
-f, --file stringdesired inventory; defaults to the discovered inventory, then the applied state1.1.0
--forcerecreate without the interactive confirmation (required without a terminal)1.1.0
-I, --image stringoverride vm_image/vm_version for selected nodes; environment overrides require 1.2.01.1.0
-M, --mem stringBase memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM1.2.0
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-n, --no-waitreturn once QEMU is running, without waiting for the guest to boot1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
-r, --repo stringimage repository URL or directory; overrides --mirror and $BARN_REPO1.1.0
-S, --scale stringInteger 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE1.2.0
--yessame as --force1.1.0
barn plan meta
barn recreate meta
barn recreate -f pigsty.yml meta --yes

barn status

Use status to check what is running and how each node is configured, from any directory.

barn status [node...] [flags]

status shows recorded node configuration and live QEMU process identity. running means a verified VM process, not a successful SSH probe. --verbose adds runtime details; --json exposes node records, notes on active operations, and failures. A degraded node makes the command exit 5 while healthy peers are still listed. Text output shows compact SPEC values such as 2c4g.

Aliases: st.

No local options beyond --help; global presentation options still apply.

barn status
barn status meta --verbose
barn --json status

barn destroy

Use destroy to remove nodes you no longer need, or the whole Linux lab while keeping persistent data disks for a later rebuild.

Warning

destroy deletes the root disks and non-persistent data disks of the selected nodes, or of every node when you pass no names. Persistent data disks are kept unless you add --delete-persistent; --purge also deletes them along with SSH keys and deployment state. See What survives each operation.

barn destroy [node...] [flags]

On a terminal you type destroy to confirm; scripts pass --yes or --force (there is no -y). --delete-persistent and --purge work only on the whole deployment. The image cache, the host network, and native Mac VMs remain.

Removing the control node makes the first remaining node the control node; update admin_ip and run up to configure its control SSH access.

Aliases: de.

OptionMeaning / defaultAvailable in
--delete-persistentalso delete owned persistent data disks1.1.0
--forcedestroy without the interactive confirmation (required without a terminal)1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
--purgeterminal disposal: also delete persistent disks, keys, and deployment state1.1.0
--yessame as --force1.1.0
barn destroy meta
barn destroy --yes
barn destroy --yes --purge

barn purge

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.

Use purge to start over: it deletes the entire Linux deployment in one step, without reading an inventory. It is also how you remove retained persistent data disks once no deployment state is left.

Caution

purge deletes immediately, with no confirmation unless you pass --ask: every node’s root disk, all persistent data disks, SSH keys, deployment state, and the default SSH fragment. See What survives each operation.

barn purge [flags]

purge takes no node names and has no --yes, -y, or --force. --ask shows the deletion scope first and proceeds only on y or yes; Enter cancels. Cached images, host networking, and Mac VMs remain. Without an applied deployment, purge still removes leftover deployment data under BARN_HOME, such as retained persistent data disks and keys, and succeeds when nothing is left; artifacts whose ownership Barn cannot verify block deletion. --parallel controls node work during disposal.

OptionMeaning / defaultAvailable in
--askshow the deletion scope and ask for y/yes before purging1.1.0
-p, --parallel intNode concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit1.2.0
barn purge --ask
barn --json purge

Implementation

See cmd/barn/command_lifecycle.go for lifecycle commands and TestPlanKeepsAnExistingLabsImageDefault in cmd/barn/lifecycle_overrides_test.go for upgrade behavior.

3 - Guest Access and Hosts

Open a shell on Linux guests, run commands and scripts, read logs, and publish SSH aliases and /etc/hosts names.

These commands reach running Linux guests from the host: ssh and exec run a shell or one command, provision streams a script to several nodes, and logs shows what a node printed. ssh-config and hosts publish node names so other host tools can reach the nodes too. Every command accepts the global options; Available in shows availability from the 1.1.0 baseline onward (version baseline).

Remote commands and --

barn ssh and barn exec share one argument rule: Barn flags and at most one node name, then --, then the remote command. They differ in what the guest receives:

barn ssh  [node] [-- command...]   # words joined into one line for the guest shell
barn exec [node] -- command...     # program and arguments passed separately
barn ssh meta -- …barn exec meta -- …
Guest receivesOne string, parsed by the guest shell, as with plain sshThe program and its arguments, with no shell
Pipes, ;, $VARWork; quote them so your local shell leaves them aloneWrap the command in sh -c '…'
Spaces, quotes, empty argumentsRe-parsed by the guest shellPreserved exactly
No commandOpens an interactive login shellFails: exec requires -- and a command
  • Before --: Barn flags such as --json, plus an optional node name. It must be a resolved node name, not an IP address, alias, or group; an unknown name exits 2. Without one, Barn picks the prepared control node, or else the first prepared node.
  • After --: everything goes to the guest, including a second -- and anything that looks like a Barn or OpenSSH flag. The first word must not be empty. For compatibility, exec also accepts one quoted string and hands it to the guest shell.
  • Exit status: Barn exits with the remote command’s status, so exit 17 in the guest makes barn exit 17. Check whether a nonzero code came from the guest before reading it as a Barn error class.
barn ssh meta -- 'df -h /data; id'           # a shell line, quoted like plain ssh
barn exec meta -- printf '<%s>\n' 'a b' ''   # 'a b' stays one argument; '' is kept
barn exec meta -- sh -c 'uptime; id'         # shell features through sh -c

barn ssh

barn ssh [flags] [node] [-- command...]

Open an interactive shell on a node, or run a shell line there (argument rules). With --json, session output goes to stderr and the final report to stdout.

No options of its own.

barn ssh
barn ssh meta
barn ssh meta -- 'df -h /data; id'

barn exec

barn exec [flags] [node] -- command...

Run one command on a node with no shell in between (argument rules); scripts and agents should use this form. Text mode passes the guest’s output and exit status straight through. With --json, the report has success, exit_code, stdout, and stderr.

Aliases: ex. No options of its own.

barn exec meta -- hostname
barn exec meta -- printf '<%s>\n' 'a b' ''
barn --json exec meta -- sh -c 'echo out; exit 17'

barn logs

barn logs [node] [flags]

Read a node’s log; start here when a node does not become ready (troubleshooting). --source serial (the default) reads the guest serial console and qemu reads QEMU diagnostics, with the QEMU argv shown only under --verbose. Both take one node and default to the prepared control node, or else the first prepared node. events reads the deployment-wide, bounded Barn event log, including setup; it takes no node and works before any deployment exists.

--follow keeps streaming: raw bytes in text mode, NDJSON with --json, and a YAML document stream with --yaml. Here -f means --follow, not --file.

Aliases: l.

OptionMeaning / defaultAvailable in
-f, --followcontinue streaming appended log data1.1.0
-s, --source stringlog source: serial, qemu, or events (default “serial”)1.1.0
barn logs meta
barn logs meta --source qemu
barn logs --source events --follow
barn --json logs meta --follow

barn provision

barn provision [node...] [flags]

Run a local Bash script on running nodes, for example to bootstrap or check several at once; with no node names, it runs on all of them. Barn streams the script over the deployment’s verified SSH connection, so no copy stays on the guest, and records its SHA-256. It never creates or starts VMs.

--script is required. Nodes run one at a time unless you raise --parallel, which must be positive: unlike lifecycle commands, provision rejects 0. --timeout bounds the whole operation. --sudo runs the script through sudo -n, so the guest user needs passwordless sudo, as official images provide. --json returns script.sha256 and per-node results[] with node, success, exit_code, stdout, and stderr; if only some nodes fail, the exit code is 5.

OptionMeaning / defaultAvailable in
-p, --parallel intPositive concurrency limit; default 1; zero is invalid1.1.0
-s, --script stringlocal Bash script to stream to each selected guest1.1.0
--sudorun the guest script through sudo -n1.1.0
-t, --timeout durationhard deadline for the operation (default 1h0m0s)1.1.0
barn provision --script ./check.sh meta
barn provision --script ./bootstrap.sh --sudo --parallel 2 --timeout 30m

barn ssh-config

barn ssh-config [node...] [flags]

Print the deployment’s OpenSSH config fragment, which lets plain ssh, scp, and other OpenSSH tools reach nodes by name (ssh meta). Lifecycle commands such as barn up keep the default fragment, ~/.ssh/barn_config, current, so you rarely need this by hand. Use it to inspect the fragment, to limit it to some nodes, or to install another one with --name.

--install writes the fragment and adds one Include line to ~/.ssh/config. --remove removes only the fragment and Include installed under that name; it needs no deployment, takes no node names, and cannot be combined with --install. If ~/.ssh/config cannot be edited safely, for example because it is a symlink, Barn writes the fragment and prints the Include line for you to add.

Aliases: sc.

OptionMeaning / defaultAvailable in
-i, --installinstall the deployment fragment and one Include in ~/.ssh/config1.1.0
--name stringSSH Host and fragment prefix (default “barn”)1.1.0
--removeremove the Include and fragment Barn installed1.1.0
barn ssh-config
barn ssh-config --install meta
barn ssh-config --install --name lab
barn ssh-config --remove --name lab

barn hosts install

barn hosts install [flags]

SSH aliases help only OpenSSH tools. To let browsers, psql, and other host programs resolve node names and aliases, publish them in a Barn-owned block of /etc/hosts; barn up does not do this.

By default, the block lists the applied nodes’ names and aliases. Since 1.2.0, -f pigsty.yml publishes the inventory’s nodes plus all.vars.vm_hosts instead, even before the VMs exist (local service names). Each run replaces the whole block, so a later run without -f drops names that came only from the inventory.

On a terminal, Barn shows the change and asks Apply this /etc/hosts change? [Y/n]. Without a terminal, or with --json or --yaml, it only prints the plan; --yes applies it without asking, though sudo may still want a password. Barn edits the file through a root-owned helper, /opt/barn/libexec/barn-hosts-helper, which it installs on first use and verifies by digest. A block that is already current needs no privilege.

Aliases: i.

OptionMeaning / defaultAvailable in
-f, --file stringInventory nodes, aliases and vm_hosts; usable before VM creation1.2.0
-y, --yesapply the displayed privileged plan without confirmation (sudo may still ask for a password)1.1.0
barn hosts install --json
barn hosts install --yes
barn hosts install -f pigsty.yml --yes

barn hosts uninstall

barn hosts uninstall [flags]

Remove the Barn-owned block from /etc/hosts, keeping every other line. It needs no inventory or deployment. Confirmation works as for hosts install, except that the terminal question, Remove the Barn block from /etc/hosts? [y/N], defaults to no.

Aliases: u.

OptionMeaning / defaultAvailable in
-y, --yesapply the displayed privileged plan without confirmation (sudo may still ask for a password)1.1.0
barn hosts uninstall --json
barn hosts uninstall --yes

Implementation

command_root.go · command_access.go · main.go

4 - Guest Time Synchronization

Measure Linux guest clocks against the host, correct them, and enable optional scheduled checks.

While the host sleeps or a VM is paused, the guest does not run, so its clock falls behind the host’s; in an offline lab, guest NTP has no source to correct it. barn time measures each Linux guest against the host clock and sets it over management SSH, so it works without guest Internet access. Barn checks clocks on demand with barn time sync, when up, start, restart, reload, or recreate brings guests to ready, and, if you opt in, every minute from an OS timer.

The guest side needs Python 3.6 or later and passwordless sudo. barn time is new in 1.3.0 (version baseline), acts on the deployment that BARN_HOME selects, and accepts the global options.

Measure and correct clocks

barn time status
barn --json time status meta node-1
barn time sync
barn time sync meta node-1 --timeout 30s

status measures; sync sets each guest clock to the host’s, forward or backward, and measures again. Without node names, both cover the whole applied deployment and skip stopped, exited, and uncreated nodes, which is not a failure. Results show the offset (positive means the guest is ahead), its uncertainty (half the round trip), and the guest’s NTP synchronization state, service, and source before any change.

A backward step moves application wall time backward too, so choose the moment deliberately when time-sensitive workloads run in the guest.

CommandOptionDefaultMeaningAvailable in
time status [node...]--timeout1mTotal deadline, from 1s to 10m1.3.0
time sync [node...]--timeout1mTotal deadline, from 1s to 10m1.3.0

Barn checks the VM process, the instance SSH identity, and the guest readiness marker, takes three samples, and uses the one with the shortest round trip, compensating for transport time with the guest’s monotonic clock. A measurement fails if all three round trips exceed 250 ms, and a sync fails if more than 500 ms of offset remains afterwards. Nodes fail independently, each with its own error, and any failure makes the exit code nonzero.

Startup checks

up, start, restart, reload, and recreate check the guests they bring to ready and correct offsets above two seconds before returning, so a barn provision that follows sees the corrected time; services already enabled in the guest may start earlier during boot. A failed check does not fail the command: it appears in the lifecycle result’s top-level warnings[] with code time_sync, and its next suggests barn time sync for the affected nodes. --no-wait skips the check.

Scheduled checks

Enable the timer when the host sleeps often or VMs stay paused between sessions:

barn time auto enable
barn time auto status
barn --json time auto status
barn time auto disable

enable installs a timer for the invoking Unix user that records the executable path, BARN_HOME, and PATH. Run it from an installed binary, and again after moving Barn or switching BARN_HOME. The timer checks every running Linux guest of the recorded BARN_HOME, whatever the current directory or inventory.

HostSchedulerJob files
macOSlaunchd calendar job~/Library/LaunchAgents/com.pgsty.barn.time.plist
Linuxsystemd user timer and oneshot service${XDG_CONFIG_HOME:-~/.config}/systemd/user/barn-time-sync.{timer,service}

A check runs every minute for at most 45 seconds, corrects offsets above two seconds, and skips the deployment while another barn command holds its lock. Missed checks run after the host resumes, but the timer never wakes the host, and it needs the user’s launchd session or systemd user manager to be running.

If drift returns within ten minutes of a correction while the guest ran continuously and its NTP reports synchronized, the guest’s NTP source disagrees with the host. Barn reports source-conflict and stops correcting that node automatically, so the two do not keep pulling the clock apart. Host sleep, VM pause, and guest reboots do not count; the guest’s monotonic clock tells them apart. To clear the conflict, align the guest’s NTP source with the host or run barn time sync; an offset back within the threshold or a guest reboot also clears it.

status shows whether the job files are installed and the scheduler has them active, plus the latest result from $BARN_HOME/time-last.json, which each run replaces. Correction history lives in $BARN_HOME/time-sync.json; Barn prunes it when nodes or deployments are destroyed, and barn purge removes it with time-last.json. disable stops the timer and removes its job files; manual and startup checks keep working.

Host NTP and offline Pigsty

barn time corrects the clock but gives the guest no NTP source, so Pigsty’s node_timex_sync_status need not become 1. For continuous synchronization in an offline lab, serve time from the host: macOS ships sntpd, disabled by default, and Linux can use chronyd. Let the server fall back to its local clock when no upstream source is reachable, and allow only the lab network. Pigsty rewrites the Chrony configuration when it deploys NODE, so point the guests at the host’s .1 address on the lab /24 through node_ntp_servers in the Pigsty inventory. Once Chrony keeps the guests synchronized, you can disable the Barn timer and keep barn time sync for manual corrections.

Implementation

command_time.go · timesync · timejob

5 - Image Commands

Refresh signed catalogs, inspect or download images, import local files, and prune caches.

Refresh signed catalogs, inspect or download images, import local files, and prune caches.

barn image update is available from 1.4.0. Version baseline · Global options

Official repositories and HTTP sources require a trusted detached signature. An explicitly selected custom HTTPS repository or local directory can be unsigned, provided the source is exactly that repository’s catalog.json. Any supplied signature must verify. See catalog trust.

barn update

barn update [flags]

Fetch catalog.json and its signature when required by repository policy, verify trust and revision rules, then atomically activate the catalog. Ordinary commands read local metadata. A newly built local repository can be read directly before its first explicit update. Remote catalogs require an explicit refresh. This updates image metadata, not the Barn executable. Repository precedence is --repo > --mirror > BARN_REPO > the global official repository. See repository selection and trust.

OptionMeaning / defaultAvailable in
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-r, --repo stringimage repository URL or directory; overrides --mirror and $BARN_REPO1.1.0
barn update
barn update --mirror
barn --json update --repo /srv/barn

barn image list

barn image list [flags]

List every catalog architecture and registered local image. It has no image selector or architecture filter. The active local catalog is used; run barn update explicitly to refresh it. Aliases barn images and barn im select the same image command group.

Aliases: ls.

OptionMeaning / defaultAvailable in
-r, --repo stringimage repository URL or directory; overrides $BARN_REPO1.1.0
barn image list
barn --json image list
barn image list --repo /srv/barn

barn image info

barn image info [image[:channel]|image@version-prefix] [flags]

Inspect metadata and verified cache state for one image, using the catalog default if omitted. Select a family (d13), shorthand family alias (e/el/rocky → el10, u/ubuntu → u26, d/debian → d13), architecture-suffixed alias (el10a, d13x, da), channel (d13:stable), or numeric version prefix (el9@9). Architecture defaults to native; an explicit -A arm64 agrees with d13a, while -A amd64 or -A native conflicts with it (exit 2). The compatibility spelling --architecture/-a is also accepted for --arch/-A. It does not download the artifact. Supported aliases and exact embedded versions are in Linux images.

Aliases: in.

OptionMeaning / defaultAvailable in
-A, --arch stringartifact architecture (defaults to native): native, amd64 (x86_64, x64), or arm64 (aarch64, a64)1.1.0
-r, --repo stringimage repository URL or directory; overrides $BARN_REPO1.1.0
barn image info
barn image info el10a
barn image info d13 -A arm64
barn --json image info el9@9

barn image pull

barn image pull [image[:channel]|image@version-prefix] [flags]

Download the selected artifact and verify its SHA-256, byte size, qcow2 structure, and virtual capacity before activating the cache entry. Omitted image and architecture select the catalog default and native host architecture. Shorthand family and architecture-suffixed aliases such as el10a and d13x work here as well (a matching -A is accepted, a conflicting architecture or explicit native exits 2). Existing valid cached bytes are reused. The catalog’s upstream URL is provenance, not a download fallback. --architecture/-a remains a compatibility alias. A foreign artifact does not install the corresponding QEMU emulator.

Aliases: p.

OptionMeaning / defaultAvailable in
-A, --arch stringartifact architecture (defaults to native): native, amd64 (x86_64, x64), or arm64 (aarch64, a64)1.1.0
--mirroruse the China official repository at repo.pigsty.cc; overridden by --repo1.1.0
-r, --repo stringimage repository URL or directory; overrides --mirror and $BARN_REPO1.1.0
barn image pull
barn image pull d13 --mirror
barn image pull d13 -A amd64 --repo /srv/barn

barn image update

barn image update [image[:channel]...] [flags]

Barn refreshes the selected repository’s catalog under its trust policy, then downloads and verifies the selected files. With no arguments, it updates the image families and architectures already in the cache. An empty cache results in a catalog refresh only.

To fetch a specific build into an empty cache, name an architecture alias such as d13i (amd64) or d13a (arm64). A bare family such as d13 updates its cached architectures and uses the host architecture for its first download. The default channel is stable. Use image pull for a pinned version such as d13@20261123.2671.1. Existing VMs keep their original base images.

The command alias is u.

OptionEffectAvailable in
-A, --arch stringSelect one architecture, including native, amd64 or arm641.4.0
-d, --dry-runVerify the candidate catalog and preview downloads and requested cleanup without writing local state1.4.0
--pruneAfter successful downloads, remove files eligible under the normal pruning rules1.4.0
--mirrorSelect the China official repository1.4.0
-r, --repo stringSelect a repository URL or directory. Takes precedence over --mirror and BARN_REPO1.4.0
barn image update --dry-run
barn image update d13i d13a
barn image update --mirror --prune --dry-run

--prune applies to the whole cache, including when you name individual images. The active catalog, applied VMs and registered local aliases protect the files they reference. Pruning rules

barn image import

barn image import <path> [flags]

Copy a local regular qcow2 image into the private cache and validate its container, optionally against an expected digest. Relative paths, ~/, and symlinks to regular files are accepted. qemu-img is required; importing does not boot the image, add cloud-init, or change credentials.

A local-* name registers an immutable inventory reference and requires boot mode plus the source login user. Named imports can record a foreign architecture with -A; qcow2 metadata does not identify CPU architecture, and unnamed imports cannot use -A. Set both vm_image and a matching vm_arch when using it. See import and cache rules.

Aliases: i.

OptionMeaning / defaultAvailable in
-A, --arch stringGuest architecture recorded with --name; defaults to native; does not convert the image1.1.0
-b, --boot stringrequired with --name: bios or uefi1.1.0
--name stringImmutable local-* alias; requires --boot and --source-user1.1.0
-s, --sha256 stringoptional expected SHA-2561.1.0
-u, --source-user stringrequired with --name: source image login user1.1.0
barn image import ./base.qcow2
barn image import ./debian-13-generic-arm64.qcow2 --name local-dev --boot uefi --source-user debian -A arm64

barn image sync

barn image sync <url|path> [flags]

Activate a catalog from one exact URL or local file, reading its adjacent .sig signature under the trust policy above. This is the recovery/import path; use update for the configured repository’s normal endpoint. --repo chooses which repository’s active metadata to replace. An unsigned custom source must be exactly <repo>/catalog.json; an arbitrary recovery file requires a trusted signature.

Older revisions require --allow-downgrade. For custom repositories that allow unsigned catalogs, switching from a previously signed catalog to an unsigned one also requires this flag. It never permits an invalid signature or bypasses the official-repository signature requirement and revision-content checks. Future downgrade protection still remembers the highest revision.

Aliases: sy.

OptionMeaning / defaultAvailable in
--allow-downgradeactivate a catalog older than the newest revision seen so far1.1.0
-r, --repo stringRepository whose active catalog is replaced1.1.0
barn image sync /srv/barn/catalog.json
barn image sync --repo /srv/barn /srv/recovery/catalog.json
barn image sync --allow-downgrade /srv/recovery/catalog.json

barn image reset

barn image reset [flags]

Reactivate the catalog embedded in the current binary for the selected repository. It keeps the highest accepted revision used by downgrade protection. Cached images and VM disks are retained; this is not a cache deletion command.

OptionMeaning / defaultAvailable in
-r, --repo stringRepository whose active catalog is reset to the embedded catalog1.1.0
barn image reset
barn --json image reset --repo /srv/barn

barn image prune

barn image prune [flags]

List reclaimable cache files by default. Use --yes to delete the candidates or --dry-run to preview them. The selected active catalog, applied node base-image digests, and registered local aliases protect their referenced images. Recognized staging files and read-only quarantine files such as *.qcow2.corrupt-<timestamp> are also eligible for removal.

Preview with the same repository selection you will use for deletion. Deletion is sequential; an error on a later file does not restore files already removed. See pruning rules.

Aliases: pr.

OptionMeaning / defaultAvailable in
-d, --dry-runshow unreferenced images and stale staging files without deleting1.1.0
-r, --repo stringimage repository URL or directory; overrides $BARN_REPO1.1.0
-y, --yesDelete the listed unreferenced files; mutually exclusive with --dry-run1.1.0
barn image prune --dry-run
barn image prune --repo /srv/barn --dry-run
barn image prune --repo /srv/barn --yes

Implementation

The 1.5.0 image commands are in cmd/barn/command_image.go and cmd/barn/images.go. Catalog verification is covered by internal/image/manifest_test.go.

The version baseline lists changes through 1.5.0.

6 - Repository Commands

Scan, build and verify a repository of qcow2 images, with optional metadata in repo.yaml.

A static repository has a flat images/ directory and a generated catalog.json. In 1.5.0, barn repo build reads names, versions and architectures from filenames. Add repo.yaml for aliases, channels, nonstandard names or different boot settings. Build a static repository · Repository format

barn repo scan /srv/barn     # inspect the files under images/
barn repo build /srv/barn    # write catalog.json
barn repo verify /srv/barn   # compare the catalog with the images and optional metadata

All three have been available since 1.1.0. Each takes one repository root and has no options beyond the global options.

barn repo scan

barn repo scan <root> [flags]

Report the state of every qcow2 file without changing anything or needing qemu-img:

StateMeaning
trackedSelected by filename inference or repo.yaml, and present
missingReferenced by repo.yaml but absent from images/
untrackedPresent in images/ but not referenced by repo.yaml
unsafeNot a safe regular qcow2 file

--json returns root and the four arrays. The scan exits 0 whenever it completes, even with findings, so a script must check missing and unsafe itself:

barn --json repo scan /srv/barn | jq -e '(.missing + .unsafe) | length == 0'

barn repo build

barn repo build <root> [flags]

Inspect selected images with qemu-img and atomically write catalog.json with the final digests and sizes. A supplied repo.yaml controls selection. A missing or unsafe declared artifact fails the build.

With an explicit revision, increase it when the catalog changes. With the revision omitted, Barn assigns it automatically and preserves the previous bytes on an unchanged rebuild. Upload immutable images before publishing the catalog. Signing and trust rules

barn repo build /srv/barn
barn --json repo build /srv/barn

barn repo verify

barn repo verify <root> [flags]

Rebuild the catalog in memory from the filenames, optional repo.yaml and actual image bytes, and require a byte-for-byte match with the existing catalog.json. Requires qemu-img. Run it before publishing or after copying a repository. It checks consistency only; clients check signatures when they activate the catalog.

barn repo verify /srv/barn
barn --json repo verify /srv/barn

Implementation

The self-hosted repository guide gives a two-command example.

7 - Host Network Commands

Inspect, install, repair, and remove the fixed-IP network that lets Linux nodes reach each other.

Every Linux node gets two NICs: one reaches the Internet through QEMU’s built-in NAT, and one sits on a fixed /24 where the host and the other nodes reach it at the address your inventory names (why two NICs). These commands manage the host side of that second network, socket_vmnet on macOS and the barn0 bridge on Linux. barn setup and the first interactive barn up install it for you (host preparation); use these commands to check, repair, reconfigure, or remove it.

One network serves all Linux guests on the host; native Mac VMs have their own. install and uninstall print a privileged plan first and, on a terminal, ask before applying it. Without a terminal, or with --json or --yaml, they only print the plan; --yes applies it without asking, though sudo may still want a password.

barn network also answers to n and net. Every command accepts the global options; Available in shows availability from the 1.1.0 baseline onward (version baseline).

barn network status

barn network status [flags]

Show the backend, installed CIDR, ownership, health, and the preflight findings that lifecycle commands check before changing anything. It is read-only. --cidr checks against an expected subnet; without it, status inspects the installed one. For partial or invalid results, see troubleshooting.

On Linux, 1.5.0 checks KVM access, bridge prerequisites and the configured private network. Run barn doctor for the full QEMU capability check.

Aliases: st.

OptionMeaning / defaultAvailable in
-c, --cidr stringOptional expected private /24; otherwise inspect the installed subnet1.1.0
barn network status
barn --json network status --cidr 10.10.10.0/24

barn network install

barn network install [flags]

Install or repair the backend for --cidr: socket_vmnet on macOS in host or shared vmnet mode, or barn0 through the active Linux network manager, which accepts only host. An existing network must match the chosen subnet and mode, so check status before changing either.

On a fresh Mac, run barn setup instead. A first install needs a pinned socket_vmnet archive and a new vmnet interface UUID, which setup supplies; without both --archive and --interface-id, network install exits 3 with reason network_absent and suggests barn setup. Both flags are macOS-only.

Aliases: i.

OptionMeaning / defaultAvailable in
-a, --archive stringmacOS: pinned socket_vmnet archive1.1.0
-c, --cidr stringnetwork: an RFC1918 IPv4 /24 (default “10.10.10.0/24”)1.1.0
-i, --interface-id stringmacOS: persistent vmnet UUID1.1.0
-m, --mode stringmacOS vmnet mode: host or shared (default “host”)1.1.0
-y, --yesapply the displayed privileged plan without confirmation (sudo may still ask for a password)1.1.0
barn network install --json
barn network install --cidr 10.10.10.0/24 --yes

macOS Internet Sharing

Install and repair work while Internet Sharing is on, as long as its vmnet preferences set neither a custom subnet address nor a mask. If the preview cannot read those preferences, it says so, and Barn checks them after you approve, before writing network files or restarting socket_vmnet. A subnet that conflicts with a live interface, route, or node address blocks the plan at preview. Preferences that turn out unreadable, conflicting, or only half set stop the operation before the host changes.

barn network uninstall

barn network uninstall [flags]

Remove Barn-owned network configuration and restore the host settings recorded at install. Stop the Linux nodes first; uninstall refuses while any node is running. The terminal question, Remove the Barn network? [y/N], defaults to no. VM disks and native Mac VM networks stay in place.

Aliases: u.

OptionMeaning / defaultAvailable in
-y, --yesapply the displayed privileged plan without confirmation (sudo may still ask for a password)1.1.0
barn stop
barn network uninstall --json
barn network uninstall --yes

Implementation

The 1.5.0 status checks are in cmd/barn/command_network.go and internal/doctor/network.go.

8 - macOS Commands

Syntax, options, and examples for every barn mac subcommand.

Syntax, options, and examples for every barn mac subcommand. The machine model, networks, JSON results, and failure reasons these commands share are defined in the Mac Runtime Reference; a guided first run is in macOS Virtual Machines.

Common rules

  • Host. The commands need an Apple Silicon Mac on macOS 27 or later with the matching Barn.app, run as the logged-in desktop user (requirements). At most two macOS VMs run at a time per Mac; starting a third fails with mac_vm_limit.
  • Machine names. A command with an optional [name] uses the only existing machine, or mac1. With several machines and none named mac1, pass a name. configure, recreate, and destroy always need one. start and stop take several names or --all, not both.
  • Sizes. --memory and --disk are binary even when written GB: 16G, 16GiB, and 16GB all mean 16 GiB, and a bare number is bytes. Linux inventory GB is decimal.
  • Confirmation. recreate and destroy print what they will delete and ask you to type the command name. --yes or --force skips the question and is required without a terminal; neither command has a -y shorthand. Commands that download macOS from Apple (up, setup, image update) ask first; -y/--yes skips that question and is required without a terminal.
  • State. Machines live under $BARN_HOME/mac, separate from the Linux inventory. These commands ignore the Linux BARN_IMAGE/BARN_ARCH/BARN_CPU/BARN_MEM/BARN_SCALE/BARN_DISK overrides.

Every option below has been available since 1.1.0.

barn mac ls

Start here to see what exists: every machine with its state, address, SSH readiness, macOS build, resources, and shares.

barn mac ls [flags]

It reads local records and queries running machines; it never creates, downloads, or starts anything. barn mac without a subcommand runs ls. The JSON shape is in ls output.

Aliases: list, status, st.

No local options beyond --help; global presentation options still apply.

barn mac ls
barn --json mac ls

barn mac up

Use up to get a machine running: it creates the machine the first time, starts it afterwards, and returns once SSH and passwordless sudo work.

barn mac up [name] [flags]

The default name is mac1. On a Mac without a prepared macOS base, up first downloads the restore image from Apple after you confirm and installs it once; later machines clone that base in seconds. A --disk size that differs from the prepared base’s capacity installs a matching base first.

Creation options apply only to a new machine. On an existing machine up just starts it; an option that differs from the recorded setting fails with mac_configuration_conflict, and the next: line prints the command to use instead. --share names default to the folder’s last path component, and ~/ expands to your home directory.

--no-wait returns once the VM is running. On a first boot, provisioning may still be in progress; run barn mac up NAME again to wait for SSH and finish initialization before using ssh or exec.

OptionMeaning / defaultAvailable in
--clipboard on|offon/off, true/false, or yes/no; default on, active while the desktop window is focused1.1.0
--cpu intvCPUs, default 4; minimum 2, maximum host logical CPU count1.1.0
--disk sizeBase capacity, minimum 32 GiB; default uses the prepared base, or 100 GiB initially1.1.0
--ipsw stringinstall macOS from this restore image instead of downloading from Apple1.1.0
--memory sizeMemory, default 8 GiB; a whole MiB from 4 GiB to host RAM1.1.0
-n, --no-waitreturn once the VM runs; first boot may still be initializing1.1.0
--openshow the desktop as soon as the VM runs1.1.0
--share [name=]path[:ro]Repeatable [name=]path[:ro|:rw]; default writable, mounted under /Volumes/My Shared Files1.1.0
--subnet stringCanonical private /24, or auto; default selects the first free subnet1.1.0
--user stringGuest administrator; default is the host username, or barn if that name is invalid1.1.0
-y, --yesdownload macOS from Apple without asking (required without a terminal)1.1.0
barn mac up
barn mac up dev --cpu 8 --memory 16G --share ~/src --open
barn mac up build --yes --no-wait

barn mac start

Use start to boot machines that have already completed their first up. It waits for SSH and never creates a machine or downloads anything.

barn mac start [name...] [flags]

Select names or --all, not both. A machine that has not finished its first boot fails with mac_not_initialized: if it is running, watch its first boot with barn mac open NAME; if it is stopped, continue with barn mac up NAME --open. --recovery boots macOS Recovery with its desktop shown and does not wait for SSH.

OptionMeaning / defaultAvailable in
--allstart every machine1.1.0
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--openshow the desktop as soon as the VM runs1.1.0
--recoveryboot macOS Recovery and show its desktop1.1.0
barn mac start mac1
barn mac start --all
barn mac start mac1 --recovery

barn mac stop

Use stop to shut machines down cleanly through macOS; disks and settings stay as they are.

barn mac stop [name...] [flags]

A machine that has not stopped after two minutes is powered off, and the result says so ("forced": true). --force powers off at once, like holding the power button; unsaved work in the guest is lost.

OptionMeaning / defaultAvailable in
--allstop every machine1.1.0
--forcePower off immediately instead of requesting shutdown; unsaved guest work is lost1.1.0
barn mac stop dev
barn mac stop --all
barn mac stop dev --force

barn mac restart

Use restart to apply settings saved with configure, or to reboot a guest that misbehaves.

barn mac restart [name] [flags]

It shuts the machine down normally and starts it again. It takes at most one name and has no --all.

OptionMeaning / defaultAvailable in
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--openshow the desktop as soon as the VM runs1.1.0
barn mac restart dev
barn mac restart dev --open

barn mac configure

Use configure to change a machine’s CPUs, memory, shared folders, network, or clipboard setting without touching its disk or account.

barn mac configure <name> [flags]

CPUs, memory, shared folders, and the subnet change only while the machine is stopped; otherwise the command fails with mac_running. The clipboard setting can change anytime. Saved configuration, including a clipboard change, applies at the next start; to toggle clipboard sharing for the current session, use the menu bar.

Omitted options keep their values. --share adds a share or replaces the share of that name; --unshare removes one. --subnet auto moves the machine to the first free subnet, which is the fix for mac_subnet_in_use.

OptionMeaning / defaultAvailable in
--clipboard on|offon/off, true/false, or yes/no; omitted retains the setting1.1.0
--cpu intvCPUs, minimum 2 and maximum host logical CPU count; omitted retains current value1.1.0
--memory sizeMemory, a whole MiB from 4 GiB to host RAM; omitted retains current value1.1.0
--share [name=]path[:ro]Add or replace a named share; repeatable, writable by default, optional :ro or :rw1.1.0
--subnet stringmove to this private /24 network, or auto for the first free one1.1.0
--unshare stringArraystop sharing the named folder (repeatable)1.1.0
barn mac stop dev
barn mac configure dev --cpu 8 --memory 16G --share ~/src
barn mac configure dev --unshare src --clipboard off
barn mac start dev

barn mac recreate

Use recreate to get a clean disk from the base image while keeping the machine’s name and settings, or, with --update, to move the machine to the newest prepared macOS.

Warning

recreate erases the machine’s disk: files, apps, and settings inside the guest are lost. Shared folders on the host are untouched. Copy anything you need off the guest first.

barn mac recreate <name> [flags]

The new machine keeps its name, account, CPUs, memory, disk capacity, shared folders, clipboard setting, and address, and gets a new login password and new SSH keys.

--update clones the default base that barn mac image update prepared, at the machine’s own disk capacity. If the new macOS build is prepared only at another capacity, prepare it first, for example barn mac setup --disk 200G.

OptionMeaning / defaultAvailable in
--forceskip the confirmation (required without a terminal)1.1.0
-n, --no-waitreturn once the VM runs, without waiting for SSH1.1.0
--updateuse the newest prepared macOS base1.1.0
--yesSame as --force; no -y shorthand1.1.0
barn mac recreate dev
barn mac image update --yes
barn mac recreate dev --update --yes

barn mac destroy

Use destroy to delete machines you no longer need.

Warning

destroy powers each named machine off and deletes its disk, SSH keys, password, and settings. The shared macOS base, other machines, and shared folders on the host are kept.

barn mac destroy <name...> [flags]

Explicit names are required. Run barn mac image prune afterwards to remove bases that no machine uses.

OptionMeaning / defaultAvailable in
--forceskip the confirmation (required without a terminal)1.1.0
--yesSame as --force; no -y shorthand1.1.0
barn mac destroy dev
barn mac destroy mac1 mac2 --yes

barn mac open

Use open to see and use the machine’s desktop; it starts a stopped machine first.

barn mac open [name] [flags]

Closing the window keeps the machine running in the background, and the clipboard is shared while the window is focused. A running machine that has not finished its first boot can be watched here; for a stopped one, use barn mac up NAME --open.

No local options beyond --help; global presentation options still apply.

barn mac open
barn mac open dev

barn mac ssh

Use ssh for an interactive shell in the machine, or to run a shell command line in it.

barn mac ssh [flags] [name] [-- command...]

Without a command, ssh opens an interactive session. A command after -- is joined into one line for the guest shell, as plain ssh does, and its exit status is returned. Argument rules are in SSH and exec.

No local options beyond --help; global presentation options still apply.

barn mac ssh dev
barn mac ssh dev -- 'sw_vers; id'

barn mac exec

Use exec in scripts: it runs one program with its arguments passed exactly as given and returns the program’s exit status.

barn mac exec [flags] [name] -- command...

A command after -- is required. Use sh -c explicitly for pipelines and other shell expressions. With --json the result carries exit_code, stdout, and stderr. Argument rules are in SSH and exec.

No local options beyond --help; global presentation options still apply.

barn mac exec dev -- sw_vers
barn mac exec dev -- printf '<%s>\n' 'a b' ''
barn --json mac exec dev -- sh -c 'echo out; exit 3'

barn mac password

Use password when the guest desktop asks for the login password, at the lock screen or an administrator prompt.

barn mac password [name] [flags]

The password is stored next to the machine’s SSH key with the same protection. --copy puts it on the clipboard instead of printing it.

OptionMeaning / defaultAvailable in
-c, --copycopy to the clipboard instead of printing1.1.0
barn mac password dev
barn mac password dev --copy

barn mac ssh-config

Use ssh-config to let ssh, scp, rsync, and editors reach each machine by name, with its own key and pinned host key.

barn mac ssh-config [flags]

Without options it prints the OpenSSH fragment. The first machine to become ready installs the fragment as one Include in ~/.ssh/config, and lifecycle commands keep it current. --remove deletes only what Barn installed and keeps it out until --install. A name that ~/.ssh/config already uses for another host is published by address only. If ~/.ssh/config is a symlink or hard link, the command fails with ssh_config_linked and prints the Include line for you to add.

--install and --remove are mutually exclusive. This command takes no machine names.

OptionMeaning / defaultAvailable in
-i, --installinstall the entries as one Include in ~/.ssh/config1.1.0
--removeremove the entries Barn installed1.1.0
barn mac ssh-config
barn mac ssh-config --install
barn mac ssh-config --remove

barn mac logs

Use logs when a machine fails to start, loses its network, or does not shut down: it shows the last lines of the machine’s runtime log, including Apple Virtualization errors.

barn mac logs [name] [flags]

--lines/-n must be positive and defaults to 100. Here -n means lines, not no-wait. There is no follow option.

OptionMeaning / defaultAvailable in
-n, --lines intnumber of recent lines (default 100)1.1.0
barn mac logs dev
barn mac logs dev --lines 200

barn mac setup

Use setup to prepare the macOS base ahead of time, for example in a provisioning script, so the first up only has to clone it.

barn mac setup [flags]

It downloads macOS from Apple after you confirm, or reads --ipsw, and installs it once into the unbooted base that every machine is cloned from. up does the same automatically when no base is prepared.

OptionMeaning / defaultAvailable in
--disk sizeBase capacity, at least 32 GiB. Defaults to the current base capacity or 100 GiB for the first base1.1.0
--ipsw stringinstall macOS from this restore image instead of downloading from Apple1.1.0
-y, --yesdownload macOS from Apple without asking (required without a terminal)1.1.0
barn mac setup --yes
barn mac setup --ipsw ~/Downloads/restore.ipsw --disk 200G

barn mac image ls

Use image ls to see which restore images and bases take up disk space, and which machines use them.

barn mac image ls [flags]

It lists each restore image and base with its state and disk usage. It reads local state only and does not start the native runner.

Aliases: list.

No local options beyond --help; global presentation options still apply.

barn mac image ls
barn --json mac image ls

barn mac image update

Use image update to move to Apple’s newest macOS 27 build.

barn mac image update [flags]

It asks Apple for the newest macOS 27 restore image, downloads it after you confirm, and installs it as the default base for new machines. Existing machines keep their base until you run barn mac recreate NAME --update.

OptionMeaning / defaultAvailable in
--ipsw stringuse this restore image instead of downloading from Apple1.1.0
-y, --yesdownload without asking (required without a terminal)1.1.0
barn mac image update --yes
barn mac image ls

barn mac image prune

Use image prune to reclaim disk space from bases that no machine uses.

barn mac image prune [flags]

It lists unused bases other than the current default. --installers adds downloaded restore images and partial downloads. Nothing is deleted without --yes.

OptionMeaning / defaultAvailable in
--installersinclude downloaded restore images and partial downloads1.1.0
-y, --yesDelete the listed unused images; otherwise only list candidates1.1.0
barn mac image prune
barn mac image prune --installers --yes

barn mac doctor

Run doctor first when something goes wrong, and after installing or upgrading Barn.

barn mac doctor [flags]

It checks macOS and Apple Silicon support, the Mac component’s signature, free disk space, the prepared base, and every machine: its files, keys, shared folders, network, and SSH. It changes nothing and starts nothing, and exits 3 if any check fails.

No local options beyond --help; global presentation options still apply.

barn mac doctor
barn --json mac doctor

Implementation

command_mac.go