Running Intel binaries in Debian ARM with Rosetta
Tags: apple, debian, intel, windows
Published: 2023-01-12 08:29:16

> This article originally appeared on my personal dev blog: [Byte High, No Limit](https://andrewowen.net/blog/).

I've mentioned UTM before. It's a nice wrapper for [QEMU](https://www.qemu.org/ "QEMU") that enables you to create ARM virtual machines and emulate non-ARM machines on macOS. It's a free download from the [website](https://mac.getutm.app/ "UTM for macOS"), or you can get it in the [app store](https://apps.apple.com/us/app/utm-virtual-machines/id1538878817?mt=12 "Mac App Store"). But one of the features I've been looking forward to is being able to use Rosetta to do X64 to ARM64 instruction translation, which is supported in the latest version of UTM on macOS Ventura. I was hoping to be able to install Intel VMs using Rosetta, but for that you still have to use QEMU. What you can do is install a Debian ARM VM, enable Rosetta, and then run X64 Debian packages on that VM. This can be useful if there's a particular package you need that doesn't have a native ARM build. Thus far I've only got it to run packages, and not individual Intel binaries. There is also a big caveat:

> There is a bug present in Linux virtual machines on Ventura and the base M1 chip that causes the virtual machine to randomly kernel panic and freeze. Unfortunately, this means that base M1 users should avoid Apple Virtualization backend until Apple or Linux maintainers provide a fix.

I'm running on an M1 Pro, and that seems to work well. After you've installed UTM you'll need the [Debian Net Installer](https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/). You'll also need to [install Rosetta](https://support.apple.com/en-us/HT211861 "Install Rosetta 2").

#### Set up the VM

1. Open UTM and click Add ( ➕ ) to open the VM creation wizard.
2. On the Start panel, click Virtualize, then on the Operating System panel, click Linux.
3. On the Linux panel, select Use Apple Virtualization, then select Enable Rosetta (x86\_64 Emulation).
4. Click Browse and select the Debian installer ISO you downloaded earlier, then click Next.
5. Choose the amount of RAM and CPU cores you want the VM to use, then click Next. I used the default settings.
6. Set the maximum drive space to allocate, then click Next. I left this at the default 64GB. The image won't take up the full amount when you create it, and can be trimmed if you have sufficient disk space for a copy, so you should set this to the maximum amount you think you'll need.
7. (Optional) Choose a shared folder to mount in the VM, then click Next. If you skip this step, you can select the folder later from the VM toolbar.
8. Click Save to create the VM and then click Run ( [▶️ ](https://emojipedia.org/play-button/)) to start the VM.

#### Install Debian

1. When the VM boots, select Install and follow the setup wizard.
2. When formatting the disk, install to Virtual disk 1 (vda), using entire disk, all files in one partition
3. From Software selection, select GNOME, SSH server and standard system utilities.
4. After installation, eject the disk and reboot.

#### Enable sudo

```shell
$ set USERNAME=`whoami`
$ su -p
# /usr/sbin/usermod -aG sudo $USERNAME
```

After you enable sudo for the default user, you must restart the VM for the change to take effect.

#### Install the software

1. Install the guest tools: sudo apt install spice-vdagent.
2. Install binary format support: sudo apt install binfmt-support.
3. Create a mount point: sudo mkdir /media/rosetta.
4. Mount Rosetta: sudo mount -t virtiofs rosetta /media/rosetta.
5. Add this line to /etc/fstab: rosetta	/media/rosetta	virtiofs	ro,nofail	0	0.
6. Register Rosetta as an X64 ELF handler:

```shell
sudo / usr / sbin / update - binfmts--install rosetta / media / rosetta / rosetta \
--magic "\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00" \
--mask "\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff" \
--credentials yes--preserve no--fix - binary yes
```

The magic parameter describes the first 20 bytes of the ELF header for X64 binaries. The Linux kernel performs a bitwise logical AND with the first 20 bytes of any binary you try to run with the mask value. If there's a match, it uses the registered handler to interpret the binary. Otherwise, it reports an error.

7\. Enable X64 packages:

```shell
sudo dpkg --add-architecture amd64
sudo apt update
```

Now you can now install and run any X64 package in the Debian repository with `sudo apt install packagename:amd64`.

#### Install WINE

One such package is WINE, which will enable you to run some 64-bit Windows binaries. But you'll also need to install WINE32 to get it to launch. I'm not sure if Rosetta can be persuaded to run 32-bit binaries as well. I'll have to do some further investigation. You'll also need to enable X86 pakcages:

```shell
sudo dpkg --add-architecture i386
sudo apt update
```

Then you can install WINE with:

```shell
sudo apt install wine64:amd64
sudo apt install wine32:i386
```

So far, I've only got the built-in file explorer working (launch with `wine64 explorer`). If I get 32-bit apps working I'll write a new post on it.