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.
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 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 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,
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
there 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.
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.