This is the multi-page printable view of this section.
Command Reference
- 1: Preparation and Utilities
- 2: Linux Lifecycle
- 3: Guest Access and Hosts
- 4: Guest Time Synchronization
- 5: Image Commands
- 6: Repository Commands
- 7: Host Network Commands
- 8: macOS Commands
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
| Label | Availability | Behavior |
|---|---|---|
| 1.1.0 | Options available across 1.1.0–1.5.0 | 1.1.0 used 2 vCPUs / 4 GiB by default and accepted CPU/memory resize through the inventory |
| 1.2.0 | Added in 1.2.0 | Resource 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.0 | Added in 1.3.0 | barn 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.0 | Added in 1.4.0 | barn image update, catalog signing key rotation, Debian 13.8 on both architectures, and immediate power-off during Linux purge |
| 1.5.0 | Changed in 1.5.0 | New 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
| Task | Commands and detailed reference |
|---|---|
| Prepare | setup, init, validate, doctor |
| Plan and create | plan, up |
| Start and stop | start, stop, restart, reload |
| Change and inspect | resize, recreate, status |
| Delete | destroy, purge |
| Access Linux guests | ssh, exec, logs, provision, ssh-config |
| Publish host names | hosts install, hosts uninstall |
| Synchronize clocks | time status, sync, auto |
| Refresh catalog | update, image sync, image reset |
| Manage Linux images | image list, info, pull, update (1.4.0), import, prune |
| Maintain a repository | repo scan, build, verify |
| Host network | network status, install, uninstall |
| Native macOS VMs | mac ls, up, start, stop, restart, configure, recreate, destroy |
| Mac access | mac open, ssh, exec, password, ssh-config, logs |
| Mac preparation | mac setup, doctor, image ls, image update, image prune |
| CLI utilities | version, completion, help |
Global options
| Option | Meaning |
|---|---|
-h, --help | Human-readable help for the selected command; exits 0 |
--json | Structured JSON on stdout; progress and diagnostics stay on stderr |
--yaml | Structured YAML on stdout; mutually exclusive with --json |
-v, --verbose | Bounded diagnostics on stderr |
--version | Root-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
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
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
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.
Aliases: s.
What setup changes
Setup skips steps that are already satisfied and prints the whole plan before the first change:
| Step | What it does | Root |
|---|---|---|
dependencies | Installs missing QEMU, qemu-img, UEFI firmware, and OpenSSH: brew install qemu on macOS (Homebrew required), apt-get or dnf on Linux | Linux only |
capabilities | Runs the host checks of barn doctor | No |
network | Installs 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 Linux | Yes |
verify | Re-checks the installed network | No |
config | Writes the generated inventory, or uses the existing one | No |
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.
--yesskips that question and is required without a terminal, where setup otherwise exits2. It cannot answersudo: without a terminal,sudomust work without a password, or setup exits3with reasonsudo_unavailable(troubleshooting).--dry-runprints the plan and changes nothing; itsnext:line is the command that applies it. It cannot be combined with--yes.barn --json setupreportsready,blocked,steps[],dependencies(withmissing[]and the exact package-managercommands[]),network, andnext/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
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-c, --cidr string | generated template network as a canonical RFC1918 IPv4 /24 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-d, --dry-run | show the resolved setup plan without changing anything | 1.1.0 |
-f, --file string | Inventory to prepare; mutually exclusive with a template argument | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-m, --mode string | macOS fixed-IP network backend: host or shared (default “host”) | 1.1.0 |
-r, --repo string | image repository URL or local directory, also used for socket_vmnet; overrides --mirror and $BARN_REPO | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
-y, --yes | accept the one-time setup plan (required without a terminal) | 1.1.0 |
barn init
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).
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-c, --cidr string | rebase the generated template to a canonical RFC1918 IPv4 /24 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
--force | Overwrite the destination inventory; default preserves existing files | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
-o, --output string | write to this path instead of ./barn.yml; ‘-’ writes to stdout | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
barn validate
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | Inventory to validate; otherwise use local discovery, with no applied-state fallback | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
-r, --repo string | image repository whose catalog checks the images; overrides $BARN_REPO | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
barn doctor
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 version
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 completion
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.
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
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 to | Run | What happens to disks |
|---|---|---|
| See what a change would do | plan | Nothing; read-only |
| Create the lab, or bring it back after a stop or reboot | up | Kept |
| Boot, shut down, or reboot existing nodes as they are | start, stop, restart | Kept |
Restart nodes and re-apply the inventory (stop, then up) | reload | Kept; nodes new in the inventory are created |
| Change CPU or memory, or grow the root disk | resize | Kept |
| Change image, architecture, data disks, network, or shares | recreate | Root and non-persistent data disks replaced |
| Remove some nodes, or the whole lab but keep persistent data | destroy | Deleted, except persistent data disks |
| Start over from nothing | purge | Everything 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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | desired inventory; defaults to the discovered inventory, then the applied state | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
-r, --repo string | image repository URL or directory; overrides $BARN_REPO | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | desired inventory; defaults to the discovered inventory, then the applied state | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-n, --no-wait | return once QEMU is running, without waiting for the guest to boot | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
-r, --repo string | image repository URL or directory; overrides --mirror and $BARN_REPO | 1.1.0 |
--rollback | remove safe artifacts from nodes that fail to prepare | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
barn start
Use start to boot nodes that already exist, from any directory: it reads applied state, not the inventory, and never creates nodes.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-n, --no-wait | return once QEMU is running, without waiting for the guest to boot | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
barn stop
Use stop to shut nodes down and free host CPU and memory; root disks, data disks, keys, and deployment state all stay.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
barn restart
Use restart to reboot nodes exactly as they were created. Inventory edits are ignored; use reload to pick them up.
restart stops and starts existing nodes from applied state, then waits for SSH and checks guest clocks unless --no-wait is set.
| Option | Meaning / default | Available in |
|---|---|---|
-n, --no-wait | return once QEMU is running, without waiting for the guest to boot | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | desired inventory; defaults to the discovered inventory, then the applied state | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-n, --no-wait | return once QEMU is running, without waiting for the guest to boot | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
-r, --repo string | image repository URL or directory; overrides --mirror and $BARN_REPO | 1.1.0 |
--rollback | remove safe artifacts from nodes that fail to prepare | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | desired inventory; defaults to the discovered inventory, then the applied state | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
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.
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | override deployment vm_arch: native, amd64, or arm64; environment overrides require 1.2.0 | 1.1.0 |
-C, --cpu string | Base vCPUs before scale, integer 1–256; effective CPU count is also limited to 256; overrides BARN_CPU | 1.2.0 |
-D, --disk string | Absolute root capacity, at least the base virtual size; bare integer means GiB; overrides BARN_DISK | 1.2.0 |
-f, --file string | desired inventory; defaults to the discovered inventory, then the applied state | 1.1.0 |
--force | recreate without the interactive confirmation (required without a terminal) | 1.1.0 |
-I, --image string | override vm_image/vm_version for selected nodes; environment overrides require 1.2.0 | 1.1.0 |
-M, --mem string | Base memory before scale, minimum 512 MiB; bare integer means MiB; overrides BARN_MEM | 1.2.0 |
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-n, --no-wait | return once QEMU is running, without waiting for the guest to boot | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
-r, --repo string | image repository URL or directory; overrides --mirror and $BARN_REPO | 1.1.0 |
-S, --scale string | Integer 1–256 multiplying base CPU and memory only; disk does not scale; overrides BARN_SCALE | 1.2.0 |
--yes | same as --force | 1.1.0 |
barn status
Use status to check what is running and how each node is configured, from any directory.
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 destroy
Use destroy to remove nodes you no longer need, or the whole Linux lab while keeping persistent data disks for a later rebuild.
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--delete-persistent | also delete owned persistent data disks | 1.1.0 |
--force | destroy without the interactive confirmation (required without a terminal) | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
--purge | terminal disposal: also delete persistent disks, keys, and deployment state | 1.1.0 |
--yes | same as --force | 1.1.0 |
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.
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--ask | show the deletion scope and ask for y/yes before purging | 1.1.0 |
-p, --parallel int | Node concurrency: omitted = max(1, logical CPUs - 2); 0 = all selected nodes; positive = limit | 1.2.0 |
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
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 meta -- … | barn exec meta -- … | |
|---|---|---|
| Guest receives | One string, parsed by the guest shell, as with plain ssh | The program and its arguments, with no shell |
Pipes, ;, $VAR | Work; quote them so your local shell leaves them alone | Wrap the command in sh -c '…' |
| Spaces, quotes, empty arguments | Re-parsed by the guest shell | Preserved exactly |
| No command | Opens an interactive login shell | Fails: 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 exits2. 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,execalso accepts one quoted string and hands it to the guest shell. - Exit status: Barn exits with the remote command’s status, so
exit 17in the guest makesbarnexit17. Check whether a nonzero code came from the guest before reading it as a Barn error class.
barn ssh
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 exec
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 logs
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.
| Option | Meaning / default | Available in |
|---|---|---|
-f, --follow | continue streaming appended log data | 1.1.0 |
-s, --source string | log source: serial, qemu, or events (default “serial”) | 1.1.0 |
barn provision
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.
| Option | Meaning / default | Available in |
|---|---|---|
-p, --parallel int | Positive concurrency limit; default 1; zero is invalid | 1.1.0 |
-s, --script string | local Bash script to stream to each selected guest | 1.1.0 |
--sudo | run the guest script through sudo -n | 1.1.0 |
-t, --timeout duration | hard deadline for the operation (default 1h0m0s) | 1.1.0 |
barn ssh-config
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.
| Option | Meaning / default | Available in |
|---|---|---|
-i, --install | install the deployment fragment and one Include in ~/.ssh/config | 1.1.0 |
--name string | SSH Host and fragment prefix (default “barn”) | 1.1.0 |
--remove | remove the Include and fragment Barn installed | 1.1.0 |
barn hosts install
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.
| Option | Meaning / default | Available in |
|---|---|---|
-f, --file string | Inventory nodes, aliases and vm_hosts; usable before VM creation | 1.2.0 |
-y, --yes | apply the displayed privileged plan without confirmation (sudo may still ask for a password) | 1.1.0 |
barn hosts uninstall
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.
| Option | Meaning / default | Available in |
|---|---|---|
-y, --yes | apply the displayed privileged plan without confirmation (sudo may still ask for a password) | 1.1.0 |
Implementation
4 - Guest Time Synchronization
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
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.
| Command | Option | Default | Meaning | Available in |
|---|---|---|---|---|
time status [node...] | --timeout | 1m | Total deadline, from 1s to 10m | 1.3.0 |
time sync [node...] | --timeout | 1m | Total deadline, from 1s to 10m | 1.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:
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.
| Host | Scheduler | Job files |
|---|---|---|
| macOS | launchd calendar job | ~/Library/LaunchAgents/com.pgsty.barn.time.plist |
| Linux | systemd 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
5 - Image Commands
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
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.
| Option | Meaning / default | Available in |
|---|---|---|
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-r, --repo string | image repository URL or directory; overrides --mirror and $BARN_REPO | 1.1.0 |
barn image list
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.
| Option | Meaning / default | Available in |
|---|---|---|
-r, --repo string | image repository URL or directory; overrides $BARN_REPO | 1.1.0 |
barn image info
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | artifact architecture (defaults to native): native, amd64 (x86_64, x64), or arm64 (aarch64, a64) | 1.1.0 |
-r, --repo string | image repository URL or directory; overrides $BARN_REPO | 1.1.0 |
barn image pull
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | artifact architecture (defaults to native): native, amd64 (x86_64, x64), or arm64 (aarch64, a64) | 1.1.0 |
--mirror | use the China official repository at repo.pigsty.cc; overridden by --repo | 1.1.0 |
-r, --repo string | image repository URL or directory; overrides --mirror and $BARN_REPO | 1.1.0 |
barn image update
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.
| Option | Effect | Available in |
|---|---|---|
-A, --arch string | Select one architecture, including native, amd64 or arm64 | 1.4.0 |
-d, --dry-run | Verify the candidate catalog and preview downloads and requested cleanup without writing local state | 1.4.0 |
--prune | After successful downloads, remove files eligible under the normal pruning rules | 1.4.0 |
--mirror | Select the China official repository | 1.4.0 |
-r, --repo string | Select a repository URL or directory. Takes precedence over --mirror and BARN_REPO | 1.4.0 |
--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
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.
| Option | Meaning / default | Available in |
|---|---|---|
-A, --arch string | Guest architecture recorded with --name; defaults to native; does not convert the image | 1.1.0 |
-b, --boot string | required with --name: bios or uefi | 1.1.0 |
--name string | Immutable local-* alias; requires --boot and --source-user | 1.1.0 |
-s, --sha256 string | optional expected SHA-256 | 1.1.0 |
-u, --source-user string | required with --name: source image login user | 1.1.0 |
barn image sync
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.
| Option | Meaning / default | Available in |
|---|---|---|
--allow-downgrade | activate a catalog older than the newest revision seen so far | 1.1.0 |
-r, --repo string | Repository whose active catalog is replaced | 1.1.0 |
barn image reset
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.
| Option | Meaning / default | Available in |
|---|---|---|
-r, --repo string | Repository whose active catalog is reset to the embedded catalog | 1.1.0 |
barn image prune
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.
| Option | Meaning / default | Available in |
|---|---|---|
-d, --dry-run | show unreferenced images and stale staging files without deleting | 1.1.0 |
-r, --repo string | image repository URL or directory; overrides $BARN_REPO | 1.1.0 |
-y, --yes | Delete the listed unreferenced files; mutually exclusive with --dry-run | 1.1.0 |
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
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
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
Report the state of every qcow2 file without changing anything or needing qemu-img:
| State | Meaning |
|---|---|
tracked | Selected by filename inference or repo.yaml, and present |
missing | Referenced by repo.yaml but absent from images/ |
untracked | Present in images/ but not referenced by repo.yaml |
unsafe | Not 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 repo build
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 verify
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.
Implementation
The self-hosted repository guide gives a two-command example.
7 - Host Network Commands
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
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.
| Option | Meaning / default | Available in |
|---|---|---|
-c, --cidr string | Optional expected private /24; otherwise inspect the installed subnet | 1.1.0 |
barn network install
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.
| Option | Meaning / default | Available in |
|---|---|---|
-a, --archive string | macOS: pinned socket_vmnet archive | 1.1.0 |
-c, --cidr string | network: an RFC1918 IPv4 /24 (default “10.10.10.0/24”) | 1.1.0 |
-i, --interface-id string | macOS: persistent vmnet UUID | 1.1.0 |
-m, --mode string | macOS vmnet mode: host or shared (default “host”) | 1.1.0 |
-y, --yes | apply the displayed privileged plan without confirmation (sudo may still ask for a password) | 1.1.0 |
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
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.
| Option | Meaning / default | Available in |
|---|---|---|
-y, --yes | apply the displayed privileged plan without confirmation (sudo may still ask for a password) | 1.1.0 |
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. 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 withmac_vm_limit. - Machine names. A command with an optional
[name]uses the only existing machine, ormac1. With several machines and none namedmac1, pass a name.configure,recreate, anddestroyalways need one.startandstoptake several names or--all, not both. - Sizes.
--memoryand--diskare binary even when writtenGB:16G,16GiB, and16GBall mean 16 GiB, and a bare number is bytes. Linux inventoryGBis decimal. - Confirmation.
recreateanddestroyprint what they will delete and ask you to type the command name.--yesor--forceskips the question and is required without a terminal; neither command has a-yshorthand. Commands that download macOS from Apple (up,setup,image update) ask first;-y/--yesskips that question and is required without a terminal. - State. Machines live under
$BARN_HOME/mac, separate from the Linux inventory. These commands ignore the LinuxBARN_IMAGE/BARN_ARCH/BARN_CPU/BARN_MEM/BARN_SCALE/BARN_DISKoverrides.
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.
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 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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--clipboard on|off | on/off, true/false, or yes/no; default on, active while the desktop window is focused | 1.1.0 |
--cpu int | vCPUs, default 4; minimum 2, maximum host logical CPU count | 1.1.0 |
--disk size | Base capacity, minimum 32 GiB; default uses the prepared base, or 100 GiB initially | 1.1.0 |
--ipsw string | install macOS from this restore image instead of downloading from Apple | 1.1.0 |
--memory size | Memory, default 8 GiB; a whole MiB from 4 GiB to host RAM | 1.1.0 |
-n, --no-wait | return once the VM runs; first boot may still be initializing | 1.1.0 |
--open | show the desktop as soon as the VM runs | 1.1.0 |
--share [name=]path[:ro] | Repeatable [name=]path[:ro|:rw]; default writable, mounted under /Volumes/My Shared Files | 1.1.0 |
--subnet string | Canonical private /24, or auto; default selects the first free subnet | 1.1.0 |
--user string | Guest administrator; default is the host username, or barn if that name is invalid | 1.1.0 |
-y, --yes | download macOS from Apple without asking (required without a terminal) | 1.1.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--all | start every machine | 1.1.0 |
-n, --no-wait | return once the VM runs, without waiting for SSH | 1.1.0 |
--open | show the desktop as soon as the VM runs | 1.1.0 |
--recovery | boot macOS Recovery and show its desktop | 1.1.0 |
barn mac stop
Use stop to shut machines down cleanly through macOS; disks and settings stay as they are.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--all | stop every machine | 1.1.0 |
--force | Power off immediately instead of requesting shutdown; unsaved guest work is lost | 1.1.0 |
barn mac restart
Use restart to apply settings saved with configure, or to reboot a guest that misbehaves.
It shuts the machine down normally and starts it again. It takes at most one name and has no --all.
| Option | Meaning / default | Available in |
|---|---|---|
-n, --no-wait | return once the VM runs, without waiting for SSH | 1.1.0 |
--open | show the desktop as soon as the VM runs | 1.1.0 |
barn mac configure
Use configure to change a machine’s CPUs, memory, shared folders, network, or clipboard setting without touching its disk or account.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--clipboard on|off | on/off, true/false, or yes/no; omitted retains the setting | 1.1.0 |
--cpu int | vCPUs, minimum 2 and maximum host logical CPU count; omitted retains current value | 1.1.0 |
--memory size | Memory, a whole MiB from 4 GiB to host RAM; omitted retains current value | 1.1.0 |
--share [name=]path[:ro] | Add or replace a named share; repeatable, writable by default, optional :ro or :rw | 1.1.0 |
--subnet string | move to this private /24 network, or auto for the first free one | 1.1.0 |
--unshare stringArray | stop sharing the named folder (repeatable) | 1.1.0 |
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.
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--force | skip the confirmation (required without a terminal) | 1.1.0 |
-n, --no-wait | return once the VM runs, without waiting for SSH | 1.1.0 |
--update | use the newest prepared macOS base | 1.1.0 |
--yes | Same as --force; no -y shorthand | 1.1.0 |
barn mac destroy
Use destroy to delete machines you no longer need.
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.
Explicit names are required. Run barn mac image prune afterwards to remove bases that no machine uses.
| Option | Meaning / default | Available in |
|---|---|---|
--force | skip the confirmation (required without a terminal) | 1.1.0 |
--yes | Same as --force; no -y shorthand | 1.1.0 |
barn mac open
Use open to see and use the machine’s desktop; it starts a stopped machine first.
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 ssh
Use ssh for an interactive shell in the machine, or to run a shell command line in it.
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 exec
Use exec in scripts: it runs one program with its arguments passed exactly as given and returns the program’s exit status.
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 password
Use password when the guest desktop asks for the login password, at the lock screen or an administrator prompt.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-c, --copy | copy to the clipboard instead of printing | 1.1.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
-i, --install | install the entries as one Include in ~/.ssh/config | 1.1.0 |
--remove | remove the entries Barn installed | 1.1.0 |
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.
--lines/-n must be positive and defaults to 100. Here -n means lines, not no-wait. There is no follow option.
| Option | Meaning / default | Available in |
|---|---|---|
-n, --lines int | number of recent lines (default 100) | 1.1.0 |
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.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--disk size | Base capacity, at least 32 GiB. Defaults to the current base capacity or 100 GiB for the first base | 1.1.0 |
--ipsw string | install macOS from this restore image instead of downloading from Apple | 1.1.0 |
-y, --yes | download macOS from Apple without asking (required without a terminal) | 1.1.0 |
barn mac image ls
Use image ls to see which restore images and bases take up disk space, and which machines use them.
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 update
Use image update to move to Apple’s newest macOS 27 build.
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.
| Option | Meaning / default | Available in |
|---|---|---|
--ipsw string | use this restore image instead of downloading from Apple | 1.1.0 |
-y, --yes | download without asking (required without a terminal) | 1.1.0 |
barn mac image prune
Use image prune to reclaim disk space from bases that no machine uses.
It lists unused bases other than the current default. --installers adds downloaded restore images and partial downloads. Nothing is deleted without --yes.
| Option | Meaning / default | Available in |
|---|---|---|
--installers | include downloaded restore images and partial downloads | 1.1.0 |
-y, --yes | Delete the listed unused images; otherwise only list candidates | 1.1.0 |
barn mac doctor
Run doctor first when something goes wrong, and after installing or upgrading Barn.
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.