宿主机系统:esxi6

虚拟机系统:ubuntu16.04

显卡型号:GTX1070

需求:使用esxi虚拟出一台机器,虚拟出来的这台机器使用宿主机的显卡

首先需要在esxi界面中设置显卡直通,设置方法为:

使用浏览器登录esxi的web界面,在主机——管理——硬件——PCI设备——找到GTX1070后勾选——点击 显卡直通——最后把宿主机(也就是物理机)重启,步骤如下图:

上图中PCI设备中的第一个GTX1070就是显卡,紧接着应该是GTX1070上带的声卡,那就都选中吧!

调整esxi虚拟机的配置:

右击虚拟机——编辑设置——添加其它设备——PCI设备——选择GTX1070后保存即可,如下图:

最后一张图中,预留所有内存,如果不点击此选项,添加PCI设备后启动电源可能遇到问题。

显卡添加后,在虚拟机中安装显卡驱动

虚拟机中操作

apt-get install software-properties-commonadd-apt-repository ppa:graphics-drivers/ppaapt-get install nvidia-367reboot

重启后执行命令:

nvidia-smi

报错:

Unable to determine the device handle for GPU 0000:0B:00.0: Unknown Error

解决:

宿主机中操作:

找到虚拟机的vmx文件,在其中添加内容

hypervisor.cpuid.v0 = "FALSE"

然后重启宿主机

[root@localhost:~] df -hFilesystem   Size   Used Available Use% Mounted onVMFS-5       3.8T  12.5G      3.8T   0% /vmfs/volumes/datastore1 (7)vfat       249.7M   8.0K    249.7M   0% /vmfs/volumes/70cb307a-40abe180-5fc5-9676290f20e8vfat         4.0G   6.4M      4.0G   0% /vmfs/volumes/59b7beaa-2fe55e21-1523-1866daf3f486vfat       249.7M 172.6M     77.1M  69% /vmfs/volumes/6b542e7d-36108b49-6650-c7db5e16a932vfat       285.8M 203.6M     82.2M  71% /vmfs/volumes/59b7be71-74239e59-f059-1866daf3f486[root@localhost:~] ls /vmfs/volumes/datastore1\ \(7\)/new/new.vmx/vmfs/volumes/datastore1 (7)/new/new.vmx[root@localhost:~] tail -2 /vmfs/volumes/datastore1\ \(7\)/new/new.vmxcleanShutdown = "FALSE"hypervisor.cpuid.v0 = "FALSE"[root@localhost:~] rebootesxi的reboot重启特别慢,可以手动重启,或者在浏览器中在电源选项中重新引导[root@localhost:~] shutdown.sh[root@localhost:~] reboot

参考:

 

另一个报错:

Unable to determine the device handle for GPU 0000:01:00.0: Unable to communicate with GPU because it is insufficiently powered.This may be because not all required external power cables areattached, or the attached cables are not seated properly.

解决:

显卡的电源线没插好

 

参考

This suggests that that the K40 is not properly connected to the power supply: Sorry, my stupid mistake. Now, i read the datasheet ...the reason for malfuction was the missing 8-pin ATX-Connector.I only connected two 6-pin connectors. Thanks to Nvidia,good papers. thanks to txbob.

esxi重启命令(暂时没试过,不过esxi中好像没有shutdown命令):

reboot -fhaltshutdown

参考: