NVIDIA GPU, Optimus Prime and Ubuntu 18.04 Woes

Amitosh Swain Mahapatra
2 min readMay 6, 2018

--

I’m not a great fan of NVIDIA — thanks to their never ending driver issues. But, unfortunately, I have to use them (for CUDA). And their Linux driver support has been the worst. And the open-source Nouveau has never ever worked for me.

While AMD is friendly enough to provide a deb and a rpm package, NVIDIA provides a self-extracting archive which has no respect for the system whatsoever. Thankfully, Fedora and Ubuntu have a version in their repos.

My daily driver is a Dell Inspiron 7567 which comes with a i7 7700HQ and a NVIDIA 1050Ti. It ran flawlessly with Fedora till 27 and Ubuntu till 17.10. It is actually certified to run Ubuntu 16.04.

Starting from 18.04, Ubuntu decided to change the way it was packaging NVIDIA drivers. Earlier, it used to pull “nvidia-prime” and “bbswitch-dkms” for Optimus laptops. Now they opt for a blacklisting approach than the regular “update-alternatives” using OpenGL Vendor Dispatch.

In the absence of “bbswitch”, Ubuntu tries to load “nouveau” to do the power saving magic — which never works and instead causes a big kernel oops. Oops!

And after 20 hours of banging the keyboard and endless power cycles, I finally found it! Eureka. This requires you to first install NVIDIA drivers.

  1. Disable “nvidia-fallback.service”, using “systemctl disable nvidia-fallback.service”
  2. The key is to blacklist “nouveau” and prevent it from loading. Do that GRUB, by adding “nouveau.blacklist=1”.
  3. For power-savings install “bbswitch-dkms” and add “bbswitch” to “/etc/modules”.

Detailed Instructions

Here is what you need to do:
Install NVIDIA drivers from ubuntu repos, with apt & ubuntu-drivers

sudo ubuntu-drivers autoinstall

After installing, disable the “nvidia-fallback” service:

sudo systemctl disable nvidia-fallback.service

Blacklist nouveau driver using GRUB config. In /etc/default/grub look for a line GRUB_CMDLINE_LINUX . Add nouveau.blacklist=1 into that parameter. If the line is not present add this line GRUB_CMDLINE_LINUX="nouveau.blacklist=1"

The third optional step is bbswitch (only for laptop users interested for power savings, if your system supports it.) Install “bbswitch-dkms”

sudo apt install bbswitch-dkms

Configure the system to load it by appending bbswitch in /etc/modules

To switch to Intel graphics run

sudo prime-select intel

To use NVIDIA (for external display etc)

sudo prime-select nvidia

And reboot to take effect

To disable the card on boot run

echo "options bbswitch load_state=0" | sudo tee /etc/modprobe.d/bbswitch.conf

Read more info about bbswitch here.

Reboot and that's it! It also allows me to use CUDA when needed. I don’t do any Linux gaming, so I disable the NVIDIA GPU using “prime-select” and “bbswitch”. This gives me around ~7 hours of battery for normal web stuff.

--

--