Create an every day Linux desktop with a Windows VM for gaming

guide

#1

Here goes,

I set out to run an Xubuntu desktop, but I also want windows to play games. So instead of dual booting which is annoying, i used the gpu-passthrough method which allows the windows VM direct access to the GPU so it can run games with ease.

There are more tweaks you can do other than whats listed below, like dedicated ram (using hugepages) or a dedicated hard drive or ssd for the windows vm which will increase it’s performance.

Hardware used:

CPU: Core i7-4790 (NB! Must support virtualization technology)
GPU: Radeon R9 280 (NB! must be UEFI capable)
Ram: 16Gb

  • Enable Virtualization options in bios, enable primary display as the intel gpu.
    (we want the intel gpu for the xubuntu and the dedicated gpu for the windows vm)

  • Connect a monitor to the intel gpu and another monitor to the dedicated GPU.

  • Load up Xubuntu.

  • Install the required packages:

sudo apt-get update sudo apt-get install qemu-kvm seabios qemu-utils ovmf virt-manager -y

  • Next step is to isolate your dedicated gpu for use by the windows VM.

It should give you a list similar to this:
(we are looking for the device ID’s, in this case 1002:679a & 1002:aaa0)

01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti PRO [Radeon HD 7950/8950 OEM / R9 280] [1002:679a] 01:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT HDMI Audio [Radeon HD 7970 Series] [1002:aaa0]

  • Next we need to get xubuntu to load our Vm modules & black list the GPU so it’s free for the windows VM.
  • Add the following lines:

pci_stub vfio vfio_iommu_type1 vfio_pci kvm kvm_intel

  • Modify the bootloader
  • Modify the following line: (note: AMD cpu’s use amd_iommu=on)
  • Update grub
  • Blacklist the dedicated gpu so that xubuntu doesnt use it and it’s free for windows VM
  • Add the following lines (The hardware ID’s we got above!)
  • Rebuild the initramfs
  • Reboot.

  • To verify if you have successfully blacklisted the gpu you can run the following command:
    (this will show you all devices captured by pci-stub for use in our VM)

  • Next: Setup the VM. (I’m going to go into great detail as you should know what you need by now)
    I used virtual machine manager GUI for this as it’s fast and easy. (virt-manager)
    NB: Make sure you set the bios type to UEFI
  • Click Add hardware
  • Select “PCI Host Device”
  • Select the AMD GPU
  • Click finish (repeat the process for the AMD HDMI Audio)

If you’ve done this correctly, when you start the VM, the second monitor attached to the dedicated GPU will come to life with your VM.


#2

Thx Flea, i will be buggin you soon :yum: Quite keen to try this weekend.
I recently formatted again and went for a dual boot Ubuntu Mate and Windows.

As a useless sidenote:
Had some issues after installing the new 17.04 as they have now given 2 options for swap file.
On the default now the swap file does not have a seperate partition and when enabling encryption on install causes a 3-5min boot time. Just changing /etc/crypttab to cryptswap1 /swapfile /dev/urandom swap,offset=1024,cipher=aes-xts-plain64 fixed it.

Another user experience on the above:
https://davidyat.es/2016/09/08/gpu-passthrough/


#3

@thisgeek brought up a valid point in the whatsapp group.

  • What if i want to game on linux? (with the powerful dedicated gpu)

Some possible solutions: (i’ll investigate this some more)
Script it to unblacklist the gpu then reboot. (what a pain)
Maybe the game runs on the intel gpu ?
Setup another vm but linux based tied to the dedicated gpu.
Have two dedicated gpu’s in your system, one for linux another for windows.


#4

Just a side note for the guys who run K series processors from Intel. (eg: i7-3770k, i7 4770k etc)

The K series processors from intel DO NOT HAVE VT-D technology (allowing pci-passthough), it was removed from a hardware level as VT-D is unstable under overclocking.


#5

Oh well that sux


#6

After some extensive testing, “Ubuntu 16.04.2 LTS” requires the least amount of fiddling (also no noticeable bugs) and works VERY well. Xubuntu required a lot of tweaking and messing about to get the VM running decently.


#7

edit: Sadly this lags, best to just pass-though the entire USB Controller

I want to pass through only certain usb devices, the VM setup:

Note: apparmor blocks this, you have to stop apparmor

or stop it from loading completely:

EDIT
This is the setup giving me the best results: (gpu-passthough, USB-passthrough, hdd-passthrough)

Pic of the hdd-passthrough:


#8

Here’s a nice alternative for gaming natively on linux (other than Steam)

I’ve personally tested the World of Warcraft & Overwatch, both work flawlessly.

Grab this app: Lutris https://lutris.net/

Lutris contains a big library of games. This library has custom scripts to allow Windows games to run on Linux. Simply go to the website, search for a game, click install. It will open your Lutris app, download the required scripts and runners and install the game for you. Once the game is installed you can just run it from Lutris.

Install Ukuu and run the latest kernel if you have an AMD card, Nvidia users just get the latest Unix driver from Nvidia’s website. https://github.com/teejee2008/ukuu

On the laptop, I had to just click on one checkbox for them to run (the laptop has hybrid graphics)


#9

How does it deal with anti cheat systems like punkbuster? Don’t they throw a shit fit?


#10

" BattlEye Anti-Cheat doesn’t work on Wine by design"


#11

Most Anti-cheat software is not compatible with “compatibility layers” by design.
(Wine is a compatibility layer, not an emulator - common misunderstanding)

If you play games that use Punkbuster or BattlEye which do not run natively on Linux you have two options, either run a VM with passthrough or run a Windows Desktop.

Arma 3 which uses BattlEye runs natively via Steam for Linux.

https://www.evenbalance.com/pbsetup.php - PunkBuster also supports Linux natively.

Here’s a nice reddit sub for you: https://www.reddit.com/r/wine_gaming/


#12

Since nobody here will be buying BF5 I’m staying on linux :slight_smile: