Preparation and Utilities
8 minute read
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.