Skip to content

macOS Virtual Machines

Run macOS 27 virtual machines on Apple Silicon with barn mac — create, connect, share files and the clipboard, and clean up.

Use barn mac when you need a clean macOS machine to build, test, or reproduce a macOS-specific bug, and want to throw it away afterwards. Each VM gets an administrator account with passwordless sudo, SSH with pinned keys, a desktop window, shared host folders, and clipboard sharing. VMs run under your own user account through Apple’s Virtualization framework, so nothing needs sudo.

Mac VMs are separate from the Linux lab: they don’t read barn.yml, their state lives in $BARN_HOME/mac (default ~/.barn/mac), and Linux barn destroy or barn purge never touches them.

Requirements

  • An Apple Silicon Mac running macOS 27 or later, with a logged-in desktop session. Guests also run macOS 27.
  • About 65 GiB of free disk space for the first VM: the IPSW download (23.8 GiB for macOS 27.2.1) plus 40 GiB that Barn requires for the restore. Each VM is an APFS clone of the base image and uses more space as the guest writes to disk. The first base defaults to 100 GiB of capacity.
  • Barn.app, the native app bundle that runs the VMs, from the same release as the CLI. Homebrew and the Apple Silicon release archive include it.

Apple’s Virtualization framework runs at most two macOS VMs at a time on one Mac, counting VMs from every virtualization tool and an in-progress base-image install. You can keep more stopped VMs on disk and start any two of them, subject to the Apple software license.

Install

brew install pgsty/infra/barn
barn version
barn mac doctor

Homebrew installs the signed, notarized Barn.app together with the matching CLI and helper; you don’t need Go or Xcode. The installer and manual archive include the app on Apple Silicon too. Stop running Mac VMs before upgrading or replacing the app.

To develop Barn itself, see Build the Mac component.

Create your first machine

barn mac up

On a Mac with no prepared base, Barn 1.4.0 selects macOS 27.2.1 (26B131) and asks before downloading it:

info: macOS 27.2.1 (26B131) is not prepared on this Mac yet.
download:  23.8 GiB from Apple (updates.cdn-apple.com)
then:      install macOS once into a reusable base (about 20 minutes)
free:      551.2 GiB
Download macOS from Apple now? [Y/n]

After you confirm, Barn:

  1. Downloads the restore image from Apple (updates.cdn-apple.com), resuming any partial transfer and checking Apple’s published SHA-256.
  2. Installs macOS once into an unbooted base image. The install uses one of the two VM slots while it runs.
  3. Clones mac1 from the base with APFS copy-on-write, boots it, creates your account, and waits until SSH and passwordless sudo work.
NAME  ADDRESS      STATE    MESSAGE
mac1  10.10.20.10  running  created and ready; macOS 27.2.1 (26B131), user alice
ready: barn mac ssh mac1
desktop: barn mac open mac1

Later VMs clone the same base in seconds. If an earlier release prepared this Mac, run barn mac image update to prepare 27.2.1 for new VMs; existing VMs keep their current base.

If you already have Apple’s restore image, pass it with --ipsw to skip the download. On the same APFS volume Barn clones the file instead of copying it:

barn mac up --ipsw ~/Downloads/UniversalMac_27.2.1_26B131_Restore.ipsw

In scripts, pass --yes to allow the download, or run barn mac setup beforehand to prepare the base without creating a VM. A new VM started with --no-wait returns as soon as its process runs; run barn mac up NAME without --no-wait to finish SSH and sudo setup before using ssh or exec.

Work in the machine

Shell and commands

barn mac ssh                                  # interactive shell
barn mac exec -- sw_vers                      # run one program
barn mac ssh -- 'id; sudo -n true && echo sudo works'
ProductName:		macOS
ProductVersion:		27.2.1
BuildVersion:		26B131

The guest administrator account has your host username unless you set --user at creation. Put -- before the remote command. ssh passes a command string to the guest shell; exec runs the program with its arguments directly, so wrap pipelines and redirection in sh -c (see the SSH/exec contract). Both return the remote exit status, and --json captures stdout, stderr, and exit_code:

barn --json mac exec -- sh -c 'echo out; exit 3'
{
  "command": "exec",
  "node": "mac1",
  "host": "10.10.20.10",
  "arguments": ["sh", "-c", "echo out; exit 3"],
  "success": false,
  "exit_code": 3,
  "stdout": "out\n"
}

The full schema is in the Mac reference.

Desktop

barn mac open

barn mac open shows the guest desktop in a native window; the guest display follows the window size (View → Enter Full Screen for full screen). Closing the window leaves the VM running. Run barn mac open again to reopen it, or to boot a stopped VM and show its display.

While the guest window has focus, keyboard shortcuts go to the guest, so use the menu bar for host actions:

Menu itemAction
Machine → Share ClipboardToggle plain-text clipboard sync for this session
Machine → Restart…Restart macOS inside the guest
Machine → Shut Down…Shut the guest down cleanly (same as barn mac stop)
Window → Keep Running in BackgroundHide the window and keep the VM running
Barn → Quit Barn…Choose whether to keep the VM running in the background or shut it down

When you log out of or shut down the host, Barn asks the guest to shut down and powers it off if it misses the timeout.

Each VM has a random password for the lock screen and GUI administrator prompts. Copy it to the host clipboard without printing it:

barn mac password --copy

Clipboard

Clipboard sharing moves plain text over the VM’s SSH channel, so the guest needs no extra agent. Focusing the guest window brings in text copied on the host; switching back to a host app brings out text copied in the guest. Password-manager items marked concealed, images, and files are never transferred.

To turn clipboard sharing off for a VM from its next start, run barn mac configure mac1 --clipboard off.

Shared folders

Pass --share when creating a VM to mount host directories in the guest under /Volumes/My Shared Files/<name>:

barn mac up dev --cpu 8 --memory 16G --share ~/src --share docs=~/Documents:ro
barn mac exec dev -- ls "/Volumes/My Shared Files"

The share name defaults to the directory’s basename; append :ro for read-only. Each path must resolve to an existing directory (symlinks are fine), and Barn never creates or deletes the host directory. To change shares on an existing VM, stop it and use configure:

barn mac stop dev
barn mac configure dev --share data=/Volumes/Work/data --unshare docs
barn mac start dev

VirtioFS in macOS guests can briefly serve cached contents after a host-side edit. When a build needs the exact bytes immediately, copy files onto the guest disk with scp or rsync.

SSH from other tools

When the first Mac VM becomes ready, Barn adds a marked Include line to ~/.ssh/config, so ssh mac1, scp, rsync, and IDE Remote-SSH work with each VM’s own key and pinned host key:

ssh mac1 'uptime'
rsync -a ./project/ mac1:project/
barn mac ssh-config              # print the generated entries
barn mac ssh-config --remove     # remove Barn's Include and stop re-adding it
barn mac ssh-config --install    # add it back

If ~/.ssh/config is a symlink managed by a dotfile tool, Barn leaves it alone and prints the Include line for you to add. If your own config already has a Host alias with a VM’s name, Barn keeps yours and writes its entry by IP address only.

Multiple machines

VM names are lowercase letters and digits, start with a letter, and may contain inner hyphens. Creation flags (--cpu, --memory, --disk, --user, --share) apply when creating a VM. CPU and memory default to 4 vCPUs and 8 GiB. Without --disk, the VM inherits the default base’s capacity, or uses 100 GiB for the first base.

barn mac up dev --cpu 8 --memory 16G
barn mac ls
NAME  ADDRESS      STATE    SSH    USER   OS            CPU  MEMORY  DISK                 SHARED
dev   10.10.21.10  running  ready  alice  macOS 27.2.1  8    16 GiB  504.0 MiB / 100 GiB  src,data
mac1  10.10.20.10  running  ready  alice  macOS 27.2.1  4    8 GiB   4.7 GiB / 100 GiB
limit: 2 of 2 macOS VMs are running; stop one before starting another

Without a name, commands act on the only VM, or on mac1; when several exist, Barn asks you to name one. A --disk size different from the prepared base’s capacity makes Barn install a new base at that size first.

Each VM gets its own private /24, starting at 10.10.20.0/24 with the guest at .10. Barn skips subnets that overlap your LAN, VPNs, the Linux lab, or other Mac VMs.

Everyday lifecycle

barn mac stop dev               # clean shutdown; powers off after 2 minutes
barn mac start dev              # boot and wait for SSH
barn mac restart dev            # stop and start, applying pending configure changes
barn mac stop --all             # stop every running Mac VM

barn mac stop --force powers off at once; barn mac start --recovery boots macOS Recovery with the desktop window open.

barn mac up never changes an existing VM. Passing a different creation flag points you to configure:

error: dev already exists, so --cpu would not apply; its configuration and data were preserved
next: barn mac configure dev --cpu 4

Stop the VM before changing CPUs, memory, shared folders, or subnet (clipboard sharing can change while it runs):

barn mac stop dev
barn mac configure dev --cpu 6 --memory 12G --subnet auto
barn mac start dev

barn mac recreate replaces the disk with a fresh clone of the base and keeps the name, account, hardware settings, shares, and IP. barn mac destroy deletes the VM. Both ask for typed confirmation on a terminal; pass --yes in scripts.

barn mac recreate dev
barn mac destroy dev
OperationGuest disk and installed appsHardware settings, IP, and account
stop / start, restart, repeated upKeptKept
configureKeptUpdated as requested
recreateReplaced with a fresh macOS cloneKept; new login password and SSH keys
destroyDeletedDeleted; the base image stays

macOS versions and disk space

barn mac image ls
KIND           OS            BUILD   STATE  ON DISK   CAPACITY  USED BY
base           macOS 27.0    26A428  ready  26.7 GiB  100 GiB   mac1
base           macOS 27.2.1  26B131  ready  25.6 GiB  100 GiB   default
restore image  macOS 27.0    26A428  ready  24.8 GiB  -
restore image  macOS 27.2.1  26B131  ready  23.8 GiB  -

APFS clones share blocks with their base, so ON DISK and the per-VM disk figures overlap and don’t add up.

barn mac image update prepares the newest macOS 27 build Barn supports and makes it the default for new VMs. Existing VMs keep their disks and bases. To move a VM to the new base, back up its files and run barn mac recreate NAME --update. For a VM with a custom disk size such as 200G, first prepare a base of that size with barn mac setup --disk 200G.

barn mac image prune lists base images that no VM uses and aren’t the default; --installers adds downloaded .ipsw files, and --yes deletes them:

barn mac image prune --installers         # preview
barn mac image prune --installers --yes   # delete

Clean up

barn mac ls                                 # list Mac VMs
barn mac destroy mac1 dev                   # delete selected VMs
barn mac image prune --installers --yes     # delete cached IPSWs and unused bases

Destroying the last Mac VM removes its ~/.ssh/config entries and keeps the default base image. To remove all Mac VM state:

  1. Destroy every Mac VM (barn mac destroy ...) and run barn mac ssh-config --remove.
  2. Delete $BARN_HOME/mac (default ~/.barn/mac).
  3. Optionally delete ~/Library/Preferences/com.pgsty.barn.plist (io.pgsty.barn.mac-runner.plist in 0.9.0), which stores the desktop window geometry.

Troubleshooting

Start with barn mac doctor. It checks the host, Barn.app, base images, free space, and every VM, and exits 3 if any check fails. barn mac logs [name] shows startup, network, and Virtualization framework logs.

SymptomFix
dev and mac1 are running; macOS allows 2 macOS virtual machines at a timeRun the suggested barn mac stop NAME, or quit another tool’s macOS VM. See Requirements.
preparing macOS needs … GiB free on this volumeFree space, or run barn mac image prune --installers --yes.
… has a 200 GiB disk, but macOS … is prepared only at 100 GiBRun the printed barn mac setup --disk 200G, then barn mac recreate NAME --update.
network … overlaps route … on startA VPN or new route now covers the VM’s subnet. Run barn mac configure NAME --subnet auto.
ssh mac1 from another SSH client fails with No route to hostAllow your terminal or IDE in System Settings → Privacy & Security → Local Network, or use /usr/bin/ssh (barn mac ssh and exec use it).
mac_runner_missing or mac_runner_protocolThe CLI and Barn.app come from different builds. Reinstall Barn so they match; for a source build, use the bin/mac/barn from one make mac-build.
Starting a VM fails from a remote SSH sessionRun barn mac in a terminal on the Mac’s logged-in desktop session, with the login keychain unlocked.

Every error reason and exit code is listed in the Mac reference.

Apple Account sign-in is unreliable in macOS guests under Apple’s Virtualization framework. USB passthrough, snapshots, and suspend/resume aren’t supported.

Table reader