macOS Virtual Machines
11 minute read
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
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
On a Mac with no prepared base, Barn 1.4.0 selects macOS 27.2.1 (26B131) and asks before downloading it:
After you confirm, Barn:
- Downloads the restore image from Apple (
updates.cdn-apple.com), resuming any partial transfer and checking Apple’s published SHA-256. - Installs macOS once into an unbooted base image. The install uses one of the two VM slots while it runs.
- Clones
mac1from the base with APFS copy-on-write, boots it, creates your account, and waits until SSH and passwordlesssudowork.
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:
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
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:
The full schema is in the Mac reference.
Desktop
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 item | Action |
|---|---|
| Machine → Share Clipboard | Toggle 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 Background | Hide 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:
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>:
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:
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:
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.
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 --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:
Stop the VM before changing CPUs, memory, shared folders, or subnet (clipboard sharing can change while it runs):
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.
| Operation | Guest disk and installed apps | Hardware settings, IP, and account |
|---|---|---|
stop / start, restart, repeated up | Kept | Kept |
configure | Kept | Updated as requested |
recreate | Replaced with a fresh macOS clone | Kept; new login password and SSH keys |
destroy | Deleted | Deleted; the base image stays |
macOS versions and disk space
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:
Clean up
Destroying the last Mac VM removes its ~/.ssh/config entries and keeps the default base image. To remove all Mac VM state:
- Destroy every Mac VM (
barn mac destroy ...) and runbarn mac ssh-config --remove. - Delete
$BARN_HOME/mac(default~/.barn/mac). - Optionally delete
~/Library/Preferences/com.pgsty.barn.plist(io.pgsty.barn.mac-runner.plistin0.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.
| Symptom | Fix |
|---|---|
dev and mac1 are running; macOS allows 2 macOS virtual machines at a time | Run the suggested barn mac stop NAME, or quit another tool’s macOS VM. See Requirements. |
preparing macOS needs … GiB free on this volume | Free space, or run barn mac image prune --installers --yes. |
… has a 200 GiB disk, but macOS … is prepared only at 100 GiB | Run the printed barn mac setup --disk 200G, then barn mac recreate NAME --update. |
network … overlaps route … on start | A 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 host | Allow 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_protocol | The 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 session | Run 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.