Gaming on an Android VM on Linux

So you can do the gacha grind on your computer instead of your phone

libvirt Linux virtualization gaming Android

I wanted to run Android games (specifically Arknights) on my NixOS box, but Anbox seems to be broken on NixOS. So, I figured out a way to make it work in Libvirt. Other people wanted to do it too, so here’s a guide.

Assumptions about you

Ingredients

Recipe

1. Create a VM

You’ll want to create a new VM with the downloaded ISO as your boot disk. When prompted for the type of OS, select Android 9.0.

As for specs and storage space, you should consider how much space and power the games you’ll play want. I just went with 4 cores and 8gb RAM, but 8gb might admittedly be overkill.

Before booting your machine, make sure to do the following things to your VM’s configuration:

Pretend your internet is Wi-Fi

Android doesn’t like ethernet connections for some reason, you’ll want to set your NIC to use the rtl8139 device, which emulates a wi-fi card.

NIC emulating an rtl8139

Enable 3D Acceleration

Go into the Video device, and set it to Virtio. Make sure to check the 3D acceleration box.

Video Virtio and 3D acceleration

However, you aren’t done; if you run the VM now, you’ll get an error complaining that it can’t find OpenGL. You need to go to the Display Spice device and set “Listen type” to None, and check the OpenGL box. OpenGL will ask you for a GPU to use (given by their PCI addresses) so select the one you want to use, or Auto to have it guess.

Display Spicetoggles

2. Partition, format, and install

Run your VM and you’ll be greeeted with this screen. Just go to the “install” setting.

The initial installer grub screen

It will ask you to pick a partition, but there’s no partitions, so you’ll have to use the built-in partition manager.

No available partitions.

You’ll just want to create a MBR partition table with 1 partition on it.

Partition to make one partition on a MBR table.

The new partition showing up in the wizard

Then, when you quit the partition manager, you can select that one partition, and follow the wizard:

Then, you’re all done with installation, and you can reboot.

3. Booting and setting up Android

If all goes well, Android will boot and go into the setup screen.

Android booting in a VM!

Android setup screen.

Now, just set up the machine like any normal Android device.

Prompted for preferred home app.

Finished setting up!

4. Install your games or whatever

It doesn’t matter if you install your apps before or after setting up ARM translation. I prefer to do it before so that I can take a VM snapshot and not have to download so many things in the next (somewhat error-prone) step goes wrong.

Your games might crash on boot. That’s okay, we fix it in the next step.

5. Set up ARM translation

This step is needed to play games that are only packaged for ARM. Note that some games might trick you and pretend they work on x86 and install properly without warnings (I’m looking at you, Arknights), but they’ll crash on start. It’s just safest to do this step first.

Open up the Terminal Emulator app and start running commands!

a. Enter root mode

su

obviously puts you into root mode. You might need to say “yes” to a confirmation.

b. Download libhoudini

wget -O /etc/houdini9_y.sfs http://dl.android-x86.org/houdini/9_y/houdini.sfs

The -O flag is especially important because it needs to be in a very specific spot on your filesystem!

Also, Android’s version of wget doesn’t seem to like https, so you’ll just have to deal with http. Shoulda thought about that before getting MITM’ed.

c. Create missing directories and files

touch /etc/modprobe.conf
mkdir -p /etc/modprobe.d

For some reason, these files are missing when you install Android-x86, which is really weird because you’d think that they’d be very important files. No matter; it’s required as a workaround for the next part.

d. Enable native bridge

enable_nativebridge

This script does a bunch of things (good things, I’d hope) but it seems to enable the ARM translation

e. Check it in the settings

Now, go turn on Settings > Android-x86 options > Enable native bridge.

Once all of these steps are done, you should be able to play ARM games inside the VM! If not, try rebooting. If that still doesn’t work, then I don’t know.

Arknights is successfully running!