Skip to content

Instantly share code, notes, and snippets.

@oktay-sen
Last active May 16, 2021 14:43
Show Gist options
  • Save oktay-sen/24663b585f2c330cfca227014227667b to your computer and use it in GitHub Desktop.
Save oktay-sen/24663b585f2c330cfca227014227667b to your computer and use it in GitHub Desktop.
Win 10 Gaming VM on Pop! OS 20.04 LTS

Win 10 Gaming VM on Pop!_OS 20.04 LTS

This is a guide on the steps I took to get a Windows 10 virtual machine with dedicated graphics working. My goal is to primarily use Pop!_OS for general desktop use, development, etc, while also being able to play all of my games without compromises.

The steps below are mostly from following different guides I found online to get various things working correctly. I'm collecting them here so I can recreate the same setup in the future.

The hardware I used

  • Ryzen 7 1700 (Having 8 cores is useful. I'd recommend at least 6 cores)
  • Gigabyte B450 Aorus M
  • 2x 16GB ram running @ 2400 MHz (Need at least 16 GB, though I'd recommend 32 GB to be comfortable)
  • PNY Quadro P400v2 (Host GPU)
  • Radeon RX 5500 XT 8GB (Guest GPU)
  • 500GB SATA SSD
  • 750W PSU

Preparation

(Steps originally from MathiasHueber.com)

  1. Make sure AMD-V, IOMMU and SVM module are enabled in the BIOS

  2. Install required software

    sudo apt install qemu-kvm qemu-utils libvirt-daemon-system libvirt-clients bridge-utils virt-manager ovmf
  3. Enable IOMMU in the kernel

    sudo kernelstub -o "amd_iommu=on amd_iommu=pt"
  4. Identify PCI id of the guest GPU

    Download and run list-iommu.sh below, and find the entry for your guest GPU. If you're lazy you can copy-paste this:

    curl -sL https://gist.githubusercontent.com/oktay-sen/24663b585f2c330cfca227014227667b/raw/bd77d5b97718a43eebc5d6dce6d1d231bd6eec98/list-iommu.sh | bash - | grep Radeon

    You should see an output like IOMMU Group 17 09:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 14 [Radeon RX 5500/5500M / Pro 5500M] [1002:7340] (rev c5)

    In this case the PCI id is 1002:7340

  5. Enable vfio for the guest GPU

    sudo kernelstub --add-options "vfio-pci.ids=1002:7340"
  6. Reboot

  7. Verify that step 5 worked by checking lspci -nnv output

    09:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 14 [Radeon RX 5500/5500M / Pro 5500M] [1002:7340] (rev c5) (prog-if 00 [VGA controller])
    Subsystem: ASRock Incorporation Navi 14 [Radeon RX 5500/5500M / Pro 5500M] [1849:5126]
    Flags: bus master, fast devsel, latency 0, IRQ 63
    Memory at e0000000 (64-bit, prefetchable) [size=256M]
    Memory at f0000000 (64-bit, prefetchable) [size=2M]
    I/O ports at f000 [size=256]
    Memory at f7800000 (32-bit, non-prefetchable) [size=512K]
    Expansion ROM at f7880000 [disabled] [size=128K]
    Capabilities: <access denied>
    Kernel driver in use: vfio-pci
    Kernel modules: amdgpu
    

    You should get Kernel driver in use: vfio-pci

Create the VM

(Steps originally from MathiasHueber.com)

  1. Download the latest Windows 10 image from Microsoft
  2. Install Virtual Machine Manager from Pop!_Shop and open
  3. Click "Create new Virtual Machine"
  4. Select "Local Install Media"
  5. Choose "Use ISO Image" and select the Windows 10 image. Keep "Automatically detect operating system" selected.
  6. Configure the machine with the amount of RAM and threads you'd like. I recommend 16 GB ram and 8 cores.
  7. Create a disk image with a good amount of storage. I created a 200GB image for this.
  8. Select "Customise configuration before install" and finish.
  9. Make the following changes to the configuration:

Initial VM configuration

Overview

  • Chipset: Q35
  • Firmware: UEFI x86_64: /usr/share/OVMF/OVMF_CODE.fd

CPUs

  • Model: EPYC-IBPB (Usually you should use host-passthrough)
  • Check "Enable available CPU security flaw mitigations"
  • Sockets: 1
  • Cores: 4
  • Threads: 2 (Note: This is threads per core, not total threads)

Additional Hardware

  • Add a "PCI Host Device" and select the guest GPU
  1. Install Windows 10 as normal
  2. Install latest VirtIO drivers for Windows
#!/bin/bash
# change the 999 if needed
shopt -s nullglob
for d in /sys/kernel/iommu_groups/{0..999}/devices/*; do
n=${d#*/iommu_groups/*}; n=${n%%/*}
printf 'IOMMU Group %s ' "$n"
lspci -nns "${d##*/}"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment