Blacklist your guest's gaming GPU
Use lspci to check which PCI bus the cards are currently on and which uuid they are using:
lspci -nn | grep -i nvidia |
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK104 [GeForce GTX 760] [10de:1187] (rev a1)
01:00.1 Audio device [0403]: NVIDIA Corporation GK104 HDMI Audio Controller [10de:0e0a] (rev a1)
06:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] [10de:1380] (rev a2)
06:00.1 Audio device [0403]: NVIDIA Corporation Device [10de:0fbc] (rev a1)
Open /etc/initramfs-tools/modules with your favourite text editor, add these two lines to this file:
# blacklisting the Guest graphics card pci_stub ids=10de:1187,10de:0e0a |
sudo update-initramfs -u |
After reboot you can confirm this has worked for you by issuing:
dmesg | grep pci-stub |
[ 10.095954] pci-stub: add 10DE:1187 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000 [ 10.095968] pci-stub 0000:06:00.0: claimed by stub [ 10.095974] pci-stub: add 10DE:0E0A sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000 [ 10.095986] pci-stub 0000:06:00.1: claimed by stub [ 17.278891] pci-stub 0000:06:00.0: enabling device (0000 -> 0003) |
Create VFIO file
lspci -nn | grep -i nvidia |
06:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK104 [GeForce GTX 760] [10de:1187] (rev a1)
06:00.1 Audio device [0403]: NVIDIA Corporation GK104 HDMI Audio Controller [10de:0e0a] (rev a1)
0000:06:00.0 0000:06:00.1 |
Create bootstrap script
user#!/bin/bash
#1st PART
configfile=/etc/vfio-pci.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
#2nd PART
sudo qemu-system-x86_64 \
-enable-kvm \
-M q35 \
-m 8192 \
-cpu host,kvm=off \
-smp 4,sockets=1,cores=4,threads=1 \
-bios /usr/share/seabios/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=06:00.0,bus=root.1,addr=00.0,multifunction=on,x-vga=on \
-device vfio-pci,host=04:00.1,bus=root.1,addr=00.1 \
-usb -usbdevice host:0dc6:3910 \
-soundhw all \
-drive if=none,file="/{path}/{filename}.img'',id=disk,format=raw -device ide-hd,bus=ide.0,drive=disk \
# -drive file="/{path}/{filename}'Windows.iso'',id=isocd -device ide-cd,bus=ide.1,drive=isocd \
# -drive file="/{path}/{filename}'virtio-win-0.1.102.iso'',id=isocd -device ide-cd,bus=ide.1,drive=isocd \
-net nic,model=virtio,vlan=0,macaddr=52:54:00:12:34:56 \
-net tap,vlan=0 \
-boot menu=on
exit 0
Key
-cpu host,kvm=off,migratable=off,+invtsc,enforce uses the host CPU as the type and kvm=off is needed for the GTX to work with the Windows guest. Nvidia don't want to see any Hypervisor extensions...why I can only guess.
If you see (multiple) errors like the one below, migratable=off,+invtsc,enforce will resolve the issue:
warning: host doesn't support requested feature: CPUID.80000001H:EDX [bit 12] |
This option will simulate an SMP (Symmetric multiprocessing) system with number of CPU's in my system I have a 8 core CPU without hyperthreading, I've assigned the VM 1 socket 4 cores and 1 threads giving me 4 cores on the guest and leaving 4 cores on the host.
-vga noneSelect type of VGA card to emulate. As we're not emulating, we're passing the actual hardware to the VM, we disable this option with none.
See below:
Appropriately amend the -drive file line to point to the /{path}/{filename} of your VM and the CD images used in the build (the CD iso's can be removed post install). Remove the # symbols from the beginnings of the two CD iso image lines or remove the lines if unused.
When I was finished I followed the advice in one of the guides I read and saved my file into /usr and called it vm1. Once you've saved the script change the permission to make the file executable:
sudo chmod 755 /usr/vm1 |
You might also want to go through the entries after qemu-system-x86_64 \ and play the remark it out game. Add a # to the beginning of the line and then try to launch your VM. If everything works you don't need the entry leave the #, if the VM fails remove the #, and move to the next line.
Audio Emulation
qemu-system-$ARCH --audio-help |
-soundhw hda
You might need to start qemu like this:
QEMU_PA_SAMPLES=128 QEMU_AUDIO_DRV=pa qemu-system-x86_64...
For alsa:
QEMU_ALSA_DAC_BUFFER_SIZE=512 QEMU_ALSA_DAC_PERIOD_SIZE=170 QEMU_AUDIO_DRV=alsa qemu-system-x86_64...
qemu-system-x86_64 -soundhw -help
Valid sound card names (comma separated):
sb16e es1370 ac97 adlib gus cs4231a hda pcspk | Creative Sound Blaster 16 ENSONIQ AudioPCI ES1370 Intel 82801AA AC97 Audio Yamaha YM3812 (OPL2) Gravis Ultrasound GF1 CS4231A Intel HD Audio PC speaker |
Networking
I've never been a big fan of NetworkManager (Ceni is much better tool) so losing it was no issue for me, if this is a problem for you I am sure guide for setting up a bridge with NM exist. Entering values directly in /etc/network/interfaces will automatically disable NM.
Edit /etc/network/interfaces and either comment or replace the existing configuration with the following (NB: change the values for your network):
auto lo iface lo inet loopback auto br0 iface br0 inet static
|
auto lo iface lo inet loopback auto br0 iface br0 inet dhcp
|
sudo /etc/init.d/networking restart |
Afterword
However, ask questions and have a go yourself and by all means point out inadequacies and omissions.