An (almost) authoritative guide to nvidia Prime and Bumblebee

This applies to Kubuntu 15.10 and almost certainly other Ubuntu derivatives. It may also help those on other distros to figure out where things are going wrong.

A couple of months ago, some upgrade or other hosed my Kubuntu install. Instead of the log-in screen, I was presented with a black screen (henceforth known as “the blank void of frustration”). I didn’t have time to fix it, so I simply junked everything to do with nvidia, Bumblebee and got on with what I needed to do. Now I have time to be sufficiently annoyed by it, I have set about fixing the blasted thing.

What I present here are the steps I went through to get nvidia PRIME and Bumblebee working in my T430. I suggest a lot of reboots here as not only does that force modules etc to get reloaded but it ensures we catch the blank void of frustration issue as early as possible. This is important as some nvidia/Bumblebee configs appear to work and then on the next restart, you end up looking at a blank void of frustration.

I suggest using the more stable nvidia-352 driver, but you could use any version that you prefer. The open source nouveau will work as well, just take care to alter the steps where relevant. I am also using the new graphics-drivers PPA. The Bumblebee project looks like it has stalled and this PPA allows access to newer versions of the modules.
You can skip the PPA install if using a PPA makes you worried, but you might find the the versions in your repros are not stable on modern kernels and you also have to keep in mind that some nvidia/kernel/DE versions don’t play nice, so you might end up needing the PPA anyway.

Preparation

Firstly, if the laptop has ever run Windows, then you need to boot back into Windows and ensure that all the nvidia settings are at full power. Settings like “Flight-mode” are not available in Linux (no, not even PowerMizer covers it) and as they survive a reboot, any changes made in Windows will affect Linux.

Getting nvidia working

This is simply a case of ensuring that any previous configs are completely removed from your system and then installing the relevant packages.

sudo apt-get purge .*nvidia.* bumblebee.* .*primus.*
sudo apt-get --purge autoremove
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get [dist-]upgrade
sudo apt install nvidia-352 nvidia-prime nvidia-settings

If you have created any nvidia-settings.rc files, delete them. Reboot

Check that everything is working. Run a few programs, maybe check an external monitor works etc.
Fire-up nvidia-settings and switch the PRIME profile to Intel.
Reboot (don’t just log-out like nvidia-settings suggests, see comments above)

Once you’ve logged back in, open nvidia-settings again and check it’s still on Intel. We now have the nvidia drivers and so on installed, but we’re running on Intel. The nvidia GPU will still be powered at this point, so you’re not going to get any battery saving benefits just yet. That all comes with Bumblebee.

Brinigng in Bumblebee

Next we need to install Bumblebee. This will give use the ability to run on Intel with the nvidia GPU powered off, but wake it up so we can run specific, graphically demanding programs on it.

sudo apt install bumblebee

Note: DO NOT install bumblebee-nvidia

Open bumblebee.conf in the text editor of your choice as root

sudo vi /etc/bumblebee/bumblebee.conf

On line 22 set the driver to nvidia and then replace all occurences of nvidia-current with nvidia-352. Save and close.

To avoid any auto-detect problems, find out where the nvidia card is:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09)
01:00.0 VGA compatible controller: NVIDIA Corporation GF108M [NVS 5400M] (rev ff)

Edit /etc/bumblebee/xorg.conf.nvidia by uncommenting line 19 and make sure the BusID matches the nvidia entry from above (it’s probably “PCI:01:00:0“)

sudo vi /etc/bumblebee/xorg.conf.nvidia

Now we need to make sure that the nvidia modules are correctly blacklisted by Bumblebee, when I initially tried nvidia-361 it would fail because the black list was missing. Once added it seemed to run OK.

sudo vi /etc/modprobe.d/bumblebee.conf

And make sure it contains a section for you chosen nvidia module; I had to add this:

# 358
blacklist nvidia-358
blacklist nvidia-358-updates
blacklist nvidia-experimental-358
# 361
blacklist nvidia-361
blacklist nvidia-361-updates
blacklist nvidia-experimental-361

Reboot

Testing

Base line (I got 222fps, 287fps and 287fps respectively):

vblank_mode=0 /opt/VirtualGL/bin/glxspheres64 -v
vblank_mode=0 optirun /opt/VirtualGL/bin/glxspheres64 -v
vblank_mode=0 primusrun /opt/VirtualGL/bin/glxspheres64 -v

Whilst this is mostly just to make sure that opti/primusrun work, you can see that the fps results show the limitations that can be encountered using an nvidia GPU this way.

You can also check that the nvidia card is on or off. This is the result when the above tests are not running.

cat /proc/acpi/bbswitch
0000:01:00.0 OFF

Finalising

When using the the discrete card, you might discover you need to tweak its settings. Open nvidia-settings. Nottice the problem? The card is not available because it’s running on Intel. You can try opti/primusrun nvidia-settings, but it won’t work, you’ll get something like this:

ERROR: nvidia-settings could not find the registry key file. This file should have been installed along with this driver at
       /usr/share/nvidia/nvidia-application-profiles-key-documentation. The application profiles will continue to work, but
       values cannot be prepopulated or validated, and will not be listed in the help text. Please see the README for possible
       values and descriptions.

To get access to the card, you need this incantation:

optirun -b none /usr/bin/nvidia-settings  -c :8

I suggest you add a second entry to your launcher that uses it. Second? Read on, intrepid explorer.

Using nvidia-prime and bumblebee at the same time

So we have nvidia-prime installed & Bumblebee; therefore we can use nvidia-prime when we want the full power of the nvidia card, even if it isn’t the most stable in this configuration. Open nvidia-settings using either launcher entry (see above) and set PRIME profiles to nvidia. Log-out and in; no need to reboot this time. Now test it (I got 445fps):

vblank_mode=0 /opt/VirtualGL/bin/glxspheres64 -v

Much faster this time and depending on *exactly* how you laptop is wired, external screens should now work. On my T430, this is how to get access to external monitors via the DsiplayPort; something that isn’t possible when running on Intel.  If you try to use opti/primusrun in this mode, you’ll get an error and that makes total sense as we’re running on nvidia:

vblank_mode=0 primusrun /opt/VirtualGL/bin/glxspheres64 -v
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  154 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  32
  Current serial number in output stream:  31

You can also switch back to using the Bumblebee way by launching the non-optimus nvidia-settings and going back to Intel.

WARNING: Whatever you do, DO NOT reboot with PRIME set to nvidia, always switch it back to Intel or you’ll get a blank void of frustration on your next boot. Having PRIME set to nvidia seems to cause X to segfault (see Error 3 below).

Upgrading

The next time you upgrade your nvidia package (e.g. to nvidia-361) remember to update /etc/bumblebee/bumblebee.conf as well and to check /etc/modprobe.d/bumblebee.conf, otherwise opti/primusrun will fail due to the Bumblebee daemon (bumblebeed) having failed to start correctly.

PRIME vs primusrun vs optirun

PRIME is the nvidia card permantly on and with everything running on it. There is none of the overhead encountered with opti/primusrun. This shouldn’t be seen as a knock against the Bumblebee Project, more as the direct result of business decisions taken by nvidia and the Linux Foundation trade association. The up-shot of these is that the graphics system can’t make use of the most efficient ways to move the frames around. Whilst PRIME may give the most performance, you ave the hassle of having to log out and in.

optirun creates a second instance of X and copies the framebuffer back, this is a slower and older method. It is still useful as some applications will not run with faster primusrun (e.g. nvidia-settings). If using Bumblebee, try primusrun first.

TODO

What I’d love to do is find a way to wrap launching of applications that need nvidia in such a way that they get a plain launch if I’m on prime, or launched via primusrun if I’m on Intel. There must be a way to query the PRIME settings, or the presence of Bumblebee, and then make a choice whether to do a plain launch of the program or to run it via opti/prmusrun. If I figure it out, I’ll add it here and if you know already; just let me know via the comments.

It would be nice if there was a way to auto-update /etc/bumblebee/bumblebee.conf as well. I guess some hacking with awk/sed could do that, but I guess it would be better if it was integrated into the a packaged somehow.

Issues

Error 1: primus: fatal: failed to connect to Bumblebee daemon: Permission denied

Make sure you are in the bumblebee group and if tnot, add yourself:

groups | grep bumblebee
sudo adduser $USER bumblebee

Logout and in, then try again

Error 2 #1: Blank void of frustration aka Boot to black screen

What normally happens is you get the usual splash screen, then instead of your login screen you get the blank void of frustration.
Have you checked that you have a blacklist entry for your nvidia module in etc/modprobe.d/bumblebee.conf? If not, do so a now, add it if missing and reboot.

Error 2 #2: Blank void of frustration aka Boot to black screenGet to a TTY (e.g. Ctrl-Alt-F1) and as the systemd GPU Manaer can get its knickers in a twist, try disabling it then reboot:

sudo systemctl mask gpu-manager.service

You can restore it later if you need to:

sudo systemctl unmask gpu-manager.service

Error 3: Blank void of frustration aka Boot to black screen after rebooting with PRIME set to nvidia

If you cat /var/log/Xorg.0.log, you’ll probably see a segfault. Unfortunately I have not found a CLI way to set the PRIME status back to Intel, all you can do is remove everything (first two lines of code above) and then reboot to get back to the desktop. You can quickly re-install all the packages with the following:

sudo apt install nvidia-352 nvidia-prime nvidia-settings bumblebee

Use nvidia-settings again and set PRIME back to Intel; and edit the Bumblebee config files. For some reason, a simply apt-get remove isn’t enough.

Resources

Leave a Reply