Virtual machine gaming through VirtualBox and VMWare have shown to be difficult. You need a graphics card to play high end games such as Call of Duty Modern Warfare. Virtual machines on Windows OS such as VirtualBox can only utilize your CPU for graphics; meaning you can't play your high end games. Even Roblox or Minecraft can be a challenge. This guide will talk about gaming on a virtual machine called KVM. It can utilize your GPU via PCI passthrough technology. The guide applies to anyone who needs to use their GPU on a VM, but this is most commonly appealing to gamers.

PCI passthrough gives your virtual machine direct access to a PCI slot. There is no virtualization. This provides a near bare-metal connection, meaning there will be minimal latency.  I'll specifically be talking about GPU passthrough.

We'll be installing Windows 10 on KVM with GPU passthrough for gaming. This guide is basically a walkthrough of a simplified version of my setup.

Attention for the newbies: This guide will be updated with even more explained details when ever I come around to making the video

Prerequisites

This guide assumes you have everything below:

  • Compatible CPU for virtualization and supports integrated graphics
  • Two monitors with HDMI in
  • Two HDMI cables
  • Motherboard with HDMI out
  • One GPU with HDMI out
  • Manjaro Linux KDE OS installed. How to install: https://bit.ly/3e3rwqg

Installing KVM

KVM stands for Kernel-based Virtual Machine. It is a virtual machine technology that functions as a hypervisor.

Launch the terminal and enter the following command to install KVM and necessary dependencies.

sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager ovmf

The next two steps are very important and often ignored by many users. Make sure to complete it, or else you will get error “adduser: The group `libvirtd’ does not exist” when you run the Virtual Machine Manager after installation is complete!

Enable the service by entering the below command:

sudo systemctl enable libvirtd.service

Start the service using below command:

sudo systemctl start libvirtd.service

Virtual Machine manager should now be installed on your computer. You can launch it from ‘Applications’. Look for ‘Virtual Machine Manager’, not KVM!

Create and start your virtual machine. It is very much straight forward and similar to VirtualBox. Start your VM after creating it and immediately turn it off. This is just to create some configuration files to be automatically configured later. Attaching a GPU will be explained in the following.

Setting up GPU passthrough

Reserving the GPU for the VM

Plug in a video cable from your motherboard to your first monitor. Plug in another video cable from your GPU to your second monitor.

By default, your VM will rely on very minimal graphics. To correct this, we can have the VM use a graphics card via PCI passthrough. Unfortunately, two machines can't share GPUs, so you'll need a dedicated GPU for the VM. We'll redact the GPU from the host and have the host use the CPU's integrated graphics instead, thus leaving the GPU available for the VM. To use integrated graphics on the host, enter the system BIOS settings. Look through the settings for your first graphics handler and change it to be the CPU's integrated graphics. In my case, it was originally the first PCI lane, which was the GPU. I had to change this to the CPU. Save and reboot your computer. Graphics should then output from the motherboard's video port onto your first monitor.

Your VM won't be able to passthrough the GPU because it is still in use by Manjaro Linux. Even if there is nothing on the GPU's monitor, it still in use. You'll want to blacklist the GPU. Do the following.

Run the command:

sudo nano /etc/modprobe.d/blacklist.conf

Paste in the following text content to prevent the host OS from using NVidia and AMD GPUs:

#Disables NVidia GPUs
blacklist nouveau
blacklist nvidia
#Disables AMD GPUs
blacklist radeon

Save the file by pressing "ctrl+x" -> "y" -> "enter"

Finally, reboot your computer.

Updating Grub

Run the command and grab the PCI ids of your graphics card. You should grab all IDs related to your graphics card, including, but not limited to: The VGA ID, the sound ID, and the USB C ID. Older cards may not have USB C on them.

lspci -nn

For preparation, open up a text editor and put the IDs side by side, delimited by a comma. For example:

10de:2345,10de:7327,10de:2344

Edit the grub configuration with the command:

sudo nano /etc/default/grub

Replace the related lines with the following, but using your formatted PCI ids instead of mine.

GRUB_CMDLINE_LINE_DEFAULT="quiet intel_iommu=on vfio-pci.ids=10de:2345,10de:7327,10de:2344"
GRUB_CMDLINE_LINE="intel_iommu=on vfio-pci.ids=10de:2345,10de:7327,10de:2344"

Your GPU should now be reserved for the VM.

At this point, you should now be able to add a new module to your VM. Click the add module button, choose PCI, then choose all of the IDs you added from the configuration above. Save and start your VM. Once the VM has loaded, you will start to see video outputting from the GPU to your second monitor!

Error Fix

Patching "error43"

Some games will have trouble running properly or even launching. This is just NVidia preventing VMs from running properly. To fix this, you will need to patch the error43 error with a script. This script will edit the virtual machine's XML. Be sure to replace "yourvirtualmachinesname" with your VM's name.

Run the two commands:

sudo pip install -U https://github.com/PassthroughPOST/virsh-patcher/archive/master.zip
sudo virshpatcher --error43 --vendor-id 123456789ab yourvirtualmachinesname

You can now install Windows 10 and use it to play games! Be sure to install your graphics cards drivers too.