How to Pass GPU to a VM (PCI Passthrough) on Arch Linux
Categories:
5 minute read
PCI passthrough is a powerful feature that allows a physical PCI device—such as a GPU—to be directly assigned to a virtual machine. This provides near-native performance and enables tasks like gaming, machine learning, and 3D rendering inside a VM. Arch Linux, with its bleeding-edge nature and flexibility, is an ideal platform for setting up GPU passthrough using QEMU/KVM and libvirt. However, the process requires careful configuration at several levels: the kernel, bootloader, VM manager, and VM itself.
In this guide, we’ll walk through the full setup for GPU passthrough on Arch Linux, including prerequisites, system configuration, troubleshooting tips, and common pitfalls.
Prerequisites
Before diving into configuration, make sure your system supports virtualization and IOMMU, and you have the right hardware setup:
1. Hardware Requirements
- CPU support for virtualization: Intel VT-x/VT-d or AMD-V/AMD-Vi (IOMMU).
- Two GPUs or an iGPU + dGPU: One GPU must be available for the host; the other for the VM. Trying to pass through the only GPU to a VM requires advanced techniques (e.g., looking-glass, vfio-pci-override) and is not recommended for beginners.
- UEFI firmware: Modern systems with UEFI firmware are strongly recommended for passthrough setups.
- Compatible GPU: Most modern NVIDIA and AMD GPUs work, but consumer-grade NVIDIA cards may require workarounds (e.g., for the error 43 issue).
2. Software Requirements
- Arch Linux with an up-to-date system
- QEMU
- libvirt
- virt-manager (GUI tool for managing VMs)
- Kernel modules:
vfio
,vfio_pci
,vfio_iommu_type1
,kvm
,kvm_intel
orkvm_amd
Step 1: Enable IOMMU in BIOS and Kernel
BIOS/UEFI Settings
Enter your BIOS/UEFI firmware and enable the following:
- Intel systems: Enable “VT-d” and “VT-x”
- AMD systems: Enable “SVM” and “IOMMU”
Kernel Parameters
Edit your bootloader to enable IOMMU:
For GRUB
- Edit
/etc/default/grub
:
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet intel_iommu=on iommu=pt"
# For AMD systems, use: amd_iommu=on iommu=pt
- Regenerate GRUB config:
sudo grub-mkconfig -o /boot/grub/grub.cfg
- Reboot your system.
Step 2: Verify IOMMU Groupings
After reboot, verify your devices are in separate IOMMU groups:
#!/bin/bash
shopt -s nullglob
for g in /sys/kernel/iommu_groups/*; do
echo "IOMMU Group ${g##*/}:"
for d in $g/devices/*; do
echo -e "\t$(lspci -nns ${d##*/})"
done
done
Run this script. Your GPU and its audio device (typically listed separately) must be isolated in their own IOMMU group or with other devices you can afford to pass through.
If the devices are not properly isolated, enable ACS override patch or rearrange PCIe slots if available.
Step 3: Bind GPU to VFIO Driver
Identify the GPU
Run:
lspci -nnk | grep -iA 3 vga
Note the PCI IDs for the GPU and its audio part, e.g., 10de:1b80
and 10de:10f0
.
Blacklist Host GPU Drivers
Create a file /etc/modprobe.d/blacklist-nvidia.conf
(for NVIDIA) or equivalent for AMD:
blacklist nouveau
blacklist nvidia
Add IDs to VFIO
Edit or create /etc/modprobe.d/vfio.conf
:
options vfio-pci ids=10de:1b80,10de:10f0
Replace IDs with your actual GPU and audio IDs.
Regenerate initramfs
sudo mkinitcpio -P
Reboot your system again.
Verify VFIO Binding
After reboot:
lspci -nnk -d 10de:1b80
It should say Kernel driver in use: vfio-pci
.
Step 4: Set Up QEMU/KVM and Libvirt
Install Required Packages
sudo pacman -S qemu virt-manager libvirt edk2-ovmf dnsmasq bridge-utils
Enable and start libvirtd:
sudo systemctl enable --now libvirtd
Add your user to the libvirt group:
sudo usermod -aG libvirt $(whoami)
Log out and back in to apply group changes.
Step 5: Configure OVMF (UEFI Firmware for VMs)
Enable UEFI support for VMs by verifying the OVMF firmware is installed:
ls /usr/share/edk2-ovmf/x64
In virt-manager, you can now select “UEFI” under firmware when creating a new VM.
Step 6: Create and Configure the Virtual Machine
- Open virt-manager and create a new VM.
- Choose a Linux distribution and continue.
- At the “Customize configuration before install” screen, check the box.
- Set Firmware to UEFI (OVMF).
- In “Add Hardware,” select PCI Host Device and add your GPU and its audio function.
- Under Display, remove SPICE and set up with “None” to avoid host display conflicts.
- Add a virtual keyboard or tablet for input if necessary.
- Install guest OS (Windows, Linux, etc.) as usual.
Step 7: Guest-Specific Configuration
Windows Guests (For NVIDIA GPUs)
To avoid Error 43:
- Ensure the guest uses a UEFI firmware.
- Use
q35
chipset for the VM. - Spoof the vendor ID by editing XML:
sudo virsh edit your-vm-name
Inside the <domain>
block, add:
<features>
<hyperv>
<vendor_id state='on' value='1234567890ab'/>
</hyperv>
</features>
- Install official NVIDIA drivers inside the VM.
Linux Guests
For AMD/NVIDIA, install appropriate drivers inside the guest. No vendor spoofing is needed.
Troubleshooting Tips
- Black screen or no signal? Make sure you disabled the host driver and the GPU is bound to vfio-pci.
- Host freezes during boot? Your GPU may be the primary boot device. Try moving the GPU to another PCIe slot or boot using iGPU.
- Can’t isolate GPU in IOMMU group? Consider enabling the ACS override patch. You can add
pcie_acs_override=downstream,multifunction
to your GRUB command line. Be aware this introduces potential security risks.
Optional: Looking Glass (For Single GPU Passthrough)
If you want to pass through your only GPU and still control the host, consider setting up Looking Glass, a tool for sharing the guest’s frame buffer back to the host over a shared memory interface. This is an advanced topic and deserves a dedicated guide.
Conclusion
PCI passthrough is a complex but highly rewarding setup that allows you to harness the power of a GPU inside a virtual machine with nearly native performance. Arch Linux offers a robust and flexible environment for this, though it requires manual setup of kernel modules, IOMMU, and careful GPU isolation.
Once completed, this setup enables powerful use-cases such as gaming on Windows VMs, CUDA development inside Ubuntu guests, or even running macOS in a VM for development. While the learning curve is steep, the performance and flexibility gains make it worthwhile for enthusiasts and professionals alike.
Take your time, read the logs, and experiment in a controlled manner—virtualization mastery is within reach.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.