kvm 虚拟机安装 ubuntu-16.04.4-desktop操作系统并安装显卡驱动

注意: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

posted @ 2022-01-24 15:01  lixinliang  阅读(889)  评论(0编辑  收藏  举报