一、系统环境准备
1、egrep '(vmx|svm)' /proc/cpuinfo
2、close firewalld and selinux
3、yum install qemu-kvm libvirt virt-install bridge-utils -y
4、验证是否安装成功
lsmod | grep kvm
5、开启kvm服务,并且设置其开机自动启动
systemctl start libvirtd
systemctl enable libvirtd
6、配置网卡为网桥模式
cd /etc/sysconfig/network-scripts
#创建ifcfg-br0
BOOTPROTO=static
DEVICE=br0
TYPE=Bridge
NM_CONTROLLED=no
IPADDR=192.168.1.95
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=61.177.7.1
DNS2=8.8.8.8
#移除掉原来的 ifcfg-enp0s25 ,重新创建该文件,内容如下:
BOOTPROTO=none
DEVICE=enp0s25
NM_CONTROLLED=no
ONBOOT=yes
BRIDGE=br0
#重启网络服务
systemctl restart network
#查看网卡就会多一块br0
[root@kvm-server images]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether b8:2a:72:d9:8c:02 brd ff:ff:ff:ff:ff:ff
inet6 fe80::ba2a:72ff:fed9:8c02/64 scope link
valid_lft forever preferred_lft forever
3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether b8:2a:72:d9:8c:03 brd ff:ff:ff:ff:ff:ff
4: eno3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether b8:2a:72:d9:8c:04 brd ff:ff:ff:ff:ff:ff
5: eno4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether b8:2a:72:d9:8c:05 brd ff:ff:ff:ff:ff:ff
6: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 52:54:00:10:4b:45 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:10:4b:45 brd ff:ff:ff:ff:ff:ff
8: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether b8:2a:72:d9:8c:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.141.83/24 brd 192.168.141.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::ba2a:72ff:fed9:8c02/64 scope link
valid_lft forever preferred_lft forever
11: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master virbr0 state UNKNOWN group default qlen 1000
link/ether fe:54:00:68:d1:59 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fe68:d159/64 scope link
valid_lft forever preferred_lft forever
二、安装虚拟机
0、制作镜像
[root@kvm-server images]# qemu-img create -f qcow2 /var/lib/libvirt/images/win7.qcow2 100G
1、传镜像文件
[root@kvm-server ~]# cd /var/lib/libvirt/images/
[root@kvm-server images]# ll
total 15300424
-rwxrwxrwx. 1 777 qemu 443 Jan 17 18:24 installwin7.sh
-rwxrwxrwx. 1 777 qemu 2949120 Jan 17 12:06 virtio-win-0.1.134_amd64.vfd
-rwxrwxrwx. 1 qemu qemu 168509440 Jan 17 12:19 virtio-win-0.1.134.iso
-rw-r--r--. 1 root root 8376 Jan 17 18:25 virt.txt
-rwxrwxrwx. 1 qemu qemu 3420557312 Oct 18 2016 windows7.iso
-rwxrwxrwx. 1 qemu qemu 7813267456 Jan 17 18:39 windows7.qcow2
2、创建虚拟机
[root@kvm-server images]# cat installwin7.sh
#!/bin/sh
virt-install --connect qemu:///system \
--name win7 --ram 4096 --vcpus=2 --cpuset=auto \
--disk path=/var/lib/libvirt/images/windows7.qcow2,bus=virtio,size=100,format=qcow2 \
--network=network=default,model=virtio \
--graphics vnc,port=5910 \
--disk device=cdrom,path=/var/lib/libvirt/images/windows7.iso \
--disk device=cdrom,path=/var/lib/libvirt/images/virtio-win-0.1.134.iso \
--os-type=windows --os-variant=win7 --boot cdrom,hd
3、查看虚拟机
[root@kvm-server images]# virsh list
Id Name State
----------------------------------------------------
2 win7 running
4、检查服务
[root@kvm-server images]# netstat -lntup|grep 5910
tcp 0 0 0.0.0.0:5910 0.0.0.0:* LISTEN 40520/qemu-system-x
5、更改配置文件网卡名称
[root@kvm-server ~]# cd /etc/libvirt/qemu
[root@kvm-server qemu]# ll
total 4
drwx------. 3 root root 42 Jan 17 16:53 networks
-rw-------. 1 root root 4086 Jan 17 18:31 win7.xml
[root@kvm-server qemu]# virsh edit win7
Domain win7 XML configuration not changed.
将:
<interface type='network'
<mac address='52:54:00:0b:f8:a5'/>
<source network='default'/>
修改为:
<interface type='bridge'>
<mac address='52:54:00:0b:f8:a5'/>
<source bridge='br0'/>
6、关闭后再启动虚拟机
[root@kvm-server qemu]# cd /var/lib/libvirt/images/
[root@kvm-server images]# ll
total 11511624
-rwxrwxrwx. 1 777 qemu 443 Jan 17 18:24 installwin7.sh
-rwxrwxrwx. 1 777 qemu 2949120 Jan 17 12:06 virtio-win-0.1.134_amd64.vfd
-rwxrwxrwx. 1 qemu qemu 168509440 Jan 17 12:19 virtio-win-0.1.134.iso
-rw-r--r--. 1 root root 8376 Jan 17 18:25 virt.txt
-rwxrwxrwx. 1 qemu qemu 3420557312 Oct 18 2016 windows7.iso
-rwxrwxrwx. 1 root root 7928414208 Jan 17 19:01 windows7.qcow2
[root@kvm-server images]# sh installwin7.sh
ERROR Guest name 'win7' is already in use.
[root@kvm-server images]# virsh undefine win7
Domain win7 has been undefined
[root@kvm-server images]# sh installwin7.sh
WARNING Unable to connect to graphical console: virt-viewer not installed. Please install the 'virt-viewer' package.
WARNING No console to launch for the guest, defaulting to --wait -1
Starting install...
Domain installation still in progress. Waiting for installation to complete.
三、找台带桌面的linux系统
1、安装virt-manager软件
sudo apt-get install virt-manager -y
2、启动软件
virt-manager
3、设置连接
192.168.141.83:5910
4、安装windows7系统,查找阵列卡驱动,分区,安装系统。
5、带键盘的kvm_vm管理软件
三、内核优化
1、kvm-vt-d 功能
#检查下硬件是否支持kvm vt-d功能
检查下硬件是否支持vt-d,支持的话查看内核参数是否支持,仍然支持的话查看是否开启,intel 开启命令是在grub.conf kernel那行添加intel_iommu=on,AMD 则需要添加“iommu=pt iommu=1”
如果你想在系统启动时加载一个内核参数,需修改GRUB的配置模板(/etc/default /grub),添加"名称=值”的键值对到GRUB_CMDLINE_LINUX变量,添加多个时用空格隔开,例如GRUB_CMDLINE_LINUX="...... name=value"(如果没有GRUB_CMDLINE_LINUX变量时,用GRUB_CMDLINE_LINUX_DEFAULT替代即可),然后使用grub2-mkconfig -o /boot/grub2/grub.cfg更新grub.cfg文件
#有开启iommu的日志输出类似如下:
[root@kvm-server ~]# dmesg | grep -e DMAR -e IOMMU
[ 0.000000] ACPI: DMAR 0x000000007D3346F4 000160 (v01 DELL PE_SC3 00000001 DELL 00000001)
[ 0.109964] DMAR: Host address width 46
[ 0.109965] DMAR: DRHD base: 0x000000d6000000 flags: 0x0
[ 0.109970] DMAR: dmar0: reg_base_addr d6000000 ver 1:0 cap d2078c106f0466 ecap f020de
[ 0.109971] DMAR: DRHD base: 0x000000df900000 flags: 0x1
[ 0.109974] DMAR: dmar1: reg_base_addr df900000 ver 1:0 cap d2078c106f0466 ecap f020de
[ 0.109975] DMAR: RMRR base: 0x0000007f458000 end: 0x0000007f46ffff
[ 0.109976] DMAR: RMRR base: 0x0000007f450000 end: 0x0000007f450fff
[ 0.109976] DMAR: RMRR base: 0x0000007f452000 end: 0x0000007f452fff
[ 0.109977] DMAR: ATSR flags: 0x0
[ 0.109979] DMAR-IR: IOAPIC id 2 under DRHD base 0xd6000000 IOMMU 0
[ 0.109979] DMAR-IR: IOAPIC id 0 under DRHD base 0xdf900000 IOMMU 1
[ 0.109980] DMAR-IR: IOAPIC id 1 under DRHD base 0xdf900000 IOMMU 1
[ 0.109981] DMAR-IR: HPET id 0 under DRHD base 0xdf900000
[ 0.109981] DMAR-IR: x2apic is disabled because BIOS sets x2apic opt out bit.
[ 0.109982] DMAR-IR: Use 'intremap=no_x2apic_optout' to override the BIOS setting.
[ 0.110819] DMAR-IR: Enabled IRQ remapping in xapic mode
2、显卡透传
#查看显卡参数
[root@kvm-server ~]# lspci -nn|grep VGA
0c:00.0 VGA compatible controller [0300]: Matrox Electronics Systems Ltd. G200eR2 [102b:0534]
42:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP106GL [Quadro P2000] [10de:1c30] (rev a1)
3、other
#给内核加启动参数
1. Fedora or CentOS7
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg //生成grub2的配置文件
$ sudo yum install grub2-tools.x86_64 //没有grub2-mkconfig命令时,先安装grub2-tools
带EFI的系统,grub.cfg文件会是在/boot/efi下,比如CentOS7:/boot/efi/EFI/centos/grub.cfg
4、ubuntu显卡直通
#GPU Passthrough with KVM and Debian Linux
#fedora 2003
一、测试报告
1、查询设备ID
[root@kvm-server ~]# virsh nodedev-list | grep pci
pci_0000_42_00_0
pci_0000_42_00_1
2、过滤显卡
参数说明:显卡驱动和音频驱动
[root@kvm-server 0000:42:00.0]# lspci -nn|grep NVIDIA
42:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP106GL [Quadro P2000] [10de:1c30] (rev a1)
42:00.1 Audio device [0403]: NVIDIA Corporation GP106 High Definition Audio Controller [10de:10f1] (rev a1)
[root@kvm-server 0000:42:00.0]# cd /sys/bus/pci/devices/0000:42:00.0
[root@kvm-server 0000:42:00.0]# ls
boot_vga device hwmon i2c-16 i2c-7 modalias resource0 subsystem
broken_parity_status dma_mask_bits i2c-1 i2c-17 i2c-8 msi_bus resource1 subsystem_device
class driver i2c-10 i2c-18 i2c-9 msi_irqs resource1_wc subsystem_vendor
config driver_override i2c-11 i2c-2 irq numa_node resource3 uevent
consistent_dma_mask_bits drm i2c-12 i2c-3 local_cpulist power resource3_wc vendor
current_link_speed drm_dp_aux_dev i2c-13 i2c-4 local_cpus remove resource5
current_link_width enable i2c-14 i2c-5 max_link_speed rescan revision
d3cold_allowed graphics i2c-15 i2c-6 max_link_width resource rom
#备注:默认没有driver文件,需要在virtual machine manager里面,添加 pci host device 设备,找到显卡p2000驱动,点完成。
启动虚拟机时会报错,无法启动。再删除pci host device 设备,再进cd /sys/bus/pci/devices/0000:42:00.0目录,就会发现,多了一个driver文件夹。
3、挂载vfio驱动
modprobe vfio
modprobe vfio-pci
#解绑
echo 0000:42:00.0 > /sys/bus/pci/devices/0000\:42\:00.0/driver/unbind
echo 0000:42:00.1 > /sys/bus/pci/devices/0000\:42\:00.1/driver/unbind#绑定
echo 10de 1c30 > /sys/bus/pci/drivers/vfio-pci/new_id
echo 10de 10f1 > /sys/bus/pci/drivers/vfio-pci/new_id
4、查看是否加载成功
[root@kvm-server 0000:42:00.0]# dmesg
5、查看加载信息
[root@kvm-server ~]# dmesg |grep iommu
[ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-4.13.16-100.fc25.x86_64 root=/dev/mapper/fedora_kvm--server-root ro rd.lvm.lv=fedora_kvm-server/root rd.lvm.lv=fedora_kvm-server/swap rhgb quiet intel_iommu=on
[ 0.000000] Kernel command line: BOOT_IMAGE=/vmlinuz-4.13.16-100.fc25.x86_64 root=/dev/mapper/fedora_kvm--server-root ro rd.lvm.lv=fedora_kvm-server/root rd.lvm.lv=fedora_kvm-server/swap rhgb quiet intel_iommu=on
[ 0.939074] iommu: Adding device 0000:00:00.0 to group 0
[ 0.939096] iommu: Adding device 0000:00:01.0 to group 1
[ 0.939114] iommu: Adding device 0000:00:01.1 to group 2
[ 0.939133] iommu: Adding device 0000:00:02.0 to group 3
[ 0.939155] iommu: Adding device 0000:00:02.2 to group 4
[ 0.939174] iommu: Adding device 0000:00:03.0 to group 5
[ 0.939193] iommu: Adding device 0000:00:03.2 to group 6
[ 0.939231] iommu: Adding device 0000:00:05.0 to group 7
[ 0.939248] iommu: Adding device 0000:00:05.2 to group 7
[ 0.939267] iommu: Adding device 0000:00:11.0 to group 8
[ 0.939304] iommu: Adding device 0000:00:16.0 to group 9
[ 0.939321] iommu: Adding device 0000:00:16.1 to group 9
[ 0.939336] iommu: Adding device 0000:00:1a.0 to group 10
[ 0.939351] iommu: Adding device 0000:00:1c.0 to group 11
[ 0.939371] iommu: Adding device 0000:00:1c.7 to group 12
[ 0.939386] iommu: Adding device 0000:00:1d.0 to group 13
[ 0.939401] iommu: Adding device 0000:00:1e.0 to group 14
[ 0.939436] iommu: Adding device 0000:00:1f.0 to group 15
[ 0.939451] iommu: Adding device 0000:00:1f.2 to group 15
[ 0.939496] iommu: Adding device 0000:01:00.0 to group 16
[ 0.939522] iommu: Adding device 0000:01:00.1 to group 16
[ 0.939566] iommu: Adding device 0000:02:00.0 to group 17
[ 0.939590] iommu: Adding device 0000:02:00.1 to group 17
[ 0.939607] iommu: Adding device 0000:03:00.0 to group 18
[ 0.939623] iommu: Adding device 0000:09:00.0 to group 19
[ 0.939641] iommu: Adding device 0000:0a:00.0 to group 20
[ 0.939657] iommu: Adding device 0000:0a:01.0 to group 21
[ 0.939694] iommu: Adding device 0000:0b:00.0 to group 20
[ 0.939699] iommu: Adding device 0000:0c:00.0 to group 20
[ 0.939724] iommu: Adding device 0000:3f:08.0 to group 22
[ 0.939750] iommu: Adding device 0000:3f:09.0 to group 23
[ 0.939810] iommu: Adding device 0000:3f:0a.0 to group 24
[ 0.939826] iommu: Adding device 0000:3f:0a.1 to group 24
[ 0.939843] iommu: Adding device 0000:3f:0a.2 to group 24
[ 0.939859] iommu: Adding device 0000:3f:0a.3 to group 24
[ 0.939896] iommu: Adding device 0000:3f:0b.0 to group 25
[ 0.939912] iommu: Adding device 0000:3f:0b.3 to group 25
[ 0.939979] iommu: Adding device 0000:3f:0c.0 to group 26
[ 0.939999] iommu: Adding device 0000:3f:0c.1 to group 26
[ 0.940031] iommu: Adding device 0000:3f:0c.2 to group 26
[ 0.940048] iommu: Adding device 0000:3f:0c.3 to group 26
[ 0.940065] iommu: Adding device 0000:3f:0c.4 to group 26
[ 0.940132] iommu: Adding device 0000:3f:0d.0 to group 27
[ 0.940149] iommu: Adding device 0000:3f:0d.1 to group 27
[ 0.940167] iommu: Adding device 0000:3f:0d.2 to group 27
[ 0.940188] iommu: Adding device 0000:3f:0d.3 to group 27
[ 0.940205] iommu: Adding device 0000:3f:0d.4 to group 27
[ 0.940241] iommu: Adding device 0000:3f:0e.0 to group 28
[ 0.940259] iommu: Adding device 0000:3f:0e.1 to group 28
[ 0.940338] iommu: Adding device 0000:3f:0f.0 to group 29
[ 0.940358] iommu: Adding device 0000:3f:0f.1 to group 29
[ 0.940377] iommu: Adding device 0000:3f:0f.2 to group 29
[ 0.940399] iommu: Adding device 0000:3f:0f.3 to group 29
[ 0.940419] iommu: Adding device 0000:3f:0f.4 to group 29
[ 0.940437] iommu: Adding device 0000:3f:0f.5 to group 29
[ 0.940525] iommu: Adding device 0000:3f:10.0 to group 30
[ 0.940544] iommu: Adding device 0000:3f:10.1 to group 30
[ 0.940565] iommu: Adding device 0000:3f:10.2 to group 30
[ 0.940583] iommu: Adding device 0000:3f:10.3 to group 30
[ 0.940603] iommu: Adding device 0000:3f:10.4 to group 30
[ 0.940626] iommu: Adding device 0000:3f:10.5 to group 30
[ 0.940645] iommu: Adding device 0000:3f:10.7 to group 30
[ 0.940701] iommu: Adding device 0000:3f:13.0 to group 31
[ 0.940720] iommu: Adding device 0000:3f:13.1 to group 31
[ 0.940739] iommu: Adding device 0000:3f:13.4 to group 31
[ 0.940757] iommu: Adding device 0000:3f:13.5 to group 31
[ 0.940804] iommu: Adding device 0000:3f:16.0 to group 32
[ 0.940827] iommu: Adding device 0000:3f:16.1 to group 32
[ 0.940846] iommu: Adding device 0000:3f:16.2 to group 32
[ 0.940865] iommu: Adding device 0000:40:01.0 to group 33
[ 0.940883] iommu: Adding device 0000:40:02.0 to group 34
[ 0.940901] iommu: Adding device 0000:40:03.0 to group 35
[ 0.940918] iommu: Adding device 0000:40:03.2 to group 36
[ 0.940959] iommu: Adding device 0000:40:05.0 to group 37
[ 0.940980] iommu: Adding device 0000:40:05.2 to group 37
[ 0.941028] iommu: Adding device 0000:42:00.0 to group 38
[ 0.941053] iommu: Adding device 0000:42:00.1 to group 38
[ 0.941079] iommu: Adding device 0000:7f:08.0 to group 39
[ 0.941107] iommu: Adding device 0000:7f:09.0 to group 40
[ 0.941164] iommu: Adding device 0000:7f:0a.0 to group 41
[ 0.941185] iommu: Adding device 0000:7f:0a.1 to group 41
[ 0.941205] iommu: Adding device 0000:7f:0a.2 to group 41
[ 0.941226] iommu: Adding device 0000:7f:0a.3 to group 41
[ 0.941261] iommu: Adding device 0000:7f:0b.0 to group 42
[ 0.941281] iommu: Adding device 0000:7f:0b.3 to group 42
[ 0.941352] iommu: Adding device 0000:7f:0c.0 to group 43
[ 0.941378] iommu: Adding device 0000:7f:0c.1 to group 43
[ 0.941400] iommu: Adding device 0000:7f:0c.2 to group 43
[ 0.941420] iommu: Adding device 0000:7f:0c.3 to group 43
[ 0.941441] iommu: Adding device 0000:7f:0c.4 to group 43
[ 0.941509] iommu: Adding device 0000:7f:0d.0 to group 44
[ 0.941530] iommu: Adding device 0000:7f:0d.1 to group 44
[ 0.941555] iommu: Adding device 0000:7f:0d.2 to group 44
[ 0.941577] iommu: Adding device 0000:7f:0d.3 to group 44
[ 0.941598] iommu: Adding device 0000:7f:0d.4 to group 44
[ 0.941634] iommu: Adding device 0000:7f:0e.0 to group 45
[ 0.941656] iommu: Adding device 0000:7f:0e.1 to group 45
[ 0.941735] iommu: Adding device 0000:7f:0f.0 to group 46
[ 0.941758] iommu: Adding device 0000:7f:0f.1 to group 46
[ 0.941784] iommu: Adding device 0000:7f:0f.2 to group 46
[ 0.941807] iommu: Adding device 0000:7f:0f.3 to group 46
[ 0.941830] iommu: Adding device 0000:7f:0f.4 to group 46
[ 0.941855] iommu: Adding device 0000:7f:0f.5 to group 46
[ 0.941944] iommu: Adding device 0000:7f:10.0 to group 47
[ 0.941967] iommu: Adding device 0000:7f:10.1 to group 47
[ 0.941990] iommu: Adding device 0000:7f:10.2 to group 47
[ 0.942020] iommu: Adding device 0000:7f:10.3 to group 47
[ 0.942047] iommu: Adding device 0000:7f:10.4 to group 47
[ 0.942070] iommu: Adding device 0000:7f:10.5 to group 47
[ 0.942094] iommu: Adding device 0000:7f:10.7 to group 47
[ 0.942150] iommu: Adding device 0000:7f:13.0 to group 48
[ 0.942175] iommu: Adding device 0000:7f:13.1 to group 48
[ 0.942197] iommu: Adding device 0000:7f:13.4 to group 48
[ 0.942220] iommu: Adding device 0000:7f:13.5 to group 48
[ 0.942271] iommu: Adding device 0000:7f:16.0 to group 49
[ 0.942295] iommu: Adding device 0000:7f:16.1 to group 49
在kvm中虚拟机,直通 独立P2000显卡
1、blos中开启vt-d 参数
2、添加intel_iommu=on,参数到grub文件中,
[root@kvm-server ~]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora_kvm-server/root rd.lvm.lv=fedora_kvm-server/swap rhgb quiet intel_iommu=on"
GRUB_DISABLE_RECOVERY="true"
3、加载grub文件到内核中
[root@kvm-server ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
#查看加载是否成功
vim /boot/grub2/grub.cfg
linux16 /vmlinuz-4.13.16-100.fc25.x86_64 root=/dev/mapper/fedora_kvm--server-root ro rd.lvm.lv=fedora_kvm-server/root rd.lvm.lv=fedora_kvm-server/swap rhgb quiet intel_iom
mu=on
4、reboot 重启系统
5、双显卡,把VGA线接到板载显卡上面
6、在kvm中安装系统
- 启动方式选择:UEFI and Q35
- 选择windows7.iso
- 选择irtio-win-0.1.134.iso
- 加载显卡----pci host device ----P2000 (备注:这就是需要穿透的显卡)
- 加载音频(显卡音频)---pci host device ----Audio (备注:这就是需要穿透的显卡)
7、安装系统驱动
8、安装完成windows7系统,修改win7.xml配置文件
9、编辑kvm xml 文件
[root@kvm-server qemu]# cd /etc/libvirt/qemu
[root@kvm-server qemu]# ll
total 12
drwx------. 3 root root 42 Jan 17 16:53 networks
-rw------- 1 root root 4134 Jan 18 19:02 win7.xml
-rw-------. 1 root root 4086 Jan 18 10:50 win7.xml.bak
#编辑kvm xml 文件
添加图上部分代码,开启隐藏显卡检测功能。
[root@kvm-server qemu]# virsh edit win7
#使修改的配置文件生效
[root@kvm-server ~]# virsh define win7.xml
9、修改win7.xml 网卡的桥接br0选项
10、启动windows7虚拟机,进入系统安装显卡驱动,完装完成,重启系统。
dmesg |grep -i iommu
dmesg |grep IOM
dmesg |grep iommu
11、安装virt-manager软件
#ubuntu系统
sudo apt-get install virt-manager -y
#fedora系统
dnf install virt-manager -y
12、安装remote-viewer,spice链接,安装系统。
spice://192.168.141.83:5900
#执行 Virt-viewer 并联机至虚拟机桌面
启动 Virt-viewer,在 Connection Address 字段输入:"Spice://: QVM port",例如:Spice://192.168.1.1:5901 并点击 "Connect"。
#连接时要先清空防火墙
iptables -F
iptalbes -L