sodcalculator

10 Tech How-To

macOS Beta in Apple Virtualization Framework: How-To

Guide 10-30085 · Updated · Step by step

This guide shows you how to run a macOS beta (like the latest developer or public beta) inside Apple’s Virtualization Framework, using a Swift script and a restore image from Apple. You’ll end up with a bootable virtual machine on your Mac that runs the beta alongside your current system—ideal for testing apps or exploring new features without risking your main setup. You’ll need a Mac with Apple silicon (M1 or newer) or an Intel Mac with supported hardware, Xcode installed, and Apple’s macOS restore image (IPSW) file.

What You’ll Need

  • A Mac with Apple silicon (M1, M2, M3, etc.) or an Intel Mac with VT-x support (most 2010+ models).
  • macOS 12.0 or later (the Virtualization framework is available from macOS 11, but the latest APIs are easier on 12+).
  • Xcode installed (from the Mac App Store) to compile the Swift script.
  • Apple’s macOS beta restore image (IPSW) file—download from Apple’s developer site or the public beta site. Make sure it matches the beta you want (e.g., macOS Sequoia beta).
  • At least 20 GB of free disk space (the VM disk image plus the IPSW).
  • Basic comfort with Terminal and Swift scripting.

Step-by-Step

  1. Download the macOS beta IPSW. Go to Apple’s developer downloads (developer.apple.com/download) or the Apple Beta Software Program site (beta.apple.com), sign in, and download the latest macOS beta restore image for your Mac’s architecture (Apple silicon vs Intel). Save it to a known folder, e.g., ~/Downloads.
  2. Create a working directory. Open Terminal and run: mkdir ~/macos-vm && cd ~/macos-vm. This keeps all VM files in one place.
  3. Write the Swift script. Create a file named main.swift with a text editor (e.g., nano main.swift). The script will use the Virtualization framework to create a VM, attach the IPSW as a restore image, and boot it. Below is a minimal working example (for macOS 12+ on Apple silicon). You’ll need to adjust the paths to match your IPSW and disk image.
  4. Compile the script. Run swiftc -o macos-vm main.swift -framework Virtualization. This produces an executable named macos-vm. If you get errors, ensure you’re running a recent macOS and Xcode command-line tools are installed (xcode-select --install).
  5. Run the VM installer. Execute ./macos-vm. The script will create a virtual machine, load the IPSW, and boot into the macOS installer. Follow the on-screen prompts to install the beta onto the virtual disk (which is a file on your Mac, not your real drive).
  6. After installation, reboot the VM. The script should automatically restart the VM into the installed beta. If not, run the script again—it will detect the existing disk and boot directly.
  7. Use the beta. Once booted, you can interact with the beta as you would with any macOS. To stop the VM, just shut down from the Apple menu, or press Ctrl+C in Terminal (if the script is in the foreground).

Here’s a sample main.swift that works for Apple silicon (adjust the paths):

import Virtualization
import Foundation

let vm = VZVirtualMachine()
let bootLoader = VZMacOSBootLoader()
let config = VZVirtualMachineConfiguration()

// CPU and memory
let cpu = VZVirtualMachineConfiguration()
cpu.cpuCount = 4
cpu.memorySize = 4 * 1024 * 1024 * 1024 // 4 GB

// Create a 40 GB disk image
let diskPath = "disk.img"
if !FileManager.default.fileExists(atPath: diskPath) {
    FileManager.default.createFile(atPath: diskPath, contents: nil)
}
let disk = try VZDiskImageStorageDeviceAttachment(url: URL(fileURLWithPath: diskPath), readOnly: false)
let storage = VZVirtioBlockDeviceConfiguration(attachment: disk)

// Attach the IPSW as a restore image
let restoreImageURL = URL(fileURLWithPath: "/path/to/YourBeta.ipsw")
let restoreImage = try VZMacOSRestoreImage(url: restoreImageURL)
let configuration = VZMacOSVirtualMachineConfiguration()
configuration.bootLoader = bootLoader
configuration.cpuCount = cpu.cpuCount
configuration.memorySize = cpu.memorySize
configuration.storageDevices = [storage]
configuration.restoreImage = restoreImage

