Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Apple Extends macOS Virtualization Capabilities and Introduces Rosetta for Linux Binaries

Apple Extends macOS Virtualization Capabilities and Introduces Rosetta for Linux Binaries

This item in japanese


At WWDC 2022, Apple showcased its latest advancement in virtualization support on macOS. Apple Virtualization Framework enables configuring and creating virtual machines on Apple Silicon to run macOS or Linux. New in the upcoming macOS Ventura, Linux VMs can leverage the GPU and use Rosetta to run unmodified x86-64 Linux binaries.

The Virtualization Framework was introduced in macOS BigSur, a.k.a macOS 11, two years ago as an alternative to the Hypervisor Framework. As Apple engineer Benjamin Poulin showed, the Virtualization Framework offers a high-level API to configure and create VMs on macOS using Swift. Actually, the Virtualization Framework is just a higher-level layer running on top of the Hypervisor Framework, as shown in the following image.

(Image courtesy of Apple)

VZVirtualMachineConfiguration is the core class that allows developers to define the hardware they want to have available in their VMs, including how many CPUs, how much memory, storage, and other devices. Once you have a configuration, you can instantiate and run a virtual machine using VZVirtualMachine as well as attach it to a view to display it inside a macOS window using VZVirtualMachineView:

var configuration = VZVirtualMachineConfiguration()
configuration.cpuCount = 4
configuration.memorySize = (4 * 1024 * 1024 * 1024) as UInt64
configuration.storageDevices = [newBlockDevice()]
configuration.pointingDevices = [newPointingDevice()]

let virtualMachine = VZVirtualMachine(configuration: configuration)
try await virtualMachine.start()

let virtualMachineView = VZVirtualMachineView()
virtualMachineView.virtualMachine = virtualMachine

A VM created in this way is sort-of equivalent to a physical device where you can install the OS, explain Poulin, who also details all the steps required to install and run macOS from an image. Among supported devices is the GPU, which enables running Metal with almost native performance inside of a VM.

As mentioned, you can virtualize not only macOS but Linux as well. In macOS Ventura, Apple is introducing support for the EFI boot loader, which is able to discover any virtual device attached to a VM from which to boot. This makes it possible to download an ISO Linux image, attach it to a virtual storage device, create a boot loader, and boot into the OS, as Poulin shows. This is possible both on Intel and ARM CPUs provided you download the appropriate distribution for your hardware.

Additionally, with macOS Ventura, you will be able to use VirtioGPU 2D, a virtualization device that allows Linux to provide interfaces to the host. This makes it possible to display a Linux GUI inside a macOS window, similarly to how you can display a macOS GUI within a macOS window.

Possibly the most interesting new virtualization feature coming with macOS Ventura is support for Rosetta to run unmodified x86-64 Linux binaries. This too can be easily configured for a given Linux VM using Swift. The general idea is you share the Rosetta directory from macOS into your Linux guest OS, then launch the Rosetta interpreter from the Linux shell:

let rosettaDir = try! VZLinuxRosettaDirectoryShare()
let directorySharingDevice = VZVirtioFileSystemDeviceConfiguration(tag: "RosettaShare")
directorySharingService.share = rosettaDirectoryShare

configuration.directorySharingDevice = directorySharingService

By launching the Rosetta interpreter under Linux, any x86-64 Linux binary will be automatically translated to ARM using Rosetta, just like it happens for x86-64 binaries on macOS running on Apple Silicon.

New in macOS Ventura are also trackpad support and VirtioFS support for macOS. VirtioFS was already available for sharing files with a Linux guest VM and now can be used also to share files with a macOS guest, too.

About the Author

Rate this Article