环境
已安装nvidia 显卡 驱动
操作系统:CentOS Linux release 7.9.2009 (Core)
内核版本:Linux 5.4.135-1.el7.elrepo.x86_64
显卡 型号:rtx 6000
kvm版本:
virsh version
Compiled against library: libvirt 4.5.0
Using library: libvirt 4.5.0
Using API : QEMU 4.5.0
Running hypervisor: QEMU 1.5.3
解绑GPU 设备
1.配置GRUB_CMDLINE_LINUX(实测,有效),查询要解绑的设备,记录设备id号
lspci -nn|grep NVIDIA |grep VGA
或者 lspci -nn|grep NVIDIA
2.修改 /etc/default/grub文件的GRUB_CMDLINE_LINUX
vi /etc/default/grub
以下是内容,新增加 GRUB_CMDLINE_LINUX行: intel_iommu=on pci-stub.ids=10de:1e30″
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=”intel_iommu=on crashkernel=auto spectre_v2=retpoline rhgb quiet rdblacklist=nouveau pci-stub.ids=10de:1e30″
GRUB_DISABLE_RECOVERY=”true”
3.更新grub2 conf,执行如下命令
grub2-mkconfig -o /boot/grub2/grub.cfg
4.重启系统
reboot
验证并查看nvidia 显卡
1.执行nvidia-smi ,看不到显卡,证明显卡已经被解绑
# nvidia-smi
NVIDIA-SMI has failed because it couldnt communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
2.验证内核支持iommu
cat /proc/cmdline | grep iommu
结果输出: intel_iommu=on
3.验证VT-D是否启用
dmesg |grep -e DMAR -e IOMMU
安装win10虚拟机
qemu-img create -f qcow2 /home/kvm-machines/shaoyan.qcow2 200G
virt-install –name shaoyan –ram 4096 –vcpus=8 –os-type=windows –accelerate –cdrom=/home/kvm_images/win10.iso –disk path=/home/kvm-machines/shaoyan.qcow2,format=qcow2,bus=ide –bridge=br0 –autostart –vnc –vncport=5910 –vnclisten=0.0.0.0
宿主机安装软件包
yum -y groups install GNOME Desktop virt-manager virt-viewer dejavu-lgc-sans-fonts
显卡加载vfio驱动
1.显卡加载vfio驱动
modprobe vfio
modprobe vfio-pci
2.从服务器卸载1张显卡的4个设备
virsh nodedev-detach pci_0000_b1_00_0
virsh nodedev-detach pci_0000_b1_00_1
virsh nodedev-detach pci_0000_b1_00_2
virsh nodedev-detach pci_0000_b1_00_3
3.验证显卡设备是否加载vfio-pci驱动,加载成功
# lspci -vv -s b1:00.0 | grep driver
Kernel driver in use: vfio-pci
[root@rtx_6000 10.147.100.107 ~ ]
# lspci -vv -s b1:00.1 | grep driver
Kernel driver in use: vfio-pci
[root@rtx_6000 10.147.100.107 ~ ]
# lspci -vv -s b1:00.2 | grep driver
Kernel driver in use: vfio-pci
[root@rtx_6000 10.147.100.107 ~ ]
# lspci -vv -s b1:00.3 | grep driver
Kernel driver in use: vfio-pci
win10虚拟机添加NVDIA显卡
1.通过远控卡登录服务器透传显卡,执行startx 调出可视化页面
startx
2.添加显卡硬件
3.查看显卡
显卡驱动安装
1.要安装显卡驱动,需要修改虚拟机win10的配置文件 否则显卡驱动安装过程中自检会报错ERROR CODE 43,驱动不允许安装在虚拟机上。#编辑VM XML
virsh edit shaoyan
#修改第一行
暂无评论内容