// Create and start the VM
try vm.start() { result in
    switch result {
    case .success:
        print("VM started")
    case .failure(let error):
        print("Failed to start: \(error)")
    }
}
RunLoop.main.run()

This is a simplified version—you’ll need to add more setup for network, display, and input. For a complete, working example, refer to Apple’s official Virtualization framework documentation and sample code (search for “VZMacOSVirtualMachineConfiguration” in Xcode’s documentation).

Common Mistakes

  • Using the wrong IPSW. Apple silicon Macs need a different IPSW than Intel Macs. Check the file name or use the correct download link.
  • Not enough disk space. The IPSW is several GB, and the disk image grows over time. Ensure you have at least 20 GB free.
  • Forgetting to set the restore image. If you skip the restore image, the VM won’t know how to install macOS. Always attach the IPSW.
  • Compilation errors. The Virtualization framework is only available on macOS 11+. If you’re on an older macOS, update first. Also, ensure you use swiftc with the framework flag.
  • Running the VM on unsupported hardware. The Virtualization framework requires hardware virtualization support. On Intel Macs, it must be enabled in System Settings > Boot Camp or via the firmware. Most modern Macs have it on by default.

Tips

  • Use a separate disk image for each beta. That way, you can test multiple betas without interference.
  • Allocate enough memory. Give the VM at least 4 GB of RAM, preferably 8 GB if your Mac can spare it.
  • Enable network and display. For a usable VM, you’ll need to add a network device (VZNATNetworkDeviceAttachment) and a graphics device (VZMacGraphicsDeviceConfiguration). See Apple’s sample code.
  • Keep the IPSW after installation. You can delete it to save space, but you’ll need to re-download it if you want to reinstall.
  • Use a snapshot. The Virtualization framework supports snapshots (VZSnapshot) to save the VM state—great for testing risky changes.

Troubleshooting

  • VM won’t boot. Check that the IPSW is compatible with your Mac’s architecture. Also, ensure the disk image has enough space (create it with a size larger than the minimum required). If you see a “Restore image is not supported” error, re-download the IPSW.
  • Compilation fails with “module not found”. Make sure you’re using the correct SDK. Run xcrun --sdk macosx --show-sdk-path and add -sdk $(xcrun --show-sdk-path) to the swiftc command.
  • VM is extremely slow. Reduce the CPU count or memory allocation, or close other apps. Also, ensure your Mac is plugged in (power management can throttle performance).
  • No display output. You need to attach a graphics device. Add let graphics = VZMacGraphicsDeviceConfiguration() and set its resolution, then add it to the configuration.
  • Network not working. Add a network attachment: let network = VZNATNetworkDeviceAttachment() and add it to the configuration. Ensure your Mac has an active internet connection.
  • “Cannot start VM because the host doesn’t support virtualization.” This is rare on Apple silicon, but on Intel Macs, check that VT-x is enabled in the BIOS (or via System Settings > Startup Disk > Firmware Password, but that’s different). Also, ensure you’re not running inside another VM (nested virtualization is not supported).

Frequently Asked Questions

Can I run the beta without Xcode?

Yes, but you need to compile the Swift script. You can use the Swift compiler from the Command Line Tools, which you can install with xcode-select --install—that doesn’t require the full Xcode app.

Is this legal and safe?

Yes, Apple’s Virtualization framework is designed for this purpose. You’re using Apple’s own tools and a legitimate beta IPSW. Just follow the beta agreement terms (don’t install on your primary machine unless you’re prepared for bugs).

Can I install the beta on an Intel Mac?

Yes, but the Virtualization framework on Intel Macs has some limitations (e.g., no hardware acceleration for graphics). It works but may be slower. The process is similar, but the IPSW is different.

Will my existing apps work in the VM?

Most apps will work, but some may not be compatible with the beta OS. That’s the point of testing—you can check compatibility before upgrading your main Mac.

Can I use the VM to test iOS apps?

Yes, you can run the Simulator inside the VM, but it will be slower. For better performance, run the Simulator on your host Mac and just test the beta features of macOS.

How do I update the beta in the VM?

You can update through System Settings > Software Update within the VM, just like a real Mac. However, you may need to re-download the IPSW if the update fails.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →