注目イベント!
アドベントカレンダー2024開催中!
一年を締めくくる特別なイベント、アドベントカレンダーを今年も開催しています!
初心者からベテランまで楽しめる内容で、毎日新しい技術トピックをお届けします。
詳細はこちらから!
event banner

Using Virtual Machines on macOS/Linux with Tart

| 7 min read
Author: masahiro-kondo masahiro-kondoの画像
Information

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

Introduction

#

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[1]. 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.

What is Tart?

#

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.

Installation

#

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

Launching a macOS VM

#

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.

tart run sonoma-xcode

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

Launching an Ubuntu VM

#

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.

tart run ubuntu

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.

Creating Custom Images

#

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

Information

On EC2's Marketplace, AMIs of Tart optimized for use on AWS are available.

AWS Marketplace: Tart Virtualization for macOS

It's easier than managing macOS images with Packer, and the performance is also good.

Tart is now available on AWS Marketplace - Tart

CI Runner

#

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

Conclusion

#

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[2]. With Tart, desktop environments are also available, which seems useful for testing Linux desktop applications.

For Windows... let's use a physical machine[3].

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

Information

GitHub is also enhancing its macOS Actions Runner, so prices may come down eventually.

Introducing the new, Apple silicon powered M1 macOS larger runner for GitHub Actions


  1. VMware Fusion is now compatible, and VirtualBox is also making progress towards compatibility. - Does Virtualbox work on Apple Silicon Mac? ↩︎

  2. Of course, you could use X server or VNC, but OrbStack is mainly for container use, so I don't think it's worth the effort. ↩︎

  3. During the Intel Mac era, I used to run Windows on VMware Fusion for Office, but with Office 365, it's no longer necessary. ↩︎

豆蔵では共に高め合う仲間を募集しています!

recruit

具体的な採用情報はこちらからご覧いただけます。