Aug 30, 2016

How To Install And Configure Bumblebee In Ubuntu 16.04 (With Nvidia-361 Or Nvidia-370)

Bumblebee logo

The Bumblebee package available in the official Ubuntu 16.04 repositories needs a tweak to work with Nvidia 361 graphics drivers. Furthermore, if you want to use a newer Nvidia graphics drivers version, such as 370, the discrete card is not turned off, resulting in it being used all the time, and not just when running apps or games with "optirun", as it should.

So here's how to properly install and configure Bumblebee in Ubuntu 16.04, to get it to work with nvidia-361 and nvidia-370 (the latter from the Graphics Drivers PPA).

Bumblebee is a daemon for managing Optimus hybrid graphics chipsets. It allows running applications and games using the discrete GPU (on demand - e.g. using "optirun some-game").

Ubuntu already provides a way of switching between Intel and Nvidia GPUs, by using Nvidia Prime (with Nvidia Prime installed, you can select which GPU to use from Nvidia Settings > PRIME Profiles), but this sets the GPU for the whole desktop, and not just for specific applications and games. For instance, if you select Nvidia, the desktop and every application you run will use the Nvidia GPU.

For some (like me), using the whole desktop on the Nvidia GPU can cause excessive heating, making Bumblebee a better option for running games.

Install and configure Bumblebee in Ubuntu 16.04

Please read the whole article very carefully, and follow the instructions exactly as mentioned in this article. Misconfiguring Bumblebee can have results the desktop not loading, or the display manager not showing up, and you'll have to recover from this via TTY. So use this at your own risk and only if you know how to debug it and recover from any issues that may occur!

The instructions below assume you've already installed some Nvidia graphics drivers (nvidia-361 or nvidia-370). 

I tested this on a Dell XPS L702x laptop running Ubuntu (w/ Unity) 16.04, with nvidia-361 from the official repositories (and Bumblebee from the official repositories), and with nvidia-370 from the Graphics Drivers PPA (with Bumblebee from the Bumblebee Development PPA).

1. Install Nvidia Prime and set it to "intel"

In my test under Ubuntu 16.04, not having Nvidia Prime installed and set to "intel" results in an xorg.conf file being created under /etc/X11/ upon each reboot (or LightDM restart), which causes a black login screen.

To install nvidia-prime and set it to use the Intel graphics card, use the following commands:
sudo apt install nvidia-prime
sudo prime-select intel

Do not use Nvidia Settings to set the Prime PROFILES to Nvidia, because it will cause issues after a reboot (in my test, it causes a black login screen)!

2. Install Bumblebee

In my test, I needed to edit a configuration file to get Bumblebee from the official repositories to work with nvidia-361 drivers (step 3).

For nvidia-370 from the Graphics Drivers PPA however, the Nvidia graphics card wasn't turned off (this can be checked with "cat /proc/acpi/bbswitch" - it should say "off" when no app is using the Nvidia graphics card, e.g. if you didn't run any app or game using "optirun") and I was unable to find a workaround for this.

I did get it to work though, by installing Bumblebee from its development PPA. So to get Bumblebee to work properly with nvidia-370 in Ubuntu 16.04, you'll need to install Bumblebee from THIS PPA.

If you want to use Bumblebee with nvidia-361, install Bumblebee from the official Ubuntu 16.04 repositories:
sudo apt install bumblebee

To get Bumblebee to work with nvidia-370, install it from the Bumblebee Development PPA (read the PPA description before adding it!):
sudo add-apt-repository ppa:bumblebee/testing
sudo apt update
sudo apt install bumblebee

3. Blacklist the the Nvidia driver you're using by adding it to /etc/modprobe.d/bumblebee.conf (bit via AskUbuntu)

Open /etc/modprobe.d/bumblebee.conf with a text editor (as root) - I'll use Gedit below:
gksu gedit /etc/modprobe.d/bumblebee.conf
And at the end of the file, add the following:

- for nvidia-361 (assuming you've installed Bumblebee from the official repositories; the Bumblebee package in the Bumblebee Development PPA already has this):
# 361
blacklist nvidia-361
blacklist nvidia-361-updates
blacklist nvidia-experimental-361
- for nvidia-370 (from the Graphics Drivers PPA):
# 370
blacklist nvidia-370
blacklist nvidia-370-updates
blacklist nvidia-experimental-370
... and save the file.

Important: if later on you install some newer Nvidia graphics drivers (e.g. nvidia-371, nvidia-372, etc.), you'll need to add them to /etc/modprobe.d/bumblebee.conf, in the same way as explained above, but for the new driver version.

4. Configure Bumblebee

Open the Bumblebee configuration file with a text editor (as root) - I'll use Gedit for the command below:
gksu gedit /etc/bumblebee/bumblebee.conf
... and in this file, change the following options so they look like below:

- for nvidia-361:
  • Driver=nvidia
  • KernelDriver=nvidia-361
  • LibraryPath=/usr/lib/nvidia-361:/usr/lib32/nvidia-361
  • XorgModulePath=/usr/lib/nvidia-361/xorg,/usr/lib/xorg/modules

- for nvidia-370:
  • Driver=nvidia
  • KernelDriver=nvidia-370
  • LibraryPath=/usr/lib/nvidia-370:/usr/lib32/nvidia-370
  • XorgModulePath=/usr/lib/nvidia-370/xorg,/usr/lib/xorg/modules

... and save the file.

Important: just like step 2, if later on you install some newer Nvidia graphics drivers (e.g. nvidia-371, nvidia-372, etc.), you'll need to change all "nvidia-xxx" occurances in /etc/bumblebee/bumblebee.conf with the new driver.

5. Reboot

That's it. After rebooting, the "cat /proc/acpi/bbswitch" command should display "OFF" as ouput, meaning that the discrete card is turned off by default.

To try out Bumblebee, use "optirun some_app_or_game". To configure the Nvidia settings for Bumblebee, launch the settings using the following command:
optirun -b none /usr/bin/nvidia-settings  -c :8

I should also mention that if you later want to remove Bumblebee, make sure to purge it ("sudo apt purge bumblebee"), to make sure its configuration files are removed, or else you'll experience issues, like the Nvidia drivers remaining blacklisted.

If you encounter issues, see the DEBIAN.readme file (/usr/share/doc/bumblebee/README.Debian on Debian/Ubuntu systems with Bumblebee installed) which explains some possible solutions, as well as the Bumblebee wiki.

via Web Upd8 - Ubuntu / Linux blog