debian 9 双显卡安装NVIDIA显卡驱动

本文最后编辑日期为2018.09.08 晚8点半,因为之前写的内容不够准确,而且官方wiki又在今年8月更新了内容,所以这里对之前的内容进行大幅修改,仅保留正确可行的方法------N卡独显的安装!

2018.09.27 update ! this article just suitable debian-live iso , if you use 650M iso, you will get a error "can't load kernel modules". Please certain you iso image ,good luck!

 

 

1、打开终端,root登录,使用如下命令查看自己的显卡型号

$ lspci -nn | egrep -i "3d|display|vga"

2、记下Nvidia显卡的型号与最前边的编号,比如下边是我的输出,标红处为需要记下的,请参考

00:02.0 VGA compatible controller [0300]: Intel Corporation 3rd Gen Core processor Graphics Controller [8086:0166] (rev 09)
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107M [GeForce GT 645M] [10de:0fd9] (rev a1)

3、输入命令,查看,如果命令不存在请安装sudo apt-get install nvidia-detect

$ nvidia-detect

我的输出如下,重要处已标红:

Detected NVIDIA GPUs:
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GK107M [GeForce GT 645M] [10de:0fd9] (rev a1)

Checking card:  NVIDIA Corporation GK107M [GeForce GT 645M] (rev a1)
Your card is supported by all driver versions.
It is recommended to install the
    nvidia-driver
package.

如果你的输出和我的相同,那么之后的安装完全和本教程一致即可,否则需要指定驱动版本号

如果不相同则说明您的显卡不支持最新的驱动,需要指定版本,这里的驱动版本请参考https://wiki.debian.org/NvidiaGraphicsDrivers#Drivers

查到了结果请记住该版本号,之后安装会用到!

4、使用vim或gedit等文本操作工具修改源

gedit /etc/apt/sources.list

在最下边加入一行(如果有的话就不用添加了)

deb http://httpredir.debian.org/debian/ stretch main contrib non-free

5、保存并退出,更新源列表,安装必要信赖,如果在第三部与我的结果不同,请在标红处添加驱动版本号,相同请直接复制命令

# apt-get update
# apt-get install linux-headers-$(uname -r|sed 's/[^-]*-[^-]*-//')
# apt-get install -t stretch-backports nvidia-driver

安装进程中可能会有确认的界面,直接回车,如有冲突与请选择ok

6、安装完成,重启

reboot

7、此时正常的情况是可以进入桌面的,并且nouveau已经被之前的安装程序添加了禁用blacklist,此时N卡驱动并没有被DM(desktop manager)加载,这里我们几步配置以启用驱动

查看/etc/X11目录,查看有没有xorg.conf文件,没有则创建,添加如下代码

注意:BusID是我们之前在第2步记录的编号,但是有点区别,比如我的编号为01:00.0,那么我的BusID应为1:0:0

Section "Module"
    Load "modesetting"
EndSection

Section "Device"
     Identifier "nvidia"
     Driver "nvidia"
     BusID "1:0:0"
     Option "AllowEmptyInitialConfiguration"
EndSection

保存并退出

8、创建切换N卡脚本

# vim /usr/local/bin/switch_nvidia.sh

添加内容,红字部分为dpi,普通屏幕无需修改,高分辨率的请自行参考资料

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
xrandr --dpi 96

保存并退出,授予执行权限

# chmod +x /usr/local/bin/switch_nvidia.sh

9、根据DM (Desktop Manager)的类型选择配置文件进行修改,请自行选择

(1)LightDM

  打开/etc/lightdm/lightdm.conf

  搜索display-setup-script=,一般是第二个,去除前边的#号注释,修改为如下:

display-setup-script=/usr/local/bin/switch_nvidia.sh

  保存后,重启lightdm

# systemctl restart lightdm.service

  界面会自动重启,重启之后驱动已经安装完毕

(2)SDDM

  打开/usr/share/sddm/scripts/Xsetup

  在文件最后添加并保存退出

/usr/local/bin/switch_nvidia.sh

  重启SDDM

# systemctl restart sddm

(3)SDM

  分别创建两个相同内容,但不同名的快捷方式(.desktop文件)

  /usr/share/gdm/greeter/autostart/optimus.desktop/etc/xdg/autostart/optimus.desktop

  内容如下:

[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer

  保存并退出,重启SDM

# systemctl restart gdm3.service

10、检查驱动是否正常加载

glxinfo | grep rendering  

输出为yes即正常,我的输出如下:

$ glxinfo | grep rendering  
direct rendering: Yes
    GL_NV_path_rendering, GL_NV_pixel_data_range, GL_NV_point_sprite, 
    GL_NV_path_rendering, GL_NV_pixel_data_range, GL_NV_point_sprite, 
    GL_NV_packed_float_linear, GL_NV_path_rendering,

如果出现miss之类的输出,请检查第8步和第9步是否正确

除了这个方法验证,还有NVIDIA X Server Settings 程序是否如下显示而不是只打开的时候出现未加载提示并只显示两行

 

以上就是我综合了多篇wiki加上个人实践带给大家的N卡驱动安装教程。

本文未经许可可以转载,但请在明显的地方注明出处

posted @ 2017-11-20 12:53  东北小狐狸  阅读(16294)  评论(0编辑  收藏  举报