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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
2019-01-24 centos 7.2下搭建vsftp 虚拟用户
2019-01-24 centos7.2下部署 python3
2019-01-24 centos7.2 下 部署单节点redis 3.2.5
2019-01-24 centos 7.2 下 nginx 1.14.1 安装部署