Skip to content

Instantly share code, notes, and snippets.

@darkcores
Last active February 29, 2020 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkcores/52da1390983186210454148ed92650b1 to your computer and use it in GitHub Desktop.
Save darkcores/52da1390983186210454148ed92650b1 to your computer and use it in GitHub Desktop.

VGPU Notes

Running guests with virtual intel graphics.

Boot params

i915.enable_gvt=1

Services

sudo systemctl start ebtables libvirtd gvtvgpu
[Unit]
Description=Create Intel GVT-g vGPU

[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo '64c5b05a-8289-45f0-ac06-9189392de416' > /sys/devices/pci0000:00/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_4/create"
ExecStop=/bin/sh -c "echo '1' > /sys/devices/pci0000:00/0000:00:02.0/64c5b05a-8289-45f0-ac06-9189392de416/remove"
RemainAfterExit=yes

[Install]
WantedBy=graphical.target

For only qemu command

sudo systemctl start gvtvgpu

Virt manager

sudo -E virt-viewer --attach

Qemu

This feels the most resposive, but I have no idea about spice channels for copy/paste etc.

/usr/bin/qemu-system-x86_64 \
    -m 8192 -smp 3 -M q35 \
    -name local-display-vm \
    -hda /var/lib/libvirt/images/kali.qcow2 \
    -enable-kvm \
    -drive if=pflash,format=raw,unit=0,readonly,file=/usr/share/ovmf/x64/OVMF_CODE.fd \
    -drive if=pflash,format=raw,unit=1,file=/usr/share/ovmf/x64/OVMF_VARS.fd \
    -vga none \
    -display gtk,gl=on \
    -k en-us \
    -machine kernel_irqchip=on \
    -cpu host -usb -usbdevice tablet \
    -device vfio-pci,sysfsdev=/sys/bus/pci/devices/0000:00:02.0/64c5b05a-8289-45f0-ac06-9189392de416,display=on,x-igd-opregion=on

Windows guest (local)

#!/bin/bash

systemctl is-active --quiet gvtvgpu || systemctl start gvtvgpu

PWD=/home/jorrit
HOME=/home/jorrit
export DISPLAY=':0.0'

# Start QEMU
qemu-system-x86_64 \
    -enable-kvm \
    -m 8G \
    -smp cores=2,threads=2,sockets=1,maxcpus=4 \
    -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
    -machine type=pc,accel=kvm,kernel_irqchip=on \
    -global PIIX4_PM.disable_s3=1 \
    -global PIIX4_PM.disable_s4=1 \
    -name windows-gvt-g-guest \
    -soundhw hda \
    -usb \
    -device usb-tablet \
    -display gtk,gl=on \
    -device vfio-pci,sysfsdev=/sys/devices/pci0000:00/0000:00:02.0/64c5b05a-8289-45f0-ac06-9189392de416,x-igd-opregion=on,display=on,rombar=0,ramfb=on,driver=vfio-pci-nohotplug \
    -drive file=/home/jorrit/VirtualBox\ VMs/windows.qcow2,format=qcow2,l2-cache-size=8M \
    -vga none \


read -n 1 -s -r -p "Press any key to continue"

Windows guest local (spice)

#!/bin/bash

systemctl restart gvtvgpu

PWD=/home/jorrit
HOME=/home/jorrit
export DISPLAY=':0.0'

# Start QEMU
qemu-system-x86_64 \
    -enable-kvm \
    -m 8G \
    -smp cores=2,threads=2,sockets=1,maxcpus=4 \
    -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
    -machine type=pc,accel=kvm,kernel_irqchip=on \
    -global PIIX4_PM.disable_s3=1 \
    -global PIIX4_PM.disable_s4=1 \
    -name windows-gvt-g-guest \
    -soundhw hda \
    -usb \
    -device usb-tablet \
    -display spice-app,gl=on \
    -device vfio-pci,sysfsdev=/sys/devices/pci0000:00/0000:00:02.0/64c5b05a-8289-45f0-ac06-9189392de416,x-igd-opregion=on,display=on,rombar=0,ramfb=on,driver=vfio-pci-nohotplug \
    -drive file=/home/jorrit/VirtualBox\ VMs/windows.qcow2,format=qcow2,l2-cache-size=8M \
    -vga none \
    -device virtio-serial-pci \
    -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
    -chardev spicevmc,id=spicechannel0,name=vdagent \
    -spice unix,addr=/tmp/vm_spice.socket,disable-ticketing,image-compression=off,gl=on,rendernode=/dev/dri/by-path/pci-0000:00:02.0-render \
    # -spice addr=none,disable-ticketing 
    #-device virtio-serial-pci -spice port=5930,disable-ticketing -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent \ 
    #-device virtio-serial -chardev spicevmc,id=vdagent,name=vdagent \
    #-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \


read -n 1 -s -r -p "Press any key to continue"

Windows guest external hdd

qemu-system-x86_64 \
    -enable-kvm \
    -m 8G \
    -smp cores=2,threads=2,sockets=1,maxcpus=4 \
    -cpu host,hv_relaxed,hv_spinlocks=0x1fff,hv_vapic,hv_time \
    -machine type=pc,accel=kvm,kernel_irqchip=on \
    -global PIIX4_PM.disable_s3=1 \
    -global PIIX4_PM.disable_s4=1 \
    -drive if=pflash,format=raw,unit=0,readonly,file=/usr/share/ovmf/x64/OVMF_CODE.fd \
    -drive if=pflash,format=raw,unit=1,file=/usr/share/ovmf/x64/OVMF_VARS.fd \
    -name windows-gvt-g-guest \
    -soundhw hda \
    -usb \
    -device usb-tablet \
    -display gtk,gl=on \
    -device vfio-pci,sysfsdev=/sys/devices/pci0000:00/0000:00:02.0/64c5b05a-8289-45f0-ac06-9189392de416,x-igd-opregion=on,display=on,rombar=1,romfile=/vbios_gvt_uefi.rom,ramfb=on,driver=vfio-pci-nohotplug \
    -drive file=/dev/sda,format=raw \
    -vga none \

Sources

  1. https://www.reddit.com/r/VFIO/comments/8h352p/guide_running_windows_via_qemukvm_and_intel_gvtg/
  2. https://blog.bepbep.co/posts/gvt/
  3. https://wiki.archlinux.org/index.php/Intel_GVT-g
  4. https://github.com/intel/gvt-linux/wiki/Dma_Buf_User_Guide
  5. https://github.com/intel/gvt-linux/wiki/GVTg_Setup_Guide
  6. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_tuning_and_optimization_guide/sect-virtualization_tuning_optimization_guide-virt_manager-cpu_options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment