Home / Linux Admin /
I am probably missing some steps in this overview - I used these resources:
It is assumed you have hardware capable of doing hardware passthrough (IOMMU support on motherboard and processor) and multiple graphics cards (typically onboard + dedicated). My setup is Intel processor with onboard for Linux and NVidia 1050 Ti for Windows VM. I am running Ubuntu 18.04 LTS as a hypervisor and Windows 10 as a VM. For simplicity, I will be ignoring any AMD variations. It will be similar and likely found through the links listed above. Obviously you also need enough hardware capabilities to handle both the host OS and the VM (lots of RAM and multi core processor essentially).
Note that many of these commands will require root privileges - I am not paying enough attention to denote when that's necessary.
nano -B /etc/default/grub) to have the the GRUB_CMDLINE_LINUX_DEFAULT setting read GRUB_CMDLINE_LINUX_DEFAULT="modprobe.blacklist=nouveau quiet splash intel_iommu=on"
update-grubdmesg | grep -i "Directed I/O"[ 0.754554] DMAR: Intel(R) Virtualization Technology for Directed I/Oapt update && apt upgradeapt install qemu-kvm seabios qemu-utils cpu-checker hugepages ovmfadduser username libvirtadduser username libvirt-qemulspci | grep VGA00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] (rev a1)
lspci -nn | grep 01:00.01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP107 [GeForce GTX 1050 Ti] [10de:1c82] (rev a1)
01:00.1 Audio device [0403]: NVIDIA Corporation GP107GL High Definition Audio Controller [10de:0fb9] (rev a1)
10de:1c82 and 10de:0fb9 - we will need to tell pci-stub to capture these at boot so that they are available to pass to the video card to the VMGRUB_CMDLINE_LINUX_DEFAULT="modprobe.blacklist=nouveau quiet splash intel_iommu=on pci-stub.ids=10de:1c82,10de:0fb9"/etc/initramfs-tools/modules and add this to the end of the file:
pci-stub
vfio
vfio_iommu_type1
vfio_pci
vhost-net
update-initramfs -uupdate-grubrebootlsmod | grep vfio
vfio_pci 45056 0
vfio_virqfd 16384 1 vfio_pci
irqbypass 16384 2 kvm,vfio_pci
vfio_iommu_type1 24576 0
vfio 28672 2 vfio_iommu_type1,vfio_pci
dmesg | grep pci-stub
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-20-generic root=UUID=be3fcb78-a978-42b3-8645-d0eecca915c0 ro modprobe.blacklist=nouveau quiet splash intel_iommu=on pci-stub.ids=10de:1c82,10de:0fb9 vt.handoff=1
[ 0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.15.0-20-generic root=UUID=be3fcb78-a978-42b3-8645-d0eecca915c0 ro modprobe.blacklist=nouveau quiet splash intel_iommu=on pci-stub.ids=10de:1c82,10de:0fb9 vt.handoff=1
[ 3.510239] pci-stub: add 10DE:1C82 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[ 3.510248] pci-stub 0000:01:00.0: claimed by stub
[ 3.510259] pci-stub: add 10DE:0FB9 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[ 3.510264] pci-stub 0000:01:00.1: claimed by stub
[ 422.555531] pci-stub 0000:01:00.0: claimed by stub
[ 422.579562] pci-stub 0000:01:00.1: claimed by stub
[ 675.694232] pci-stub 0000:01:00.0: claimed by stub
[ 675.718286] pci-stub 0000:01:00.1: claimed by stub
[ 2991.730642] pci-stub 0000:01:00.0: claimed by stub
[ 2991.754611] pci-stub 0000:01:00.1: claimed by stub
[ 3002.475349] pci-stub 0000:01:00.0: claimed by stub
[ 3002.495329] pci-stub 0000:01:00.1: claimed by stub
[10904.458024] pci-stub 0000:01:00.0: claimed by stub
[10904.478002] pci-stub 0000:01:00.1: claimed by stub
[67840.033312] pci-stub 0000:01:00.0: claimed by stub
[67840.053308] pci-stub 0000:01:00.1: claimed by stub
dmesg | grep VFIO
[ 3.512148] VFIO - User Level meta-driver version: 0.3
kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
lsmod | grep kvm
kvm_intel 204800 0
kvm 593920 1 kvm_intel
irqbypass 16384 2 kvm,vfio_pci
ip a - output should resemble this:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether de:ad:be:ef:ca:fe brd ff:ff:ff:ff:ff:ff
inet 192.168.1.124/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s25
valid_lft 86369sec preferred_lft 86369sec
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:ad:52:17:5f:de brd ff:ff:ff:ff:ff:ff
inet 192.168.142.1/24 brd 192.168.142.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:30:17:7c:ad brd ff:ff:ff:ff:ff:ff
lo and anything that starts with vir - in this case, that leaves enp0s25. If you have multiple NICs, you'll want the one that actually has an IP address assigned to it./etc/network/interfaces file to look like this (of course, replace enp0s25 with whatever your value is):
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto br0
iface br0 inet dhcp
bridge_ports enp0s25
bridge_stp off
bridge_maxwait 5
ifup br0 (br0 is the bridge interface we just created) OR simply reboot. I opted to reboot.
4096Customize configuration before install box
host-passthrough into the model field:

<devices> section (virsh edit [vmname] - more thorough instructions are listed later in this document) - obviously change the path variables to match your settings<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sdc3'/>
<target dev='vdb' bus='virtio'/>
</disk>

fs0:dircd efidircd bootdirbootx64.efi
NetKVM - network

viostor - storage

qxldod (qxl for windows prior to 8 iirc - more info in the wiki) - (non passthrough) video acceleration

Final configurations
setup hugepages
hugeadm --explain
hugeadm:ERROR: No hugetlbfs mount points found, edit /etc/default/qemu-kvm to either add or uncomment this line:
KVM_HUGEPAGES=1the output should resemble:
Total System Memory: 15787 MB
Mount Point Options
/dev/hugepages rw,relatime,pagesize=2M
Huge page pools:
Size Minimum Current Maximum Default
2097152 0 0 0 *
...
/etc/sysctl.conf with a line like:
vm.nr_hugepages = 6605hugeadm --explain again
The recommended shmmax for your currently allocated huge pages is 13851688960 bytes.
To make shmmax settings persistent, add the following line to /etc/sysctl.conf:
kernel.shmmax = 13851688960
/etc/sysctl.conf and add the line it requestedhugeadm --set-recommended-shmmax to set it for now without rebootingvirsh edit [name of vm no brackets]<os> tag
<memoryBacking>
<hugepages/>
</memoryBacking>
virsh edit [name of vm no brackets] again<features> tag (the ########### can be any 12 hexadecimal characters, for example 123456790ab)
...
<features>
<hyperv>
...
<vendor_id state='on' value='############'/>
...
</hyperv>
...
<kvm>
<hidden state='on'/>
</kvm>
</features>
...
KMODE_EXCEPTION_NOT_HANDLED when launching some games, add this line in /etc/modprobe.d/kvm.conf:
options kvm ignore_msrs=1this document last modified: May 14 2018 01:50
Home / Linux Admin /