Configurazione VGA passthrough con libvirt e qemu-kvm

  • creare una nuova macchina virtuale e impostare il chipset Q35 (forse non è necessario)
  • è necessario un BIOS di tipo UEFI: per la compatibilità con VGA passthrough, scaricare OVMF da e impostarlo per la VM

  • CPU: scrivere ‘host-passthrough’ in virtmanager
  • cambiare BUS disco1 in VirtIO
  • scheda rete: ‘dispositivo host’ selezionare la macvlan creata (vedere in seguito), modello virtio
  • aggiungere i dispositivi pass-through PCI (NVIDIA) e USB (mouse e tastiera)
  • da shell, editare l’ XML della VM e aggiungere a :
  • in alternativa (ma è preferibile il precedente punto):
    <!-- modificare il namespace-->
    <!-- aggiungere i seguenti parametri -->

Continua a leggere “Configurazione VGA passthrough con libvirt e qemu-kvm”

VGA passthrough con OVMF e QEMU-KVM

libvirt: parametri per QEMU

Bisogna modificare lo XML creato da virt-manager:

virsh edit nome_della_VM

per modificare i parametri passati a QEMU per fare lo spoof per i driver NVIDIA:

<!-- modificare il namespace-->
<domain type='kvm' xmlns:qemu=''>
<!-- aggiungere i seguenti parametri -->
<qemu:arg value='-cpu'/>
<qemu:arg value='host,hv_time,kvm=off,hv_vendor_id=null'/>

Installare i driver VirtIO

Scaricare la ISO da:, e cercare i driver nelle seguenti directory:

  • NetKVM/: Virtio Network driver
  • viostor/: Virtio Block driver
  • guest-agent/: QEMU Guest Agent 32bit and 64bit MSI installers
  • qemupciserial/: QEMU PCI serial device driver
  • Balloon/: Virtio Memory Balloon driver

How I setup the VM

  1. Set up VM
  2. Select Windows 10
  3. Add a new vDisk using Virtio Bus (iothread + Write back Cache) as Virtio0
  4. add Qemu agent -> yes
  5. Add windows 10 Iso as First DVD on Sata0
  6. Add Virtio-win-0.1.117 as secondary DVD on Sata1
  7. Select Virtio Controller via Options Tab (afaik best practice is to use SCSI ontop of Virtio controller for Windows on SSDs)
  8. Verify your boot Orders. —> Disk then CD-Rom
  9. Install windows 10
  10. Start Windows VM
  11. Boot from Windows ISO (press any key to start from DVD/CD . . .) select “Install Now”, select windows 10 pro x64, custom install, “load Driver” option
  12. Select Virtio-DVD > Viostor > w8.1 > amd64
  13. Install Red Hat VirtIO SCSI controller (driver for your virtio0)
    “load Driver” option
  14. Select Virtio-DVD > VioSCSI > w8.1 > amd64
    uncheck the checkbox
  15. Install Red Hat VirtIO SCSI pass-through controller (in case you need it later)
    “load Driver” option
  16. Select Virtio-DVD > netKVM > w8.1 > amd64
    uncheck the checkbox
  17. Install Red Hat VirtIO Ethernet Adapter (you will need this later)
  18. Install windows regularly (like you’d normally do)

Debian QEMU – VGA passthrough – Virt-Manager

Binding e unbinding dei driver
One new feature in the 2.6.13-rc3 kernel release, is the ability to bind and unbind drivers from devices manually from user space. Previously, the only way to disconnect a driver from a device was usually to unload the whole driver from memory, using rmmod.

In the sysfs tree, every driver now has bind and unbind files associated with it:

$ tree /sys/bus/usb/drivers/ub/
|-- 1-1:1.0 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0
|-- bind
|-- module -> ../../../../module/ub
`-- unbind

In order to unbind a device from a driver, simply write the bus id of the device to the unbind file:

echo -n "1-1:1.0" > /sys/bus/usb/drivers/ub/unbind

and the device will no longer be bound to the driver:

$ tree /sys/bus/usb/drivers/ub/
|-- bind
|-- module -> ../../../../module/ub
`-- unbind

To bind a device to a driver, the device must first not be controlled by any other driver. To ensure this, look for the “driver” symlink in the device directory:

$ tree /sys/bus/usb/devices/1-1:1.0
|-- bAlternateSetting
|-- bInterfaceClass
|-- bInterfaceNumber
|-- bInterfaceProtocol
|-- bInterfaceSubClass
|-- bNumEndpoints
|-- bus -> ../../../../../../bus/usb
|-- modalias
`-- power
`-- state

Then, simply write the bus id of the device you wish to bind, into the bind file for that driver:

echo -n "1-1:1.0" > /sys/bus/usb/drivers/usb-storage/bind

And check that the binding was successful:

$ tree /sys/bus/usb/devices/1-1:1.0
|-- bAlternateSetting
|-- bInterfaceClass
|-- bInterfaceNumber
|-- bInterfaceProtocol
|-- bInterfaceSubClass
|-- bNumEndpoints
|-- bus -> ../../../../../../bus/usb
|-- driver -> ../../../../../../bus/usb/drivers/usb-storage
|-- host2
| `-- power
| `-- state
|-- modalias
`-- power
`-- state

As the example above shows, this capability is very useful for switching devices between drivers which handle the same type of device (both the ub and usb-storage drivers handle USB mass storage devices, like flash drives.)

A number of “enterprise” Linux distributions offer multiple drivers of different version levels in their kernel packages. This manual binding feature will allow configuration tools to pick and choose which devices should be bound to which drivers, allowing users to upgrade only specific devices if they wish to.

In order for a device to bind successfully with a driver, that driver must already support that device. This is why you can not just arbitrarily bind any device to any driver. To help with the issue of adding new devices support to drivers after they are built, the PCI system offers a dynamic_id file in sysfs so that user space can write in new device ids that the driver should bind too. In the future, this ability to add new driver IDs to a running kernel will be moved into the driver core to make it available for all buses.

Metodo alternativo

echo 1002 6739 | sudo tee /sys/bus/pci/drivers/vfio-pci/new_id


In this directory, there is a new_id file entry that can be used to dynamically add VID PID pair like this :

echo VID PID >new_id

Per caricare i moduli VFIO all’accensione e assegnarli ai dispositivi:
Edit the initramfs at /etc/initram-fs/modules to ensure it has VFIO modules loaded on boot:

sudo vim /etc/initram-fs/modules

# Add to file

sudo update-initramfs -u

Create a new module file located at /etc/modprobe.d/local.conf. This step binds the video cards to VFIO on boot so they are not claimed by the host OS (this script also binds VFIO post boot):

sudo vim /etc/modprobe.d/local.conf

# Add to file
options vfio-pci ids=10de:1b80,10de:10f0
options vfio-pci disable_vga=1

Reboot the server.

Note: 10de:1b80, 10de:10f0 are specific to our GPU hardware (GTX 1080s). These numbers refer to the video card and onboard audio. You can find your specific model / vendor numbers by running:

lspci -nnk | grep -i nvidia

4b:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:1b80] (rev a1)
4b:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:10f0] (rev a1)

At this point your physical host should be setup and ready to passthrough GPUs to guest VMs. You can verify IOMMU and VFIO are working by running the following:

sudo find /sys/kernel/iommu_groups/ -type l

# Your output should be a long listing of lines like this


lspci -nnk

# Find your VGA controllers, it should look similar to this

4b:00.0 VGA compatible controller [0300]: NVIDIA Corporation Device [10de:1b80] (rev a1)
    Subsystem: ASUSTeK Computer Inc. Device [1043:8591]
    Kernel driver in use: vfio-pci

GPU primaria: estrazione ROM
Primary GPU Workaround

Another quirk that needs to be addressed is only necessary if you are passing through your primary GPU but interesting nonetheless. This behavior occurs with the GTX 1080, but did not with a Geforce 210 in my testing, so your results may vary.

Like motherboards, GPUs have their own BIOS (aka ROM) and when the computer boots the primary GPU is using a “shadowed” copy of the ROM file. This causes issues when doing passthrough. To workaround this you need to get a copy of a non-shadowed ROM file which is specific to the GPU model. In our case we had other non-primary GPUs we could dump the ROM from. You can also try 3rd party websites that provide ROMs but I did not have success with those.

First unbind a non-primary GPU from vfio-pci (if it is bound), for example:

echo “0000:4b:00.0” | sudo tee /sys/bus/pci/drivers/vfio-pci/unbind

Then dump the ROM contents to a file:

echo 0 | sudo tee /sys/devices/pci0000:00/0000:00:03.0/0000:4b:00.0/rom

sudo cat /sys/devices/pci0000:00/0000:00:03.0/0000:4b:00.0/rom &gt; gpu.rom

echo 1 | sudo tee /sys/devices/pci0000:00/0000:00:03.0/0000:4b:00.0/rom

Note: The echo 0 and echo 1 basically just switches the ROM into a readable state and then back again if you’re curious.

After you have a good ROM file you need to add this code to your VMs XML in the definition of the GPU which added earlier:

