This is an evolutive post, it might change from time to time, i’m using this setup everyday, some update may break some configuration you’ll find in this post.
If you find an error while you read it, don’t hesitate to send me an e-mail to contact+blog at makz.me
For less than one year now, i use my “D.Va” build, my main OS is Archlinux and i have a dualboot for playing games on Windows. Unfortunately this is not convenient at all for me, everytimes when i’m on windows playing a game, i have to connect to my server or fix a bug in a piece of code and i have to reboot, if i listen to myself i could reboot 5 times per days, and i’m used to never turn off my computer so sometime i’m on windows for two weeks and it’s two weeks i don’t work at home, the other time it’s 2 weeks on Arch and i can’t play a single game …
Here, we have a dramatic case of first world problem.
So i decided to exeperiment the gaming in a virtual machine !
My idea was to pass my 1080 to a windows virtual machine and play on this one, after some tests with spare graphic card i have and it’s successful,i have almost the same perfomances as a native windows !
So i decided to mod my “D.Va” build and definitively implement this setup on my main rig.
I ran into some problems and if you want to reproduce the same setup, here’s the first needs for this setup :
My principal problem was the notion of “Primary GPU”, my motherboard don’t let me choose which GPU will be selected as “Primary” so i had to move my graphic card to another PCI-e connector, Unfortunately i have a custom watercooling and it’s not this easy ^^, i bought a second hand GTX980 to use it as my Primary GPU on Archlinux, moved my 1080 to the second 16x connector and mod my watercooling to have something fully integrated.
Okay once you have a correct hardware we can start !
Because you use another GPU, you need to connect your screen to the second GPU.
the idea in the end, is when you start your VM, it disable your main screen in linux, the VM start, your screen detect the input from the second GPU and autoswitch to this input, when the VM is down, you reactive your screen in linux and the screen switch back.
For my setup i’ve complexified the process, it’ll be explained later in this article.
So it’ll look like that
For the first setup i recommend using a second screen (one per GPU) it’ll be easier in case of problems.
Install virt-manager & qemu
If your Passthrough GPU have the UEFI support install the OVMF bios from AUR
First of all you need to enable IOMMU
Add intel_iommu=on (or amd_iommu=on if you have a AMD CPU) in the grub cmd line
Update your grub.cfg
Reboot and check if IOMMU is correctly enabled
We are good, now enable vfio
Find your the ID of your GPU
Here we can see my ID is xxxx:xxxx & xxxx:xxxx
And we load the kernel module at boot
Rebuild the initrd
And reboot. Check if the module is correctly loaded
And if the GPU is correctly isolated, with this command you should see if the driver in use is “vfio-pci”
If this method is not working you could use the old method “pci-stub”, but i didn’t use it, refer to the archlinux wiki
Okay, now our GPU is ready, time to create the VM !
At first we need to configure libvirtd to tell him to use the OVMF bios
Then simply create with virt-manager a vm, don’t forget to check “Customize before install” select the UEFI firmware.
CPU Section, set the model “host-passthrough”
Thoses are basic settings, you may want to tune your VM for your own setup.
Once the VM is create, add PCI devices (basicaly your GPU & your USB controller (I recommend to not add the USB controller at first or the VM will grab your keyboard/mouse and if you get in trouble you’ll have to find a way to shutdown the VM without keyboard (SSH))).
For your first start, i recommend to use a dedicated screen on the second GPU and other keyboard/mouse only for the VM.
Your Windows is ready to rock ? Nice.
The idea is to remove your spare display used for the installation and connect the second input of your main display to the second GPU.
Then we create a qemu hook in libvirt which disable the linux primary display, this will force your display to go into “Auto-Input mode” and it’ll switch to the second GPU input once the VM GPU is initialized.
Here’s my hook script, as you can see at first i used xrandr to turn off/on the primary screen and adapt my resolution but since few updates, using xrandr generate a segfault into gnome-shell and it kill my graphical interface “No good”
So i end up using nvidia-settings.
You’ll only have a good sound with the hardware virtualisation but Windows 10 removed the AC97 support so we have to trick him, you need to boot with disabled driver signature and then Windows will let you install AC97 driver.
Check this post for more informations.
To connect the qemu sound to pulseaudio, you’ll have to edit the libvirtd/qemu configuration
Then edit the domain key in the libvirt VM XML file
And finally add the QEMU PulseAudio environment variables at the end (edit the user id if needed)
To avoid input lag we passthrough the Keyboard/Mouse or directly the USB controller but that mean, your linux is unusable while Windows is running.
The idea here is to use a mouse/keyboard sharing software like Synergy and set the Windows as server and linux as client.
Everyone who already worked with more than one screen know one is not enough !
So the final step is to add the possibility to switch from “2 linux screens - 1 windows” to “1 linux screen - 2 windows”.
I did that with a simple KVM switch and a simple script in bash that check every 5 seconds if my “switched” screen is present on linux, if it’s not, it change the geometry to enable just one screen, and vice-versa.
This is the physical setup
This script is running as a service with systemd.
The more ram your VM has, the longer it take to boot the VM, you’ll see once you boot it, all CPU thread goes to 100% for few seconds/minutes then the VM boot.
This is because th arch kernel is Pre-emptive by default.
To fix that, i’ve compiled my own kernel, you can find it on this repo
The kernel is named “linux-makz-rt”, install it and update grub then you can boot on it !
Changes on the kernel
I’m trying to update the kernel as soon as arch update the official kernel, if i’m too slow or if you have any suggestions to improve the kernel, send me an email to contact+kernel at makz.me !