Quantcast
Channel: Ubuntu Forums - Virtualisation
Viewing all articles
Browse latest Browse all 4211

[ubuntu] Ubuntu 14.04 KVM VGA Passthrough Nvidia GTX "How To"

$
0
0
I spent a frustrating week trying to get this to work so I hope this thread will help other people out. I kept getting stuck at "code 43" in windows after installing the nvidia driver. Turns out I had the wrong version of qemu and didn't use the kvm=off feature, which is the key to passing this card through correctly.

Here are my machine's specs

ASUS Sabertooth 990fx rev2
AMD FX8350
ATI Radeon HD 6450 (Host's Card)
EVGA Nvidia GTX 560 Ti (Windows 7 guest Card)

I used qemu-system-x86_64 version 2.1.2. It allows you to use kvm=off. You can get it by using the Serge Hallyn repo here:
Code:

sudo add-apt-repository ppa:serge-hallyn/virt
I had some problems getting the seabios to work right after I upgraded qemu, due to a symlink missing, so do this:
Code:

sudo ln -s /usr/share/seabios/bios.bin /usr/share/qemu/
You're going to need kvm installed using this tutorial:
https://help.ubuntu.com/community/KVM/Installation

You're also going to need to download the 3.18.0 kernel from here:
https://www.kernel.org/pub/linux/ker...ux-3.18.tar.xz

You're going to need the ACS and i915 patches from here:
https://docs.google.com/file/d/0Bxp_...E5NE9mOUk/edit
Just click the download button at the top of the page.

Extract the linux-3.18.tar.gz file, I used archive manager to do this. Then move the files from the linux-mainline folder, containing the patches, into the linux-3.18 folder you just extracted. I'm no compiling expert, but this is what I did:
Code:

make mrproper
Code:

patch -p1 < override_for_missing_acs_capabilities.patch
Code:

patch -p1 < i915_317.patch
After that just make menuconfig or however you want to configure your kernel and then compile. Don't forget to enable all of the KVM, VFIO, and virtualization things. If you don't know how to do this, there are hundreds of tutorials on the webs.

Reboot into the new kernel.

Here is the rest of the info you need. Remember this is for an AMD processor. If you have an intel processor, you'll have to change the relevant items. Important stuff in bold.

/etc/default/grub
Code:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1 pcie_acs_override=downstream i915.enable_hd_vgaarb=1"
lspci -nn | grep NVIDIA
Code:

07:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF114 [GeForce GTX 560 Ti] [10de:1200] (rev a1)
07:00.1 Audio device [0403]: NVIDIA Corporation GF114 HDMI Audio Controller [10de:0e0c] (rev a1)

/etc/modules
Code:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

lp
rtc
pci_stub
vfio
vfio_iommu_type1
vfio_pci
kvm
kvm_amd

/etc/initramfs-tools/modules
Code:

# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
pci_stub ids=10de:1200,10de:0e0c

/etc/vfio-pci1.cfg
Code:

0000:07:00.0
0000:07:00.1

reboot your computer

Check to make sure the card got stubbed at boot by using
Code:

dmesg | grep pci-stub
You should see your cards ID followed by "claimed by stub" I stubbed both the graphics and the sound on the card.

Now for the Guest's startup script. I had to patch mine together using like 4 different startup scripts I saw on different forums, youtube, ect.

I have an extra keyboard, mouse, and usb audio device hooked up to my computer just for this and here's my lsusb output, just so you can see how I got the ID's for passing the usb to the guest.

Code:

lsusb
Code:

Bus 009 Device 002: ID 059b:0579 Iomega Corp. eGo Portable Hard Drive
Bus 009 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 013 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 012 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 008 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 011 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 008: ID 0461:4d03 Primax Electronics, Ltd Kensington Mouse-in-a-box
Bus 007 Device 007: ID 06a3:8021 Saitek PLC Eclipse II Keyboard
Bus 007 Device 006: ID 046d:c326 Logitech, Inc.
Bus 007 Device 005: ID 046d:c068 Logitech, Inc. G500 Laser Mouse
Bus 007 Device 004: ID 058f:9254 Alcor Micro Corp. Hub
Bus 007 Device 003: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 007 Device 002: ID 0409:0059 NEC Corp. HighSpeed Hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 010 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 1bcf:0c31 Sunplus Innovation Technology Inc. SPIF30x Serial-ATA bridge
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

/usr/Windows

Code:

#!/bin/bash

configfile=/etc/vfio-pci1.cfg

vfiobind() {
    dev="$1"
        vendor=$(cat /sys/bus/pci/devices/$dev/vendor)
        device=$(cat /sys/bus/pci/devices/$dev/device)
        if [ -e /sys/bus/pci/devices/$dev/driver ]; then
                echo $dev > /sys/bus/pci/devices/$dev/driver/unbind
        fi
        echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id
 
}

modprobe vfio-pci

cat $configfile | while read line;do
    echo $line | grep ^# >/dev/null 2>&1 && continue
        vfiobind $line
done

sudo qemu-system-x86_64 -enable-kvm -M q35 -m 4096 -cpu host,kvm=off \
-smp 4,sockets=1,cores=1,threads=1 \
-bios /usr/share/qemu/bios.bin -vga none \
-device ioh3420,bus=pcie.0,addr=1c.0,multifunction=on,port=1,chassis=1,id=root.1 \
-device vfio-pci,host=07:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on,romfile=/home/ben/Downloads/GF114.rom \
-device vfio-pci,host=07:00.1,bus=root.1,addr=00.1 \
-drive file=/home/ben/KVM-Images/Windows.img,id=disk,format=raw -device ide-hd,bus=ide.0,drive=disk \
-drive file=/home/ben/Downloads/windows.iso,id=isocd -device ide-cd,bus=ide.1,drive=isocd \
-usb -usbdevice host:06a3:8021 -usbdevice host:0461:4d03 -usbdevice host:0d8c:013c \
-boot menu=on

exit 0

To make this script executable run

Code:

sudo chmod +x /usr/Windows
Make sure you have a monitor attached to your nvidia card and startup with:
Code:

sudo /usr/Windows
Good luck, I hope this helps people where I got stuck. The kvm=off feature only works in qemu 2.1.2.

Viewing all articles
Browse latest Browse all 4211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>