Using Virtual Machines on macOS/Linux with Tart

11 hours ago 1

Information

To reach a broader audience, this article has been translated from Japanese.
You can find the original version here.

When I was using an Intel-based MacBook, I regularly used virtualization software such as VirtualBox and VMware Fusion. Initially, when I switched to a MacBook with an M1 chip, these software options were not compatible, and I ended up not using them anymore. Recently, I discovered Tart, a virtualization tool that makes it easy to set up virtual machines on Apple Silicon Macs, so I'd like to introduce it.

Tart is a virtualization toolset exclusively for Apple Silicon Macs. It is implemented on Apple Silicon's native Virtualization Framework, allowing macOS and Linux to run efficiently.

Tart is using Apple’s native Virtualization.Framework that was developed along with architecting the first M1 chip. This seamless integration between hardware and software ensures smooth performance without any drawbacks.

You can find the Tart GitHub repository here:

GitHub - cirruslabs/tart: macOS and Linux VMs on Apple Silicon to use in CI and other automations

Tart's VM images can be managed in an OCI-compatible registry, and the official images are published in GitHub's Package Registry.

https://github.com/orgs/cirruslabs/packages

Additionally, Cirrus Runners, a CI runner using Tart, is also available.

Information

Tart is free for use on personal machines. Organizations exceeding a certain number of server installations need to obtain a paid license.

Support & Licensing - Tart

Usage on personal computers including personal workstations is royalty-free, but organizations that exceed a certain number of server installations (100 CPU cores for Tart and/or 4 hosts for Orchard) will be required to obtain a paid license.

You can get a general idea of how to use it by looking at the Quick Start.

Quick Start - Tart

Install it with Homebrew.

brew install cirruslabs/cli/tart

You can fetch, launch, and configure machine images with the tart CLI.

Let's fetch an image of macOS Sonoma with Xcode installed. Specify the registry's image and a local name (in the following example, sonoma-xcode).

$ tart clone ghcr.io/cirruslabs/macos-sonoma-xcode:latest sonoma-xcode pulling manifest... pulling disk (54.0 GB compressed)... 0%

The download will start. It's 54GB, so it will take quite some time. It finishes like this:

98% pulling NVRAM...

Launch the VM.

macOS starting

It starts up quite fast.

macOS Desktop

Xcode also launched properly. My host machine is running macOS Ventura, but I can use the latest Xcode in a macOS Sonoma VM (though I only use Xcode Command Line Tools).

run xcode

The default memory is 8GB, which is a bit small, so let's expand it.

8GB

First, stop the VM from the Control menu.

stop

Use the Tart CLI to specify the VM and set the memory size in MB.

tart set sonoma-xcode --memory 16384

Relaunch the VM with tart run, and the memory has successfully increased.

16GB

Fetch an Ubuntu VM image.

$ tart clone ghcr.io/cirruslabs/ubuntu:latest ubuntu pulling disk (0.9 GB compressed)... 0%

It's just under 1GB, so it finishes quickly.

It's a good idea to expand the default disk size of 20GB before launching.

tart set ubuntu --disk-size 50

Launch it.

It launches, but the GUI is not set up, leading to a console login screen.

Ubuntu console

The default user/password is admin/admin.

To use the desktop environment, I installed the module.

sudo apt update sudo apt install ubuntu-desktop

After restarting the VM, the GUI login screen appeared.

login gui

Logging in, I could successfully use the desktop environment.

Ubuntu desktop

After spending a few hours setting up the environment and building applications, it was a smooth and comfortable VM environment.

With the Tart CLI, you can create VM images from macOS IPSW files (firmware format files like those for iOS) or Linux ISO images.

Example of creating a macOS image.

tart create --from-ipsw=latest sonoma-vanilla

Information

When executing the above command, it seems to download the IPSW file from ipsw.me to create the image.

Example of creating a Linux image.

tart create --linux ubuntu tart run --disk focal-desktop-arm64.iso ubuntu

Since it's possible to push to an OCI registry, you can push images to ECR or similar and pull them when needed.

Managing VMs - Tart

There's also a plugin for Packer, allowing you to create and manage Tart images with Packer.

Building with Packer - Tart

For macOS, Cirrus Runners use Tart, and for Linux, they use vetu, a virtualization technology, to provide CI runners. They can be used from GitHub Actions or GitLab CI.

For GitHub Actions, simply set up the Cirrus Runners app for your organization, and then specify Cirrus Runners in your workflow file.

name: Tests jobs: test: runs-on: ghcr.io/cirruslabs/macos-sonoma-xcode:latest

GitHub Actions - Tart

For macOS, it seems to be much cheaper than the runners hosted by GitHub.

Pricing - Cirrus Runners

The experience of using VMs with Tart was satisfactory.

Although I have no plans to use macOS VMs for now, being able to quickly set up a VM for testing or when you don't want to significantly alter the configuration of your host machine is reassuring.

The VMs introduced in the previous article "OrbStack - A Fast and Lightweight Container & Linux VM Environment Exclusively for macOS" only supported shell environments. With Tart, desktop environments are also available, which seems useful for testing Linux desktop applications.

For Windows... let's use a physical machine.

For native app development on macOS and iOS, Cirrus Runners seems like a good solution for building CI/CD pipelines.

Read Entire Article