Skip to content

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.

Table reader