Patch dei driver NVIDIA

  1. Using KVM/qemu, boot your Windows 10 VM using the kvm=off option described above.
  2. Inside Windows, download the Nvidia graphics driver for your graphics card from here
    The latest driver for my Nvidia GTX 970, as of this writing, is 372.54.
  3. Run the Nvidia driver installer. It will unpack the files to C:/NVIDIA/DisplayDriver/{version}/Win10_64/International/Display.Driver, with the driver as of this writing it will be C:\NVIDIA\DisplayDriver\372.54\Win10_64\International\Display.DriverExit the Nvidia installer once it unpacked the files !!!
  4. Download the Windows WDK from here: the webpage that opens, go to step 2, then click “Install Windows Driver Kit (WDK) 10”. You do NOT need to install the other stuff!

    Run the installer and install the Windows Driver Kit (WDK).

  5. Download Python from As of this writing the latest version is 3.5.2Run the installer.
  6. To enable testsigning:
    1. Right-click on the Windows menu icon and select “Command Prompt (Admin)”
    2. On the command prompt, enter
      Bcdedit.exe -set TESTSIGNING ON</code>

      and press Enter

    Later, if you wish to disable testsigning, use the following command:

    Bcdedit.exe -set TESTSIGNING OFF

    Important: Please be aware of the security risks when you run testsigned drivers.

  7. Reboot your Windows 10 VM.
  8. Open and download the two script files (a Powershell script and a Python script):
    • gencert.ps1

    Both files must reside in the same location. (Note: I opened the file, copied the content into an empty Notepad file and saved it.)

  9. Open the Windows File Explorer and go to the folder where you saved the two files.Click “File”, then select “Open command prompt” -> “Open command prompt as administrator”.
  10. Before running the script, open the file in Notepad or with IDLE (right click on the file and select) and check that the driver version you are going to install is actually supported by this patch. See below for reference:
    # TODO: Wildcard Search
    PATCHES = {
    “41FF978804000085C0”: “31C0909090909085C0”, # 361.91 – 368.39
    “41FF97B804000085C0”: “31C0909090909085C0”, # 372.54
  11. Copy and paste the following onto the command line: C:\NVIDIA\DisplayDriver\372.54\Win10_64\International\Display.Driver

    and hit Enter.Note: Replace the version (here “372.54”) in the path name with the Nvidia driver version you downloaded.

    The script will run for a few minutes, after which you see “Warnings: None”. Hit Enter.

    The Python script will now execute the Powershell script and testsign the driver.

  12. Using the File Explorer, go to

    and run “setup.exe” to install the patched Nvidia driver.

  13. Shutdown Windows and modify your qemu start script:
    -cpu host,hv_vapic,hv_time,hv_relaxed,hv_spinlocks=0x1fff \

    Note: Remove the “kvm=off” option and instead add “hv_vapic,hv_time,hv_relaxed,hv_spinlocks=0x1fff”

XEN laptop

per il desktop vedere qui:

per i notebook, l’ uso di XEN è limitato dal fatto che ci vuole un doppio monitor per sfruttare il VGA passthrough:

Forum Regular
posted 2013-Nov-6, 4:03 pm

Hi guys,

I’m thinking about buying a new laptop and using Xen on it. Probably with Debian or Ununtu Gnome as dom0.

I’ve never messed around with VGA passthrough and I’m wondering what’s possible with it on a laptop. It seems most people use 2 graphics cards in a desktop and a physical kvm switcher to switch between the two.

If I bought a laptop with onboard Intel graphics and discrete Nvidia graphics, will I be able to run a Linux dom0 (and use Gnome, etc) and then spin up a Windows domU and somehow switch between the two on the same screen? With keyboard and mouse working in both?

I don’t think this is yet possible but thought I’d ask 🙂 I saw a demo somewhere on Youtube where they’ve nailed it on Android tablets… press power and Vol-UP and you switch to a new tablet instance!. I was hoping there’d be an easy way to switch between two instances on a laptop and have everything work nicely…


Whirlpool Forums Addict
posted 2013-Nov-6, 4:43 pm

Make sure both CPU and Mainboard support VT-d……and that you can enable this in the bios. The Intel site is a good guide to what CPU’s and mainboard chipsets support this.

I’d try to avoid any laptop with an nVidia card, as I think only the Quadro cards are able to be passed through with any success. The Intel GPU should be able to be passed through.

I think it is probably PCI passthrough that you are after. That was the easiest way for me to passthrough graphics cards.

You can use a VNC viewer to access DomU on the same screen.

Forum Regular
posted 2013-Nov-13, 12:21 pm

I didn’t have any luck passing through my nvidia either, so I opted to buy an ATI card, and the pass through works out of the box.

You could otherwise pass through the onboard intel graphics to windows (vt-d), while linux uses the nvidia card.

Once windows has booted and is using say the onboard intel graphics… then no, you can’t switch between them (unless you rdp,etc). but I would recommend hooking two monitors up if you’re able to do it that way.

Xen VGA passthrough – hardware

The Tesla (2xx/3xx) and Fermi (4xx) series of GPUs can be modified by modifying the BIOS. Earlier cards can also be modified, but the modification is slightly different to what is described in this article. There is no hardware modification required on any of these cards. The modification is performed by modifying what is known as the “straps” that configure the GPU at initialization time. The nouveau project (free open source nvidia driver implementation for Xorg) has reverse engineered and documented some of the straps, including the device ID locations. We can use this to change the device ID the card reports. This causes the driver to enable a different set of features that it wouldn’t normally expose on a gaming grade card, even though the hardware is perfectly capable of it (you are only supposed to have those features if you paid 4-8x more for what is essentially the same (and sometimes even inferior) card by buying a Quadro).
il post originale della modifica NVidia
esempio di configurazione

Xen virtualizzazione

Schede VGA condivise tra macchine virtuali:

CAD at a distance: Using Citrix for workstation virtualization
The very newest generation of GPUs, such as the NVIDIA VGX K2 , are designed for hardware virtualization. VGX provides direct access to the GPU frame buffer, maintaining high performance even with large 3D models. Citrix expects their NVIDIA VGX-accelerated XenDesktop platform to be able to serve up to 100 users with a single multi-GPU graphics card, using both OpenGL and DirectX.


Xen 4.3 e Win8 VGA pass-through

Spiega come far funzionare la scheda VGA anche dopo il reboot del domU.

VGA passthrough – situazione

February 1st, 2013


The VGA passthrough club – did you succeed, and how?

I can’t do away with Windoze, but I hate dual-boot. I also need native (or near-native) graphics support in the Windows VM.

In the end I chose Xen to host Linux and a Windows 7 VM which uses a dedicated graphics card for native graphics performance. It works extremely well, with what I consider top-notch performance that doesn’t stand (much) behind a native Windows installation on bare metal.

In fact, I’m so thrilled about it that I wonder why not every dual-booter is switching to virtualization. (I’m actually not that surprised since it was quite challenging to get it working.)

Here my questions:

Has anybody tried VGA passthrough?

If yes, which hypervisor/method did you use (Xen, KVM, VMware, etc.)?

How easy or difficult was it?

In the end I would like to know if there are perhaps better or easier ways to get it working. Thanks in advance for your feedback!
LM14 64bit (Ubuntu 12.10) with Xen hypervisor 4.1.2 and Windows 7 Pro 64 bit guest using VGA passthrough


February 3rd, 2013


Re: The VGA passthrough club – did you succeed, and how?

You indeed need suitable hardware. Here is what you need:

1. CPU with VT-d (Intel) or AMD-Vi (AMD) support. This feature is also called IOMMU. See, or for Intel CPU’s see

2. A motherboard that supports VT-d. See the Wikipedia link above, as well as…e-motherboards and

3. A motherboard BIOS that supports VT-d. I’m not joking here, one BIOS release may support VT-d, the next one doesn’t. In some cases there is no way going back to the earlier BIOS that does support it. See links under 2.

4. A graphics card that supports VGA passthrough. In general, most modern AMD (ATI) graphics cards will work, but it’s best to check here…TestedAdapters and
Some Nvidia graphics adapters are also supported, namely the Quadro series of “Multi-OS” capable cards starting with the Quadro 2000 model upwards (the Quadro 600 for example isn’t specified as “Multi-OS”). There are some more Nvidia graphics adapters that work, but first check the links above if it’s listed.
The newer Xen 4.2 hypervisor supposedly improves graphics cards compatibility, though I haven’t tried it.

It is MUCH easier if you have two graphics cards, or a CPU internal GPU (like on most new Intel desktop CPUs) and a discrete graphics card for passthrough.One will serve Linux, the other your Windows guest.

If your hardware doesn’t meet the above, either replace the incompatible part, or forget the whole thing!

I’ve written a how-to for Linux Mint 13/14, which should likewise work with Ubuntu 12.04 and 12.10:

Now to your questions.

My goal was to get fast switching on 2 desktops, the way you would have 2 full OSes booted simultaneously.

My PC works as if I have two PCs. I could hook up two screens, keyboards and mice and two people would be able to use it at the same time, with full video acceleration on both. Right now I switch from one to the other via KVM button and the input selector on my screen, but if I have to go forth and back a lot I run a remote desktop in Windows to connect to my Linux dom0, or vice versa. I use a SAMBA share under Linux to copy files between the two.

Can you confirm your Windows 7 installation behaves as native?

95% yes. Everything except the following two issues work as if I was running Windows directly on the hardware. The two issues I’ve found are:
I) Youtube video stops after a few seconds, hangs for a while, and continues, just to stop again after a few seconds. This is most likely a networking issue with the bridge, though I haven’t figured out what exactly. Somehow Windows “looses” the DNS server, or access to it. One work around would be to pass through a dedicated NIC. I haven’t tried it though.
II) I can’t watch video using VLC when the video file is on a network drive. I believe this is the same network problem as above.
EDIT: Both problems are solved now using the latest GPLPV drivers under Windows.

Other than these two issues I haven’t found any problem.

What about other peripherals? Scanner, printer, gamepad, etc.?

In addition to the graphics card, I’m passing 2 USB controllers through to Windows. Everything connected to these ports is fully controlled by Windows, with Windows native drivers.
Just an example how well this works: I use Windows for photo editing. To calibrate my screen I use a spectrophotometer (some device that measures light / colors) which is connected via USB. The software then shows different color patches on the screen which my calibrating device reads and reports back to the PC (via USB port). At the end, the software loads the corrected color curve directly into my screen via the DVI port of the graphics card. This can only work when the calibration software is able to communicate with the graphics card.
Other external devices I frequently use under Windows are:
– Keyboard and mouse are connected via KVM USB switch;
– CF card reader (to transfer photos from the camera’s CF cards to the PC);
– External hard drive for backup – it’s automatically detected by the backup program when I connect it to the USB port;
– USB audio controller – a low-cost ~5$ USB stick that works without any issues, it’s permanently plucked in;
– USB flash drives – they work as expected.

I haven’t set up my printer yet to work with Windows. But I can’t see any reason why it shouldn’t work. I have both a USB 2.0 and a USB 3.0 controller passed to Windows. The transfer speed is as expected. If you have an external HDD or memory card reader to connect, use a USB 3.0 controller – it makes a huge difference.

Good luck!


February 7th, 2013


Re: The VGA passthrough club – did you succeed, and how?

I can’t do away with Windoze, but I hate Has anybody tried VGA passthrough?

Yes, I have a setup with 2 desktops, each running in their own virtual machine with passed through radeon4350 and usb cards.
Apart from that, a few other virtual machine servers run on the same hardware.

Which hypervisor/method did you use (Xen, KVM, VMware, etc.)?

I’m using Xen 4.2 at the moment, it seems to me that in general Xen is way ahead of the game when it comes to PCI Passthrough.

How easy or difficult was it?

Once i started to use the catalyst driver instead of the open source driver (which complains about not being able to find the bios), everything was pretty straight forward.
I installed ubuntu and windows7 in a vnc session and later installed Catalyst. Windows 8 was even easier, it installed a working vga driver out of the box.
Note that i just used pci-passthrough, not the advanced vga-passthrough patches.
Besides the vga adapter itself, i also passthrough the onboard audio of the adapter (hdmi), and an usb controller, so basically i have 2 seperate terminals, each running their own os (either Ubuntu/Windows7/Windows8).
All operating systems behave asif they run on native hardware, only difference is that the boot screen doesn’t appear on my vga cards, because i chose to do only pci-passthrough. The boot window appears on the VNC session.

Note that as stated above, using the right CPU, Mainboard and VGA Card is essential here.
In my case: Intel Core i7 860, Asus P7P55D Evo, Asus EAH4350 Silent.


You can use any number of cards from any number of manufacturers.

Dom0 won’t care because while it will know that there are devices there, you’ll be passing kernel boot parameters to tell it to ignore looking for and binding drivers to the cards so it will just leave them alone for the domUs to deal with.

Each domU will only know about the card assigned to it so they in turn won’t care that you have multiple video cards from either the same manufacturer or different ones. As long as the domU’s OS has drivers for the card(s) assigned to it, it’ll be able to use it fully.

My Xen server setup has a cheap Nvidia card for the Xen host and a Radeon 7750 driving multiple monitors dedicated to one of the guests. Works like a charm.

Note: there are still some issues with rebooting domUs that have assigned VGA adapters. The video card may not be reset during the reboot process and may fail to initialize properly following the reboot. I haven’t found a solution for this yet so you may want to do some searches on FLR (Function Level Resets) with Xen VGA passthrough.