Skip to main content

Arch Linux PCI Passthrough

Based on the following articles:

    https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF https://github.com/vanities/GPU-Passthrough-Arch-Linux-to-Windows10 https://old.reddit.com/r/archlinux/comments/5yi7w7

    Prerequisites

      IOMMU-enabled CPU IOMMU-enabled Motherboard At least 2 GPUs (preferably two different models) At least 2 displays
      Note:
      IOMMU is a generic name for Intel VT-d and AMD-Vi
      

      Setting up devices

      The following assumes that IOMMU has been enabled in the BIOS beforehand.

      To enable PCI passthrough, we'll first have to figure out the IDs of the devices to pass through. These can be determined using lspci -nnk. There you should find an entry like this:

      01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1)
      	Subsystem: eVga.com. Corp. GP104 [GeForce GTX 1080] [3842:6183]
      	Kernel driver in use: nvidia
      	Kernel modules: nouveau, nvidia_drm, nvidia
      01:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)
      	Subsystem: eVga.com. Corp. GP104 High Definition Audio Controller [3842:6183]
      	Kernel driver in use: snd_hda_intel
      	Kernel modules: snd_hda_intel
      

      The IDs we want are these:

      01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP104 [GeForce GTX 1080] [10de:1b80] (rev a1) 01:00.1 Audio device [0403]: NVIDIA Corporation GP104 High Definition Audio Controller [10de:10f0] (rev a1)

      Now that we know these IDs, we can adjust our kernel parameters to enable IOMMU. For that we'll have to edit the /etc/default/grub file. There we'll have to add intel_iommu=on and pci_stub.ids=<IDS> the GRUB_CMDLINE_LINUX_DEFAULT variable. An example configuration would look like this:

      # /etc/default/grub
      ...
      GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on pci_stub.ids=10de:1b80,10de:10f0"
      ...
      

      Now update grub:

      sudo grub-mkconfig -o /boot/grub/grub.cfg
      

      After rebooting, your PCI device should now be isolated and ready to use with a VM. To make sure that the devices have been isolated successfully, check the output of lspci -nnk again. This time, the output should look like this:

      02:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM204 [GeForce GTX 970] [10de:13c2] (rev a1)
      	Subsystem: eVga.com. Corp. GM204 [GeForce GTX 970] [3842:2974]
      	Kernel driver in use: pci-stub
      	Kernel modules: nouveau, nvidia_drm, nvidia
      02:00.1 Audio device [0403]: NVIDIA Corporation GM204 High Definition Audio Controller [10de:0fbb] (rev a1)
      	Subsystem: eVga.com. Corp. GM204 High Definition Audio Controller [3842:2974]
      	Kernel driver in use: pci-stub
      	Kernel modules: snd_hda_intel
      

      The key difference being the kernel driver, which is now pci-stub instead of nvidia.

      Setting up virtual machine

      Install the following software:

      sudo pacman -S qemu libvirt ovmf virt-manager
      

      then enable and start libvirt:

      sudo systemctl enable libvirt.service
      sudo systemctl enable libvirt.socket
      sudo systemctl start libvirt.service
      sudo systemctl start libvirt.socket
      

      and enable the default libvirt network:

      sudo virsh net-autostart default
      sudo virsh net-start default
      

      Add your user to the libvirt group:

      sudo gpasswd -a $USER libvirt
      

      Now we can start setting up the VM itself. Start virt-manager and create a new VM. Insert the Windows installation disk, define the amount of memory and CPU cores the VM is allowed to have, set up storage and specify the name.

      Before hitting Finish, select Customize configuration before install.

      In the next configuration window, set the firmware to UEFI in Overview.

      For better IO performance, add the following hardware:

        Controller:Type=SCSI,ModelVirtIO SCSI Storage:CDROM,SATA with the ISO from here.

        Now we can start the VM and start instaling Windows. Sometimes the VM doesn't correctly boot from the ISO, in which case you will enter a prompt. Just enter exit and choose the boot device manually should this happen.

        Proceed to install Windows as usual. If you decided to use the SCSI controller, you'll need to install the drivers using the downloaded ISO file.