user@host
~
$
The Trivial Guide™ to
Virtual Machines for Gaming
Normally when you run a virtual machine the graphics performance will suffer because a virtual graphics card has to be emulated.
But it's possible to let the VM directly access a real graphics card.
You can play games on your computer or use Steam In-Home Streaming
to play them on another computer, on the Steam Link or even on an Android device while the games are actually running on a virtual machine.
With more cards it's even possible to run multiple virtual machines at once.
Finally this means you can run a secure and modern system that respects your freedom and also play any Windows exclusive title that you can’t live without, today.
Enter at your own risk
Hardware virtualization extensions
Example motherboard for an Intel CPU:
ASUS Z170-P
-
F2 Enter BIOS at startup
-
F7
Advanced Mode
-
Advanced
-
CPU Configuration
- Enable Intel Virtualization Technology
- System Agent (SA) Configuration
- Enable VT-d (IOMMU)
-
F10 Save & restart
For AMD it might be known as AMD-V and AMD-Vi or IOMMU
Find and consult your mothersboard's manual when necessary
inxi -M
Machine:
Type: Desktop Mobo: ASUSTeK model: Z170-P v: Rev X.0x
serial: UEFI: American Megatrends v: 3805 date: 05/16/2018
List some machine data including motherboard model
IOMMU grouping
ls /sys/class/iommu
dmar0
Ensure IOMMU is enabled by successfully listing any units
lspci | grep VGA
01:00.0
VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] (rev a1)
List PCI video devices
ls /sys/bus/pci/devices/0000\:01\:00.0/iommu_group/devices/
0000:00:01.0 0000:01:00.0 0000:01:00.1
List all devices in the same IOMMU group
lspci -ks 01:00
01:00.0
VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GP107 [GeForce GTX 1050 Ti]
Kernel driver in use: nouveau
01:00.1
Audio device: NVIDIA Corporation GP107 HDMI Audio Controller (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GP107 HDMI Audio Controller
Kernel driver in use: snd_hda_intel
Show kernel drivers in use on a selected bus and slot
I recommended using nano instead of vim below
Device reservation
Override all drivers, on a bus above zero, in the same IOMMU group
Driver interception, a simpler way to install the vfio-pci driver early
sudo mkdir /etc/modprobe.d
Make the directory modprobe.d in /etc
sudo vim /etc/modprobe.d/intercept.conf
install nouveau "/sbin/intercept-vfio-nouveau.sh"
install snd_hda_intel "/sbin/intercept-vfio-intel-audio.sh"
-
- Edit a new configuration file
- Refer to shell scripts that should run a custom module installation
sudo vim /sbin/intercept-vfio-nouveau.sh
echo
vfio-pci
> /sys/bus/pci/devices/0000:01:00.0/driver_override;
modprobe vfio-pci;
modprobe --ignore-install nouveau;
-
- Edit a new shell script
- Override the graphics driver with the vfio-pci module, then install any remaining graphics as normal
sudo vim /sbin/intercept-vfio-intel-audio.sh
echo
vfio-pci
> /sys/bus/pci/devices/0000:01:00.1/driver_override;
modprobe vfio-pci;
modprobe --ignore-install snd_hda_intel;
-
- Edit a new shell script
- Override the HDMI audio driver and install any remaining compatible audio as normal
sudo chmod +x /sbin/intercept-vfio-nouveau.sh
sudo chmod +x /sbin/intercept-vfio-intel-audio.sh
Change file modes to allow the scripts to be executed
sudo shutdown -r now
Reboot now
lspci -ks 01:00
01:00.1
VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GP107 [GeForce GTX 1050 Ti]
Kernel driver in use: vfio-pci
01:00.1
Audio device: NVIDIA Corporation GP107 HDMI Audio Controller (rev a1)
Subsystem: Micro-Star International Co., Ltd. [MSI] GP107 HDMI Audio Controller
Kernel driver in use: vfio-pci
Show kernel drivers in use on a selected bus and slot
Virtual Machine Manager
One for all Linux games and the other for Windows exclusives
Download Solus Budgie,
Windows 10 64-bit
and VirtIO drivers
sudo eopkg install virt-manager
Install Virtual Machine Manager
sudo eopkg install ovmf
Install Open Virtual Machine Firmware
sudo systemctl enable --now libvirtd.service
Start the libvirt daemon now and enable autostart
sudo mv ~/Downloads/*.iso /var/lib/libvirt/images
Move all downloaded iso files to a more convenient directory
Virtual Machines Creation
They can be installed and run simultaneously until they have been assigned the GPU
Go ahead and proceed unless mentioned
-
- File
- New Virtual Machine
-
- Browse...
- Choose the Solus or Win10 iso respectively
-
- Memory (RAM): 4096
- CPUs: 2
- 40 GiB
-
☑ Customize configuration before install
Configuration customization
-
- Overview
- Firmware: UEFI x86_64: /usr/share/OVMF/OVMF_CODE.fd
- Chipset: Q35
-
- CPUs
- Model: host-passthrough
-
- Boot options
- ☑ Disk 1
- ☑ CDROM 1
-
- CDROM 1
- Advanced options
- Disk bus: SATA
-
- Disk 1
- Advanced options
- Disk bus: VirtIO
-
- NIC
- Device model: virtio
-
- Add Hardware
- Storage
- Device type: CDROM device
- Manage...
- Choose the virtio-win iso
- ✔ Begin Installation
-
- View
- Resize to VM
Solus installation
- Install OS
-
- Just follow the instructions or proceed with defaults
- Restart now
Solus upgrade
sudo eopkg upgrade && sudo shutdown now
Upgrade to the latest release and shutdown
Windows installation
Press any key to boot from CD or DVD
If you're late on your first attempt, do the following:
-
- Virtual Machine
- Shutdown
- Force off
-
- View
- 🔘 Details
-
- CDROM 1
- Connect
- Browse...
- Choose the Win10 iso
-
- View
- 🔘 Console
-
- Virtual Machine
- Run
Unless mentioned proceed with defaults and localization
-
I don´t have a product key
-
Custom: Install Windows only (advanced)
Loading VFIO drivers
-
- Load driver
- Browse
- CD Drive (E:) virtio-win
- viostor
- w10
- amd64
-
- Load driver
- Browse
- CD Drive (E:) virtio-win
- NetKVM
- w10
- amd64
Account (Optional)
- Offline account
- Sign in with Microsoft Instead? No
-
Create a really memorable password Next
Services (optional)
Protect your data and integrity. Just say no.
- Do more with your voice Don't use speech recognition
- Let Microsoft use your location No
- Find my device No
- Send diagnostic data to Microsoft Basic
- Improve inking & typing recognition No
- Get tailored experiences with diagnostic data No
- Let apps use advertising ID No
Driver workaround (NVIDIA only)
You can successfully install the official NVIDIA driver if you disguise the VM
sudo virsh --connect qemu:///system
Connect the virtual shell to a system instance
virsh # edit generic
Edit the virtual machine named generic
<features>
<hyperv>
<vendor_id state='on' value='SurelyNotKVM'/>
</hyperv>
<kvm>
<hidden state='on'/>
</kvm>
</features>
Insert any missing XML elements where indicated
Adding real hardware to a VM
The device is already in use by other guests Yes
-
- Select a VM
- Open
- View
- 🔘 Details
-
- Add Hardware
- PCI Host Device
- 0000:01:00.0 NVIDIA Corporation GP107 [GeForce GTX 1050 Ti]
-
- Add Hardware
- PCI Host Device
- 0000:01:00.1 NVIDIA Corporation GP107 HDMI Audio Controller
-
- Add Hardware
- USB Host Device
- 001:003 Logitech, Inc. Classic Keyboard 200
-
- Add Hardware
- USB Host Device
- 001:007 Holtek Semiconductor, Inc. USB Gaming Mouse
-
- Display Spice
- Remove
-
- Video QXL
- Remove
-
- Serial 1
- Remove
-
- Virtual Machine
- Run
-
Switch your monitor input to the VM's GPU
The host devices will be exclusively available to the VM when it runs
More content to come below
Check that 3D works
Unigine Heaven for Linux or Windows
Installing proprietary drivers
sudo eopkg install nvidia-glx-driver-current
Install the proprietary NVIDIA driver for the current kernel
sudo eopkg install nvidia-glx-driver-32bit
Install the 32-bit proprietary NVIDIA driver for steam
Steam
sudo eopkg install steam
Install Steam (including Linux Steam Integration)
Use Steam In-Home Streaming to stream games, with sound, to the host
Has this been helpful to you? Any token amount is appreciated. [Button]