I wanted the smallest possible way to run a macOS VM with an iPhone passed through
over USB, so Xcode in the guest could talk to a phone. macOS 27 added USB passthrough
to the Virtualization framework, so I built the supervisor and the Accessory Access
hand-over, and all of it worked right up to the last step: the framework rejects any
device with an isochronous endpoint in any of its USB configurations, and every
iPhone has one in its USB audio configuration. Apple does not allow it, full stop.
That dead end is written up in docs/USB-PASSTHROUGH.md for the next person who
hits the same wall.
What was left turned out to be useful on its own: a small Swift VM supervisor for Apple Silicon that runs macOS or Linux guests, with first-boot user provisioning for macOS and cloud-init for Linux. No third-party packages, guest agent, TCP control port, or runtime dependency beyond macOS frameworks. The daemon never spawns a command. The whole thing is small enough to read in one sitting, which was the point while debugging USB and is still the point now.
Why not Tart? Tart is the mature choice if you want OCI image distribution, CI integration and a large feature set. vmctl is for when you want a dependency-free supervisor you can audit in an afternoon.
VMs are named, mac by default. Linux guests run side by side, and alongside one
macOS guest; only one macOS guest runs or installs at a time. Each VM is sized at
create time, so how many fit is up to you and the host's memory.
Install
Requires an Apple Silicon Mac, macOS 13 or later, and Xcode or Command Line Tools with Swift and the macOS 27 SDK (Xcode 27+) to build. The daemon deliberately fails compilation for Intel.
With Homebrew, which builds from source and ad-hoc signs on your machine:
brew install raugustinus/vmctl/vmctl
From a checkout:
make
sudo make install # or: make install PREFIX="$HOME/.local"Without installing, run ./bin/vmctl in place of vmctl below.
make install also installs zsh completion as $(PREFIX)/share/zsh/site-functions/_vmctl.
zsh ships a _vmctl of its own, for OpenBSD's unrelated vmctl, and uses whichever it
finds first in $fpath. The Homebrew and /usr/local site-functions directories come
before zsh's own, so those installs just work. For PREFIX="$HOME/.local", add this to
~/.zshrc before compinit runs:
fpath=("$HOME/.local/share/zsh/site-functions" $fpath)
Then run rm -f ~/.zcompdump* once, because zsh caches which _vmctl it picked.
Use
Fastest path: a Debian cloud image, a key-only user created by cloud-init on first boot, SSH a few minutes later.
curl -LO https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-arm64.raw vmctl create lin --linux --image "$PWD/debian-13-genericcloud-arm64.raw" vmctl start lin --user dev --ssh-key ~/.ssh/id_ed25519.pub vmctl list # the IP column fills once the guest has a lease ssh dev@"$(vmctl ip lin)" vmctl stop lin
Installing from an arm64 ISO through a console window is under "Linux guests" below. A macOS guest needs a local Apple restore image and a long install:
vmctl create mac --restore /absolute/path/to/Apple.ipsw vmctl start mac vmctl status mac vmctl ip mac vmctl logs mac vmctl stop mac
make builds release binaries and ad-hoc signs them; SIGN_IDENTITY=... make uses a
Developer ID instead. make test runs the suite and make clean removes .build
and bin. make install copies both signed binaries into $(PREFIX)/bin
(default /usr/local; make uninstall removes them). Both also remove a vmctld left by builds before the rename. Keep vmctl and vmd next
to each other; a symlink to vmctl elsewhere is fine. The Makefile selects SwiftPM's native engine for
compatibility with older Swift tools and this environment (BUILD_SYSTEM= overrides
it); Swift 6.4 warns that this engine is deprecated. It disables release debug
symbols. No Homebrew, Go, Node, Python, or package downloads are used.
create requires a local Apple macOS restore IPSW, obtained separately. It
validates compatibility through Apple's restore-image APIs; it does not download
an image or invoke another VM tool. Installation is long-running. The client
waits, but closing the client does not cancel installation. status/logs can be
used independently during installation. Default resources are 4 CPUs, 8 GiB RAM,
and a sparse 64 GiB disk (or the restore image's higher minimum CPU/RAM values).
The host must have enough resources for configuration validation and installation.
First-boot user and SSH setup (macOS 27+)
Build this version with the macOS 27 SDK (Xcode 27+). Normal lifecycle commands
retain the macOS 13 deployment baseline; provisioning requires macOS 27+ on both
host and guest. Apple provides VZMacGuestProvisioningOptions for creating the
initial account and enabling SSH without a console window.
vmctl create dev --restore "$HOME/Downloads/UniversalMac_27.0_26A428_Restore.ipsw" vmctl start dev --user dev --full-name "Developer" # Enter and confirm the guest password at the hidden terminal prompts. vmctl ip dev ssh dev@GUEST_IP
Do not start this fresh VM without --user first. Apple only evaluates provisioning
on the first boot after restore. The manager records eligibility during creation
and consumes it before any start attempt, including ordinary start. After a
failed/crashed start the guest may already have booted, so provisioning is not
retried automatically. Recreate under another name if needed. Existing VMs from
older vmctl versions have unknown boot history and cannot use this operation.
This is initial setup, not an add-user or reset-password command for existing VMs.
--full-name defaults to the username. SSH is enabled and automatic login is
explicitly disabled. Passwords are read using readpassphrase on the controlling
terminal, confirmed, and sent only through the authenticated private Unix socket.
They are not accepted via flags, environment variables, or stdin and are never
written to config/logs. They necessarily exist briefly in process/framework memory;
Swift String copies cannot be guaranteed to be securely erased. The terminal input
buffer is cleared after reading. Failed provisioning API validation/start returns
generic errors to avoid reflecting credentials from framework error descriptions.
running still means VM start succeeded, not that guest user creation or SSH has
finished. Wait for guest setup before connecting. Xcode installation is
separate. Screen Sharing is not enabled automatically; use the optional local
console below to enable it in guest System Settings.
Upgrading an already running daemon
Replacing the binary does not replace the running process. First stop your active
VM with vmctl stop mac, then quit the daemon in Activity Monitor or with
pkill -TERM -x vmd. Builds before the rename call it vmctld.
The next CLI call starts the newly signed daemon. Do this before creating the
new VM, so its first-boot eligibility and guest version are recorded. Your existing
mac directory is preserved; use a new name such as dev for the new installation.
Builds replace executables atomically so an existing daemon keeps its original
executable. An old daemon rejects the distinct provisioning wire command rather
than silently starting a VM without account creation.
Apple reference: Guest provisioning.
Linux guests
Linux VMs use Apple's generic platform with EFI boot, a persisted
VZGenericMachineIdentifier, an EFI variable store, and virtio disk, network,
entropy and graphics devices. NAT, ip, console, stop, logs and list behave
as for macOS guests. Restart an older daemon before using these commands.
The cloud-image route is the quickstart above. The other route installs from an arm64 ISO through the local console window:
vmctl create deb --linux vmctl start deb --iso "$HOME/Downloads/debian-13.7.0-arm64-netinst.iso" vmctl console deb # install, create your user, tick "SSH server" vmctl start deb # boots from disk; --iso is per boot, never stored
create --linux prepares a sparse disk, or copies the raw image into it and extends
it to the disk size (cloud images grow their root filesystem on first boot). The copy
is an instant APFS clone on the same volume. The Linux disk defaults to 20 GiB;
--disk 40G (also 512M, 1T, or a bare number of GiB) picks another size between
1 GiB and 4 TiB, in whole MiB. The size is a ceiling the guest sees, not space taken: the file
is sparse and grows only with what the guest writes, which du -h on disk.img shows.
An image larger than the chosen disk is rejected. qcow2 images are rejected; convert
them elsewhere. Names containing amd64, x86_64 or i386 are refused, because only
arm64 guests boot here; an unbootable image otherwise shows up as running followed a
second later by a guest_powered_off log event. Image and ISO paths must be absolute
local regular files. Resources default to 4 CPUs and 8 GiB, clamped to the host's
allowed range; --cpus 1 --memory 512M (a bare memory number is GiB) picks others,
up to this host's core count and installed RAM. They are fixed at create time.
created means the disk is prepared, not that anything is installed.
If create --disk, --cpus or --memory reports daemon_upgrade_required, the running
daemon predates the flag and built the defaults; remove that VM directory, restart the
daemon and retry.
--iso attaches the installer as a read-only USB mass storage device for that boot
only. --user on a Linux VM writes a cloud-init NoCloud seed (cloud-init.img, a
FAT12 volume labelled CIDATA holding user-data, meta-data and a network-config
that makes the guest identify itself to DHCP by MAC, so vmctl ip can find it) and
attaches it read-only. The same first-boot rule as macOS provisioning applies, and it only has
an effect on images that run cloud-init, such as Debian, Ubuntu or Fedora cloud
images. For ISO installs, create the user in the installer instead. Only the
configured account is created, not the image's default user. It gets /bin/bash
and passwordless sudo.
With --ssh-key, which takes a public key line or the path of a .pub file, the
account is key-only: no password prompt, password login locked, SSH password
authentication disabled. Without it, the password is prompted as for macOS and SSH
password login is enabled. The seed holds the sha512-crypt hash of the password,
never the plaintext, and the public key. vmctl never reads, stores or forwards your
private keys; the only private key it makes is the guest's own SSH host key (see
below). docs/AGENT-ACCESS.md explains how that fits an AI-agent workflow.
--ssh-key and --iso are rejected for macOS VMs; --restore for Linux VMs.
The seed also generates your Mac's locale in the guest (from LC_ALL, LC_CTYPE or
LANG, when it is a plain UTF-8 locale such as en_US.UTF-8). macOS's ssh sends
those variables, so without it every login warns cannot change locale. It is done
with locale-gen from runcmd, not cloud-init's locale: key, which fails the
whole cloud-init run on Debian.
Graceful stop sends an ACPI power-button event; a guest that ignores it is forced
off after 30 seconds. Rosetta and nested virtualization are not configured.
Share a project directory
vmctl create proj --linux --image "$PWD/debian-13-genericcloud-arm64.raw" \ --cpus 2 --memory 4G --disk 10G --share ~/code/myproject vmctl start proj --user dev --ssh-key ~/.ssh/vm-proj.pub ssh dev@"$(vmctl ip proj)" # ~/myproject is the host directory, live
--share DIR attaches one host directory over virtiofs at every boot; DIR:ro makes
it read-only for the guest. With start --user, cloud-init mounts it at
~<user>/<directory name> through an /etc/fstab entry (nofail, so a boot never
waits on it), and gives the account your Mac's UID. virtiofs shows host owners'
UIDs unchanged, so files in the share belong to the guest user and files the guest
creates belong to you on the Mac. Without --user, mount it yourself:
sudo mount -t virtiofs vmctl /mnt.
The guest can read, change and delete everything in the shared directory, and
nothing outside it. That is the point for an agent working on one project, and also
the risk: commit or back up before letting anything loose in a read-write share. /
and your home directory are refused. The share is fixed at create time and checked
at every start, so a moved or deleted project directory makes start fail with
invalid_share instead of booting without it. VMs created before --share have no
share; create a new one, which takes seconds from the APFS-cloned image.
Mount a guest directory on the Mac
The reverse of --share: the files live on the guest's disk, the guest sees nothing of
the Mac, and the Mac reads and writes them, for an editor or IDE that runs here.
vmctl mount proj /home/dev/src/project # on ~/vm/proj/project vmctl mount proj /home/dev/src/project ~/code/project-vm vmctl mount proj # what is mounted vmctl umount proj [<mount-point>] [--force] # unmount and forget
It needs a running Linux VM started with --user. The first time, vmctl sets the guest
up over SSH as that account (which has passwordless sudo): it installs the NFS server
where it is missing and apt-get exists, and exports that one directory to the address
this Mac has on the VM network, and to no other. Every access from the Mac is mapped to
the account, so files written here belong to it in the guest. On the Mac the directory
is mounted with NFSv3 from an unprivileged port, so no sudo is needed; soft,intr
makes a guest that is gone an error instead of a hang, and nothing in it is trusted as a
device or a setuid program.
vmctl stop and vmctl rm unmount first, forcibly: a mount whose server is gone makes
every program that looks at it wait. vmctl start mounts again what was mounted, also
when the guest came back with another address. umount removes the export in the guest
when it can be reached.
Things a network mount does not do: file-change events do not reach the Mac, so an IDE
sees what was changed inside the guest when it refreshes; and git refuses a repository
whose files belong to another user until you allow it (vmctl mount prints the line).
Guest paths are limited to letters, digits, ., _, - and /.
Reach VMs by name with ssh and git
Provisioning a Linux VM (start --user) adds a Host <name>.vm block to
~/.vmctl/ssh_config, and rm removes it. vmctl never reads or edits ~/.ssh/config;
add this line yourself, at the top, before any Host block:
Include ~/.vmctl/ssh_configThen:
ssh proj.vm
git remote add vm proj.vm:myproject && git push vm mainThe block sets the user, a ProxyCommand that looks up the VM's current address
with vmctl ip, StrictHostKeyChecking yes against a per-VM known_hosts file,
ForwardAgent no, and IdentitiesOnly yes with the private key next to the
--ssh-key .pub file. vmctl makes the guest's host key on the Mac and installs it
through cloud-init, so the first connection is already verified.
After every provisioning, vmctl runs ssh -G proj.vm to check whether the Include
is in effect. It says so if it isn't, and warns if an earlier block in your
config (such as Host *) turns agent forwarding back on. VMs provisioned before
this feature, and macOS guests, have no pinned key; vmctl ssh-config <vm> --user dev --host-key <file> adds one. Run vmctl help ssh-config for details.
Resolve <name>.vm everywhere (optional)
The ssh_config entries only help ssh. For curl proj.vm:8080, a browser, or one
guest reaching another, vmd also answers DNS for the vm zone: <name>.vm resolves to
a running VM's address, the one vmctl ip reports, with a 5-second TTL. It listens on
127.0.0.1:15353 (UDP) only, answers nothing outside vm, and needs no setup inside vmctl.
Something on port 53 has to forward to it; with Homebrew's dnsmasq:
# /opt/homebrew/etc/dnsmasq.d/vm.conf
server=/vm/127.0.0.1#15353Host lookups then need one resolver file (sudo once):
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolver/vm
Guests use the NAT gateway (192.168.64.1) for DNS by default, and that is macOS's own
DNS proxy, not dnsmasq. To send them to dnsmasq instead, give dnsmasq an address
that always exists, a loopback alias, and provision with --dns:
vmctl start proj --user dev --ssh-key ~/.ssh/vm-proj.pub --dns 10.254.254.254--dns sets that one server through cloud-init's network config and turns off the
servers DHCP and IPv6 router advertisements name. Guests reach a loopback alias through
the NAT, so dnsmasq never listens on your LAN.
Why an alias, not 192.168.64.1: the bridge and its address exist only while a VM
runs. dnsmasq on macOS cannot bind an address or interface that appears after it
starts (bind-dynamic and hostsdir reloading need Linux), and in wildcard mode it
contends with mDNSResponder, which holds *:53 while Internet Sharing is on. A
LaunchDaemon that adds the alias at boot and then restarts dnsmasq:
<!-- /Library/LaunchDaemons/local.lo0-alias.plist, root:wheel 644 --> <plist version="1.0"><dict> <key>Label</key><string>local.lo0-alias</string> <key>ProgramArguments</key><array> <string>/bin/sh</string><string>-c</string> <string>/sbin/ifconfig lo0 alias 10.254.254.254/32 && /bin/launchctl kickstart -k system/sh.brew.dnsmasq</string> </array> <key>RunAtLoad</key><true/> </dict></plist>
with interface=lo0 and bind-interfaces in dnsmasq.conf.
Guest console log
Every Linux VM has a virtio console (hvc0). The guest's output reaches the Mac
through it rather than through the guest's disk, so it keeps arriving after the guest
can no longer read or write its own disk, or when SSH is down:
vmctl logs proj --console # the last ~24 KB vmctl logs proj --console --follow # and everything after it
Provisioning with --user sets the guest up to use it. GRUB gets console=tty0 console=hvc0, for kernel messages (disk and filesystem errors among them), boot
status and the emergency shell's output, and cloud-init reboots the guest once at the
end of the first boot to apply it; the VM stays running throughout. Journal entries
at warning and above are forwarded too. Routine service output, logged at info, is
not: a service whose disk has failed can retry thousands of times a second. Without
--user you only see what the image itself writes there. The output is
guest-controlled text: vmctl shows control characters as ^X and drops colour codes,
so a guest cannot send escape sequences to your terminal.
It is kept in logs/console.log, in files of up to 8 MiB. When a run's first file
fills up it becomes console.start.log and is kept until the next run's first file
replaces it, so the start of a run, often the first error, survives any amount of
output after it. Later files rotate through console.log.1.
Direct kernel boot
--kernel skips EFI and boots a Linux kernel directly, microVM style:
vmctl create tiny --linux --kernel "$PWD/Image" --initrd "$PWD/initrd" \ --image "$PWD/rootfs.ext4" --cpus 1 --memory 512M vmctl start tiny # returns in about a tenth of a second vmctl logs tiny --console --follow
The kernel must be an uncompressed arm64 Image. Virtualization does not decompress
kernels, so gzip vmlinuz files (gunzip -c vmlinuz > Image) and EFI zboot images
(Alpine, recent Ubuntu) are refused at create time with a hint. The kernel and initrd
are copied into the VM directory, so the VM does not depend on the originals. The
default command line is console=hvc0 root=/dev/vda rw, for an unpartitioned root
filesystem on the disk; pass --cmdline to replace it entirely, for example
root=/dev/vda1 for a partitioned cloud image. A cloud-init seed from --user
appears as /dev/vdb.
A kernel-boot VM has no firmware, display, keyboard or pointer: only virtio disk,
network, entropy and the virtio console (hvc0), read with vmctl logs <name> --console. console and --iso are refused. The boot mode, kernel and command
line are fixed at create time.
Design notes
Architecture and lifecycle, storage and security, the Apple APIs used, and the
validation record are in docs/DESIGN.md and docs/VALIDATION.md.
List saved VMs
vmctl list # NAME STATE IP # dev running 192.168.64.3 # mac stopped -
Names are sorted alphabetically. States come from the supervisor, just like
status; listing never opens config files or disk images. The IP column is the
same best-effort NAT lease lookup as ip, using the MAC the supervisor kept in
memory when it started the VM; it shows - for every VM that is not running and
for a running VM with no readable unexpired lease yet. An empty store prints
only the header. Only private, user-owned VM directories with valid names are
listed; symlinks and unrelated entries are ignored. A saved directory can represent
an incomplete installation, so stopped does not imply it is bootable.
list takes no arguments. Restart an older daemon to enable this new command.
Open a local console and enable Screen Sharing
After upgrading, stop the active VM and quit the old daemon (vmd, or vmctld in older builds) in Activity
Monitor. Run the updated binaries from Terminal in your logged-in desktop session.
Restarting the VM supplies the new virtual keyboard and mouse devices. Do not
repeat --user for an already-booted VM.
vmctl start dev vmctl console dev
console requires the named VM to be running. It opens (or brings forward) one
native window displaying the existing daemon-owned VZVirtualMachine. It never
opens a second disk attachment, transfers VM ownership, or launches a second VM.
The CLI returns after requesting the window. Clicking inside it sends keyboard
and pointer input to the guest; host system shortcuts remain available. The
initial display uses the host screen’s pixel density for a 1024×768-point window.
On macOS 14+, Apple’s automatic display reconfiguration updates the guest display
as the window resizes or moves between screens. On macOS 13, the initial display
configuration remains fixed. Without a host screen, the fallback is 2048×1536
pixels at 160 PPI. Guest-supported display modes can still affect effective scaling.
The console window uses an explicit sRGB color space as an SDR baseline; AppKit
handles output conversion to the host display. HDR/wide-gamut fidelity is not a
console feature. The visual result still depends on the guest display profile.
Closing the window leaves the VM and daemon running. Calling console again
reopens it. Guest shutdown/error closes the view and releases its VM reference.
Quitting the daemon through its Dock icon uses the existing graceful/forced
shutdown sequence. A daemon started without a desktop session can still manage
VMs headlessly, but it cannot show a console; restart it in a desktop Terminal.
No additional entitlements, TCP listeners, clipboard bridge or guest agent are added.
In the guest, open System Settings → General → Sharing. Turn off Remote Management if enabled, turn on Screen Sharing, and allow your guest account. You can also complete Setup Assistant through this console on an older installation. Then, on the host, connect using:
open "vnc://$(vmctl ip dev)"After confirming the remote connection works, close the local console window. Apple's guide: Turn Mac screen sharing on or off.
Shutdown completion and immediate power-off
Normal stop keeps a 30-second graceful-shutdown deadline. In addition to Apple's
guest-stop delegate callback, the daemon checks VZVirtualMachine.state every
100 ms while waiting and completes as soon as it observes .stopped. Every control
request also reconciles a running/stopping VM against the live framework state.
No disk inspection or IP/ping timeout is used to decide that the VM is off.
Already-stopped state wins over the timeout, and cancelled timers cannot act on a
replacement VM. Multiple stop callers share the same shutdown operation.
If the guest does not shut down in response to the request, normal stop still waits for the grace period. For intentional immediate power-off instead:
This bypasses graceful shutdown and can lose unsaved guest data. It also escalates an already-pending graceful stop; duplicate forced-stop requests do not start multiple framework stop operations. The CLI still waits for confirmed termination. An older running daemon must be restarted to understand this option.
USB passthrough
Not in the shipping daemon. The attempt, what worked, and the Apple restriction that
ends it are in docs/USB-PASSTHROUGH.md; the retired code is under
experiments/usb-passthrough/. Normal lifecycle and console operation use vmd
directly and require no USB provisioning profile.
Repository layout
Package.swift, Sources/, Tests/ # the SwiftPM package
Makefile, vmd.entitlements # release build/test targets and daemon entitlements
completions/_vmctl # zsh completion, installed by make install
bin/ # signed binaries produced by make (gitignored)
docs/DESIGN.md # architecture, storage, security, Apple APIs used
docs/VALIDATION.md # record of what was tested and when
docs/AGENT-ACCESS.md # giving an AI agent SSH access without the private key
docs/USB-PASSTHROUGH.md # the iPhone passthrough attempt and why Apple blocks it
experiments/ # retired USB passthrough code and a console smoke test
LICENSE # BSD 3-Clause
License
BSD 3-Clause. See LICENSE.