NVIDIA Optimus on Linux – ThinkPad W520 & Bumblebee

[Updated 2021-10-11, see below to solve issue upgrading kernel]

After my ThinkPad T400 bit the dust, it was time to upgrade/replace. As I have been doing more CAD work, and have been tempted to play with Blender, when I saw a ThinkPad W520 with integrated Nvidia Quadro 1000M for a good price, how could I resist.

However, this was not the smooth ride I was expecting – and the first time I’ve ever had such a bad experience with Debian.

TLDR: JUST INSTALL BUMBLEBEE AND LEGACY DRIVERS

Tales of woe below..

NVIDIA Optimus is an interesting piece of technology on laptops, whereby the graphics are run from the integrated Intel chip, with the discrete graphics card kicking in when required. Great for helping to manage battery life, whilst still having more grunt than the average laptop. On Windows, I hear this works quite smoothly, but the Linux implementations leave something to be desired – namely that it has to be called when starting a program instead of kicking in automagically. Either way, I enabled Optimus in my BIOS and started investigating.

After reading the Debian wiki, I saw that I could use PRIME offloading with the nouveau drivers, just by setting “DRI_PRIME=1” before the command. This had several drawbacks…

  • I had no control over the backlight with the nouveau drivers, so screen was full brightness at all times
  • Performance was terrible – supertuxkart ran noticeably worse with the discrete graphics!

While I do prefer open source where possible, I am not a die-hard purist, so I thought installing the official NVIDIA drivers would solve my problems. And it would be similarily easy to use, just setting some environment variables before launching the desired program.  So I installed “nvidia-legacy-390xx-driver” through apt. (If you are unsure what version of the nvidia driver to install, either check this handy list, install “nvidia-detect”)

This also had its own pros and cons – I now had control over my backlight, but it completely broke OpenGL support. Nothing would start if it required OpenGL, I just got the error:-

Xlib: extension "GLX" missing on display ":0".

This was obviously a total non-starter, so I investigated how to fix this but found nothing particularly helpful. Well, nothing that worked for me – most posts were from circa 2015 and the software stack has changed enough since then that their fixes didn’t work. So back to nouveau whilst I looked further.

Finally, I saw Bumblebee. This is a series of applications intended to manage the Optimus setup, and control power to the card etc. Following the Debian Wiki

sudo apt install bumblebee-nvidia primus

This also failed miserably during installation, as by standard it tries to install the nvidia-current drivers, which no longer support my old card. One simple change, was to install  the previously found legacy drivers at the same time.

sudo apt install bumblebee-nvidia primus nvidia-legacy-390xx-driver

This has worked like a charm! To use Bumblebee, all you need to do is run append optirun to the command, ie “optirun supertuxkart”, and the discrete graphics will render that application, passing it back to the Intel card to actually paint on the screen.

My backlight control was working again, supertuxkart looked beatiful, and I wasn’t wasting battery when I dind’t need to!

I wrote the below little script to quickly find out if the card is powered up, in case I am seeing battery drain I can see if that is a cause (or just to check it is functioning as expected)

#!/bin/bash
# Display current power state of graphics cards
# (using Bumblebee & bbswitch)

STATUS=$(cat /proc/acpi/bbswitch | grep -o -E "ON|OFF")
echo GRAPHICS CARD IS CURRENTLY POWERED $STATUS

Aside from my trips to the Debian Wiki, I did a lot of searching about the GLX issues with the Nvidia drivers, and the backlight issues with the nouveau driver.

Hopefully this post will save someone else some time if the are facing similar issues.

Update – Updating Kernel

I have now updated my laptop to Debian 11 Bullseye, and things still generally work! Although it has come to light that I cannot use external monitors, but that is an issue for another time.

The biggest issue that has come to light, is that the entire setup can break when upgrading the kernel. But, it is an easy fix – a simple rebuild of an DKMS modules gets things working fine again.

I “borrowed” the below script from dolphin oracle’s video over on YouTube, but running this after any kernel updates gets everything playing nicely again:-

#!/bin/bash
#
# Rebuild DKMS drivers (ie after kernel update breaks Optirun)

for i in $(dpkg-query -l | grep dkms | awk '{print $2}'); do
    sudo dpkg-reconfigure $i
done

As always, I hope this of help to somebody!

Picture is an edit of “bumble bee (also a jigsaw puzzle )” by uhuru1701,  and a photo of my new laptop

7 thoughts on “NVIDIA Optimus on Linux – ThinkPad W520 & Bumblebee”

  1. Greetings! This is my 1st comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading through your posts. Can you suggest any other blogs/websites/forums that deal with the same subjects? Appreciate it!

  2. Hi! Currently on hour 9 today of trying to make my W520 play nice with Optimus on Linux (Debian, Ubuntu MATE, and pop!os, with a previous attempt around a year ago of regular Ubuntu).
    There’s a Reddit thread where someone pointed me at your post here (actually your old domain), and I’m having some struggles that will be lengthy to go through in comment form. Would you mind either jumping on the Reddit thread if so inclined, or sending me an email for some back-and-forth? I certainly don’t expect your help and you’re not obligated to try, but I’d appreciate it because you’ve been down this road before and your post about this is recent. We may turn up useful information that could be added to your post. As a starter question, what distribution did you do this on? Thank you

    1. This is all on Debian Stable, and survived the upgrade to Bullseye. Happy to help, drop me an email with the contact form in this site and I’ll help if I can!

Leave a Reply to kishy Cancel reply

Your email address will not be published. Required fields are marked *