Debian 9 安装 NVIDIA显卡驱动

我现在非常地庆幸,因为我正在用我的图形界面上的浏览器在写这篇文章。半个小时以前,我的图形界面无法启动,并且这种情况持续了大概一天时间,也就是我把NVIDIA driver安装在我的debian 9之后就无法启动。


本来我是要安装CUDA 8的。我采用runfile的方式来安装这个东西,经过几次安装,我才明白这个文件其实包括安装某版本的NVIDIA 驱动、CUDA8 toolkit和Samples(验证安装是否成功)。关于到哪里下载对应linux系统的runfile文件,可以参考这篇文章的第2步(注:这篇文章是关于debian8安装cuda8的,但是我感觉其中有些细节比较含糊,并且他没有我安装完之后出现的问题。什么问题?看下文。)这样之后,我的文件夹里就有一个cuda_8.0.61_375.26_linux.run文件,按照上面那篇文章,我已经blacklist nouveau了(nouveau是系统里原来的显卡驱动),我只要执行./cuda_8.0.61_375.26_linux.run或者 sh cuda_8.0.61_375.26_linux.run。这时候可能会出现一些问题:


1.执行命令之后,命令行一直停留在“Install xxx xxx ......”无法动弹的样子,我只能按ctrl c退出,我采用的方法是,到/tmp下把.X1024-lock这个文件给删掉。然后重新到runfile所在文件夹执行sh cuda_8.0.61_375.26_linux.run命令。


2.这次进行的顺利一些,然而没有安装成功,它只是给出一些比较有用的信息,大概的意思:是模块“nvidia-modeset”正在被使用,表示可能有x server正在运行......。按照上面的blacklist举一反三,我干脆把nvidia-modeset也加进黑名单。


3.我又reboot重启计算机。从前面我们又知道,在安装nvidia驱动时,X window需要关闭,所以就不要登录图形界面了,ctrl+alt+Fn打开一个tty,root登录进去操作,注意重启之后/tmp下又有一个.X1024-lock,这可能是因为系统默认是要启动图形界面,继续删除。再用命令init 3关闭X,可以ctrl+alt+F1看看,原来的图形界面是不是关闭了。然后还是来到runfile文件所在目录,执行sh cuda_8.0.61_375.26_linux.run。


4.这次有不行了。有一个warning导致安装过程终止。大概的意思是,我的/etc/modrpobe.d目录下有两个文件同时禁止了nouveau,然后blabla,我无语,这算什么问题啊。我赶紧cd过去看看,这有两个.conf文件,都是黑名单,不过名字不同,一个就是我命名的blacklist.conf,另一个名字很长,类似nvidia-installer-nouveau-blacklist.conf,看名字就知道这是就是那个安装文件自动生成的黑名单,里面就禁止了nouveau。这样的话,我只要把我的blacklist.conf里面的noveau删掉,其他不懂就行了,我也是这么做的。


5.好,再重启吧。然后仍然要关掉X,删掉lock文件(这个关于X的过程可能可以通过系统配置来避免每次开机都要这么做,但是我不知道)。来到runfile文件所在目录,执行sh cuda_8.0.61_375.26_linux.run。这次又失败了。新的问题是(我写这个的时候过去很久了,有点遗忘了,只能记得个大概,由于只有一台电脑,只能用手机边上网查问题,幸好我保存查道的网页以及当时某度的问题):跟InstallUtils有关,我上网查的问题是,"install the InstallUtils module",出来就有一篇“Can't locate InstallUtils.pm in @INC-NVIDIA Developer Forums”根据里面的回复,我执行了如下的步骤:

1)unpack .run file ./cuda*.run --tar mxvf

//就是去runfile那个文件夹把那个runfile解压
2)copy InstallUtils.pm to /usr/lib/x86_64-linux-gnu/perl-base 

//把这个文件复制到所指的文件夹那里去,用cp命令,我当时用mv,都没什么。
3)export $PERL5LIB

//最后这部我有点疑惑,不知道干什么,输出什么东西我也忘了。


6.不过这么干之后,确实有惊喜啊,就像上面那个论坛几个小哥在那里喊他的天。重启有又执行了该做的步骤之后,再次执行sh cuda_8.0.61_375.26_linux.run。最后成功安装了。上个图证明下,三项全是Installed啊。

Debian 9 安装 NVIDIA显卡驱动


然而,好景不长,待我重启电脑之后,新问题就来了,也就是无法进入图形界面。无论如何,之前的那些步骤确实是可以安装好NVIDIA驱动的。以上那些步骤并不是按照实际发生的顺序写的,因为一个问题有可能重复出现,时间也是跨越了一个星期。这里只是提出来,可以做为参考。请谨慎行事。在此声明:本人水平有限,若由于参考以上操作而造成的任何损失,本人概不负责。


现在就尴尬了,装好驱动之后竟然不能登陆桌面,就在这之后一天的时间里面十几个小时,我也不知道经历了什么,我改动了一些东西,然后现在图形界面又可以启动了,就是留下了一些后遗症或者隐患。这也提醒了我,应该建立良好的操作规范,我联想到linux系统的开发维护人员应该都是这样的吧,不然事后追索自己的操作者的有点麻烦。


不过从过去的点滴中还是可以找到一些线索,这里提出来,以供参考。我最后是卸载了NVIDIA驱动,从网上得到的一些资料,我刚开始以为跟/etc/X11/xorg.conf文件有关,频繁的改变里面的参数,其实就是关于驱动的几个参数,不是改为nouveau就是nvidia,但都不凑效。我还把lightdm给卸载了,这个display manager,因为,我使用systemctl status lightdm.service查看,它老是有问题,剩下gdm,所以default-display-manager就是它,但是还是不行。经过一番挣扎,我就卸载了nvidia驱动。改回nouveau之后,结果还是依旧,相当沮丧。我因此还重装过nouveau。最后我在这篇问答里面找到了灵感:里面提到nouveau和nvidia分别是根据不同的配置文件来配置的,而我一直误以为这两个驱动都是按照/etc/X11/xorg.conf文件来配置的。原文如下:

But going back and forth can mess things up so sometimes make sure:

1)Ubuntu nouveau uses ~/.config/monitors.xml If nvidia is enabled instead, make sure to name this .bak so it's not used
2)Nividia uses xorg.conf If nouveau/stock driver is used name this .bak
Otherwise things might boot to hung shell. Sometimes nvidia screws up xorg.conf itself (pre 11.10) and the file should be deleted.


不过,该注意的是我没有找到 ~/.config/monitors.xml 文件,这篇文章也是好几年前了,而些说的是Ubuntu。不过我还是做了尝试,将xorg.conf备份后(xorg.conf.backup)删除,再重启。这次就好了,熟悉的图形界面,不过奇怪的是我卸载了lightdm呀改成gdm,但是感觉没什么两样。我把删除xorg.conf之前的那一次系统重启的Xorg.0.log贴上:

[  1241.302] 
X.Org X Server 1.19.2
Release Date: 2017-03-02
[  1241.303] X Protocol Version 11, Revision 0
[  1241.304] Build Operating System: Linux 4.9.0-3-amd64 x86_64 Debian
[  1241.304] Current Operating System: Linux bread 4.9.0-3-amd64 #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06) x86_64
[  1241.304] Kernel command line: BOOT_IMAGE=/vmlinuz-4.9.0-3-amd64 root=UUID=1b7e0add-5375-4ed4-ac5d-bc2c4cc95366 ro quiet
[  1241.305] Build Date: 07 July 2017  06:14:06AM
[  1241.306] xorg-server 2:1.19.2-1+deb9u1 (https://www.debian.org/support) 
[  1241.306] Current version of pixman: 0.34.0
[  1241.307] Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
[  1241.307] Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[  1241.309] (==) Log file: "/var/log/Xorg.0.log", Time: Sun Aug 27 18:01:05 2017
[  1241.310] (==) Using config file: "/etc/X11/xorg.conf"
[  1241.310] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
[  1241.311] (==) ServerLayout "Layout0"
[  1241.311] (**) |-->Screen "Screen0" (0)
[  1241.311] (**) |   |-->Monitor "Monitor0"
[  1241.311] (**) |   |-->Device "Device0"
[  1241.311] (**) |-->Input Device "Keyboard0"
[  1241.311] (**) |-->Input Device "Mouse0"
[  1241.311] (==) Automatically adding devices
[  1241.311] (==) Automatically enabling devices
[  1241.311] (==) Automatically adding GPU devices
[  1241.311] (==) Max clients allowed: 256, resource mask: 0x1fffff
[  1241.311] (WW) The directory "/usr/share/fonts/X11/cyrillic" does not exist.
[  1241.311] Entry deleted from font path.
[  1241.311] (==) FontPath set to:
/usr/share/fonts/X11/misc,
/usr/share/fonts/X11/100dpi/:unscaled,
/usr/share/fonts/X11/75dpi/:unscaled,
/usr/share/fonts/X11/Type1,
/usr/share/fonts/X11/100dpi,
/usr/share/fonts/X11/75dpi,
built-ins
[  1241.311] (==) ModulePath set to "/usr/lib/xorg/modules"
[  1241.311] (WW) Hotplugging is on, devices using drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.
[  1241.311] (WW) Disabling Keyboard0
[  1241.311] (WW) Disabling Mouse0
[  1241.311] (II) Loader magic: 0x5575f1d55e00
[  1241.311] (II) Module ABI versions:
[  1241.311] X.Org ANSI C Emulation: 0.4
[  1241.311] X.Org Video Driver: 23.0
[  1241.311] X.Org XInput driver : 24.1
[  1241.311] X.Org Server Extension : 10.0
[  1241.311] (--) using VT number 3


[  1241.311] (II) systemd-logind: logind integration requires -keeptty and -keeptty was not provided, disabling logind integration
[  1241.312] (II) xfree86: Adding drm device (/dev/dri/card0)
[  1241.312] (II) xfree86: Adding drm device (/dev/dri/card1)
[  1241.313] (--) PCI:*(0:0:2:0) 8086:0416:1025:0945 rev 6, Mem @ 0xd2000000/4194304, 0xc0000000/268435456, I/O @ 0x00005000/64, BIOS @ 0x????????/131072
[  1241.313] (--) PCI: (0:1:0:0) 10de:1299:1025:0945 rev 161, Mem @ 0xd0000000/16777216, 0xa0000000/268435456, 0xb0000000/33554432, I/O @ 0x00004000/128, BIOS @ 0x????????/524288
[  1241.313] (II) LoadModule: "glx"
[  1241.313] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so
[  1241.314] (II) Module glx: vendor="X.Org Foundation"
[  1241.314] compiled for 1.19.2, module version = 1.0.0
[  1241.314] ABI class: X.Org Server Extension, version 10.0
[  1241.314] (II) LoadModule: "nouveau"
[  1241.314] (II) Loading /usr/lib/xorg/modules/drivers/nouveau_drv.so
[  1241.314] (II) Module nouveau: vendor="X.Org Foundation"
[  1241.314] compiled for 1.19.3, module version = 1.0.13
[  1241.314] Module class: X.Org Video Driver
[  1241.314] ABI class: X.Org Video Driver, version 23.0
[  1241.314] (II) NOUVEAU driver Date:   Tue Sep 20 00:31:06 2016 -0400
[  1241.314] (II) NOUVEAU driver for NVIDIA chipset families :
[  1241.314] RIVA TNT        (NV04)
[  1241.314] RIVA TNT2       (NV05)
[  1241.314] GeForce 256     (NV10)
[  1241.314] GeForce 2       (NV11, NV15)
[  1241.314] GeForce 4MX     (NV17, NV18)
[  1241.314] GeForce 3       (NV20)
[  1241.314] GeForce 4Ti     (NV25, NV28)
[  1241.314] GeForce FX      (NV3x)
[  1241.314] GeForce 6       (NV4x)
[  1241.314] GeForce 7       (G7x)
[  1241.314] GeForce 8       (G8x)
[  1241.314] GeForce GTX 200 (NVA0)
[  1241.314] GeForce GTX 400 (NVC0)
[  1241.318] (II) [drm] nouveau interface version: 1.3.1
[  1241.318] (EE) No devices detected.
[  1241.318] (EE) 
Fatal server error:
[  1241.318] (EE) no screens found(EE) 
[  1241.318] (EE) 
Please consult the The X.Org Foundation support 
at http://wiki.x.org
 for help. 
[  1241.318] (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[  1241.318] (EE) 
[  1241.385] (EE) Server terminated with error (1). Closing log file.


这里面显示no divices detected,大概是找不到显卡吧。可以看到系统启动x窗口时,使用了那个文件“Using config file: "/etc/X11/xorg.conf"”


我之前提到的隐患是这样的,现在每次启动计算机,都会有如下错误信息:

[  705.646572] nouveau 0000:01:00.0: priv: HUB0: 084014 ffffffff (1870820d)
[  705.681480] nouveau 0000:01:00.0: priv: HUB0: 10ecc0 ffffffff (1a70822c)
[  705.760438] nouveau 0000:01:00.0: DRM: resuming client object trees...
[  710.799428] nouveau 0000:01:00.0: DRM: evicting buffers...
[  710.799430] nouveau 0000:01:00.0: DRM: waiting for kernel channels to go idle...
[  710.799453] nouveau 0000:01:00.0: DRM: suspending client object trees...
[  710.800804] nouveau 0000:01:00.0: DRM: suspending kernel object tree...

可以知道的是,如果在tty里面执行xinit,这个错误信息就会不间断的跳出来。

这个不知道怎么解决。