Logo

dev-resources.site

for different kinds of informations.

Do M1 Mac Dream of x86 Linux?

Published at
11/3/2023
Categories
macos
virtualization
qemu
vagrant
Author
tetra2000
Categories
4 categories in total
macos
open
virtualization
open
qemu
open
vagrant
open
Author
9 person written this
tetra2000
open
Do M1 Mac Dream of x86 Linux?

My primary machine is MacBook Pro 14” with M1 Max chip. It’s been great so far. It’s “scary” fast. But there is only one thing I can’t do with it. It doesn’t support to run Intel based VMs with Virtualization Framework due to the limitation of Rosetta translation layer.

About the Rosetta Translation Environment | Apple Developer Documentation

Rosetta can translate most Intel-based apps, including apps that contain just-in-time (JIT) compilers. However, Rosetta doesn’t translate the following executables:

  • Kernel extensions
  • Virtual Machine apps that virtualize x86_64 computer platforms

So I can’t run x86 VMs with VirtualBox like I often done with Intel Mac.

I’ve written another article about this topic. I used UTM at last time.

How to run x86 Linux on M1 MacBook?

Running Vagrant with QEMU backend

Let’s try Vagrant as a frontend at this time. Vagrant supports bunch of virtualization softwares as its backend.

vagrant-qemu is a great plugin for Apple Silicon Mac owners like me.

QEMU support to translate CPU instructions. Actually, Docker had been used QEMU to run x86 containers on Apple Silicon Mac before its transition to Rosetta.

The Magic Behind the Scenes of Docker Desktop | Docker

With support for Apple M1 ARM Mac and QEMU included in Docker Desktop, you are able to build and use multi-architecture images (Linux x86, ARM, Windows) on whatever platform you are working on out of the box.

There is an amazing gist which describe how to run VMs with QEMU and Vagrant.

Run x86 VM's on Mac M1 arm using vagrant with qemu hypervisor

Running x86 Linux VMs

Running Rocky Linux 9

Running Rocky Linux 9 is pretty simple.

You’ll need a Vagrantfile like this.

Vagrant.configure("2") do |config|
    config.vm.box = "rockylinux/9"

    config.vm.provider "qemu" do |qe|
      qe.arch = "x86_64"
      qe.machine = "q35"
      qe.cpu = "max"
      qe.net_device = "virtio-net-pci"
      qe.memory = "8G"
      qe.smp = "cpus=10,sockets=1,cores=10,threads=1"
    end
    config.vm.synced_folder '.', '/vagrant', disabled: true
    config.vm.network "forwarded_port", guest: 8080, host: 18080
  end
Enter fullscreen mode Exit fullscreen mode

Then you can use it with no hustles.
Image description

Running Rocky Linux 8

Running Rocky Linux 8 is a bit tricky.(Including on Vagrant with VirtualBox backend)

You can’t run images on Vagrant directly.

Vagrant box rockylinux/8 - Vagrant Cloud

You’ll stuck on during vagrant up with a Vagrantfile like this.

Vagrant.configure("2") do |config|
    config.vm.box = "rockylinux/8"

    config.vm.provider "qemu" do |qe|
      qe.arch = "x86_64"
      qe.machine = "q35"
      qe.cpu = "max"
      qe.net_device = "virtio-net-pci"
      qe.memory = "8G"
      qe.smp = "cpus=10,sockets=1,cores=10,threads=1"
    end
    config.vm.synced_folder '.', '/vagrant', disabled: true
    config.vm.network "forwarded_port", guest: 8080, host: 18080
  end
Enter fullscreen mode Exit fullscreen mode

You’ll find it failed to boot by using QEMU Monitor.
Image description

I’ve experienced the symptom like this before when I tried to run this OS with Vagrant and VirtualBox. All you have to do is make UEFI available while booting.

How to do it with QEMU? Fortunately, there is a package named Open Virtual Machine Firmware(OVMF). You can download its BIOS data from a package for Debian.

Debian -- Package Search Results -- ovmf

You’ll find data.tar.xz in it when you extracted it. So extract this too. Then you’ll find the BIOS image in usr/share/OVMF/OVMF.fd.

Then you need to tweak the Vagrantfile like this.

Vagrant.configure("2") do |config|
    config.vm.box = "rockylinux/8"

    config.vm.provider "qemu" do |qe|
      qe.arch = "x86_64"
      qe.machine = "q35"
      qe.cpu = "max"
      qe.net_device = "virtio-net-pci"
      qe.memory = "8G"
      qe.smp = "cpus=10,sockets=1,cores=10,threads=1"

      # Added
      qe.extra_qemu_args = %w(-bios /path/to/OVMF.fd)
    end
    config.vm.synced_folder '.', '/vagrant', disabled: true
  end
Enter fullscreen mode Exit fullscreen mode

And….

Tada! It’s working!!

Image description

Conclusion

Vagrant made it simple to create and configure VMs. It’s nice to be able to use it to run x86 Linux on my M1 Mac.

Of course UTM is still great for GUI usage. But vagrant-qemu definitely filled more lightweight VM usage.

References

This article is also available on Medium.

vagrant Article's
30 articles in total
Favicon
Comandos Básicos de Vagrant
Favicon
🔋⚡ Ensuring High Availability with Two-Server Setup Using Keepalived
Favicon
Using Vagrant to Provision a VM and Multiple VMs
Favicon
How to Create and Configure a Multi-VM Vagrant Setup for Web and Database Servers
Favicon
Error : Loading Vagrant Up
Favicon
[pt-BR] Como utilizei o Vagrant e o Virtual Box para desenvolvimento local
Favicon
Deploying a Spring Boot Banking Application with Docker
Favicon
Resizing the disk on a Vagrant virtual machine
Favicon
🚀 Creating a Kubernetes Cluster with Vagrant: A Step-by-Step Guide 🚀
Favicon
Setup a Docker Swarm cluster using Vagrant
Favicon
Solve "[email protected]: Permission denied (publickey)" error
Favicon
Vagrant ssh alternative
Favicon
Vagrant Setup for macOS with Apple Chips
Favicon
EXPLORING DOCKER CONTAINER USING VAGRANT
Favicon
Automate Your local VM workflow
Favicon
Day 3: Exploring Vagrant and Linux Server Setup
Favicon
Vagrant: A Comprehensive Guide to Managing Virtual Environments
Favicon
Vagrant and VMWare Fusion in Mac M1
Favicon
Windows GitHub Self Hosted Runner inside a Linux Container
Favicon
How to Enable a Virtual Machine on Your Windows Laptop With Vagrant and Git Bash
Favicon
Vagrant CLI Commands Cheat Sheet
Favicon
Install Virtual Machine With Vagrant & Remotely Access it
Favicon
Run Vagrant VMs in a M1/M2/M3 Apple Sillicon Chip
Favicon
Exploring Vagrant: Simplifying Development Environments
Favicon
Do M1 Mac Dream of x86 Linux?
Favicon
Vagrant - configurando VM's de forma performática
Favicon
Getting Started with Vagrant for Local Development Environments
Favicon
Vagrant For Beginners: Box Basics in Vagrant.
Favicon
Vagrant For Beginners: Creating Your First Virtual Environment.
Favicon
Getting started with Vagrant: a beginner's Guide

Featured ones: