# Linux Lifecycle

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

---

LLMS index: [llms.txt](/v1.5/llms.txt)

---

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](/v1.5/docs/reference/commands/#versions)).

## Choosing a command {#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 |
{.wide .expand}

The full retention rules are in [What survives each operation](../../../start/storage/#what-survives-each-operation).

## Selecting nodes {#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](/v1.5/docs/reference/commands/#global-options). Specification overrides (`-I`, `-A`, `-C`, `-M`, `-S`, `-D`) and their environment variables are defined in [Configuration](../../configuration/#specification-overrides). `--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](../../cli/#lifecycle-results).

## `barn plan` {#barn-plan}

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

```text
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](../../cli/#planning)). 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 |
{.wide .expand}

```bash
barn plan
barn plan -f pigsty.yml meta
barn --json plan -I d13 -A amd64
```

## `barn up` {#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.

```text
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`](../setup/#barn-setup) 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 |
{.wide .expand}

```bash
barn up
barn up -f pigsty.yml meta
barn up --mirror --rollback
barn up meta --no-wait
```

## `barn start` {#barn-start}

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

```text
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.

| 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 |
{.wide .expand}

```bash
barn start
barn start meta --no-wait
```

## `barn stop` {#barn-stop}

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

```text
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.

| 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 |
{.wide .expand}

```bash
barn stop meta
barn stop
```

## `barn restart` {#barn-restart}

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

```text
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.

| 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 |
{.wide .expand}

```bash
barn restart
barn restart meta --no-wait
```

## `barn reload` {#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.

```text
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`.

| 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 |
{.wide .expand}

```bash
barn reload -f pigsty.yml
barn reload meta --mirror
```

## `barn resize` {#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.

```text
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](../../cli/#root-disk-growth).

| 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 |
{.wide .expand}

```bash
barn plan -f pigsty.yml meta
barn resize -f pigsty.yml meta
barn --json status meta
```

## `barn recreate` {#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](../../../start/storage/#what-survives-each-operation) has the full rules.

```text
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`.

| 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 |
{.wide .expand}

```bash
barn plan meta
barn recreate meta
barn recreate -f pigsty.yml meta --yes
```

## `barn status` {#barn-status}

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

```text
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.

```bash
barn status
barn status meta --verbose
barn --json status
```

## `barn destroy` {#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](../../../start/storage/#what-survives-each-operation).

```text
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`.

| 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 |
{.wide .expand}

```bash
barn destroy meta
barn destroy --yes
barn destroy --yes --purge
```

## `barn 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](../../../start/storage/#what-survives-each-operation).

```text
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.

| 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 |
{.wide .expand}

```bash
barn purge --ask
barn --json purge
```

## Implementation {#implementation}

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