Dual GPU Passtrough Guide
By Taha • 14 minutes read •
- The latest advances in virtualization now make it possible to run multiple operating systems simultaneously on high-performance computers. In this guide, we’ll show you how to use dual GPU migration to assign a powerful graphics card to a Windows virtual machine running on a Linux system, allowing you to run Windows and Linux seamlessly on the same machine.
- Passthrough allows a virtual machine (VM) to use the hardware directly, which is a huge advantage, especially for gamers and users of graphics-intensive applications. On a dual GPU system, you can assign one GPU to the Linux host system and the other GPU to the Windows virtual machine to maximize the graphics performance of both operating systems independently.
Prerequisites
- 16 GB of RAM or more (8 GB for each system)
- A computer with UEFI compatible two GPUs (one for the host and one for the guest)
- A CPU with virtualization support (Intel VT-x or AMD-V)
- A Linux distribution with a recent kernel (5.0 or later)
- A Windows installation ISO
Step 1: Enable IOMMU from BIOS
- IOMMU (Input/Output Memory Management Unit) is a feature that allows the system to map device memory addresses to physical memory addresses. This is essential for passthrough to work correctly. To enable IOMMU, you need to enable IOMMU (AMD-Vi for AMD chipset, VT-d for Intel chipset)
- For Intel:
- For AMD:
Step 2: Enable IOMMU in the Kernel
To enable IOMMU in the kernel, you need to add the following kernel parameters to the bootloader configuration files.
If you’re using GRUB bootloader;
Open the GRUB configuration file:
Add the following line to the
GRUB_CMDLINE_LINUX
parameter:GRUB_CMDLINE_LINUX="... intel_iommu=on iommu=pt" # For Intel GRUB_CMDLINE_LINUX="... amd_iommu=on iommu=pt" # For AMD
Update the GRUB configuration:
or
or
If you’re using systemd-boot;
Open the default kernel command line file:
Add the following line to the file:
intel_iommu=on iommu=pt # For Intel amd_iommu=on iommu=pt # For AMD
And open the current kernel configuration file:
or
Add the following line to append the
options
line:intel_iommu=on iommu=pt # For Intel amd_iommu=on iommu=pt # For AMD
Reboot the system to apply the changes.
Step 3: Verify IOMMU Support
To verify that IOMMU is enabled and working correctly, run the following command:
|
If you want to see the IOMMU groups, you can use the following script:
Add the following lines to the file:
#!/bin/bash for; do for; do done; done;
Save the file (esc + :wq) and make it executable:
Run the script:
The output will show you the IOMMU groups and the devices in each group.
)
Important
You will see the GPU vendor ID and device ID in the output. You will require this information when configuring the virtual machine. This is an AMD GPU with the vendor ID
1002
and device ID67df
([1002:67df]
). The audio device is also shown in the same group with the vendor ID1002
and device IDaaf0
([1002:aaf0]
).
Step 4: Install Required Packages
Install the required packages for this operation:
For Ubuntu/Debian:
For Fedora:
For Arch:
Step 5: Add your user to the libvirt groups
Add your user to the libvirt and kvm groups with the following command:
Note
If you’re get
group x does not exist
error, remove groupx
from the command and try again.
Step 6: Block the GPU Driver
To stop the GPU driver loading at boot, you must blacklist the driver. Create a new file in the /etc/modprobe.d/ directory with the following command to do this:
Add the following lines to file:
For NVIDIA:
For AMD or Radeon:
Now, append the GPU vendor ID and device ID to the file from the Step 3 output:
Save the file and regenerate the initramfs:
For Ubuntu/Debian:
For Fedora:
For Arch:
Step 7: Enable and Start the Libvirt Service and Reboot
Enable and start the libvirt service:
Reboot the system to apply the changes.
Step 8: Check the GPU Drivers
After rebooting the system, check if the GPU driver is loaded by inxi command. Run the following command to check the GPU driver:
Important
If you don’t see the vfio-pci driver in the output, go back to Step 6 and check the configuration file.
Step 9: Download the Windows ISO File and VirtIO ISO Drivers
- Download the Windows installation ISO from the Microsoft website: Windows 10, Windows 11
- Download the VirtIO drivers ISO from the VirtIO GitHub Page.
Step 10: Create a Windows Virtual Machine
Open the Virtual Machine Manager (virt-manager) and click
Edit > Preferences
. Now, enable theEnable XML editing
option.Click
Edit > Connection Details
. Now, switch to theVirtual Networks
tab. Select thedefault
adapter. Ensure that theAutostart
option is enabled.Then close the settings window and click the
Create a new virtual machine
button.Select the
Local install media (ISO image or CDROM)
option and click the Forward button.Click the Browse button and select the Windows ISO file. And click the Forward button.
Set the memory size to 8 GB or more and click Forward. If you have a CPU with more than 4 cores, set the CPU core to 4 or more.
Create a new disk image of at least 100 GB and click Forward.
Name the virtual machine and select the Customise configuration before installation option. Now, click the Finish button.
Go to the Overview tab and click on Firmware. Select
UEFI x86_64: /usr/share/edk2/ovmf/OVMF_CODE.secboot.fd
option.Go to the Memory tab, enable the
Enable shared memory
option.Select the
Virtio
option from theDisk bus
menu in theSATA Disk 1
tab.Select the
virtio
option from theNIC
tab in theDevice model
section.Go to the
TPM
tab, click onAdvanced options
and select TPM version to2.0
.Click the
Add Hardware
button and selectStorage
. Select theCD-ROM
device option from theDevice Type
menu.Click the
Manage
button.Click the
Browse Local
button. Select the VirtIO ISO file.In the
Boot Options
tab. Enable to SATA CDROM 1 option. Then move the SATA CDROM 1 to the top of the boot order.
Step 11: Setup Windows
Start the virtual machine and install Windows as usual.
Agree to the licence agreement and choose the custom installation option.
Select the
Load driver
option.Select
OK
. Windows will find the VirtIO drivers automatically.Select
RedHat VirtIO SCSI controller
and clickNext
.Note: If you’re installing Windows 10, you must select the
RedHat VirtIO SCSI controller (E:\amd64\w10\viostor.inf)
driver.
Click
Next
. Setup will automatically set up the partitions.Once the installation is complete, the out-of-box experience (OOBE) will appear. Since there is no network connection, we will press Shift+F10 and type the following command.
OOBE\BYPASSNRO
Once you have completed the reboot, you can proceed to set up Windows as usual. Select the
I don't have internet
option.Select
Continue with limited setup
option.Type your username and password.
Once you have made the necessary adjustments, simply press Next. The installation will complete itself.
After the installation is complete, you must install the VirtIO drivers from the VirtIO ISO file. Open the file manager and navigate to the
virtio-win
disk.Run the
virtio-win-guest-tools
program. The program will install automatically install the necessary files.
Note
The Windows update will install the GPU driver automatically, which will cause the system to crash. You must disable the automatic updates from the Group Policy Editor to prevent this.
Step 12: Setup ROM File
Important
For desktop GPUs, this step is not required with
465.xx
andlater
drivers. For laptop GPUs, this step is not required with500.xx
andlater
drivers. Refer to the NVIDIA Customer Help Page for more information.
If you’re using Linux:
NVIDIA: Download NVFlash and extract it to home folder. The file name should be
nvflash
.AMD: Download ATIFlash and extract it to home folder. The file name should be
amdvbflash
.Make the
nvflash
oramdvbflash
file executable.- NVIDIA:
chmod +x nvflash
- AMD:
chmod +x amdvbflash
- NVIDIA:
And extract the ROM file from the GPU.
- NVIDIA:
sudo ./nvflash --save vbios.rom
- AMD:
sudo ./amdvbflash -s 0 vbios.rom
- Note for AMD: Use the
-s 0
option to specify the GPU number. If you have multiple GPUs, you can change the number to extract the ROM file from the desired GPU. To learn the GPU number, use thesudo ./amdvbflash -i
command.
- Note for AMD: Use the
- NVIDIA:
If you’re using Windows:
- Install GPU-Z from the GPU-Z website.
- Open the GPU-Z and click on the
Save to file
button to extract the ROM file.
Patch the ROM file (only NVIDIA)
Note: If you’re using AMD GPU, you can skip this step.
If you’re using Linux, install the
okteta
app.Open the ROM file with the
okteta
app.Press
Ctrl + F
and search for theVIDEO
value.Select before the
VIDEO
line and press the DELETE button to remove the selected value:After the delete the value, the file should look like this:
If you’re using Windows, install the
HxD
app.
Copy the ROM file to the
/var/lib/libvirt/vgabios
directory.Change permissions of the ROM file.
Note: If you’re using Fedora, you need to change the secontext of the ROM file.
Step 13: Setup shared memory
Open
virt-manager
and click on the newly created virtual machine. Next, click on Overview and then XML.Add the following lines to xml file:
Remove the following lines from to the xml file:
Then add the following lines to the xml file:
32
Step 14: Setup looking-glass-client and looking-glass-server
Install the looking-glass-host into the virtual machine.
The binaries already available for the Looking Glass client are currently not working properly. The client program must be manually compiled.
Install the required packages for Ubuntu, Debian, or other Linux distributions.
Clone the Looking Glass repository and build the client program.
Make the change to the client directory and then compile the program.
Copy the compiled program to the
/usr/local/bin
directory.
Step 15: Setup dummy output
If you want to buy a dummy HDMI adapter. You can buy from the Amazon, or you have already a dummy HDMI adapter, you can use it.
Use the VirtualDisplay driver if you don’t want to buy an HDMI adapter. This driver creates a dummy video card for the virtual machine.
Visit the VirtualDisplay repository and download the driver.
Extract the downloaded file.
Go to the search menu. Type the
cmd
and run the command prompt as administrator. (ctrl+shift+enter is the shortcut)Install the driver certificate by typing the following command.
cd %USERPROFILE%\Downloads\IddSampleDriver-0.1 .\installCert.bat
Then open the device management console. (devmgmt.msc)
Click
Action
menu and select theAdd legacy hardware
option.Click
Next
button. Then select theInstall the hardware that I manually select from a list (Advanced)
option.Click
Next
button. Then select theDisplay adapters
option.Click
Next
button. Then click on theHave Disk
button.Click
Browse
button. Select the%USERPROFILE%\Downloads\IddSampleDriver-0.1\IddSampleDriver.inf
file.Click
Open
button. Then click on theNext
button.Click to
Install
button. Then click on theFinish
button.
Step 16: Add GPU to the Virtual Machine
Close the virtual machine and open the configuration tab. Then click
Add Hardware
buttonNext, you will see the
PCI Host Device
option. Select the GPU and audio device.You must also add the GPU ROM file from the
/var/lib/libvirt/vgabios
directory. Enter the following XML code in theOverview > XML
section.Then boot virtual machine and open the device manager (devmgmt.msc).
Open the
Display adapters
section. Right-click on theMicrosoft Basic Display Adapter
and select theDetails
tab. SelectHardware IDs
. If the hardware ID matches your GPU vendor ID and device ID from step 3, the GPU is installed correctly.If everything is working correctly, you can install the standard drivers from your video card manufacturer’s website and start using them.
Then shutdown the virtual machine and set video type
none
from theVideo QXL
tab.Finally start the virtual machine and run the
looking-glass-client
program.
Conclusion
- This guide shows you how to set up dual GPU passthrough on a Linux system. You can assign a powerful graphics card to a Windows virtual machine running on a Linux system, allowing you to run Windows and Linux on the same machine.