Run Batocera in a Virtual Machine

Running Batocera in a virtual machine is not officially supported, nor will it be an accurate representation of how it will behave, but it can be useful for quickly testing custom images or UI changes.

Except massive performance deficits compared to bare-metal installation. Virtual Machines don't take kindly to newer/modern graphics APIs and standards.

  1. Install the VirtualBox #.#.# Oracle VM VirtualBox Extension Pack (a.k.a. “Guest Additions”) too.

    If you need further help with installing VirtualBox, refer to their helpful user manual

  2. Convert the Batocera IMG file to a VDI using the command line ([Win] + [R], then type cmd). For example, for the default VirtualBox installation using Batocera v33 beta:
    "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" convertdd C:\batocera-x86_64-33-20211108.img C:\batocera-x86_64-33-20211108.vdi
  3. Resize it to be larger, can also be done via command line. For example, to create an image that's 20GB in physical size:
    "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "C:\batocera-x86_64-33-20211108.vdi” --resize 20000
  4. Run VirtualBox proper and create a new VM and select “Expert Mode”.
    1. Set the type “Microsoft Windows” and version to “Windows 7 (64bits)”; (It's just a label for predefined setup, maybe linux or oracle will be better for you, but try this one first)
    2. Set available RAM to at least 2GB (2048MB);
    3. Use the Batocera VDI file created earlier:
       VirtualBox's new VM dialogue box at expert mode.
  5. Once the VM has been created, adjust its settings like so:
    1. Processor: Processors: “2”. A higher setting might provide better performance, but try to stay within the green range for your computer. For host computers that only have two cores, use “1” here. Execution Cap: 100%.
    2. Display: Acceleration: Tick “Enable 3D Acceleration”. Video Memory: As high as you can go, “256MB” works fine.
    3. Network: Adapter 02: Tick “Enable Network”. Attached to: “Bridge Adapter”. Promiscuous mode: “Allow VMs”
    4. USB: Add desired devices (such as controllers, Bluetooth dongles, etc.) to the list:

      Peripherals that the VM automatically forwards through such as mouse, keyboard and network cards are not necessary to add here.

  6. If AUTO Audio and AUTO Video didn't work, change the following settings within Batocera:
    1. SYSTEM SETTINGSVIDEO OUTPUT to “VIRTUAL-1”,
    2. AUDIO OUTPUT to “ALSA_OUTPUT_PCI.STEREO” and
    3. AUDIO PROFILE to “PRO_AUDIO”.

      If those settings don't produce audio, keep trying all permutations of AUDIO PROFILE and AUDIO OUTPUT until you find one that does. Remember to exit the menu each time to test the change!

And we're done.

Oh the wonders of running Batocera in a virtual environment!

Post-installation setup

You can increase the output resolution releasing your cursor (right [Ctrl]) and clicking VIEWVIRTUAL SCREEN-1 in the menu toolbar of VirtualBox.

You can still add files to Batocera using the usual methods, even the network share.

As you already have the image .vdi, you can setup different environments for the same machine and test which one will be better for your PC, just make sure you are using a 64-bit one (or 32-bit if appropriate).

  1. Download the image for Batocera from the main site.
  2. Create an empty “share” image containing the partition Batocera will use for its userdata and name it share.img (replacing 5G with the size you desire, make it at least 5GB to support future upgrades):
    dd if=/dev/zero of=share.img count=5 bs=5G

    To confirm that the blank share image has been created, run

    ls -lh share.img

    to check its reported space. For instance, a 5GB blank image should report back something like:

    -rw-rw-r-- 1 XXX XXX 5.0G XXX share.img
    1. Optionally, if you don't want to use Batocera itself to format the partition, create the filesystem manually with something such as:
      mkfs.ext4 share.img

      Otherwise it's fine to, after booting Batocera, go to SYSTEM SETTINGSDEVELOPERFORMAT A DISK and format it there.

    2. Optionally, forward a gamepad connected to the host computer by running the following:
      udevadm info -q all -n /dev/bus/usb/001/002
      echo 'SUBSYSTEM=="usb", ENV{ID_MODEL}=="Usb_Gamepad", MODE="0666"' >> /etc/udev/rules.d/99-joysticks-rw.rules
  3. Then run the following to start up the Qemu virtual machine:
    ./runQemu.sh ~/batocera-x86_64-XX-XXXXXXXX.img share.img

The runQemu.sh script itself contains further instructions (that may get updated faster than this wiki). For an example of what an ordinary installation procedure might look like:

A video demonstration of Batocera being run inside a Qemu VM.

  1. Download the compressed Batocera image for x86_64 from the main site and extract the batocera*.img file from the compressed batocera*.img.tz tarball.
  2. Expand the image to the size you'd like to assign to Batocera using fallocate. At least 16 GB is recommended for full functionality, but if space is a concern then you can get away with just 7 GB:
    sudo fallocate -l 7G batocera.img
  3. Install the qemu, virt-manager and qemu-img packages for your distro:
    • On Debian/Ubuntu:
      apt-get update
      apt-get upgrade
      apt-get install qemu virt-manager qemu-img
    • On Fedora/RPM-based: Update your package lists, then:
      sudo dnf install virt-manager qemu
    • On Arch/pacman-based: Update your package lists, then:
      pacman -S virt-manager qemu
    • On Yum-based: Update your package lists, then:
      yum install virt-manager qemu
  4. Create a VM with the Batocera image as a drive in Qemu.
    1. Go to FileNew virtual machine…
    2. Ensure “Import an existing disk image” is selected.
    3. “Browse” for an existing image.
    4. Click “Browse for local…” and select the Batocera image file.
    5. The dialogue box should now look like this, proceed:
    6. Change the default Memory and CPU numbers if you choose. The defaults are good enough.
    7. Give your virtual machine a name and click Finish.
  5. (Optional) If you'd prefer to passthrough your GPU to the virtual machine for extra performance (warning: your host machine will lose access to the GPU you passthrough) follow the instructions here: https://www.server-world.info/en/note?os=Debian_11&p=kvm&f=12
  6. Enjoy!

If you face an error about the “default” network device like this:

then you are not currently passing through your network connection to the virtual machine. Run the following on your host machine to enable that:

sudo virsh net-start default

No controller workaround needed?

Post-installation setup

You can still add files to Batocera using the usual methods, even the network share.

In case you'd like to mount the share image to add files directly, run the following:

X=$(sudo losetup -f)
mkdir -p BATOCERA
sudo losetup -P $X share.img
sudo mount ${X}p1 BATOCERA
sudo chmod -R 777 BATOCERA/

Then it should be automatically detected and mounted by your desktop environment.

Untested. Reportedly, following this tutorial to set it up in addition to passing through all devices enables it to work: https://www.nicksherlock.com/2020/12/running-tails-as-a-vm-with-persistence-on-proxmox/

First, make sure you have passed it through as a USB device to the VM itself (step 7d. in the instructions above).

If it's still not working, check that the controller itself is working fine on your host machine outside of VirtualBox.

I've done that and it's still not working! I'm on a Linux-based host.

If it's still not being recognized, add the user to the correct group:

  1. Close VirtualBox
  2. Open a terminal and run sudo usermod -a -G vboxusers $USER && sg vboxusers virtualbox

Windows shouldn't have this issue as long as the program is run in administrator mode.

  • run_batocera_in_vm.txt
  • Last modified: 7 hours ago
  • by atari