ubuntu使用kvmgt配置vGPU
注意,ubuntu是支持intel gpu的显卡虚拟化的,只是默认没有开启该模块,所有linux系统,使用较新内核的话就可以支持这一特性,只要其硬件架构不是太老。但是,ubuntu的软件仓库里的软件版本实在过低,无法支持这一特性,igvt是从2015年开始实现,到2017年合流到linux内核中,而ubuntu软件仓库的qemu还是2.11版本的,已经落后近4年了,相应的libvirt和virt-manager也是版本落后,无法支持GPU虚拟化,所以只能自己编译安装。但是依赖关系并不好解决,而且,virt-manager在ubuntu上只能使用libvirt-glib-1.0(依赖于libvirt0),这导致了严重的依赖问题。所以ubuntu并不适合作为GPU虚拟化的平台。我推荐使用Archlinux或者CentOS进行配置。
请先确定硬件环境,cpu是否支持vt-x和vt-d,intel核显,Broadwell及更新的架构。
执行命令:lsmod | grep kvm,以确认是否加载kvm驱动,使用modprobe kvm加载之。
qemu和libvirt的编译见:https://blog.csdn.net/zhaihaibo168/article/details/91906210
先从qemu的编译安装开始:
一、qemu的源码编译和安装
从qemu的官网下载源码包:https://download.qemu.org/qemu-4.2.0.tar.xz
然后,提取到~/qemu-4.2.0/qemu-4.2.0,打开终端,执行以下命令:(注意不要在源码路径下编译)
sudo apt install build-essential
sudo apt build-dep qemu
sudo apt install virglrenderer*
sudo apt install libnfs-dev libgtk-3-dev libsdl2-dev libgbm-dev
现在,qemu的编译环境已经搭建好了。为了在编译安装的同时生成deb包,先安装checkinstall,执行:
sudo apt install checkinstall
将myconf拷贝到~/qemu-4.2.0目录下,内容为:
qemu-4.2.0/configure --prefix=/usr \
--enable-avx2 \
--enable-kvm \
--disable-xen \
--enable-libusb \
--enable-libnfs \
--enable-sdl \
--enable-virtfs \
--enable-vhost-net \
--enable-vhost-vsock \
--enable-vhost-scsi \
--enable-vhost-crypto \
--enable-vhost-kernel \
--enable-vhost-user \
--enable-vnc \
--enable-vnc-sasl \
--enable-vnc-jpeg \
--enable-vnc-png \
--enable-spice \
--enable-opengl \
--enable-virglrenderer \
--enable-gtk \
--audio-drv-list=oss,alsa,pa \
--target-list=x86_64-softmmu,i386-softmmu,arm-softmmu,arm-linux-user
然后,开始编译安装,执行:
cd qemu-4.2.0
./myconf
make -j4 #j后面的数字应取你的CPU的线程数
sudo checkinstall # 代替make install
执行完毕,需要改变生成的deb包的所有者,执行:
sudo chown -R user qemu4.2.0-amd64.deb
# user改为你的用户名,qemu4.2.0-amd64.deb改为生成的包的文件名
注意保存好编译的包,以供重新安装。
编译qemu,依赖关系比较复杂,但是可以直接构建好的,而libvirt依赖于qemu,virt-manager依赖于libvirt,这样就不能使用命令行直接构建环境,只能自己寻找依赖关系。
执行qemu-system-x86_64 --version以确定是否安装成功。
然后,编译libvirt,作为管理qemu-kvm的接口:
二、libvirt的源码编译和安装
从libvirt的官网下载源码包:https://libvirt.org/sources/libvirt-6.0.0.tar.xz
然后,提取到~/libvirt-6.0.0/libvirt-6.0.0,打开终端,执行以下命令:(注意不要在源码路径下编译)
sudo apt install libnl-3-dev libnl-route-3-dev libpciaccess-dev python-docutils libyajl-dev
sudo apt install ebtables bridge-utils libdevmapper-dev libxml2-dev libxml2-utils xsltproc
#sudo apt install dnsmasq # dnsmasq-base已经默认安装了
//Build libvirt
cd libvirt-6.0.0
libvirt-6.0.0/configure --prefix=/usr --with-driver-modules --with-interface --with-qemu --with-sasl
make -j4
sudo checkinstall # 注意要改变生成的deb包的所有者
这样,libvirt编译安装好了,但是需要进行一些配置:
执行virsh version,显示如下:
根据库编译:libvirt 6.0.0
使用库:libvirt 6.0.0
使用的 API: QEMU 6.0.0
运行管理程序: QEMU 4.2.0
注:如果编译时没指定--prefix=/usr 就会出现找不到路径:
virsh: error while loading shared libraries: libvirt-lxc.so.0: cannot open shared object file: No such file or directory
这时,执行ldconfig,再virsh version,显示:
error: failed to connect to the hypervisor
error: Failed to connect socket to '/usr/local/var/run/libvirt/libvirt-sock': No such file or directory
这是因为没有启动libvirtd服务。
执行service libvirtd status,显示:
Unit libvirtd.service could not be found.
执行systemctl start libvirtd,显示:Failed to start libvirtd.service: Unit libvirtd.service not found.
这是因为libvirtd.service文件不在/etc/systemd/system路径下,解决方法详见:https://www.cnblogs.com/ck1020/p/6024039.html
这里,我们可以执行:systemctl start libvirtd.service,然后执行:systemctl enable libvirtd,显示:
Created symlink /etc/systemd/system/multi-user.target.wants/libvirtd.service → /usr/lib/systemd/system/libvirtd.service.
Created symlink /etc/systemd/system/sockets.target.wants/virtlockd.socket → /usr/lib/systemd/system/virtlockd.socket.
Created symlink /etc/systemd/system/sockets.target.wants/virtlogd.socket → /usr/lib/systemd/system/virtlogd.socket.
Created symlink /etc/systemd/system/sockets.target.wants/libvirtd.socket → /usr/lib/systemd/system/libvirtd.socket.
Created symlink /etc/systemd/system/sockets.target.wants/libvirtd-ro.socket → /usr/lib/systemd/system/libvirtd-ro.socket.
再执行:service libvirtd status,显示:
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2020-02-13 17:12:38 CST; 5min ago
Docs: man:libvirtd(8)
https://libvirt.org
Process: 10652 ExecStart=/usr/sbin/libvirtd $LIBVIRTD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 10652 (code=exited, status=0/SUCCESS)
Tasks: 2 (limit: 32768)
CGroup: /system.slice/libvirtd.service
├─10805 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
└─10806 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
2月 13 17:10:38 USER systemd[1]: Started Virtualization daemon.
2月 13 17:10:38 USER dnsmasq[10805]: started, version 2.79 cachesize 150
2月 13 17:10:38 USER dnsmasq[10805]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
2月 13 17:10:38 USER dnsmasq-dhcp[10805]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
2月 13 17:10:38 USER dnsmasq-dhcp[10805]: DHCP, sockets bound exclusively to interface virbr0
2月 13 17:10:38 USER dnsmasq[10805]: reading /etc/resolv.conf
2月 13 17:10:38 USER dnsmasq[10805]: using nameserver 127.0.0.53#53
2月 13 17:10:38 USER dnsmasq[10805]: read /etc/hosts - 7 addresses
2月 13 17:10:38 USER dnsmasq[10805]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
2月 13 17:10:38 USER dnsmasq-dhcp[10805]: read /var/lib/libvirt/dnsmasq/default.hostsfile
现在测试libvirt的功能:
执行virsh -c qemu:///system,显示:
欢迎使用虚拟化环境下的交互式终端 virsh。
输入:'help' 获得命令的帮助信息
'quit' 退出
virsh #
执行virsh -c qemu:///session,显示与上相同信息。
可能存在的问题:
1、无效参数:解析用户 'libvirt-qemu' 失败
出现该问题可能是libvirt已损坏,或者出现冲突,暂时无解。我就是因此重装系统以解决之,不过,我想应该可以指定—prefix=/usr编译安装以解决。我认为是ubuntu软件仓库的libvirt安装在/usr下,而我当时默认编译安装在/usr/local下,从而引发的问题(我是先apt安装卸载再编译安装的)。
2、CheckAuthorization: Action org.libvirt.unix.manage is not registered
这是授权的问题,详见:https://wiki.archlinux.org/index.php/Libvirt_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
为了给 libvirt 组用户定义基于文件的权限以管理虚拟机,取消下列行的注释:
文件:/etc/libvirt/libvirtd.conf # 看你安装的路径,可能在/usr/local/etc/libvirt下
内容:(注意先把用户添加到libvirt组:sudo groupadd libvirt && sudo usrmod -a -G libvirt usr)
#unix_sock_group = "libvirt"
#unix_sock_ro_perms = "0777" # set to 0770 to deny non-group libvirt users
#unix_sock_rw_perms = "0770"
#auth_unix_ro = "none"
#auth_unix_rw = "none"
再重新启动libvirtd服务并查看其状态。
现在,可以开始最麻烦的一步了,编译virt-manager,由于其是python写的,很麻烦。
三、virt-manager的源码编译和安装
最新的virt-manager是用python3写的,也必须用python3编译,其依赖于python3的一些库,和libvirt-glib(ubuntu只有1.0版的,并绑定了libvirt0),这实际上导致了其难以与编译的libvirt配合。
从virt-manager官网下载源码包:https://libvirt.org/sources/libvirt-6.0.0.tar.xz
然后,提取到~/virt-manager-2.2.1,打开终端,输入以下命令:
sudo apt install python3-pip # 需要python3及pip下载py包
#sudo apt install alien # 需要rpm包构建及转换为deb包(由于一些错误无法构建rpm包)
sudo apt install intltool
cd virt-manager-2.2.1
python3 setup.py build
sudo python3 setup.py install --record install.log
#cat install.log | sudo xargs rm -rf # 卸载软件包
解决启动virt-manager报错:
sudo pip3 install libvirt-python # 解决ImportError:没有名为libvirt的模块
sudo pip3 install libxml2-python3 # 解决ImportError:没有名为libxml2的模块
以下可能需要:(请使用pip3安装python3的库,勿apt安装)
#sudo pip3 install argcomplete
#sudo pip3 install requests3 # 解决ImportError:没有模块命名的请求
#sudo pip3 install PyGObject
#sudo apt install genisoimage
virt-manager的编译安装详见:https://vpssj.net/zzzt/725.htm
解决最大的问题:ValueError:命名空间LibvirtGLib不可用
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace LibvirtGLib not available
查看virt-manager-2.2.1的源码包,可以清楚地知道其依赖关系:
INSTALL.md文件说明了安装的注意事项。
virt-manager.spec文件详细地列举了其依赖关系。
注意到:On Debian or Ubuntu based distributions, you need to install the `gobject-introspection` bindings for some dependencies like `libvirt-glib` and `libosinfo`. Look for package names that start with `'gir'`, for example `gir1.2-libosinfo-1.0`.
这是导致这个问题并使之难以解决的原因。注意gir1.2-libvirt-glib-1.0需要libvirt-glib-1.0,从而需要libvirt0,这导致了与编译的libvirt包的冲突,实际上,只需要修改gir1.2-libvirt-glib-1.0包。
解决方案如下:
去官网下载gir1.2-libvirt-glib-1.0包:https://packages.ubuntu.com/bionic/amd64/gir1.2-libvirt-glib-1.0/download
打开下载路径,在终端执行:
mkdir gir1.2-libvirt-glib-1.0_1.0.0-1_amd64
mkdir gir1.2-libvirt-glib-1.0_1.0.0-1_amd64/DEBIAN
dpkg -x gir1.2-libvirt-glib-1.0_1.0.0-1_amd64.deb gir1.2-libvirt-glib-1.0_1.0.0-1_amd64
dpkg -e gir1.2-libvirt-glib-1.0_1.0.0-1_amd64.deb gir1.2-libvirt-glib-1.0_1.0.0-1_amd64/DEBIAN
gedit gir1.2-libvirt-glib-1.0_1.0.0-1_amd64/DEBIAN/control # 去掉libvirt-glib-1.0的依赖项
cd gir1.2-libvirt-glib-1.0_1.0.0-1_amd64
dpkg -b ./ gir1.2-libvirt-glib-1.0_1.0.0-1_amd64.deb
sudo dpkg -i gir1.2-libvirt-glib-1.0_1.0.0-1_amd64.deb # 安装修改的 gir1.2-libvirt-glib-1.0
这样,仍需要libvirt-glib-1.0,所以先编译安装之:
官网下载libvirt-glib-1.0源码包:https://libvirt.org/sources/glib/libvirt-glib-1.0.0.tar.gz
然后,提取到~/libvirt-glib-1.0.0/libvirt-glib-1.0.0,打开终端,执行以下命令:
cd libvirt-glib-1.0.0
libvirt-glib-1.0.0/configure --prefix=/usr
make -j4
sudo checkinstall
再执行virt-manager,就不会报错Namespace LibvirtGLib not available,而是:
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Libosinfo not available
解决方法:sudo apt install gir1.2-libosinfo-1.0
现在可以开始进行测试了:
打开virt-manager,可以看见未连接到虚拟机,新建一个qemu-kvm的连接即可。
开始安装虚拟机,报错:启动安装时出错:Namespace GtkVnc not available
解决方法:sudo apt install gir1.2-gtk-vnc-2.0
连接到图形控制台出错:Error opening Spice console, SpiceClientGtk missing
解决方法:sudo apt install gir1.2-spiceclientgtk-3.0
可能的错误:
ImportError:不能导入名称Vte,解决:sudo apt install gir1.2-vte-2.91
四、OVMF的安装和配置
sudo apt install ovmf
详见:https://bugs.archlinux.org/task/64175
配置:
编辑/etc/libvirt/qemu.conf,添加:
nvram = [
"/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd"
]
创建并编辑/usr/share/qemu/firmware/60-ovmf-x86_64.json:
{
"description": "UEFI OVMF firmware for x86_64",
"interface-types": [
"uefi"
],
"mapping": {
"device": "flash",
"executable": {
"filename": "/usr/share/OVMF/OVMF_CODE.fd",
"format": "raw"
},
"nvram-template": {
"filename": "/usr/share/OVMF/OVMF_VARS.fd",
"format": "raw"
}
},
"targets": [
{
"architecture": "x86_64",
"machines": [
"pc-i440fx-*",
"pc-q35-*"
]
}
],
"features": [
"acpi-s3",
"amd-sev",
"verbose-dynamic"
],
"tags": [
]
}
执行:systemctl restart libvirtd
五、kvmgt及GVT-g的使用
英特尔的GVTg_Setup_Guide:https://github.com/intel/gvt-linux/wiki/GVTg_Setup_Guide
Archlinux的wiki:https://wiki.archlinux.org/index.php/Intel_GVT-g
首先启动模块:
sudo gedit /etc/initramfs-tools/modules
添加:
kvmgt vfio vfio-iommu-type1 vfio-mdev
然后,终端执行sudo update-initramfs -u
还要添加启动参数:
sudo gedit /etc/default/grub
寻找GRUB_CMDLINE_LINUX="",在双引号中添加:(可设置intel_iommu=on以开启IOMMU)
i915.enable_gvt=1 kvm.ignore_msrs=1 intel_iommu=igfx_off
保存后,执行sudo update-grub,重启。
查看是否存在/sys/devices/pci0000:00/0000:00:02.0/mdev_supported_types
现在开始创建vGPU了,为了使系统启动时自动创建vGPU,可以做一个服务:
文件:/lib/systemd/system/gvtvgpu.service
[Unit]
Description=Create Intel GVT-g vGPU
[Service]
Type=oneshot
ExecStart=/bin/sh /home/create_vgpu.sh
ExecStop=/bin/sh /home/remove_vgpu.sh
RemainAfterExit=yes
[Install]
WantedBy=graphical.target
文件:/home/create_vgpu.sh
echo "7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac" | tee "/sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/create"
echo "7ae3e614-49b2-11ea-bf92-cb97bd8ed5a5" | tee "/sys/bus/pci/devices/0000:00:02.0/mdev_supported_types/i915-GVTg_V5_8/create"
文件:/home/remove_vgpu.sh
echo "1" | tee "/sys/devices/pci0000:00/0000:00:02.0/7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac/remove"
echo "1" | tee "/sys/devices/pci0000:00/0000:00:02.0/7ae3e614-49b2-11ea-bf92-cb97bd8ed5a5/remove"
注:"7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac"和"7ae3e614-49b2-11ea-bf92-cb97bd8ed5a5"是UUID,请用uuid来生成,sudo apt install uuid,uuid -n 2,以输出2个UUID。
终端执行systemctl start gvtvgpu.service,在执行service gvtvgpu status,显示:
● gvtvgpu.service - Create Intel GVT-g vGPU
Loaded: loaded (/lib/systemd/system/gvtvgpu.service; disabled; vendor preset:
Active: active (exited) since Fri 2020-02-14 22:47:14 CST; 9min ago
Process: 4415 ExecStart=/bin/sh /home/create_vgpu.sh (code=exited, status=0/SU
Main PID: 4415 (code=exited, status=0/SUCCESS)
2月 14 22:47:14 USER systemd[1]: Starting Create Intel GVT-g vGPU...
2月 14 22:47:14 USER sh[4415]: 7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac
2月 14 22:47:14 USER sh[4415]: 7ae3e614-49b2-11ea-bf92-cb97bd8ed5a5
2月 14 22:47:14 USER systemd[1]: Started Create Intel GVT-g vGPU.
然后,执行systemctl enable gvtvgpu,显示:
Created symlink /etc/systemd/system/graphical.target.wants/gvtvgpu.service → /lib/systemd/system/gvtvgpu.service.
这样,vGPU配置完毕。现在开始使用 virt-manager 创建 Windows 10 虚拟机。
正常安装好系统,然后编辑虚拟机配置文件 XML,这必须用virsh编辑才能生效。
sudo EDITOR=nano virsh edit win10
开头的<domain type='kvm'>,修改为:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
找到<graphics type=’spice’>,修改为:(使用核显渲染,因为独显可能没有视频输出功能)
<graphics type='spice'>
<listen type='none'/>
<gl enable='yes' rendernode='/dev/dri/by-path/pci-0000:00:02.0-render'/>
</graphics>
找到<video>,开始修改,增加 <hostdev>的定义,如下:
<video>
<model type='none'/>
</video>
<hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on'>
<source>
<address uuid='7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</hostdev>
在最后的</domain>之前加入<qemu:commandline>,以配置输出视频:
<qemu:commandline>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.ramfb=on'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.driver=vfio-pci-nohotplug'/>
</qemu:commandline>
如果使用了OVMF则必须在<qemu:commandline>中更早地添加一个参数:
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.romfile=/path/to/vbios_gvt_uefi.rom'/>
完成后,ctrl+o写入,ctrl+x离开。
vbios_gvt_uefi.rom的下载地址:http://120.25.59.132:3000/vbios_gvt_uefi.rom
之后,可以配置显卡直通,详见:https://blog.csdn.net/dwj1979/article/details/85232191
https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF
在<hyperv>中,添加:
<vendor_id state='on' value='0123456789ab'/>
紧接着</hyperv>,添加:
<kvm>
<hidden state='on'/>
</kvm>
添加主机的独显设备:(这步可以在virt-manager中进行)
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</source>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</hostdev>
注意:显卡直通可以直接使用apt安装的软件包,而vGPU需要手动编译新版本的软件。并且,并不是所有显卡都可以直通的,一般的,笔记本显卡不能直接直通,笔记本显卡分为两类,MUXed可以直接直通,而MUXless不能,区别是MUXed有视频输出功能且识别为VGA Controller,MUXless无视频输出功能并被识别为3D Controller,多数笔记本独显都配合核显进行输出,不能关闭核显。
笔记本显卡直通可以查看:
MUXed:https://github.com/jscinoz/optimus-vfio-docs
MUXless:https://gist.github.com/Misairu-G/616f7b2756c488148b7309addc940b28
一个支持iGVT-g的虚拟机XML文件示例:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>win10</name>
<uuid>2d025b3d-594b-460d-b6bf-8b7fd77b5ff3</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://microsoft.com/win/10"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-q35-4.2'>hvm</type>
<loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
<nvram>/var/lib/libvirt/qemu/nvram/win10_VARS.fd</nvram>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries='8191'/>
<vendor_id state='on' value='0123456789ab'/>
</hyperv>
<kvm>
<hidden state='on'/>
</kvm>
<vmport state='off'/>
</features>
<cpu mode='host-passthrough' check='none'/>
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/media/yang/数据/kvm_img/win10.qcow2'/>
<target dev='sda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/yang/Downloads/virtio-win-0.1.171.iso'/>
<target dev='sdc' bus='sata'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='2'/>
</disk>
<controller type='usb' index='0' model='qemu-xhci' ports='15'>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
<controller type='sata' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pcie-root'/>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x10'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='2' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='2' port='0x11'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
</controller>
<controller type='pci' index='3' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='3' port='0x12'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
</controller>
<controller type='pci' index='4' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='4' port='0x13'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
</controller>
<controller type='pci' index='5' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='5' port='0x14'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</controller>
<interface type='network'>
<mac address='52:54:00:ba:b1:55'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<serial type='pty'>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='spice'>
<listen type='none'/>
<gl enable='yes' rendernode='/dev/dri/by-path/pci-0000:00:02.0-render'/>
</graphics>
<sound model='ich9'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
</sound>
<video>
<model type='none'/>
</video>
<hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on'>
<source>
<address uuid='7ae3e088-49b2-11ea-bf91-0fc9e1dfaaac'/>
</source>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</hostdev>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</source>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</hostdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='2'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='3'/>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</memballoon>
</devices>
<qemu:commandline>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.romfile=/home/yang/Downloads/vbios_gvt_uefi.rom'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.x-igd-opregion=on'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.ramfb=on'/>
<qemu:arg value='-set'/>
<qemu:arg value='device.hostdev0.driver=vfio-pci-nohotplug'/>
</qemu:commandline>
</domain>
注:
windows需要virtio驱动,详见:https://blog.51cto.com/dangzhiqiang/1833615
其中:
稳定版virtio-win iso: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
相关资源:(已编译)
链接:https://pan.baidu.com/s/1WfrecnKtwg08LTtMedBNig
提取码:0ywp