-
Notifications
You must be signed in to change notification settings - Fork 95
GVT d_KVM_Quick_Guide_for_Ubuntu
To customize a quick guide for user to build GVT-d KVM environment based on Ubuntu OS.
Ubuntu 18.04.2 or Ubuntu 18.10.
Skylake NUC
There are some third party software packages needed by host environment setup, as below:
apt-get update
apt-get install libssl-dev vim libsdl1.2-dev xtightvncviewer tightvncserver x11vnc libsdl1.2-dev uml-utilities bridge-utils python-dev arp-scan nmap qemu qemu-utils qemu-system
Make sure "Virtualization Technology for Directed I/O" option is enabled in your BIOS.
Make sure the iommu option "intel_iommu=on" existed in your menuentry kernel line, below is an example for /boot/grub/grub.cfg file on ubuntu:
menuentry 'GVT-d KVM' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-106518cd-fb74-4048-81de-3ecee7ad74d4' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 106518cd-fb74-4048-81de-3ecee7ad74d4
else
search --no-floppy --fs-uuid --set=root 106518cd-fb74-4048-81de-3ecee7ad74d4
fi
linux /boot/vmlinuz-4.18.0-17-generic root=UUID=106518cd-fb74-4048-81de-3ecee7ad74d4 ro ignore_loglevel log_buf_len=128M kvm.ignore_msrs=1 intel_iommu=on text
initrd /boot/initrd.img-4.18.0-17-generic
}
NOTICE: Since some Windows guest 3rd party application / tools (like GPU-Z / Passmark9.0) will trigger MSR read / write directly, if it access the unhanded msr register, guest will trigger BSOD soon. So we added the "kvm.ignore_msrs=1" into grub for workaround.
Since grub.cfg will be auto regenerated by linux distro version upgrade or kernel package update, suggest to also add the needed command options to "/etc/default/grub", the steps as below:
Change GRUB_CMDLINE_LINUX_DEFAULT="text"
Change GRUB_CMDLINE_LINUX="intel_iommu=on"
$sudo update-grub
$sudo systemctl set-default multi-user.target
First, you want to download a Ubuntu ISO from http://releases.ubuntu.com/, for example as below:
wget http://releases.ubuntu.com/18.04.2/ubuntu-18.04.2-desktop-amd64.iso
Second, you need to create a new image by Qemu, the example as below:
qemu-img create ubuntu-18-04-02.img 20G
Then you should create this new image with combined the Ubuntu ISO as CDROM, the example as below:
#! /bin/bash -x
/usr/bin/qemu-system-x86_64 \
-enable-kvm \
-m 2048 \
-smp 2 \
-cpu host \
-hda /home/img/ubuntu-18-04-02.img \
-cdrom /home/img/ubuntu-18.04.2-desktop-amd64.iso \
-usb -usbdevice tablet \
-net nic,macaddr=00:16:3e:60:0a:50 -net tap,script=/etc/qemu-ifup
Make sure the guest console option: "console=ttyS0,115200,8n1" existed in your menuentry kernel line, below is an example for /boot/grub/grub.cfg file on ubuntu:
menuentry 'GVT-d KVM' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-cecfbe0d-02b6-4f82' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 106518cd-fb74-4048-81de-3ecee7ad74d4
else
search --no-floppy --fs-uuid --set=root cecfbe0d-02b6-4f82-a0d0-d71353af0de4
fi
linux /boot/vmlinuz-4.18.0-17-generic root=UUID=cecfbe0d-02b6-4f82-a0d0-d71353af0de4 ro ignore_loglevel log_buf_len=128M console=ttyS0,115200,8n1
initrd /boot/initrd.img-4.18.0-17-generic
}
You need to unbind graphic card device in host as below (please do it in terminal since your monitor will black screen after you hide graphic card device):
root@gvtd-host:~# modprobe vfio
root@gvtd-host:~# modprobe vfio_pci
root@gvtd-host:~# lspci -D -nn -s 00:02.0
0000:00:02.0 VGA compatible controller [0300]: Intel Corporation Broadwell-U Integrated Graphics [8086:1622] (rev 08)
Thus it can be seen,VGA device (0000:00:02.0,vendor & device ID 8086:1622)
root@gvtd-host:~# echo 0000:00:02.0 > /sys/bus/pci/devices/0000:00:02.0/driver/unbind
root@gvtd-host:~# echo 8086 1622 > /sys/bus/pci/drivers/vfio-pci/new_id
You need to unbind USB device in host as below (since Signal processing device aslo in the same iommu_group as USB device, we should also unbind it):
root@gvtd-host:~# lspci -D -nn -s 00:14.0
0000:00:14.0 USB controller [0c03]: Intel Corporation Sunrise Point-LP USB 3.0 xHCI Controller [8086:9d2f] (rev 21)
Thus it can be seen,USB device (0000:00:14.0,vendor & device ID 8086:9d2f)
root@gvtd-host:~# echo 0000:00:14.0 > /sys/bus/pci/devices/0000:00:14.0/driver/unbind
root@gvtd-host:~# echo 8086 9d2f > /sys/bus/pci/drivers/vfio-pci/new_id
root@gvtd-host:~# lspci -D -nn -s 00:14.2
0000:00:14.2 Signal processing controller [1180]: Intel Corporation Sunrise Point-LP Thermal subsystem [8086:9d31] (rev 21)
Thus it can be seen,Signal processing device (0000:00:14.2,vendor & device ID 8086:9d31)
root@gvtd-host:~# echo 0000:00:14.2 > /sys/bus/pci/devices/0000:00:14.2/driver/unbind
root@gvtd-host:~# echo 8086 9d31 > /sys/bus/pci/drivers/vfio-pci/new_id
For GVT-d KVM, in order to let guest using the same network segment as host, you must create the network bridge in host.
You can reference the "Configuring Guest Networking" wiki page http://www.linux-kvm.org/page/Networking.
Or you can type simple manualy command like "brctl addbr br0; brctl addif br0 eth0; ifconfig eth0 0; dhclient br0" ("eth0" is your host network card).
The example of create VM script as below :
#! /bin/bash -x
/usr/bin/qemu-system-x86_64 \
-enable-kvm \
-m 2048 \
-smp 2 \
-cpu host \
-hda /home/img/ubuntu-18-04-02.img \
-vga none -nographic \
-device vfio-pci,host=00:02.0,x-igd-gms=2,id=hostdev0,bus=pci.0,addr=0x2,x-igd-opregion=on \
-usb -usbdevice tablet \
-serial stdio \
-vnc :2 \
-net nic,macaddr=00:16:3e:60:0a:50,addr=0x3 -net tap,script=/etc/qemu-ifup
Then VM desktop will be shown in your monitor, and the VM dmesg log will be printed to your host terminal.