Saturday 29 October 2016

How To Install Nvidia Drivers for hybrid Intel/Nvidia GPU in Ubuntu 16.04 LTS

TL;DR - if you are having issues getting Nvidia drivers to work in Ubuntu, particularly in a hybrid graphics setup, then check the following:
  1. Secure Boot is disabled during installation if you have a UEFI BIOS.
  2. nomodeset is not set in /etc/default/grub
~

I, like many others before me, have endured the pure pain involved with trying to get a hybrid graphics setup working in Ubuntu. Having searched for a solution myself, it is clear that the system in question impacts the solution massively. Here's my setup and what I did to get it working:

Setup:
  • MSI GT70 2OC (UK edition)
  • CPU: Intel Core i7-4700MQ Processor
  • GPU: Nvidia Geforce GTX 770M/3GB GDDR5 (hybrid with Intel Embedded)
  • OS: Ubuntu 16.04 LTS (Xenial Xerus)

 1. Find out what graphics card you've got:

Pull up a terminal session by pressing CTRL+ALT+T and run the following command:

sudo lshw -numeric -C display

My output looks as follows:


2. Find the latest supported driver


Now head over to https://www.nvidia.co.uk/Download/index.aspx?lang=en-uk and find the latest supported driver for your card (its worth noting here that at the time of writing, the latest available driver from Nvidia was 370, and this may or may not work with my GTX770M. I may test this when I'm bored):

 Make a note of the driver version that is displayed, but don't download it:


Instead, we are going to pull this straight from the Linux graphic drivers team repository.

3. Install the driver and Nvidia Prime


In your terminal, first add the repository:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

Once successfully added, install the driver and Nvidia Prime (used to jump between integrated Intel Graphics, and dedicated Nvidia graphics).

sudo apt-get install nvidia-367 nvidia-prime

 Once completed, reboot your laptop. Now this is where the fun can begin, so make sure you can access this blog from somewhere other than the laptop you're working on!


Troubleshooting


If at this point you are chucked back to the login prompt or you hit a black screen, do the following:


Workaround:


Hit CTRL+ALT+F1 to get to command-line. Or if this doesn't work, hold shift whilst you power up your laptop to get to the GRUB, then go into recovery mode.
Run the following command to activate the Intel graphics card:

sudo prime-select intel

Reboot and your problem should go away, however this doesn't fix the issue with the Nvidia GPU.

If this doesn't work, pull the nvidia drivers completely by running

sudo apt-get purge nvidia*

Reboot and your device will use the working nouveau open source driver.

Things to check:

Secure Boot:

If you have a modern laptop with a UEFI style BIOS, it may have something called secure boot. You can find information out about secure boot here. Essentially, you want to disable secure boot in your BIOS and get the Nvidia drivers working prior to re-enabling it (or leave it disabled altogether, that call is yours). So:

Run the following command in terminal to remove the Nvidia drivers:

sudo apt-get purge nvidia*

  Reboot your laptop.
Disable secure boot in your BIOS
Following the instructions to install the Nvidia drivers.
Reboot and check if you can login find after running prime-select nvidia
If you can, re-enable secure boot in your BIOS if you wish.
Check that you can still login with prime-select nvidia working.

nomodeset

If Secure Boot isn't your problem, or disabling it didn't work above, then you may need to get google searching. There are reams of different solutions out there for different models of system. If you have been trying to get the nvidia drivers working prior to landing here, then before you do any more searching,I have one more suggestion for you to try:

Whilst searching for a resolution to this (which turned out to be secure boot), one solution was to set the nomodeset parameter. So what is nomodeset? The answer from this page is:

The newest kernels have moved the video mode setting into the kernel. So all the programming of the hardware specific clock rates and registers on the video card happen in the kernel rather than in the X driver when the X server starts.. This makes it possible to have high resolution nice looking splash (boot) screens and flicker free transitions from boot splash to login screen. Unfortunately, on some cards this doesn't work properly and you end up with a black screen. Adding the nomodeset parameter instructs the kernel to not load video drivers and use BIOS modes instead until X is loaded.

So where to check? And trust me, its worth a check as I was banging my head on my desk for two days trying to find this:

Launch terminal and run the following command to edit the grub file (you can replace nano with a text editor of your choice eg. gedit, vi):

sudo nano /etc/default/grub

My grub file looked like this:


I remember setting nomodeset during the early days of troubleshooting my Nvidia woes, before I had found the Secure Boot solution. But having this set, and configuring prime-select nvidia would give me a login loop, presumably because the kernel was unable to load the nvidia drivers.

So edit your grub file to remove nomodeset and save the grub file (in nano this is CTRL+O, Enter, CTRL+X).

Importantly, you must run the following command for the changes to take effect:

sudo update-grub

Run prime-select nvidia to force the nvidia gpu to be used, then reboot and you may have resolved your issues like me!!


Hopefully this fixes your issues and gets your Nvidia GPU working in Ubuntu, or at the very least points you in the right direction. Once working, a couple of things to remember:

prime-select query will show you the selected graphics card to use

prime-select will activate the selected graphics card following a reboot

Having used Windows on my GT70 for 4 or so years before, I got quite used to Nvidia automatically jumping between integrated and dedicated graphics. I'm not sure if Nvidia Prime can do this, but if you take a look at Nvidia X Server Settings application, you will see something called "Application Profiles". I have a hunch that these may allow certain applications to run using a specific GPU, so in theory you could run prime-select intel normally, then have the Nvidia card jump in when you launch a game. I don't know if this works, there is very little information regarding it but I may have a play with this in the future.

There is also a project called Bumblebee that was created before Prime was available for jumping between integrated and dedicated graphics. This may be worth a look into. 

No comments:

Post a Comment