Configure NVIDIA Optimus in Debian, Kali Linux with bumblebee

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 NVIDIA Optimus GPU faces problems like hot GPU(around 65° C), decreased battery life, roaring cooler fan etc. etc.

nvidia optimus in debian

So if you are one of those lucky bastards 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 Debian and other directly Debian based distro like Kali Linux, LMDE etc.

Here we are going to do this with bumblebee, bbswitch, 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.


 1. 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_switcheroo module,

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

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


2. Unload nouveau modules and install bbswitch

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

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 main, contrib and non-free repository, to do so, put the line bellow in the /etc/apt/sources.list file

 deb 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 the kernel module. 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.


3. 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.conf under 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' 

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.


4. 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.


5. 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.4.1_amd64.deb 

dont forget to change the path according to where you download the file.


6. 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 

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


7. Testing switchable graphics capability

After rebooting the system, test the sample glxgears program.

 optirun -vv glxgears 

optirun glxgears , nvidia optimus in Debianthere 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.


8. 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 nvidia optimus in debian, 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 🙂 )


So, that’s it, how to setup nvidia optimus debian, this tutorial also useful for any Debian derivative like Kali Linux, or SolydXK. Use your nvidia GPU for something useful, like GPU computing with CUDA, NVIDIA OpenCL, fast password cracking with pyrit and many other computing extensive applications. If you faced any problem during the installation , just leave a comment, and don’t forget to share it with your friends.

82 Responses

  1. ivan says:

    Excellent work, works great. but I have a concern, I’m new using the kali linux system (which is where I’ve tried and done the steps of your post) and I get an average of 2700FPS. The question is, in ubuntu there is a module to load proprietary drivers and automatically installs all, why the difference is that in ubuntu average exceeds 12,000 FPS? Thank you very much.
    My card is a GTX 660M

    • Arnab says:

      Thanks Ivan for your question.
      Different drivers and kernel modules causes difference in performance, in my case Debian tends to perform better than Ubuntu. But FPS count really doesn’t matter while actual things things, I mean GPU computing with CUDA, cracking with hashcat, running games or benchmarks.
      You should try furmark benchmark on Ubuntu and Kali and spot the difference.

Leave a Reply

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