注意:kvm 虛擬機無法共享宿主機顯卡,即只有8塊顯卡,那么只能提供給8個虛擬機使用
環境准備
- 硬件: 支持虛擬化,已安裝kvm 平台
- 服務器顯卡類型:Tesla T4
- 虛擬機鏡像:ubuntu-16.04.4-desktop-amd64.iso
安裝kvm 虛擬機
- 創建虛擬機
shell>qemu-img create -f qcow2 /export/kvm-machines/dengqinwen-jiqifanyi/dengqinwen-jiqifanyi.qcow2 2048G
shell>virt-install --name dengqinwen-jiqifanyi-10.148.11.153 --boot network,hd,cdrom,menu=on --ram 131072 --vcpus=24 --os-variant=rhel6 --accelerate --cdrom=/export/iso/ubuntu-16.04.4-desktop-amd64.iso --disk path=/export/kvm-machines/dengqinwen-jiqifanyi/dengqinwen-jiqifanyi.qcow2,size=2048,bus=virtio --bridge=br0,model=virtio --autostart --vnc --vncport=5902 --vnclisten=0.0.0.0
- 透傳顯卡
shell>lspci -n |grep 10de
3d:00.0 0302: 10de:1eb8 (rev a1)
3e:00.0 0302: 10de:1eb8 (rev a1)
40:00.0 0302: 10de:1eb8 (rev a1)
41:00.0 0302: 10de:1eb8 (rev a1)
b1:00.0 0302: 10de:1eb8 (rev a1)
b2:00.0 0302: 10de:1eb8 (rev a1)
b4:00.0 0302: 10de:1eb8 (rev a1)
b5:00.0 0302: 10de:1eb8 (rev a1)
shell> virsh shutdown dengqinwen-jiqifanyi-10.148.11.153
shell> virsh edit dengqinwen-jiqifanyi-10.148.11.153
#選擇b1顯卡,增加以下內容
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0xb1' slot='0x00' function='0x0'/>
</source>
</hostdev>
shell>virsh start dengqinwen-jiqifanyi-10.148.11.153
- 安裝ubuntu 顯卡驅動
#下載驅動
shell>wget https://us.download.nvidia.com/XFree86/Linux-x86_64/470.94/NVIDIA-Linux-x86_64-470.94.run
#禁用nouveau,打開文件,在最后添加如下兩行
shell>vim /etc/modprobe.d/blacklist.conf
blacklist nouveau
options nouveau modeset=0
#更新系統修改
shell>update-initramfs -u
#重啟操作系統
shell>reboot
#驗證nouveau是否已禁用,如果沒有出現任何東西就是成功了。
shell>lsmod | grep nouveau
#關閉圖形界面,必須關閉
shell>service lightdm stop
#卸載系統中存在的驅動,默認有安裝的,一定要執行這個
shell>apt-get remove nvidia-*
#給文件權限
shell>chmod a+x NVIDIA-Linux-x86_64-470.86.run
#運行驅動文件,參考 https://www.cnblogs.com/lixinliang/p/14705315.html
shell>bash NVIDIA-Linux-x86_64-470.86.run
#安裝過程中出現的問題以及解決方法
1、he distribution-provided pre-install script failed! Are you sure you want to continue? 選擇 yes 繼續
2、Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? 選擇NO繼續
3、Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. 選擇 Yes 繼續
-
查看驅動是否安裝成功

-
安裝完成后重啟圖形界面
shell>service lightdm start
