PVE8.1 NVIDIA显卡虚拟化多开VGPU16.2--基于1050Ti

顺带接有偿部署,有需要点击链接闲鱼与我联系

记录6.5内核的PVE8.1版本配置NVIDIA显卡虚拟化的一些设置,基于GTX1050Ti。

PVE8.1.4

硬件配置

配置型号
系统PVE 8.1.4
内核Linux 6.5.11-8-pve
CPUIntel Core i5-7500 @ 3.4GHz 4核4线程
显卡GTX1050 Ti 4096MB
VGPU驱动535.129.03

VGPU_Unlock支持的显卡列表点我展开


消费级显卡支持10系列20系列但不支持30系列40系列

设备ID显卡型号VGPU模拟型号
21c4TU116 GeForce GTX 1660 SUPERQuadro RTX 6000
21d1TU116BM GeForce GTX 1660 Ti MobileQuadro RTX 6000
21c2TU116Quadro RTX 6000
2182TU116 GeForce GTX 1660 TiQuadro RTX 6000
2183TU116Quadro RTX 6000
2184TU116 GeForce GTX 1660Quadro RTX 6000
2187TU116 GeForce GTX 1650 SUPERQuadro RTX 6000
2188TU116 GeForce GTX 1650Quadro RTX 6000
2191TU116M GeForce GTX 1660 Ti MobileQuadro RTX 6000
2192TU116M GeForce GTX 1650 Ti MobileQuadro RTX 6000
21aeTU116GLQuadro RTX 6000
21bfTU116GLQuadro RTX 6000
2189TU116 CMP 30HXQuadro RTX 6000
1fbfTU117GLQuadro RTX 6000
1fbbTU117GLM Quadro T500 MobileQuadro RTX 6000
1fd9TU117BM GeForce GTX 1650 Mobile RefreshQuadro RTX 6000
1ff9TU117GLM Quadro T1000 MobileQuadro RTX 6000
1fddTU117BM GeForce GTX 1650 Mobile RefreshQuadro RTX 6000
1f96TU117M GeForce GTX 1650 Mobile / Max-QQuadro RTX 6000
1f99TU117MQuadro RTX 6000
1faeTU117GLQuadro RTX 6000
1fb8TU117GLM Quadro T2000 Mobile / Max-QQuadro RTX 6000
1fb9TU117GLM Quadro T1000 MobileQuadro RTX 6000
1f97TU117M GeForce MX450Quadro RTX 6000
1f98TU117M GeForce MX450Quadro RTX 6000
1f9cTU117M GeForce MX450Quadro RTX 6000
1f9dTU117M GeForce GTX 1650 Mobile / Max-QQuadro RTX 6000
1fb0TU117GLM Quadro T1000 MobileQuadro RTX 6000
1fb1TU117GL T600Quadro RTX 6000
1fb2TU117GLM Quadro T400 MobileQuadro RTX 6000
1fbaTU117GLM T600 MobileQuadro RTX 6000
1f42TU106 GeForce RTX 2060 SUPERQuadro RTX 6000
1f47TU106 GeForce RTX 2060 SUPERQuadro RTX 6000
1f50TU106BM GeForce RTX 2070 Mobile / Max-QQuadro RTX 6000
1f51TU106BM GeForce RTX 2060 MobileQuadro RTX 6000
1f54TU106BM GeForce RTX 2070 MobileQuadro RTX 6000
1f55TU106BM GeForce RTX 2060 MobileQuadro RTX 6000
1f81TU117Quadro RTX 6000
1f82TU117 GeForce GTX 1650Quadro RTX 6000
1f91TU117M GeForce GTX 1650 Mobile / Max-QQuadro RTX 6000
1f92TU117M GeForce GTX 1650 MobileQuadro RTX 6000
1f94TU117M GeForce GTX 1650 MobileQuadro RTX 6000
1f95TU117M GeForce GTX 1650 Ti MobileQuadro RTX 6000
1f76TU106GLM Quadro RTX 3000 Mobile RefreshQuadro RTX 6000
1f07TU106 GeForce RTX 2070 Rev. AQuadro RTX 6000
1f08TU106 GeForce RTX 2060 Rev. AQuadro RTX 6000
1f09TU106 GeForce GTX 1660 SUPERQuadro RTX 6000
1f0aTU106 GeForce GTX 1650Quadro RTX 6000
1f10TU106M GeForce RTX 2070 MobileQuadro RTX 6000
1f11TU106M GeForce RTX 2060 MobileQuadro RTX 6000
1f12TU106M GeForce RTX 2060 Max-QQuadro RTX 6000
1f14TU106M GeForce RTX 2070 Mobile / Max-Q RefreshQuadro RTX 6000
1f15TU106M GeForce RTX 2060 MobileQuadro RTX 6000
1f2eTU106MQuadro RTX 6000
1f36TU106GLM Quadro RTX 3000 Mobile / Max-QQuadro RTX 6000
1f0bTU106 CMP 40HXQuadro RTX 6000
1eb5TU104GLM Quadro RTX 5000 Mobile / Max-QQuadro RTX 6000
1eb6TU104GLM Quadro RTX 4000 Mobile / Max-QQuadro RTX 6000
1eb8TU104GL Tesla T4Quadro RTX 6000
1eb9TU104GLQuadro RTX 6000
1ebeTU104GLQuadro RTX 6000
1ec2TU104 GeForce RTX 2070 SUPERQuadro RTX 6000
1ec7TU104 GeForce RTX 2070 SUPERQuadro RTX 6000
1ed0TU104BM GeForce RTX 2080 MobileQuadro RTX 6000
1ed1TU104BM GeForce RTX 2070 SUPER Mobile / Max-QQuadro RTX 6000
1ed3TU104BM GeForce RTX 2080 SUPER Mobile / Max-QQuadro RTX 6000
1f02TU106 GeForce RTX 2070Quadro RTX 6000
1f04TU106Quadro RTX 6000
1f06TU106 GeForce RTX 2060 SUPERQuadro RTX 6000
1ef5TU104GLM Quadro RTX 5000 Mobile RefreshQuadro RTX 6000
1e81TU104 GeForce RTX 2080 SUPERQuadro RTX 6000
1e82TU104 GeForce RTX 2080Quadro RTX 6000
1e84TU104 GeForce RTX 2070 SUPERQuadro RTX 6000
1e87TU104 GeForce RTX 2080 Rev. AQuadro RTX 6000
1e89TU104 GeForce RTX 2060Quadro RTX 6000
1e90TU104M GeForce RTX 2080 MobileQuadro RTX 6000
1e91TU104M GeForce RTX 2070 SUPER Mobile / Max-QQuadro RTX 6000
1e93TU104M GeForce RTX 2080 SUPER Mobile / Max-QQuadro RTX 6000
1eabTU104MQuadro RTX 6000
1eaeTU104MQuadro RTX 6000
1eb0TU104GL Quadro RTX 5000Quadro RTX 6000
1eb1TU104GL Quadro RTX 4000Quadro RTX 6000
1eb4TU104GL T4GQuadro RTX 6000
1e04TU102 GeForce RTX 2080 TiQuadro RTX 6000
1e07TU102 GeForce RTX 2080 Ti Rev. AQuadro RTX 6000
1e2dTU102 GeForce RTX 2080 Ti Engineering SampleQuadro RTX 6000
1e2eTU102 GeForce RTX 2080 Ti 12GB Engineering SampleQuadro RTX 6000
1e30TU102GL Quadro RTX 6000/8000Quadro RTX 6000
1e36TU102GL Quadro RTX 6000Quadro RTX 6000
1e37TU102GL GRID RTX T10-4/T10-8/T10-16Quadro RTX 6000
1e38TU102GLQuadro RTX 6000
1e3cTU102GLQuadro RTX 6000
1e3dTU102GLQuadro RTX 6000
1e3eTU102GLQuadro RTX 6000
1e78TU102GL Quadro RTX 6000/8000Quadro RTX 6000
1e09TU102 CMP 50HXQuadro RTX 6000
1dbaGV100GL Quadro GV100Tesla V100 32GB PCIE
1e02TU102 TITAN RTXQuadro RTX 6000
1cfaGP107GL Quadro P2000Tesla P40
1cfbGP107GL Quadro P1000Tesla P40
1d01GP108 GeForce GT 1030Tesla P40
1d10GP108M GeForce MX150Tesla P40
1d11GP108M GeForce MX230Tesla P40
1d12GP108M GeForce MX150Tesla P40
1d13GP108M GeForce MX250Tesla P40
1d16GP108M GeForce MX330Tesla P40
1d33GP108GLM Quadro P500 MobileTesla P40
1d34GP108GLM Quadro P520Tesla P40
1d52GP108BM GeForce MX250Tesla P40
1d56GP108BM GeForce MX330Tesla P40
1d81GV100 TITAN VTesla V100 32GB PCIE
1cb6GP107GL Quadro P620Tesla P40
1cbaGP107GLM Quadro P2000 MobileTesla P40
1cbbGP107GLM Quadro P1000 MobileTesla P40
1cbcGP107GLM Quadro P600 MobileTesla P40
1cbdGP107GLM Quadro P620Tesla P40
1cccGP107BM GeForce GTX 1050 Ti MobileTesla P40
1ccdGP107BM GeForce GTX 1050 MobileTesla P40
1ca8GP107GLTesla P40
1caaGP107GLTesla P40
1cb1GP107GL Quadro P1000Tesla P40
1cb2GP107GL Quadro P600Tesla P40
1cb3GP107GL Quadro P400Tesla P40
1c70GP106GLTesla P40
1c81GP107 GeForce GTX 1050Tesla P40
1c82GP107 GeForce GTX 1050 TiTesla P40
1c83GP107 GeForce GTX 1050 3GBTesla P40
1c8cGP107M GeForce GTX 1050 Ti MobileTesla P40
1c8dGP107M GeForce GTX 1050 MobileTesla P40
1c8eGP107MTesla P40
1c8fGP107M GeForce GTX 1050 Ti Max-QTesla P40
1c90GP107M GeForce MX150Tesla P40
1c91GP107M GeForce GTX 1050 3 GB Max-QTesla P40
1c92GP107M GeForce GTX 1050 MobileTesla P40
1c94GP107M GeForce MX350Tesla P40
1c96GP107M GeForce MX350Tesla P40
1ca7GP107GLTesla P40
1c36GP106 P106MTesla P40
1c07GP106 P106-100Tesla P40
1c09GP106 P106-090Tesla P40
1c20GP106M GeForce GTX 1060 MobileTesla P40
1c21GP106M GeForce GTX 1050 Ti MobileTesla P40
1c22GP106M GeForce GTX 1050 MobileTesla P40
1c23GP106M GeForce GTX 1060 Mobile Rev. 2Tesla P40
1c2dGP106MTesla P40
1c30GP106GL Quadro P2000Tesla P40
1c31GP106GL Quadro P2200Tesla P40
1c35GP106M Quadro P2000 MobileTesla P40
1c60GP106BM GeForce GTX 1060 Mobile 6GBTesla P40
1c61GP106BM GeForce GTX 1050 Ti MobileTesla P40
1c62GP106BM GeForce GTX 1050 MobileTesla P40
1bb8GP104GLM Quadro P3000 MobileTesla P40
1bb9GP104GLM Quadro P4200 MobileTesla P40
1bbbGP104GLM Quadro P3200 MobileTesla P40
1bc7GP104 P104-101Tesla P40
1be0GP104BM GeForce GTX 1080 MobileTesla P40
1be1GP104BM GeForce GTX 1070 MobileTesla P40
1c00GP106Tesla P40
1c01GP106Tesla P40
1c02GP106 GeForce GTX 1060 3GBTesla P40
1c03GP106 GeForce GTX 1060 6GBTesla P40
1c04GP106 GeForce GTX 1060 5GBTesla P40
1c06GP106 GeForce GTX 1060 6GB Rev. 2Tesla P40
1b87GP104 P104-100Tesla P40
1ba0GP104M GeForce GTX 1080 MobileTesla P40
1ba1GP104M GeForce GTX 1070 MobileTesla P40
1ba2GP104M GeForce GTX 1070 MobileTesla P40
1ba9GP104MTesla P40
1baaGP104MTesla P40
1badGP104 GeForce GTX 1070 Engineering SampleTesla P40
1bb0GP104GL Quadro P5000Tesla P40
1bb1GP104GL Quadro P4000Tesla P40
1bb3GP104GL Tesla P4Tesla P40
1bb4GP104GL Tesla P6Tesla P40
1bb5GP104GLM Quadro P5200 MobileTesla P40
1bb6GP104GLM Quadro P5000 MobileTesla P40
1bb7GP104GLM Quadro P4000 MobileTesla P40
1b06GP102 GeForce GTX 1080 TiTesla P40
1b07GP102 P102-100Tesla P40
1b30GP102GL Quadro P6000Tesla P40
1b38GP102GL Tesla P40Tesla P40
1b70GP102GLTesla P40
1b78GP102GLTesla P40
1b80GP104 GeForce GTX 1080Tesla P40
1b81GP104 GeForce GTX 1070Tesla P40
1b82GP104 GeForce GTX 1070 TiTesla P40
1b83GP104 GeForce GTX 1060 6GBTesla P40
1b84GP104 GeForce GTX 1060 3GBTesla P40
1b39GP102GL Tesla P10Tesla P40
1b00GP102 TITAN XTesla P40
1b01GP102 GeForce GTX 1080 Ti 10GBTesla P40
1b02GP102 TITAN XpTesla P40
1b04GP102Tesla P40
179cGM107 GeForce 940MXTesla M10
17c2GM200 GeForce GTX TITAN XTesla M60
17c8GM200 GeForce GTX 980 TiTesla M60
17f0GM200GL Quadro M6000Tesla M60
17f1GM200GL Quadro M6000 24GBTesla M60
17fdGM200GL Tesla M40Tesla M60
1617GM204M GeForce GTX 980MTesla M60
1618GM204M GeForce GTX 970MTesla M60
1619GM204M GeForce GTX 965MTesla M60
161aGM204M GeForce GTX 980 MobileTesla M60
1667GM204M GeForce GTX 965MTesla M60
1725GP100Tesla P40
172eGP100Tesla P40
172fGP100Tesla P40
174dGM108M GeForce MX130Tesla M10
174eGM108M GeForce MX110Tesla M10
1789GM107GL GRID M3-3020Tesla M10
1402GM206 GeForce GTX 950Tesla M60
1406GM206 GeForce GTX 960 OEMTesla M60
1407GM206 GeForce GTX 750 v2Tesla M60
1427GM206M GeForce GTX 965MTesla M60
1430GM206GL Quadro M2000Tesla M60
1431GM206GL Tesla M4Tesla M60
1436GM206GLM Quadro M2200 MobileTesla M60
15f0GP100GL Quadro GP100Tesla P40
15f1GP100GLTesla P40
1404GM206 GeForce GTX 960 FAKETesla M60
13d8GM204M GeForce GTX 970MTesla M60
13d9GM204M GeForce GTX 965MTesla M60
13daGM204M GeForce GTX 980 MobileTesla M60
13e7GM204GL GeForce GTX 980 Engineering SampleTesla M60
13f0GM204GL Quadro M5000Tesla M60
13f1GM204GL Quadro M4000Tesla M60
13f2GM204GL Tesla M60Tesla M60
13f3GM204GL Tesla M6Tesla M60
13f8GM204GLM Quadro M5000M / M5000 SETesla M60
13f9GM204GLM Quadro M4000MTesla M60
13faGM204GLM Quadro M3000MTesla M60
13fbGM204GLM Quadro M5500Tesla M60
1401GM206 GeForce GTX 960Tesla M60
13b3GM107GLM Quadro K2200MTesla M10
13b4GM107GLM Quadro M620 MobileTesla M10
13b6GM107GLM Quadro M1200 MobileTesla M10
13b9GM107GL NVS 810Tesla M10
13baGM107GL Quadro K2200Tesla M10
13bbGM107GL Quadro K620Tesla M10
13bcGM107GL Quadro K1200Tesla M10
13bdGM107GL Tesla M10Tesla M10
13c0GM204 GeForce GTX 980Tesla M60
13c1GM204Tesla M60
13c2GM204 GeForce GTX 970Tesla M60
13c3GM204Tesla M60
13d7GM204M GeForce GTX 980MTesla M60
1389GM107GL GRID M30Tesla M10
1390GM107M GeForce 845MTesla M10
1391GM107M GeForce GTX 850MTesla M10
1392GM107M GeForce GTX 860MTesla M10
1393GM107M GeForce 840MTesla M10
1398GM107M GeForce 845MTesla M10
1399GM107M GeForce 945MTesla M10
139aGM107M GeForce GTX 950MTesla M10
139bGM107M GeForce GTX 960MTesla M10
139cGM107M GeForce 940MTesla M10
139dGM107M GeForce GTX 750 TiTesla M10
13b0GM107GLM Quadro M2000MTesla M10
13b1GM107GLM Quadro M1000MTesla M10
13b2GM107GLM Quadro M600MTesla M10
1347GM108M GeForce 940MTesla M10
1348GM108M GeForce 945M / 945ATesla M10
1349GM108M GeForce 930MTesla M10
134bGM108M GeForce 940MXTesla M10
134dGM108M GeForce 940MXTesla M10
134eGM108M GeForce 930MXTesla M10
134fGM108M GeForce 920MXTesla M10
137aGM108GLM Quadro K620M / Quadro M500MTesla M10
137bGM108GLM Quadro M520 MobileTesla M10
137dGM108M GeForce 940ATesla M10
1380GM107 GeForce GTX 750 TiTesla M10
1381GM107 GeForce GTX 750Tesla M10
1382GM107 GeForce GTX 745Tesla M10
1340GM108M GeForce 830MTesla M10
1341GM108M GeForce 840MTesla M10
1344GM108M GeForce 845MTesla M10
1346GM108M GeForce 930MTesla M10


PVE基本设置

安装PVE过程略过,提前将pve安装好,在安装VGPU前先将pve底层设置优化一下
本篇文章将大量使用nano文本编辑命令,至于怎么使用自行百度,这里不重复造轮子了。 知道如何保存就行Ctrl +X 输入“Y”回车保存

BIOS设置


提前在BIOS开启以下参数

  • 开启VT-d --硬件直通必须开启
  • 开启SRIOV --如有
  • 开启Above 4G --如有
  • 关闭安全启动 --在security菜单 secure boot 改disabled

更换系统源

国内清华源
编辑sources.list,将原有的源链接在句首加 # 注释掉,更换以下清华源信息
nano /etc/apt/sources.list

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

更换企业源

国内清华源
编辑pve-enterprise.list,将原有的源链接在句首加 # 注释掉,更换以下清华源信息
nano /etc/apt/sources.list.d/pve-enterprise.list

deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bookworm pve-no-subscription

修复源401错误

编辑ceph.list,将原有的源链接在句首加 # 注释掉,添加中科大ceph源
nano /etc/apt/sources.list.d/ceph.list

deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription

执行更新源

apt update 

LXC容器更源

国内清华源

# 备份APLInfo.pm
cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back
# 替换为清华源:
sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
# 重启服务后生效
systemctl restart pvedaemon.service

PVE常用优化脚本

可以做下以下优化
1)去掉登录订阅提示;
2)合并local-lvm以最大化利用硬盘空间;
3)添加CPU频率硬盘温度;
4)删掉不用的内核等信息,减少驱动安装不上等问题;

# 下载pve_source二进制文件到/root目录
wget https://yangwenqing.com/files/pve/pve_source.tar.gz && tar zxvf /root/pve_source.tar.gz && /root/./pve_source

开启硬件直通

需要提前在主板BIOS开启虚拟化功能,才能开启硬件直通。在BIOS开启vt-d,AMD平台是iommu,并且开启SRIOVAbove 4G选项

Intel CPU

使用nano命令编辑grub
nano /etc/default/grub

# 开启iommu分组,在里面找到:GRUB_CMDLINE_LINUX_DEFAULT="quiet"项将其修改为
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt pcie_acs_override=downstream,multifunction"
# 更新grub
update-grub

加载内核模块

加载内核模块,使用nano命令加入以下信息
nano /etc/modules

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

屏蔽设备

添加设备黑名单,编辑pve-blacklist.conf
nano /etc/modprobe.d/pve-blacklist.conf

# 直通AMD显卡,请使用下面命令
blacklist radeon
blacklist amdgpu 
# 直通NVIDIA显卡,请使用下面命令
blacklist nouveau
blacklist nvidia
blacklist nvidiafb
# 直通INTEL核显,请使用下面命令
blacklist i915
blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
# 允许不安全的设备中断
options vfio_iommu_type1 allow_unsafe_interrupts=1

执行更新initramfs

# 更新initramfs
update-initramfs -u -k all
# 重启
reboot

验证是否开启直通

# 验证是否开启iommu
dmesg | grep iommu
或者
dmesg | grep -e DMAR -e IOMMU -e AMD-Vi

出现如下例子。则代表成功

[ 1.341100] pci 0000:00:00.0: Adding to iommu group 0
[ 1.341116] pci 0000:00:01.0: Adding to iommu group 1
[ 1.341126] pci 0000:00:02.0: Adding to iommu group 2
[ 1.341137] pci 0000:00:14.0: Adding to iommu group 3
[ 1.341146] pci 0000:00:17.0: Adding to iommu group 4

此时输入命令

find /sys/kernel/iommu_groups/ -type l 
#出现很多直通组,就代表成功了。如果没有任何东西,就是没有开启
lsmod | grep vfio
# 检测模块是否加载
vfio_pci               16384  4
vfio_pci_core          94208  1 vfio_pci
vfio_iommu_type1       49152  2
vfio                   57344  17 vfio_pci_core,vfio_iommu_type1,vfio_pci
iommufd                73728  1 vfio
irqbypass              16384  41 vfio_pci_core,kvm
#出现这类信息,就代表成功了。

配置VGPU_Unlock

# 创建vgpu_unlock文件夹
mkdir /etc/vgpu_unlock
# 创建profile_override.toml文件
touch /etc/vgpu_unlock/profile_override.toml
# 创建nvidia-vgpud.service.d,nvidia-vgpu-mgr.service.d启动服务
mkdir /etc/systemd/system/{nvidia-vgpud.service.d,nvidia-vgpu-mgr.service.d}
# 写入路径信息
echo -e "[Service]\nEnvironment=LD_PRELOAD=/opt/vgpu_unlock-rs/target/release/libvgpu_unlock_rs.so" > /etc/systemd/system/nvidia-vgpud.service.d/vgpu_unlock.conf
echo -e "[Service]\nEnvironment=LD_PRELOAD=/opt/vgpu_unlock-rs/target/release/libvgpu_unlock_rs.so" > /etc/systemd/system/nvidia-vgpu-mgr.service.d/vgpu_unlock.conf
# 重新加载服务
systemctl daemon-reload

执行完成后,cat下查看服务配置是否与下边一致
cat /etc/systemd/system/{nvidia-vgpud.service.d,nvidia-vgpu-mgr.service.d}/*

[Service]
Environment=LD_PRELOAD=/opt/vgpu_unlock-rs/target/release/libvgpu_unlock_rs.so
[Service]
Environment=LD_PRELOAD=/opt/vgpu_unlock-rs/target/release/libvgpu_unlock_rs.so

下载预编译好的libvgpu_unlock_rs.so文件

mkdir -p /opt/vgpu_unlock-rs/target/release
cd /opt/vgpu_unlock-rs/target/release
wget -O libvgpu_unlock_rs.so https://yangwenqing.com/files/pve/vgpu/vgpu_unlock/rust/libvgpu_unlock_rs_20230207_44d5bb3.so

安装VGPU驱动

安装显卡驱动需要用到的依赖

apt install build-essential dkms mdevctl pve-headers-$(uname -r)
# 下载显卡驱动
wget "https://yun.yangwenqing.com/ESXI_PVE/vGPU/NVIDIA/16.2/NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run"
# 赋予执行权限
chmod +x NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run
# 安装驱动(默认回车直至安装完成即可)
./NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run
# 重启
reboot

其他补充提示:

1) 如之前安装过了显卡驱动,则需要先卸载,再安装

# 卸载显卡驱动
./NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run --uninstall
# 移除显卡相关程序
sudo apt-get remove --purge nvidia-*
# 安装驱动(默认回车直至安装完成即可)
./NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run

2) 下载慢?试试aria2吧

# 在pve安装aria2
apt install aria2
# 4线程下载文件
aria2c -s 4 -x 4 -j 10 'https://yun.yangwenqing.com/ESXI_PVE/vGPU/NVIDIA/16.2/NVIDIA-Linux-x86_64-535.129.03-vgpu-kvm-patched.run'

重启完成后查看相关服务状态

# 查看相关服务状态
systemctl status {nvidia-vgpud.service,nvidia-vgpu-mgr.service}
# 重新启动相关服务
systemctl restart {nvidia-vgpud.service,nvidia-vgpu-mgr.service}
# 停止相关服务
systemctl stop {nvidia-vgpud.service,nvidia-vgpu-mgr.service}

查看相关服务状态
随后使用nvidia-smi
nvidia-smi
以及mdevctl types查看
mdevctl types

搭建fastapi-dls授权服务

NVIDIA VGPU并非免费产品,需要对VGPU驱动购买许可才能正常使用VGPU,这里我用fastapi-dls项目来取得90天的试用许可。你可以在内网或者外网部署好Docker环境,然后搭建fastapi-dls授权服务,我这里提供一个pve lxc的Docker容器,部署到内网进行授权。

# 进入pve备份文件夹
cd /var/lib/vz/dump/
# 使用wget命令下载lxc docker 容器备份包
wget https://yun.yangwenqing.com/ESXI_PVE/PVE/LXC/FASTAPI-DLS/vzdump_lxc_docker_root_123123.tar.zst
# 或者使用aria2c命令多线程下载lxc docker 容器备份包
aria2c -s 4 -x 4 -j 10 'https://yun.yangwenqing.com/ESXI_PVE/PVE/LXC/FASTAPI-DLS/vzdump_lxc_docker_root_123123.tar.zst'
# 重命名为vzdump-lxc-100-2023_11_14-15_docker.tar.zst
mv vzdump_lxc_docker_root_123123.tar.zst vzdump-lxc-100-2023_11_14-15_docker.tar.zst

LXC容器信息:

  • 默认IP地址:192.168.3.74
  • 账号:root
  • 密码:123123

1)将下载下来的LXC容器进行还原
还原LXC容器
2)并将原来的IP改为自己内网的IP,我这里用的就是3网段就不改了。
修改IP
3)登录LXC容器(账号:root密码:123123)并创建授权服务:
创建授权服务

# 删除旧的容器
docker rm af06b7705582
# 创建授权服务,注意下边的IP(192.168.3.74)改为刚刚自己修改好的
docker run --restart always -d -e DLS_URL=192.168.3.74 -e DLS_PORT=443 -p 443:443  makedie/fastapi-dls

把LXC容器设置开机自启

创建虚拟机(Win10为例)


创建win10虚拟机
勾选ROM-Bar和PCIE在Mdev类型中选择vgpu设备

其中 GRID P40-1Q 是 mdev 的名字,P40--显卡名,1--1G 显存,Q 代表 vWS
关于最后一位字母,如下
A = Virtual Applications (vApps)
B = Virtual Desktops (vPC)
C = AI/Machine Learning/Training (vCS or vWS)
Q = Virtual Workstations (vWS)(性能最佳)
在配置vgpu的时候,选择正确的型号型号即可。

资源下载

# Windows 10 Enterprise LTSC 2021 (x64) - DVD (Chinese-Simplified).ISO
https://yun.yangwenqing.com/Windows/MSDN/Windows_Desktop/Windows10/Windows%2010%20Enterprise%20LTSC%202021%20(x64)%20-%20DVD%20(Chinese-Simplified).ISO
# virtIO驱动
https://yun.yangwenqing.com/ESXI_PVE/PVE/Windows/VirtIO_Drivers/virtio-win-0.1.240.iso
# NVIDIA Guest驱动 537.70
https://yun.yangwenqing.com/ESXI_PVE/vGPU/NVIDIA/16.2/Guest_Drivers/537.70_grid_win10_win11_server2019_server2022_dch_64bit_international.exe

安装NVIDIA Guest驱动

创建好系统之后,在系统中开启远程功能。如远程桌面,todesk,vnc,向日葵,parsec等然后安装 NVIDIA Guest驱动
安装NVIDIA Guest驱动

启用授权

1)在浏览器访问fastapi-dls授权服务:https://192.168.3.74/-/client-token会自动下载好授权文件
下载授权文件
2)下载后放入C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken\这个目录下
将授权文件放到指定路径
3) 重启NVIDIA Display Container Ls服务,即可获得授权
也可以在cmd窗口使用nvidia-smi -q命令查看授权情况
如授权失败,需要检查电脑时间是否对得上授权服务器时间
重启服务
4)使用Todesk远程工具连接上虚拟机跑个鲁大师测试一下,显卡是否正常工作
鲁大师


想解除60帧?
编辑nano /etc/vgpu_unlock/profile_override.toml文件,加入以下信息关闭虚拟机重新开机生效。

[profile.nvidia-46]
num_displays = 1
display_width = 1920
display_height = 1080
max_pixels = 2073600
cuda_enabled = 1
frl_enabled = 0
framebuffer = 939524096

参数说明:
[profile.nvidia-46]nvidia-46 为vgpu型号的参数。如选的不是46则改成自己选的那个型号。
num_displays 最大显示器数量
display_width = 1920
display_height = 1080
max_pixels = 2073600 这3个是虚拟显示器的分辨率,max_pixels是长宽的乘积
cuda_enabled = 1是否开启cuda
frl_enabled = 0 是否限制帧数,0为不限制
framebuffer = 939524096 1GB显存,设定vgpu的显存


突破60帧限制

自定义显卡显存大小
如要自定义修改显卡的显存大小,只需要修改framebuffer的值就好了,显存不建议低于1GB,官方说低于1GB将会禁用NVENC视频编解码器
注意:vgpu会默认占用128M,所以如果要改显存,请将结果减去128M再去换算,旧版是减去64M
例如,你期望显存为1GB,所以就用1024M-64M=960M/1024M-128M=896M
在线大小换算平台:https://www.bejson.com/convert/filesize/
换算结果

5)在PVE后台查看是否调用成功
nvidia-smi

创建虚拟机(Ubuntu23.04为例)

Ubuntu23.04

资源下载

# ubuntu-23.04-desktop-amd64.iso
https://yun.yangwenqing.com/Linux/Ubuntu/ubuntu-23.04-desktop-amd64.iso
# NVIDIA Guest驱动 535.129
https://yun.yangwenqing.com/ESXI_PVE/vGPU/NVIDIA/16.2/Guest_Drivers/NVIDIA-Linux-x86_64-535.129.03-grid.run

1) 安装显卡驱动前先将需要的依赖文件打上

# 安装ssh工具,使用第三方SSH工具(putty,终端)连接到Ubuntu,PVE里面控制台无法复制命令
sudo apt-get install openssh-server
# 开机自启ssh
sudo systemctl enable ssh.service
# 重启ssh服务
sudo systemctl restart ssh.service
# 需要所需依赖
sudo apt install build-essential linux-headers-generic libglvnd-dev pkg-config -y
# 安装dkms
sudo apt install dkms -y
# 安装32位兼容库
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 -y

2)屏蔽自带的显卡驱动

# 创建blacklist-nouveau.conf文件
sudo nano /etc/modprobe.d/blacklist-nouveau.conf
# 在blacklist-nouveau.conf文件添加如下内容:
blacklist nouveau
options nouveau modeset=0
# 重载内核initramfs
sudo update-initramfs -u
# 重启Ubuntu
sudo reboot
# 重启完成后检查nouveau是否已禁用,没有任何输出说明已经禁用
lsmod | grep nouveau
# 切换到文本命令行控制台
sudo chvt 3
# 关闭图形界面服务
sudo service gdm stop

3)安装显卡驱动

# 使用aria2c命令多线程下载 NVIDIA Guest驱动 535.129
aria2c -s 4 -x 4 -j 10 'https://yun.yangwenqing.com/ESXI_PVE/vGPU/NVIDIA/16.2/Guest_Drivers/NVIDIA-Linux-x86_64-535.129.03-grid.run'
# 给可执行权限
chmod +x NVIDIA-Linux-x86_64-535.129.03-grid.run
# 安装驱动(默认回车直至安装完成即可)
./NVIDIA-Linux-x86_64-535.129.03-grid.run
# 安装完成重启Ubuntu
reboot

4)重启完成后,使用nvidia-smi验证

root@Ubuntu23:~# nvidia-smi
Tue Feb 20 16:22:12 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.129.03             Driver Version: 535.129.03   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  GRID P40-1Q                    On  | 00000000:01:00.0 Off |                  N/A |
| N/A   N/A    P8              N/A /  N/A |      7MiB /  1024MiB |      0%      Default |
|                                         |                      |             Disabled |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A       801      G   /usr/lib/xorg/Xorg                            6MiB |
+---------------------------------------------------------------------------------------+

启用授权

# 获取授权文件
wget --no-check-certificate -O /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok https://192.168.3.74/-/client-token
# 或者
curl --insecure -L -X GET https://192.168.3.74/-/client-token -o /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok

验证授权

# 重启服务
sudo service nvidia-gridd restart
# 验证授权获取情况
nvidia-smi -q | grep License
# 看到有Licensed字样,就授权好了。
root@Ubuntu23:~# nvidia-smi -q | grep License
    vGPU Software Licensed Product
        License Status                    : Licensed (Expiry: 2024-5-20 9:40:22 GMT)

PVE去虚拟化检测部分

做完以上VGPU部分,就可以正常使用VGPU加速。专业设计,云桌面,Al深度学习用户可以不用往下看了。市面上大部分游戏都不支持在虚拟机进行游戏,如你有游戏需求,则还需要对虚拟机做以下去虚拟化操作。

# 查看你当前安装的pve-qemu-kvm版本
dpkg -l|grep kvm
# 我这里是8.1.5-3
ii  pve-qemu-kvm                         8.1.5-3                             amd64        Full virtualization on x86 hardware

安装去虚拟化修改后的版本

# 如果你的版本是9.0.2-2,执行一下命令下载并安装
wget https://yun.yangwenqing.com/ESXI_PVE/PVE/PVE%E5%8E%BB%E8%99%9A%E6%8B%9F%E5%8C%96%E6%A3%80%E6%B5%8B/PVE8.2/pve-qemu-kvm_9.0.2-2_amd64_anti_detection20240818v1.0.deb
dpkg -i pve-qemu-kvm_9.0.2-2_amd64_anti_detection20240818v1.0.deb
# 如果你的版本是8.1.5-3,执行一下命令下载并安装
wget https://yun.yangwenqing.com/ESXI_PVE/PVE/PVE%E5%8E%BB%E8%99%9A%E6%8B%9F%E5%8C%96%E6%A3%80%E6%B5%8B/PVE7.0-8.1/pve-qemu-kvm_8.1.5-3_amd64_anti_detection20240302.deb
dpkg -i pve-qemu-kvm_8.1.5-3_amd64_anti_detection20240302.deb
# 如果你的版本是7.2.0-8,执行一下命令下载并安装
wget https://yun.yangwenqing.com/ESXI_PVE/PVE/PVE%E5%8E%BB%E8%99%9A%E6%8B%9F%E5%8C%96%E6%A3%80%E6%B5%8B/PVE7.0-8.1/pve-qemu-kvm_7.2.0-8_amd64_anti_detection20230901.deb
dpkg -i pve-qemu-kvm_7.2.0-8_amd64_anti_detection20230901.deb 

Intel核显直通,在虚拟机配置文件加入以下参数
nano /etc/pve/qemu-server/虚拟机ID.conf

args: -set device.hostpci0.addr=02.0 -set device.hostpci0.x-igd-gms=0x2 -set device.hostpci0.x-igd-opregion=on -cpu host,hypervisor=off,vmware-cpuid-freq=false,enforce=false,host-phys-bits=true -smbios type=0,vendor="American Megatrends International LLC.",version=H3.7G,date='02/21/2023',release=3.7 -smbios type=1,manufacturer="Maxsun",product="MS-Terminator B760M",version="VER:H3.7G(2022/11/29)",serial="Default string",sku="Default string",family="Default string" -smbios type=2,manufacturer="Maxsun",product="MS-Terminator B760M",version="VER:H3.7G(2022/11/29)",serial="Default string",asset="Default string",location="Default string" -smbios type=3,manufacturer="Default string",version="Default string",serial="Default string",asset="Default string",sku="Default string" -smbios type=17,loc_pfx="Controller0-ChannelA-DIMM",manufacturer="KINGSTON",speed=3200,serial=DF1EC466,part="SED3200U1888S",bank="BANK 0",asset="9876543210" -smbios type=4,sock_pfx="LGA1700",manufacturer="Intel(R) Corporation",version="12th Gen Intel(R) Core(TM) i7-12700",max-speed=4900,current-speed=3800,serial="To Be Filled By O.E.M.",asset="To Be Filled By O.E.M.",part="To Be Filled By O.E.M." -smbios type=8,internal_reference="CPU FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=8,internal_reference="J3C1 - GMCH FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=8,internal_reference="J2F1 - LAI FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=11,value="Default string"

AMD核显直通,Intel、AMD、NVIDIA三家独显直通,在虚拟机配置文件加入以下参数
nano /etc/pve/qemu-server/虚拟机ID.conf

args: -cpu host,hypervisor=off,vmware-cpuid-freq=false,enforce=false,host-phys-bits=true -smbios type=0,vendor="American Megatrends International LLC.",version=H3.7G,date='02/21/2023',release=3.7 -smbios type=1,manufacturer="Maxsun",product="MS-Terminator B760M",version="VER:H3.7G(2022/11/29)",serial="Default string",sku="Default string",family="Default string" -smbios type=2,manufacturer="Maxsun",product="MS-Terminator B760M",version="VER:H3.7G(2022/11/29)",serial="Default string",asset="Default string",location="Default string" -smbios type=3,manufacturer="Default string",version="Default string",serial="Default string",asset="Default string",sku="Default string" -smbios type=17,loc_pfx="Controller0-ChannelA-DIMM",manufacturer="KINGSTON",speed=3200,serial=DF1EC466,part="SED3200U1888S",bank="BANK 0",asset="9876543210" -smbios type=4,sock_pfx="LGA1700",manufacturer="Intel(R) Corporation",version="12th Gen Intel(R) Core(TM) i7-12700",max-speed=4900,current-speed=3800,serial="To Be Filled By O.E.M.",asset="To Be Filled By O.E.M.",part="To Be Filled By O.E.M." -smbios type=8,internal_reference="CPU FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=8,internal_reference="J3C1 - GMCH FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=8,internal_reference="J2F1 - LAI FAN",external_reference="Not Specified",connector_type=0xFF,port_type=0xFF -smbios type=11,value="Default string" 

如要还原回原来的官方包pve-qemu-kvm可以到清华源去下载安装

# pve8到这个链接下载
https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/dists/bookworm/pve-no-subscription/binary-amd64/
# pve7到这个链接下载
https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/dists/bullseye/pve-no-subscription/binary-amd64/
# 下载名为pve-qemu-kvm_x.x.x-x_amd64.deb就是了。
pve-qemu-kvm_8.1.5-3_amd64.deb    27.0 MiB    2024-02-22 03:18
pve-qemu-kvm_8.1.5-4_amd64.deb    27.0 MiB    2024-03-12 22:52
pve-qemu-kvm_8.1.5-5_amd64.deb    27.0 MiB    2024-04-12 02:40
pve-qemu-kvm_8.1.5-6_amd64.deb    27.0 MiB    2024-04-29 22:50
pve-qemu-kvm_8.2.2-1_amd64.deb    28.1 MiB    2024-04-29 16:50

去除虚拟化后,大部分游戏其实已经可以正常玩了。[高级]点的游戏对虚拟机检测机制不好过,类似腾讯游戏有ACE这类检测机制就玩不了。
去除虚拟化后效果

相关文章参考

佛西博客-在Proxmox VE 7.1 中开启vGPU_unlock,实现显卡虚拟化
佛西博客-在Proxmox VE 7.4 中开启NVIDIA P106显卡虚拟化(vGPU)
B站李晓流-pve反虚拟化检测玩游戏

Last modification:November 15th, 2024 at 10:46 am
If you think my article is useful to you, please feel free to appreciate