Do M1 Mac Dream of x86 Linux?
Tags: macos, virtualization, qemu, vagrant
Published: 2023-11-03 06:19:17

---
title: Do M1 Mac Dream of x86 Linux?
published: true
description: 
tags: macos,virtualization,qemu,vagrant
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-11-03 06:07 +0000
---

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](https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment)

> 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?](https://zenn.dev/tetra2000/articles/x86_linux_on_m1)

## 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](https://github.com/ppggff/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](https://www.docker.com/blog/the-magic-behind-the-scenes-of-docker-desktop/)

> 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](https://gist.github.com/beauwilliams/69eabc42e540a309f53d55c4b8e6ffe3)

## Running x86 Linux VMs

### Running Rocky Linux 9

Running Rocky Linux 9 is pretty simple.

You’ll need a Vagrantfile like this.

```ruby
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
```

Then you can use it with no hustles.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yewfmaejuwix0rv4otde.png)



### 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](https://app.vagrantup.com/rockylinux/boxes/8)

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

```ruby
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
```

You’ll find it failed to boot by using QEMU Monitor.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/et1fitwo1mqcw9vb0dw9.png)


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](https://packages.debian.org/search?keywords=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.

```ruby
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
```

And….

Tada! It’s working!!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pjxbamanp9d7f02khoha.png)

## 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

- [Run x86 VM's on Mac M1 arm using vagrant with qemu hypervisor](https://gist.github.com/beauwilliams/69eabc42e540a309f53d55c4b8e6ffe3)
- [QEMU Monitor — QEMU  documentation](https://qemu-project.gitlab.io/qemu/system/monitor.html)
- [How To Boot UEFI on QEMU](https://www.ubuntubuzz.com/2021/04/how-to-boot-uefi-on-qemu.html#google_vignette)
- [How can I install ovmf?](https://www.reddit.com/r/voidlinux/comments/m8c5aw/how_can_i_install_ovmf/)
- [Docker Desktop 4.25: Enhancements to Docker Desktop on Windows, Rosetta for Linux GA, and New Docker Scout Image Analysis Settings | Docker](https://www.docker.com/blog/docker-desktop-4-25/)
- [Running Intel Binaries in Linux VMs with Rosetta | Apple Developer Documentation](https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta)


*This article is also available on [Medium](https://medium.com/@TETRA2000/do-m1-mac-dream-of-x86-linux-117478fc9623).*