<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
		<id>http://wiki.hoeft-online.de/index.php?action=history&amp;feed=atom&amp;title=Setup_VGAPassthrough</id>
		<title>Setup VGAPassthrough - Versionsgeschichte</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.hoeft-online.de/index.php?action=history&amp;feed=atom&amp;title=Setup_VGAPassthrough"/>
		<link rel="alternate" type="text/html" href="http://wiki.hoeft-online.de/index.php?title=Setup_VGAPassthrough&amp;action=history"/>
		<updated>2026-08-01T01:19:55Z</updated>
		<subtitle>Versionsgeschichte dieser Seite in Ingos Wiki</subtitle>
		<generator>MediaWiki 1.28.2</generator>

	<entry>
		<id>http://wiki.hoeft-online.de/index.php?title=Setup_VGAPassthrough&amp;diff=7&amp;oldid=prev</id>
		<title>Ingo: create page</title>
		<link rel="alternate" type="text/html" href="http://wiki.hoeft-online.de/index.php?title=Setup_VGAPassthrough&amp;diff=7&amp;oldid=prev"/>
				<updated>2017-09-20T10:46:45Z</updated>
		
		<summary type="html">&lt;p&gt;create page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== HowTo Setup VGAPassthrough from scratch on Debian 9 (stretch) ==&lt;br /&gt;
Author: Ingo Höft, 2017-08-10&lt;br /&gt;
&lt;br /&gt;
=== Preparation ===&lt;br /&gt;
You need a CPU with virtualization and IOMMU, two different graphic&lt;br /&gt;
cards, two keyboards and mice, one for the host, one for the guest. I&lt;br /&gt;
use one keyboard/mouse with an usb switch.&lt;br /&gt;
&lt;br /&gt;
Install a basic system for testing as described in&lt;br /&gt;
[[Setup_KVM_with_console]] but without Guest Setup.&lt;br /&gt;
&lt;br /&gt;
I have a simple older graphics card for the text console and NVIDIA for&lt;br /&gt;
the guest.&lt;br /&gt;
 ~$ lspci | grep VGA&lt;br /&gt;
 0f:00.0 VGA compatible controller: NVIDIA Corporation GF106GL [Quadro 2000] (rev a1)&lt;br /&gt;
 37:04.0 VGA compatible controller: Matrox Electronics Systems Ltd. MGA 1064SG [Mystique] (rev 03)&lt;br /&gt;
 ~$&lt;br /&gt;
The older NVIDIA Quadro 2000 does not support UEFI bios so we will&lt;br /&gt;
workaround using of debian package ovmf (UEFI firmware for virtual&lt;br /&gt;
machines). virt-install uses seabios by default. Next time I will look&lt;br /&gt;
for a newer graphics card supporting UEFI. If your graphics card support&lt;br /&gt;
UEFI you can look at [https://www.techpowerup.com/vgabios/ Video BIOS Collection]&lt;br /&gt;
or check with this [https://vfio.blogspot.de/2014/08/does-my-graphics-card-rom-support-efi.html rom-parser].&lt;br /&gt;
&lt;br /&gt;
=== Setup VGAPassthrough on host ===&lt;br /&gt;
It is important to blacklist the graphics card for the guest,&lt;br /&gt;
here NVIDIA, so the host will never see it. This should be done&lt;br /&gt;
first to avoid confusion. I had trouble. My linux box does not use&lt;br /&gt;
the right graphics card on boot and I could not see anything. The&lt;br /&gt;
nouveau driver is default for NVIDIA. For blacklisting I use kernel&lt;br /&gt;
parameter. On grub boot menu hit 'e' and append kernel parameter&lt;br /&gt;
'modprobe.blacklist=nouveau' (or what your driver is) and boot with F10.&lt;br /&gt;
&lt;br /&gt;
You should know what driver to blacklist before installing the second&lt;br /&gt;
graphics card. Maybe you can't examine it afterwards because of a black&lt;br /&gt;
screen. Use 'sudo lspci -v' to show what 'Kernel driver in use:' for the&lt;br /&gt;
video card to blacklist.&lt;br /&gt;
&lt;br /&gt;
After booting I set in /etc/default/grub for persistence&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;intel_iommu=on modprobe.blacklist=nouveau&amp;quot;&lt;br /&gt;
Now I boot with the right graphics card for the console of the host.&lt;br /&gt;
&lt;br /&gt;
The intel_iommu=on is needed for Intel CPUs, amd_iommu=on for AMD CPUs.&lt;br /&gt;
Don't forget to run&lt;br /&gt;
 ~$ update-grub&lt;br /&gt;
Now we have to load the vfio-pci driver modules for VGAPassthrough.&lt;br /&gt;
They MUST load before any other video driver so the graphics card can't&lt;br /&gt;
be occupied bye other drivers. We do it very early in initram, so edit&lt;br /&gt;
/etc/initramfs-tools/modules like this:&lt;br /&gt;
 ~$ cat /etc/initramfs-tools/modules&lt;br /&gt;
 # List of modules that you want to include in your initramfs.&lt;br /&gt;
 # They will be loaded at boot time in the order below.&lt;br /&gt;
 #&lt;br /&gt;
 # Syntax:  module_name [args ...]&lt;br /&gt;
 #&lt;br /&gt;
 # You must run update-initramfs(8) to effect this change.&lt;br /&gt;
 #&lt;br /&gt;
 # the drivers for vfio must load early in THIS order!&lt;br /&gt;
 vfio&lt;br /&gt;
 vfio_iommu_type1&lt;br /&gt;
 vfio_pci&lt;br /&gt;
 vfio_virqfd&lt;br /&gt;
 ~$&lt;br /&gt;
&lt;br /&gt;
Now we have to append the physical graphics devices to the vfio-pci&lt;br /&gt;
driver. This is somewhat tricky. You cannot passthrough simple devices&lt;br /&gt;
but only complete IOMMU groups. For further information and finding the&lt;br /&gt;
IOMMU group look&lt;br /&gt;
[https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF#Setting_up_IOMMU here]:&lt;br /&gt;
&amp;quot;An IOMMU group is the smallest set of physical devices that can be&lt;br /&gt;
passed to a virtual machine&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Using the small bash script from there for my NVIDA card I found:&lt;br /&gt;
 IOMMU Group 14 0f:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF106GL [Quadro 2000] [10de:0dd8] (rev a1)&lt;br /&gt;
 IOMMU Group 14 0f:00.1 Audio device [0403]: NVIDIA Corporation GF106 High Definition Audio Controller [10de:0be9] (rev a1)&lt;br /&gt;
There are two devices in Group 14: the VGA controller and its build in&lt;br /&gt;
audio device. That's evident.&lt;br /&gt;
&lt;br /&gt;
Now we can add the devices in the group to vfio-pci in&lt;br /&gt;
/etc/modprobe.d/vfio.conf like this:&lt;br /&gt;
 ~$ cat /etc/modprobe.d/vfio.conf&lt;br /&gt;
 options vfio-pci ids=10de:0dd8,10de:0be9&lt;br /&gt;
 options vfio-pci disable_vga=1&lt;br /&gt;
 ~$ sudo update-initramfs -u&lt;br /&gt;
You will find the device numbers from my example and I will not use VGA.&lt;br /&gt;
To get module parameters I use 'sudo modinfo vfio-pci'.&lt;br /&gt;
&lt;br /&gt;
Reboot.&lt;br /&gt;
&lt;br /&gt;
Now you should find the well set up vfio-pci driver like this:&lt;br /&gt;
 ~$ lspci -nnk -d 10de:0dd8&lt;br /&gt;
 0f:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF106GL [Quadro 2000] [10de:0dd8] (rev a1)&lt;br /&gt;
         Subsystem: Hewlett-Packard Company GF106GL [Quadro 2000] [103c:084a]&lt;br /&gt;
         Kernel driver in use: vfio-pci&lt;br /&gt;
         Kernel modules: nouveau&lt;br /&gt;
 ~$ lspci -nnk -d 10de:0be9&lt;br /&gt;
 0f:00.1 Audio device [0403]: NVIDIA Corporation GF106 High Definition Audio Controller [10de:0be9] (rev a1)&lt;br /&gt;
         Subsystem: Hewlett-Packard Company GF106 High Definition Audio Controller [103c:084a]&lt;br /&gt;
         Kernel driver in use: vfio-pci&lt;br /&gt;
         Kernel modules: snd_hda_intel&lt;br /&gt;
 ~$&lt;br /&gt;
Inspecting 'sudo journalctl -k' is also a good thing.&lt;br /&gt;
&lt;br /&gt;
=== Install virtual machine ===&lt;br /&gt;
Now it's up to install a guest with all this:&lt;br /&gt;
 ~$ virsh net-start default&lt;br /&gt;
 ~$ virt-install --virt-type kvm \&lt;br /&gt;
                 --cpu host \&lt;br /&gt;
                 --features kvm_hidden=on \&lt;br /&gt;
                 --name harley \&lt;br /&gt;
                 --location https://ftp.de.debian.org/debian/dists/stretch/main/installer-amd64/ \&lt;br /&gt;
                 --os-variant debian9 \&lt;br /&gt;
                 --extra-args &amp;quot;console=ttyS0,115200&amp;quot; \&lt;br /&gt;
                 --noautoconsole \&lt;br /&gt;
                 --disk size=10 \&lt;br /&gt;
                 --memory 2048 \&lt;br /&gt;
                 --host-device 0f:00.0 \&lt;br /&gt;
                 --host-device 0f:00.1 \&lt;br /&gt;
 ;&lt;br /&gt;
{|cellspacing=&amp;quot;10&amp;quot;&lt;br /&gt;
| --cpu&amp;amp;nbsp;host&lt;br /&gt;
|Yes of course, we want hardware accelleration and this guest with its physical device binding runs only on this host.&lt;br /&gt;
|-&lt;br /&gt;
| --features&amp;amp;nbsp;kvm_hidden=on&lt;br /&gt;
|It was told, that Nvidia does not support running consumer-grade cards in VMs.&lt;br /&gt;
|-&lt;br /&gt;
| --noautoconsole&lt;br /&gt;
|virt-install returns from running guest installation, so you can easy connect with virsh. Autoconsole will not give you the guest installation screen.  '--graphics none' does not work in any way although we only use text mode in guest installation. I don't know why. Maybe it has something to do with the bound graphics devices.&lt;br /&gt;
|-&lt;br /&gt;
| --host-device&lt;br /&gt;
|Two times - this must be the IOMMU group with its two physical devices as described above.&lt;br /&gt;
|}&lt;br /&gt;
Connect to guest installation and install as usual&lt;br /&gt;
 ~$ virsh console harley&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
If you get many error messages from virt-install, try to use&lt;br /&gt;
temporary --cpu kvm64. This is more robust and may give less and more&lt;br /&gt;
understandable messages.&lt;br /&gt;
&lt;br /&gt;
On my machine virt-install canceled the installation with error&lt;br /&gt;
messages [1]. The reason was that the pc has a buggy bios and the kernel&lt;br /&gt;
disabled interrupt remapping (found with 'sudo journalctl -k') [2].&lt;br /&gt;
But IOMMU needs this and there is a way to force this feature with&lt;br /&gt;
iommu_unsave_interrupts like this:&lt;br /&gt;
 ~$ cat /etc/modprobe.d/iommu_unsafe_interrupts.conf&lt;br /&gt;
 options vfio_iommu_type1 allow_unsafe_interrupts=1&lt;br /&gt;
 ~$ sudo update-initramfs -u&lt;br /&gt;
Reboot.&lt;br /&gt;
&lt;br /&gt;
Of course this is also needed for machines does not support interrupt&lt;br /&gt;
remapping at all.&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
I wanted to setup VGAPassthrough to do my work in an efficient way. I&lt;br /&gt;
saw it wasn't as simple as I thought so I decided to do it from scratch&lt;br /&gt;
step by step to learn how it works. After spending about a week I come&lt;br /&gt;
to this result: I'm able to start the vm and get a login prompt on the&lt;br /&gt;
screen attached to the passed through graphics card. It works. But when&lt;br /&gt;
I restart the vm I have no output on the screen. The guests graphics&lt;br /&gt;
card wasn't reset properly so I have to restart the host to get it for&lt;br /&gt;
one time again. For me that is a showstopper but it's a known problem&lt;br /&gt;
and can be fixed by using UEFI. My somewhat older NVIDIA Quadro 2000&lt;br /&gt;
doesn't support it. I have looked for nvidia-smi but test it not&lt;br /&gt;
yet. I should buy a newer graphics card with UEFI support.&lt;br /&gt;
&lt;br /&gt;
Next I wanted to login to the guest on it's login prompt but there is&lt;br /&gt;
no keybord and mouse support there. Seems that it should also passed&lt;br /&gt;
through but could only find generic hints in the many HowTos and manuals&lt;br /&gt;
like: &amp;quot;passthrough your keyboard and mouse to the vm, no problem&amp;quot;. I did&lt;br /&gt;
it and yes, it works. But I have an USB-switch for my keyboard/mouse to&lt;br /&gt;
switch between host and guest. One switch-port attached to an usb-port&lt;br /&gt;
for the host, one switch-port attached to an usb-port for the guest.&lt;br /&gt;
Booting the host with nothing connected to the guests usb-port and&lt;br /&gt;
starting the guest with keyboard/mouse connected to guests usb-port then&lt;br /&gt;
I get it to the login prompt. Seems to work but when I switch to the&lt;br /&gt;
screen of the host without switching the usb-switch back the host will&lt;br /&gt;
occupy the usb-port for the guest and I loose it for the vm. Seems that&lt;br /&gt;
I have to hide this port on the host. When looking around for a solution&lt;br /&gt;
I found this [5].&lt;br /&gt;
&lt;br /&gt;
That was the point I gave up. What will come up with sound? Do I&lt;br /&gt;
have passthrough everything? It seems there is no generic setup for&lt;br /&gt;
VGAPassthrough. I found many HowTows and Manuals but each only for a&lt;br /&gt;
special hardware. I'm not willing to investigate in development to this&lt;br /&gt;
and just make another HowTo for my machine. I have other projects.&lt;br /&gt;
Looking in a year what's going on.&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
* https://wiki.debian.org/VGAPassthrough&lt;br /&gt;
* https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF&lt;br /&gt;
* https://davidyat.es/2016/09/08/gpu-passthrough/&lt;br /&gt;
* https://forums.linuxmint.com/viewtopic.php?f=231&amp;amp;t=212692&lt;br /&gt;
* https://vfio.blogspot.de/&lt;br /&gt;
* https://www.redhat.com/archives/vfio-users/&lt;br /&gt;
* http://www.laketide.com/setting-up-gpu-passthrough-with-kvm-on-fedora/&lt;br /&gt;
* https://pve.proxmox.com/wiki/Pci_passthrough#IOMMU_interrupt_remapping&lt;br /&gt;
&lt;br /&gt;
=== Footnotes ===&lt;br /&gt;
 [1] ERROR internal error: qemu unexpectedly closed the monitor:&lt;br /&gt;
           warning: host doesn't support requested feature: CPUID.01H:EDX.ds [bit 21]&lt;br /&gt;
           warning: host doesn't support ...&lt;br /&gt;
 &lt;br /&gt;
 [2] Kernel message:&lt;br /&gt;
     &amp;quot;DMAR-IR: This system BIOS has enabled interrupt remapping on a&lt;br /&gt;
               chipset that contains an erratum making that feature&lt;br /&gt;
               unstable. To maintain system stability interrupt remapping&lt;br /&gt;
               is being disabled. Please contact your BIOS vendor for an&lt;br /&gt;
               update&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;/div&gt;</summary>
		<author><name>Ingo</name></author>	</entry>

	</feed>