Ubuntu – How to install sane graphics drivers for Nvidia Optimus hardware on *Ubuntu 16.04


Can we (please) build a community summary of how to install sane graphics drivers for Nvidia Optimus hardware on *Ubuntu 16.04?

I can see this becoming a recurring thing every few years.

Ubuntu 16.04 was released not too many months ago and I have bought a new hard disk and installed Kubuntu 16.04 on it. My laptop is something from a few years back with an intel something graphics driver on the CPU and an Nvidia GTX 670MX discrete card. (It's an optimus system.)

Now one used to get this working via some strange combination of bumblebee and nvidia drivers and editing text config files, etc, etc, you used to run primusrun/optirun executable_file and it (sort of, rather unconvincingly) worked. (Until a new update broke it again, or you wanted to use CUDA…)

See this question for additional context, and also see the questions linked there.

How do I "optimus" with Ubuntu 16.04?

It is my understanding that the new release of 16.04 does away with all the primusrun/optirun stuff, and we now have a seemlessly switching graphics solution which works "much more better" than before. (Or is this just totally wrong information and I completely misunderstood what I read online?)

So, I attempted to do a sudo apt-get install nvidia-361-updates which brought along with it nvidia-prime… I rebooted back into Kubuntu and everything seemed to be working! My graphics card started to get warm and the fan started rotating, which doesn't usually happen unless the card is "on and doing something to make it heat up". I couldn't test it any further but I assume it was rendering stuff for the desktop environment.

But, somewhile later my system just suddenly turns off. I reboot and suddenly I can't login anymore… Either the system freezes, logs out or turns off.

So I attempted to follow information in this question.

Which just made things worse. Now I can't even get to a login screen. After boot my screen stays black/blank. However I can still get to a tty window.

There are other questions here and here which describe similar issues but did not resolve the problem. (I found these after searching for ubuntu 16.04 graphics driver blank screen or something similar to this.)

What is the "right" way to do it.

I've done the classic thing of trying too many things "which might fix it", but since I don't fully understand in detail the exact effects of all the commands I'm running I've got myself into a hole and it's probably time to start again with a fresh install and get it right the first time.

So my question is, how do I "get it right"? I have an optimus laptop with an Nvidia GTX 670MX along side an Intel integrated graphics processor, what combination of drivers, ppa's and software should I install on *Ubuntu 16.04, and in what order to make my optimus hardware functional?

In addition, am I correct or incorrect in my earlier statement when I suggest that something fundamentally big has been done to improve hardware support for optimus systems in 16.04?

Best Answer

What I did

1: First I ran lspci | grep VGA to check which Nvidia graphics card/chipset my computer is using.

2: Then I went to the nvidia driver website to check which graphics driver version I should install for Linux x86_64.

3: I added the graphics drivers ppa to my system sudo apt-add-repository ppa:graphics-drivers/ppa

4: Then sudo apt-get update

5: Then sudo apt-get install nvidia-367 but you your system it will be a different driver version depending on your result from Step 2!

... will now reboot to check if it worked...

Did it work?

Probably. I can login, but I needed to change my dual screen configuration again. Now that's done it seems to work alright. If anyone has any suggestion as to how I can check the performance of my system please leave a comment.

Edit: glxgears reports 13000 FPS. Not sure what it would be without the Nvidia driver.

Update - No it doesn't work!

I have a rather irritating problem which has rendered my system unusable. When browsing files, sometimes when changing directory there is a ~1 second delay before the window updates - this makes it difficult to browse files on the system quickly.

In addition, when typing in the terminal, there is an occasional delay/lag which prevents one from running commands efficiently and quickly.

Hence my system is "unusable".

What I am trying now.

0: Fresh install of xubuntu 16.04. apt-get update / upgrade

1: sudo apt-get install intel-microcode

2: Reboot

3: sudo apt-add-repository ppa:/graphics-drivers/ppa

4: sudo apt-get install nvidia-364 (not 367)

Just checked and laptop BIOS appears to have secure boot disabled.

5: Reboot

6: glxgears -info | grep "GL_" reports that glxgears is now running using Nvidia card

7: glxinfo | grep "OpenGL version" Also suggests nvidia card is functioning.

8: ... will update if graphics problems resurface...

Updates: Noticed graphics problems when switching into/out of screensaver. This was quite annoying so ran sudo apt-get remove nvidia-*, rebooted, then sudo apt-get install nvidia-361... hopefully this driver will be better...

nvidia-361 appears to have the same problem of screen tearing when scrolling with the file manager, as did driver version nvidia-367.

Will try nvidia-361-updates... Not hopeful however.

361 still has problems with file manager scrolling and tearing... Going to try 352

I have noticed that attempting to install version 352 causes apt-get to try and install nvidia-361 as an additional package... Not sure what has caused this or if I just didn't notice before...

Tried nvidia 340... Crashed when I tried to login, so removed all nvidia packages. This appears to be the correct method, however none of these drivers seem to play nicely with my system.

I came back to this some weeks later

... and followed this guide: http://lenovolinux.blogspot.co.uk/2016/05/bumblebee-on-lenovo-t440p-nvidia-gt.html?m=1

I was getting an error with optirun but with the additional command sudo apt-get remove xserver-xorg-legacy it seemed to work, however performance doesn't seem to be as good as it used to be with 14.04!