谈谈N卡驱动的安装
Tofloor
poster avatar
deepinuser17
deepin
2020-09-28 08:18
Author
本帖最后由 deepinuser17 于 2020-10-10 11:35 编辑

论坛里有不少用户遇到了N卡驱动安装的问题。 因为没有安装合适的N卡驱动版本而遇到黑屏,卡顿,锁死等问题。

N卡驱动安装是每个Linux发行版都面临的问题。 所以在安装,使用深度20时遇到同样的问题不奇怪。

用户遇到与N卡相关的问题,很多是因为缺少信息,不熟悉N驱动安装的注意事项而导致的。


N卡驱动分开源和闭源两类

开源N卡驱动的名称是nouveau. 官方网址是: https://nouveau.freedesktop.org/wiki/.

在安装Deepin时,如果不选N卡闭源驱动,初始安装的就是nouveau。 开源的nouveau已经可以比较好的支持很多N卡,但对最近几年上市的N卡支持比较差甚至不支持。
如果使用开源的N卡驱动,机器可以稳定工作,而且对图形性能要求不是很高,选择使用开源的N卡驱动是最佳方案。
  1. $ lsmod | grep nouveau
  2. nouveau                    1953792  12
  3. mxm_wmi                 16384  1 nouveau
  4. wmi                            32768  2 mxm_wmi,nouveau
  5. i2c_algo_bit               16384  2 nvidiafb,nouveau
  6. ttm                              106496  1 nouveau
  7. drm_kms_helper      184320  1 nouveau
  8. drm                             524288  9 drm_kms_helper,ttm,nouveau
  9. video                           49152  2 apple_gmux,nouveau
Copy the Code

闭源N卡驱动

闭源N卡驱动是由厂家NVIDIA提供的。 闭源N卡驱动有多个版本。 每个版本支持的N卡不同。 所以用户需要根据自己机器上的N卡型号,来选择合适的版本。 不然即使闭源N卡驱动安装了,也无法正常使用,甚至出现黑屏。

Deepin20发行版包括了三个版本的闭源N卡驱动, 440.100, 390.138, 340.107.  在安装Deepin20时,如果选择安装闭源N卡驱动,440.100版本将被安装。 如果440.100支持机器上的N卡,安装结束以后,机器显示会正常工作。 如果440.100不支持机器上的N卡,显示会出现问题。

如果机器上的N卡不兼容440.100, 最好的办法是不选择安装闭源N卡驱动,先安装使用开源N卡驱动。 登录机器以后,再安装390版或是340版。

确定N卡的型号有几种方法:
1. 查看机器的硬件配置说明
2. 如果有Windows运行,运行N卡管理器,查看。
3. 如果已经安装了Linux发行版(任何发行版包括深度Deepin), 运行以下命令:

$ lspci | egrep "VGA|3D"

范例:
  1. $ lspci | egrep "VGA|3D"
  2. 01:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 930M] (rev a2)
  3. 这个N卡的型号是 GeForce 930M

确定了N卡型号以后,再查看哪个闭源N卡驱动版支持这个N卡。
点击“SUPPORTED PRODUCTS"标签。 按照型号查看。 如果没有找到该型号,440.100则不支持。 不能用这个版本。

点击“SUPPORTED PRODUCTS"标签。 按照型号查看。 如果没有找到该型号,390.138则不支持。 不能用这个版本。

点击“SUPPORTED PRODUCTS"标签。 按照型号查看。 如果没有找到该型号,340.107则不支持。 不能用这个版本。


安装闭源N卡驱动

确定了应该安装的闭源N卡驱动版本以后,就可以安装正确的版本了。

为了方便安装所指定的闭源N卡驱动版本,我编写了一个简单的shell脚本:deepin_install_nvidia_driver.sh

这个脚本可以用来安装任何440, 390, 340中的任何一个版本,只需要提供版本号就可以了。无论目前机器上是否已经安装了闭源N卡驱动,这个脚本都可以安装指定的版本。如果指定的版本已经安装好,这个脚本不会再重新安装同一版本。

脚本deepin_install_nvidia_driver.sh内容:
#!/bin/bash

# Check if NVIDIA driver version number is provided
if [ ! $1 ]; then
echo -e "Usage: $0 \n"
echo -e "For example:\n"
echo -e "$0 390"
exit 1
fi

nvidia_version=$1

function install_current(){
apt install nvidia-driver xserver-xorg-video-nvidia nvidia-settings nvidia-smi
}

function install_legacy(){
apt install nvidia-legacy-${nvidia_version}xx-driver xserver-xorg-video-nvidia-legacy-${nvidia_version}xx nvidia-settings-legacy-${nvidia_version}xx nvidia-legacy-${nvidia_version}xx-
smi
}

case ${nvidia_version} in
440)
install_current
;;
340|390)
install_legacy
;;
*)
esac


脚本运行方法如下:

1. 从本贴粘贴复制,deepin_install_nvidia_driver.sh
2. 修改许可.
chmod +x deepin_install_nvidia_driver.sh
3. 安装所指定的N卡驱动版本.
sudo ./deepin_install_nvidia_driver.sh  

例如安装390版本:
sudo ./deepin_install_nvidia_driver.sh 390

4. 重启机器


卸载闭源N卡驱动

如果需要从闭源N卡驱动转回到开源N卡驱动,需要卸载安装闭源N卡驱动时所安装的软件包。运行脚本deepin_remove_nvidia_driver.sh可以很方便的完成这个转换。

脚本deepin_remove_nvidia_driver.sh内容:

#!/bin/bash

# This scrīpt removes NVIDIA driver
dpkg -l | grep nvidia | awk '{ print $2 }' | xargs apt -y remove
apt -y autoremove

# Install nouveau
apt -y install xserver-xorg-video-nouveau libdrm-nouveau2


1. 从本贴粘贴复制deepin_remove_nvidia_driver.sh
2. 设置可执行许可:
chmod +x deepin_remove_nvidia_driver.sh
3. 运行脚本卸载闭源N卡驱动,恢复开源N卡驱动\
sudo ./deepin_remove_nvidia_driver.sh
4. 重启机器
Reply Favorite View the author
All Replies
1 / 2
To page
zhangn1985
deepin
2020-09-28 16:02
#1
还是集显和Amd显卡开源支持好
Reply View the author
wzb
deepin
2020-09-28 16:34
#2
技术贴理应支持。
Reply View the author
renghaoa
deepin
2020-09-28 17:22
#3
9600gt显卡,340.107驱动安装报错,无论是源内还是手动run。在15.11下安装完全没问题。
Reply View the author
deepinuser17
deepin
2020-09-28 17:54
#4
https://bbs.deepin.org/post/203002
9600gt显卡,340.107驱动安装报错,无论是源内还是手动run。在15.11下安装完全没问题。 ...

上传出错信息?
Reply View the author
renghaoa
deepin
2020-09-29 22:37
#5

Done.                  
Loading new nvidia-legacy-340xx-340.107 DKMS files...
Building for 5.7.7-amd64-desktop
Building initial module for 5.7.7-amd64-desktop
Error! Bad return status for module build on kernel: 5.7.7-amd64-desktop (x86_64)
Consult /var/lib/dkms/nvidia-legacy-340xx/340.107/build/make.log for more information.
dpkg: 处理软件包 nvidia-legacy-340xx-kernel-dkms (--configure)时出错:
已安装 nvidia-legacy-340xx-kernel-dkms 软件包 post-installation 脚本 子进程返回错误状态 10
dpkg: 依赖关系问题使得 nvidia-legacy-340xx-driver 的配置工作不能继续:
nvidia-legacy-340xx-driver 依赖于 nvidia-legacy-340xx-kernel-dkms (= 340.107-4) | nvidia-legacy-340xx-kernel-340.107;然而:
  软件包 nvidia-legacy-340xx-kernel-dkms 尚未配置。
  未安装软件包 nvidia-legacy-340xx-kernel-340.107。
  软件包 nvidia-legacy-340xx-kernel-dkms 提供了 nvidia-legacy-340xx-kernel-340.107,但它尚未被配置。

dpkg: 处理软件包 nvidia-legacy-340xx-driver (--configure)时出错:
依赖关系问题 - 仍未被配置
在处理时有错误发生:
nvidia-legacy-340xx-kernel-dkms
nvidia-legacy-340xx-driver
E: Sub-process /usr/bin/dpkg returned an error code (1)
Reply View the author
nero28
deepin
2020-09-29 23:27
#6
其实我就想像ubuntu/linuxmint那样,选一下N卡的驱动,点应用.不知道这个要什么时候才能做到. ubuntu/linuxmint上就这一点最吸引我.
Reply View the author
Comments
jingle
2020-09-30 22:33
等设备管理器强大下
随便逛逛
deepin
2020-09-29 23:34
#7
https://bbs.deepin.org/post/203002
Done.                  
Loading new nvidia-legacy-340xx-340.107 DKMS files...
Building for 5.7.7- ...

常见问题
虽然apt-get是很智能的包管理器,但是不可避免的也会出现一些问题,因此本页面集中收集最为常见的错误与解决方法


问题一
终端出现:
    E:Sub-process /usr/bin/dpkg returned an error code (1)

解决方法,终端执行:
    cd /var/lib/dpkg
    sudo mv info info.bak
    sudo mkdir info
    sudo dpkg --configure -a
    sudo apt-get install -f
    sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info.bak
    sudo rm -rf /var/lib/dpkg/info
    sudo mv /var/lib/dpkg/info.bak /var/lib/dpkg/info


https://wiki.deepin.org/wiki/%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86


Reply View the author
renghaoa
deepin
2020-09-30 00:10
#8
https://bbs.deepin.org/post/203002
常见问题
虽然apt-get是很智能的包管理器,但是不可避免的也会出现一些问题,因此本页面集中收集最为常见的 ...

按照你的方法执行完命令后。
命令sudo dpkg --configure -a不报错了,但现在开源驱动和闭源驱动都不生效了。
Reply View the author
走钢丝
deepin
2020-09-30 00:13
#9
https://bbs.deepin.org/post/203002
按照你的方法执行完命令后。
命令sudo dpkg --configure -a不报错了,但现在开源驱动和闭源驱动都不生效 ...

这个只处理安装错误,对应的包你还需要再安装。
Reply View the author
renghaoa
deepin
2020-09-30 00:21
#10
https://bbs.deepin.org/post/203002
这个只处理安装错误,对应的包你还需要再安装。

sudo apt-get install  nvidia-legacy-340xx-driver
正在读取软件包列表... 完成
正在分析软件包的依赖关系树      
正在读取状态信息... 完成      
nvidia-legacy-340xx-driver 已经是最新版 (340.107-4)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

提示已经安装过了.
Reply View the author
随便逛逛
deepin
2020-09-30 00:39
#11
https://bbs.deepin.org/post/203002
sudo apt-get install  nvidia-legacy-340xx-driver
正在读取软件包列表... 完成
正在分析软件包的依赖关 ...

sudo apt update && sudo apt install nvidia-legacy-340xx-driver --reinstall
Reply View the author
mardou
deepin
2020-09-30 00:43
#12
无论如何我要给你点赞。介绍技术方面的帖子,就要这样逻辑清晰、步骤清晰、操作清晰地写出来,是一份好帖。
Reply View the author
jiage_-2020
deepin
2020-09-30 00:53
#13
支持一下
Reply View the author
renghaoa
deepin
2020-09-30 01:02
#14
https://bbs.deepin.org/post/203002
sudo apt update && sudo apt install nvidia-legacy-340xx-driver --reinstall

覆盖安装完后问题依旧
Reply View the author
lanyun7112
deepin
2020-09-30 01:12
#15
涨知识了,一直没搞的懂开源闭源啥意思,今天看到您的科普总算明白了,还知道怎么找了,我是用隔壁https://bbs.deepin.org/post/203022这个帖子搞 好的,他的是无脑安装
Reply View the author
180******16
deepin
2020-09-30 15:41
#16
我也是安装时选了闭源驱动结果安装后过不去系统,只有重装了一次
Reply View the author
deepinuser17
deepin
2020-09-30 21:23
#17
https://bbs.deepin.org/post/203002
Done.                  
Loading new nvidia-legacy-340xx-340.107 DKMS files...
Building for 5.7.7- ...

这个问题可重复。 试装了340, 出现同样的问题。 这个问题需要深度来帮助解决了。

  1. Building for 5.4.50-amd64-desktop
  2. Building initial module for 5.4.50-amd64-desktop
  3. Error! Bad return status for module build on kernel: 5.4.50-amd64-desktop (x86_64)
  4. Consult /var/lib/dkms/nvidia-legacy-340xx/340.107/build/make.log for more information.
  5. dpkg: error processing package nvidia-legacy-340xx-kernel-dkms (--configure):
  6. installed nvidia-legacy-340xx-kernel-dkms package post-installation script subprocess returned error exit status 10
  7. dpkg: dependency problems prevent configuration of nvidia-legacy-340xx-driver:
  8. nvidia-legacy-340xx-driver depends on nvidia-legacy-340xx-kernel-dkms (= 340.107-4) | nvidia-legacy-340xx-kernel-340.107; however:
  9.   Package nvidia-legacy-340xx-kernel-dkms is not configured yet.
  10.   Package nvidia-legacy-340xx-kernel-340.107 is not installed.
  11.   Package nvidia-legacy-340xx-kernel-dkms which provides nvidia-legacy-340xx-kernel-340.107 is not configured yet.

  12. dpkg: error processing package nvidia-legacy-340xx-driver (--configure):
  13. dependency problems - leaving unconfigured
  14. Processing triggers for glx-alternative-nvidia (1.2.0-1-1+eagle) ...
  15. Processing triggers for libc-bin (2.28.8.1-1+dde) ...
  16. Processing triggers for update-glx (1.2.0-1-1+eagle) ...
  17. Processing triggers for glx-alternative-nvidia (1.2.0-1-1+eagle) ...
  18. Processing triggers for libc-bin (2.28.8.1-1+dde) ...
  19. Processing triggers for initramfs-tools (0.133.3-1+eagle) ...
  20. update-initramfs: Generating /boot/initrd.img-5.4.50-amd64-desktop
  21. cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries
  22.     nor crypto modules. If that's on purpose, you may want to uninstall the
  23.     'cryptsetup-initramfs' package in order to disable the cryptsetup initramfs
  24.     integration and avoid this warning.
  25. setupcon is missing. Please install the 'console-setup' package.
  26. W: plymouth: The plugin label.so is missing, the selected theme might not work as expected.
  27. W: plymouth: You might want to install the plymouth-themes package to fix this.
  28. I: The initramfs will attempt to resume from /dev/sda3
  29. I: (UUID=e43680f1-f768-437f-9516-a4b344fca6cc)
  30. I: Set the RESUME variable to override this.
  31. Errors were encountered while processing:
  32. nvidia-legacy-340xx-kernel-dkms
  33. nvidia-legacy-340xx-driver
  34. E: Sub-process /usr/bin/dpkg returned an error code (1)
Copy the Code


390安装没有问题。
Reply View the author
deepin-mq
deepin
2020-09-30 22:22
#18
感谢分享,内容已推荐
Reply View the author
jingle
deepin
2020-09-30 22:30
#19
膜拜下。。
Reply View the author
nero28
deepin
2020-09-30 22:55
#20
https://bbs.deepin.org/post/203002
其实我就想像ubuntu/linuxmint那样,选一下N卡的驱动,点应用.不知道这个要什么时候才能做到. ubuntu/linuxmi ...

嗯嗯 一直在等,15.7的时候我电脑还是可以切换的,后面的就切换黑屏了.
所以我安装了个mint,搞个3系统.
Reply View the author
1 / 2
To page