Debian9 testing 发行版Nvidia驱动+Bumblebee控制显卡切换

转载自:https://www.pcsuggest.com/install-and-configure-nvidia-optimus-with-bumblebee-in-debian/

大致流程:
1.查看本机显卡
lspci -v | egrep -i 'vga|3d|nvidia' | grep -i 'nvidia'
结果:
03:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 840M] (rev ff) (prog-if ff)
Kernel modules: nvidia
2.加源
3.安装内核头和bbswitch(用来切换内核显卡)
4.双显卡要把nouveau加入黑名单否则可能黑屏
5.安装NVIDIA驱动和bumblebee(用来便捷切换显卡的程序)
6.安装VitualGL包(否则使用bumblebee启动显卡但是却没有提升效果)
7.bumblebee默认的配置就能使用,一般不用配置
8.optirun + 程序名 即可使用nvidia显卡打开程序

以防连接失效,搬一下源内容。

NVIDIA Optimus, the infamous switchable graphics adaptation for laptops/notebooks by NVIDIA, still doesn't fit well with Linux.

That's why most Linux users having a laptop with optimus GPU faces problems like hot GPU(around 65° C), decreased battery life, roaring cooler fan etc. etc.!

So if you are one of those lucky person with a optimus laptop and want to use your discrete GPU rather than turn off it totally, this tutorial is for you. This guide is specially for Debian and other directly Debian based distro like Kali Linux, LMDE etc.

For newbies, if you don't know what are these things, you may have a look at the bumblebee project . Bbswitch is the kernel module used to turn off and on the discrete nvidia GPU and non-free nvidia optimus linux drivers are the proprietary GPU drivers provided by nvidia.

Advantage of bumblebee over other solutions like nvidia prime is you can run one/many specific application using the discrete nvidia GPU without restarting the current X-session on the fly.

Analyze the system

First step is to know the system thoroughly, first check nvidia card.

<pre>lspci -v | egrep -i 'vga|3d|nvidia' | grep -i 'nvidia'</pre>

This should return something like bellow, which will give you a brief information about your nvidia GPU, some recent GPU shows them as 3D controllers.

<pre>01:00.0 VGA compatible controller: NVIDIA Corporation GF108M [GeForce GT 540M] (rev ff) (prog-if ff)</pre>

Now check the currently loaded nouveau (free nvidia driver) module and vga_switcheroo module,

<pre>lsmod | grep -i 'nouveau'</pre>

<pre>lsmod | grep -i 'vga_switcheroo'</pre>

Currently Debian loads them automatically if any discrete GPU is found.

Unload nouveau modules and install bbswitch

If your kernel is loaded with the nouveau and other related modules, its the time to unload them with the modprobe command.

<pre>sudo modprobe -r nouveau
sudo modprobe -r vga_switcheroo
</pre>

Lets install bbswitch and related components to compile it. Installing bbswitch with dkms will automatically compile proper kernel module after any future kernel update.

At this point, you must enable the main, contrib and non-free repository, to do so, put the line bellow in the /etc/apt/sources.list file

<pre>deb http://ftp.debian.org/debian/ stretch main contrib non-free</pre>

Change the word stretch according to your disto, like if you are using the Debian stable jessie, replace it with jessie . If you are not sure what I'm talking about, have a look at there and check out the sources.list portion.

<pre>sudo apt-get update</pre>

<pre>sudo apt-get install gcc make linux-headers-amd64</pre>

<pre>sudo apt-get install dkms bbswitch-dkms</pre>

This will take some time to download and install the packages and compile kernel modules. when the installation is complete, load the bbswitch module.

<pre>sudo modprobe bbswitch load_state=0</pre>

Testing: Now test the if the bbswitch is working properly or not.

<pre>cat /proc/acpi/bbswitch</pre>

This should return a line with the word OFF along with the PCI bus id the nvidia GPU, the PCI bus id could vary machine by machine.

Another way to check it run the command lspci -v | grep -i 'vga' | grep -i 'nvidia' (mentioned above, watch out the fancy quotes) and check the end of the result line, if the prog-if value is ff then the GPU is off, if the value is 00 then the GPU is on.

Blacklist the nouveau module

To avoid auto load of nouveau and related modules after every reboot, they should be blacklisted. Just create a file with your favorite text editor named nouveau-blacklist.conf under the /etc/modprobe.d/ folder and put this line blacklist nouveau inside it. It could also be done with a single line command.

<pre>su -c 'echo "blacklist nouveau" >> /etc/modprobe.d/nouveau-blacklist.conf'</pre>

Just enter the root password and you are done.

The bbswitch module is loaded automatically at every power up and turns off the discrete nvidia optimus GPU, no need to load it manually.

Install nvidia non-free drivers and bumblebee

Now we have to install the non-free nvidia drivers, bumblebee and some related extra packages.

<pre>sudo apt-get install nvidia-kernel-dkms nvidia-xconfig nvidia-settings</pre>

<pre>sudo apt-get install nvidia-vdpau-driver vdpau-va-driver mesa-utils</pre>

This will install non-free nvidia drivers, nvidia kernel driver, nvidia specific OpenGL library etc. and other dependencies. Now install bumblebee,

<pre>sudo apt-get install bumblebee-nvidia</pre>

Wait some time to let the installation process finish.

Install VirtualGL

VirtualGL is required for the the optirun command as a bridge, but unfortunately Debian repository do not have the VirtualGL package, so we have to download it. Go to VirtualGL sourceforge repository and download the suitable package for your system. i.e. if you are using Debian 64 bit, download the latest amd64 package. Now install it with dpkg.

<pre>sudo dpkg -i ~/Downloads/virtualgl_2.4.1_amd64.deb</pre>

Also don't forget to change the path according to where you download the file.

Configure nvidia optimus with bumblebee

Fortunately bumblebee works fine with it's default configuration. But if you want to make any change to the settings, edit the /etc/bumblebee/bumblebee.conf file as root with your favorite text editor and restart the bumblebee service with this command sudo service bumblebeed restart .

Accessing the discrete nvidia GPU needs root privilege, so have to add your system's username to the bumblebee group.

<pre>sudo usermod -aG bumblebee $USER</pre>

Now restart the bumblebee daemon with sudo service bumblebeed restart . Now you are done, reboot the system.

Optional: You may need to add some extra configuration to the xorg.conf.nvidia file to avoid mouse module related error.

Open the /etc/bumblebee/xorg.conf.nvidia file with your favorite text editor as root , then add the extra configuration there.

<pre>Section "Screen"
Identifier "Default Screen"
Device "DiscreteNvidia"
EndSection</pre>

Save the file and exit the text editor, and restart bumblebee daemon.

Testing switchable graphics capability

After rebooting the system, you're ready to test the sample glxgears program.

<pre>optirun -vv glxgears</pre>

glxgears nvidia optimus kali linux

There should be some delay (around 3-4 sec.) before starting glxgears, if it returns around or over 1000 FPS performance, that means NVIDIA optimus is working properly.

This step is almost identical to check nvidia driver on ubuntu.

For more information about optirun command, see the man page, man optirun ,and run optirun with different arguments, like

<pre>optirun -v -b virtualgl -c jpeg glxgears</pre>

A more detailed testing and benchmarking the NVIDIA GPU could be done with furmark , which returns more accurate result than this simple glxgears test.

Troubleshooting

I didn't faced any problem during installation and testing with Debian stretch, kernel 4.1.0-amd64, nvidia-340.67 driver.

Just don't forget to add the apt non-free repository, install VirtualGL and add your user name to the bumblebee group.

Sometimes you might need to add some different GRUB parameters to block the automatic loading of nouveau driver. More on the link below.

UPDATE: As some readers are facing problems with debian nvidia optimus , I'hv written another tutorial specially for troubleshooting, based on reader feedback. I hope this will be helpful, here is the tutorial > NVIDIA Optimus troubleshooting in Debain .

Best practice: If your laptop's BIOS or UEFI allow to completely disable discrete nvidia GPU, then disable it before installing the OS and re-enable it after the installation is finished. By doing this, you could avoid some troubles caused by the vga_switcheroo kernel module. ( I did this many time 🙂 )

Conclusion

So, that's it, how to setup nvidia optimus debian, this tutorial also useful for any Debian derivative like Kali Linux, or SolydXK.

Use your nvidia GPU for something useful, like GPU computing with CUDA, NVIDIA OpenCL, fast password cracking with pyrit and many other computing extensive applications.

If you faced any problem during the installation, just leave a comment, and don't forget to share it with your friends.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,445评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,889评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,047评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,760评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,745评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,638评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,011评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,669评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,923评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,655评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,740评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,406评论 4 320
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,995评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,961评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,023评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,483评论 2 342

推荐阅读更多精彩内容