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卡驅動安裝教程。

本文未經許可可以轉載,但請在明顯的地方注明出處


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM