# Storage, Files, and Service Access

> Configure test data disks, understand retention, transfer files, and reach guest services through OpenSSH.

---

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

---

Each Linux node has a disposable root disk and separate data disks. The root disk is a copy-on-write layer over the base image, and `recreate` replaces it whenever the image or node definition changes. Data disks keep test data on their own devices, so the system can be rebuilt underneath them; with `persistent: true`, a data disk also survives `recreate` and `destroy`. This page covers disk layout and retention, then file transfer and service access, using the `meta` node at `10.10.10.10` from the [Linux Quick Start](../tutorial/).

## Configure disks before creating the VM {#configure-disks-before-creating-the-vm}

By default each node gets a 64 GiB root disk and one 128 GiB non-persistent data disk mounted at `/data`. `vm_disk` sets the root size in GiB (`64` or `64GiB`); `vm_disks` replaces the whole data-disk list, and `vm_disks: []` creates no data disks.

This single-node inventory keeps `/data` across rebuilds and adds a throwaway `/scratch`:

```yaml {title="storage.yml"}
all:
  vars:
    admin_ip: 10.10.10.10
    vm_image: d13
  children:
    nodes:
      hosts:
        10.10.10.10:
          nodename: meta
          vm_cpu: 2
          vm_mem: 4096
          vm_disk: 64
          vm_disks:
            - {path: /data, size: 64, fs: auto, persistent: true}
            - {path: /scratch, size: 32, fs: ext4, persistent: false}
```

Create the VM and check the mounts:

```bash
barn validate -f storage.yml
barn plan -f storage.yml
barn up -f storage.yml
barn exec meta -- findmnt /data
barn exec meta -- findmnt /scratch
barn exec meta -- df -h / /data /scratch
```

Sizes (`size: 64` or `size: 64GiB`) are thin-provisioned: the host file grows only as the guest writes. With `fs: auto`, Barn formats a new disk as XFS when the guest has `mkfs.xfs` and as ext4 otherwise. If `findmnt` shows nothing, the reason is in the `barn up` warnings.

If `meta` already exists with a different disk layout, `barn up` reports drift instead of changing it. Check `barn plan`, copy out anything you need, then run `barn recreate meta`, which replaces the root disk and non-persistent data disks.

## What survives each operation {#what-survives-each-operation}

| Operation | Root and non-persistent data disks | Persistent data disks (`persistent: true`) |
|---|---|---|
| `stop` then `start`, `restart`, or `reload` | Kept | Kept |
| `resize`, including root growth | Kept | Kept |
| Repeated `up` on a healthy node | Kept | Kept |
| `recreate` | Replaced | Kept and reattached |
| `destroy` (one node or the whole lab) | Deleted | Kept |
| `destroy --delete-persistent`, `destroy --purge`, or `purge` | Deleted | Deleted, including disks kept from earlier destroys |
{.wide .expand}

Newly formatted data filesystems are owned by `root`. To see `/data` survive a stop and start:

```bash
barn exec meta -- sudo -n sh -c \
  'printf "retention check\n" > /data/barn-retention.txt'
barn stop meta
barn start meta
barn exec meta -- cat /data/barn-retention.txt
```

### Reattach a persistent disk {#reattach-a-persistent-disk}

Barn matches a kept disk to its node by name and disk definition. To reattach it after `recreate` or `destroy`, keep the node name, mount `path`, `size`, and `fs` unchanged; `fs: auto` matches whichever filesystem the disk already has. A mismatched definition is refused rather than resized, renamed, or converted.

Removing a persistent disk from a node's definition takes a whole-lab teardown: `recreate` refuses an inventory that drops an attached persistent disk, so run `barn destroy --delete-persistent --yes` or `barn purge` first. Disks kept from a node you removed stay on the host until one of those commands deletes them.

### When Barn resets a data disk {#when-barn-resets-a-data-disk}

> [!WARNING]
> **Data disks are test storage, `persistent: true` included.** Barn reformats a data disk when it finds the filesystem damaged. Keep anything valuable on the host.

Barn checks data disks when a VM first boots and whenever `barn up` (or `reload`, which runs it) finds a guest whose data disks are not mounted cleanly. `--no-wait` postpones the check to the next `barn up`.

| What Barn finds | What it does | Reported in |
|---|---|---|
| A blank disk with no signature | Formats it with `fs` | `nodes[].repairs`, unless this is the disk's first format |
| A healthy ext4 or XFS filesystem | Mounts it unchanged | — |
| An ext4 or XFS filesystem that will not mount, where `e2fsck -fn` or `xfs_repair -n` reports recognized corruption | Reformats it, erasing its contents | `nodes[].repairs` |
| A partition table, a signature without a filesystem UUID, another filesystem type, features the guest tools do not support, or a checker failure Barn does not recognize | Leaves the data alone | `nodes[].warnings` |
| A missing device, failed probe, busy mount, read-only device, or host I/O error | Leaves the data alone | `nodes[].warnings` |
{.wide .expand}

Root disks and host shares are never formatted. After fixing the cause of a warning, run `barn up` again to mount the disk. `barn up` exits `0` in all of these cases, so scripts should [check `repairs` and `warnings`](../automation/#validate-json-output-alongside-the-exit-code).

## Copy files over managed SSH {#copy-files-over-managed-ssh}

Export an OpenSSH configuration to use `ssh`, `scp`, or `rsync` directly:

```bash
barn ssh-config > barn-ssh.conf
ssh -F ./barn-ssh.conf meta hostname
scp -F ./barn-ssh.conf ./storage.yml meta:/tmp/storage.yml
scp -F ./barn-ssh.conf meta:/data/barn-retention.txt ./barn-retention.txt
```

The file points at the current loopback SSH port, the deployment key path, and a per-instance `known_hosts`; it does not contain the key itself. Export it again after you recreate a node or its loopback port changes, or run `barn ssh-config --install` so plain `ssh meta` and `scp` work without `-F`.

## Reach services inside the guest {#reach-services-inside-the-guest}

A service listening on the node's fixed IP, such as PostgreSQL on `10.10.10.10:5432`, is reachable from the host and from other nodes at that address, as long as the guest firewall allows it.

For a service bound to `127.0.0.1` inside the guest, forward a host port over SSH and connect host clients to `127.0.0.1:15432`; `Ctrl-C` closes the tunnel:

```bash
ssh -F ./barn-ssh.conf -N \
  -L 127.0.0.1:15432:127.0.0.1:5432 meta
```

Management SSH uses its own loopback port, so `barn ssh` and `-L` tunnels work even when the fixed-IP network reports a limitation. The inventory has no `vm_ports` or `vm_forwards` setting; use the fixed IP or a tunnel.

SSH aliases such as `ssh meta` only help OpenSSH tools. For browsers, `psql`, and other host programs to resolve node names and `vm_alias` entries, preview and then apply the `/etc/hosts` integration:

```bash
barn hosts install --json
barn hosts install --yes
```

`barn hosts install --yes` edits the host's `/etc/hosts`, using `sudo` when needed. Run it again after adding nodes or changing addresses.

## Share a host directory {#host-directory-sharing}

To edit code on the host and build it in the guest, mount a host directory with Virtio-9p (Linux and macOS hosts). Set `vm_shares` under `all.vars` or on a host before the first `barn up`:

```yaml {title="barn.yml"}
vm_shares:
  - host: ./src
    guest: /workspace
    readonly: true
```

`host` may be relative to the inventory's real location, start with `~/`, or be a directory symlink. The directory must exist, be accessible to you, and not overlap `BARN_HOME`; you don't need to own it. Several guests may write the same tree; coordinating those writes is up to you.

Host QEMU and the guest kernel must support 9p. If the guest user cannot write a writable share, Barn mounts it read-only with a warning and leaves host ownership alone. Changing shares on an existing node needs `barn recreate <node>`. The full schema is in [Shares](../../reference/configuration/#shares); macOS guests share folders with VirtioFS instead (see [macOS shared folders](../macos/#shared-folders)).
