Xen显卡VGA passthrough
Xen4的特性中支持了VGA passthrough,但前提是cpu和主板必须支持VT-D、I/O virtualization。
使用xm dmesg 找到I/O virtualization enable、查看I/O virtualization是否开启。
首先lspci找到VGA显卡的pci设备号
例如我运行lspci后的输出: ... 00:1f.2 SATA controller: Intel Corporation 6 Series/C200 Series Chipset Family SATA AHCI Controller (rev 05) 00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller (rev 05) 01:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI Barts PRO [ATI Radeon HD 6800 Series] 01:00.1 Audio device: Advanced Micro Devices [AMD] nee ATI Barts HDMI Audio [Radeon HD 6800 Series] 03:00.0 SATA controller: Marvell Technology Group Ltd. 88SE9120 SATA 6Gb/s Controller (rev 12) ...
可以看到,01:00.0和01:00.1就是我的显卡。我们要让主机把设备空出来,这个可以通过pcistub或pciback驱动实现。
我们利用pciback这个脚本来实现显卡驱动转换
vi /sbin/pciback-bind
代码语言:javascript复制#!/bin/bash
if [ $# -eq 0 ]; then
echo "Require PCI devices in format: <domain>:<bus>:<slot>.<function>"
echo "Eg: $(basename $0) 0000:00:1b.0"
exit 1
fi
[ -z "`lsmod | grep pciback`" ] && sudo /sbin/modprobe xen-pciback
for pcidev in $@; do
if [ -h /sys/bus/pci/devices/"$pcidev"/driver ]; then
echo "Unbinding $pcidev from" $(basename $(readlink/sys/bus/pci/devices/"$pcidev"/driver))
echo -n "$pcidev" > /sys/bus/pci/devices/"$pcidev"/driver/unbind
fi
echo "Binding $pcidev to pciback"
echo -n "$pcidev" > /sys/bus/pci/drivers/pciback/new_slot
echo -n "$pcidev" > /sys/bus/pci/drivers/pciback/bind
done
用/sbin/pciback-bind 0000:01:00.0 0000:01:00.1 就可以把显卡驱动换成xen-pciback。要注意在显卡pci设备号前面加4个0,然后运行xm pci-list-assignable,输出应该是
0000:01:00.0 0000:01:00.1
然后编辑已经开好的虚拟机配置文件。
在里面直接添加
xen_platform_pci=1
gfx_passthru=0
pci=['01:00.0', '01:00.1' ]
编辑完之后我们用xm create XXX.hvm就可以开启虚拟机了,但这时的默认输出仍是虚拟显卡,所以要先用vncviewer登录win7桌面,装好amd的显卡驱动,重启。但是有的显卡本身自带驱动、只需把默认的虚拟网卡禁用就ok了。