nVidia Optimus Switchable/Bumblebee Driver Debian Installation

NVIDIA Optimus, the infamous switchable graphics adaptation for laptops/notebooks by NVIDIA, still doesn’t fit well with Linux.

That’s why most Linux users having a laptop with optimus GPU faces problems like hot GPU(around 65° C), decreased battery life, roaring cooler fan etc. etc.nvidia optimus debianSo if you are one of those lucky person with a  optimus laptop and want to use your discrete GPU rather than turn off it totally, this tutorial is for you. This guide is specially for Debianand other directly Debian based distro like Kali LinuxLMDE etc.

Here we are going to do this with bumblebeebbswitch, and non-free debian nvidia optimus drivers.

For newbies, if you don’t know what are these things, you may have a look at the bumblebee project . Bbswitch is the kernel module used to turn off and on the discrete nvidia GPU and non-free nvidia optimus linux drivers are the proprietary GPU drivers provided by nvidia.

Advantage of bumblebee over other solutions like nvidia prime is you can run one/many specific application using the discrete nvidia GPU without restarting the current X-session on the fly.

Analyze the system

First step is to know the system thoroughly, first check nvidia card.

lspci -v | egrep -i 'vga|3d|nvidia' | grep -i 'nvidia'

This should return something like bellow, which will give you a brief information about your nvidia GPU, some recent GPU shows them as 3D controllers.

01:00.0 VGA compatible controller: NVIDIA Corporation GF108M [GeForce GT 540M] (rev ff) (prog-if ff)

Now check the currently loaded nouveau (free nvidia driver) module and vga_switcheroomodule,

lsmod | grep -i 'nouveau'
lsmod | grep -i 'vga_switcheroo'

Currently Debian loads them automatically if any discrete GPU is found.

Unload nouveau modules and install bbswitch

If your kernel is loaded with the nouveau and other related modules, its the time to unload them with the modprobe command.

sudo modprobe -r nouveau
sudo modprobe -r vga_switcheroo

Lets install bbswitch and related components to compile it. Installing bbswitch with dkms will automatically compile proper kernel module after any future kernel update.

At this point, you must enable the maincontrib and non-free repository, to do so, put the line bellow in the /etc/apt/sources.list file

deb http://ftp.debian.org/debian/ stretch main contrib non-free

Change the word stretch according to your disto, like if you are using the Debian stable jessie, replace it with jessie . If you are not sure what I’m talking about, have a look at there and check out the sources.list portion.

sudo apt-get update
sudo apt-get install gcc make linux-headers-amd64
sudo apt-get install dkms bbswitch-dkms

This will take some time to download and install the packages and compile kernel modules. when the installation is complete, load the bbswitch module.

sudo modprobe bbswitch load_state=0

Testing: Now test the if the bbswitch is working properly or not.

cat /proc/acpi/bbswitch

This should return a line with the word OFF along with the PCI bus id the nvidia GPU, the PCI bus id could vary machine by machine.

Another way to check it run the command lspci -v | grepĀ  -i 'vga' | grep -i 'nvidia'(mentioned above, watch out the fancy quotes) and check the end of the result line, if the prog-if value is ff  then the GPU is off, if the value is 00 then the GPU is on.

Blacklist the nouveau module

To avoid auto load of nouveau and related modules after every reboot, they should be blacklisted. Just create a file with your favorite text editor named nouveau-blacklist.confunder the /etc/modprobe.d/ folder and put this line blacklist nouveau inside it. It could also be done with a single line command.

su -c 'echo "blacklist nouveau" >> /etc/modprobe.d/nouveau-blacklist.conf'

Just enter the root password and you are done.

The bbswitch module is loaded automatically at every power up and turns off the discrete nvidia optimus GPU, no need to load it manually.

Install nvidia non-free drivers and bumblebee

Now we have to install the non-free nvidia drivers, bumblebee and some related extra packages.

sudo apt-get install nvidia-kernel-dkms nvidia-xconfig nvidia-settings
sudo apt-get install nvidia-vdpau-driver vdpau-va-driver mesa-utils

This will install non-free nvidia drivers, nvidia kernel driver, nvidia specific OpenGL library etc. and other dependencies. Now install bumblebee,

sudo apt-get install bumblebee-nvidia

Wait some time to let the installation process finish.

Install VirtualGL

VirtualGL is required for the the optirun command as a bridge, but unfortunately Debian repository do not have the VirtualGL package, so we have to download it. Go to VirtualGL sourceforge repository and download the suitable package for your system. i.e. if you are using Debian 64 bit, download the latest amd64 package. Now install it with dpkg.

sudo dpkg -i ~/Downloads/virtualgl_2.5.2_amd64.deb

Also don’t forget to change the path according to where you download the file.

Configure nvidia optimus with bumblebee

Fortunately bumblebee works fine with it’s default configuration. But if you want to make any change to the settings, edit the /etc/bumblebee/bumblebee.conf file as root with your favorite text editor and restart the bumblebee service with this command sudo service bumblebeed restart .

Accessing the discrete nvidia GPU needs root privilege, so have to add your system’s username to the bumblebee group.

sudo usermod -aG bumblebee $USER

Now restart the bumblebee daemon with sudo service bumblebeed restart . Now you are done, reboot the system.

Optional: You may need to add some extra configuration to the xorg.conf.nvidia file to avoid mouse module related error.

Open the /etc/bumblebee/xorg.conf.nvidia file with your favorite text editor as root , then add the extra configuration there.

Section "Screen"
    Identifier "Default Screen"
    Device "DiscreteNvidia"
EndSection

Save the file and exit the text editor,  and restart bumblebee daemon.

Testing switchable graphics capability

After rebooting the system, you’re ready to test the sample glxgears program.

optirun -vv glxgears

glxgears nvidia optimus kali linuxThere sould be some delay (around 3-4 sec.) before starting glxgears, if it returns around or over 1000 FPS performance, that means NVIDIA optimus is working properly. For more information about optirun command, see the man page, man optirun  ,and run optirun with different arguments, like

optirun -v -b virtualgl -c jpeg glxgears

A more detailed testing and benchmarking the NVIDIA GPU could be done with furmark , which returns more accurate result than this simple glxgears test.

Troubleshooting

I didn’t faced any problem during installation and testing with Debian stretch, kernel 4.1.0-amd64, nvidia-340.67 driver. Just dont forget to add the apt non-free repository, install VirtualGL and add your user name to the bumblebee group.

UPDATE: As some readers are facing problems with debian nvidia optimus , I’hv written another tutorial specially for troubleshooting, based on reader feedback. I hope this will be helpful, here is the tutorial > NVIDIA Optimus troubleshooting in Debain .

Best practice: If your laptop’s BIOS or UEFI allow to completely disable discrete nvidia GPU, then disable it before installing the OS and re-enable it after the installation is finished. By doing this, you could avoid some troubles caused by the vga_switcheroo kernel module. ( I did this many time 🙂 )