If you’re looking for how to setup nVIDIA Optimus in Ubuntu, Linux Mint to harness that crazy GPU in your laptop, then you’re in the right place.
It’s easy to turn off the nVIDIA GPU to save battery, either from BIOS or with bbswitch kernel module. But it’s a bit difficult if want to use the discrete GPU rather than turning it off totally.
So, to properly configure Optimus like functionality in Ubuntu without installing tons of packages, we’ve to choose packages carefully.
It’s somewhat similar to the nVIDIA Optimus setup in Debian, lets get started.
1. Unload the nouveau kernel module
The first step is to unload the nouveau kernel driver and disable the nVIDIA GPU.
First check the if nouveau module is loaded or not at all, use this command.
lsmod | grep -i 'nouveau'
If you’re using a display manager like LightDM, SDDM or something similar, then you’ve to log out and stop it temporarily.
Log out from the desktop session and open up a virtual tty console, just press this key combo,
Login with your username and password, then use this command below.
sudo systemctl stop lightdm.service # To stop LightDM service sudo systemctl stop sddm.service # To stop SDDM
Now try to unload the
nouveau kernel module.
sudo rmmod nouveau
If noveau refuses to unload, then probably you’ve to add this,
nouveau.modeset=0 boot time kernel parameter to the
/etc/default/grub file and update the grub. Finally reboot the laptop and repeat the above process.
Click here for more about how to add the kernel parameter, on the section 3.
2. Install bbswitch to turn of the nVIDIA GPU
After successfully unloading the nouveau kernel module, lets install the bbswitch module.
You’re going to need a working internet connection at this step, first update the system and and install bbswitch.
sudo apt-get update && sudo apt-get upgrade
Assuming you’ve enabled all the updated repository on Ubuntu. After upgrading all the packages, install bbswitch.
sudo apt-get install gcc make linux-headers-`uname -r` sudo apt-get install dkms bbswitch-dkms
When the installation is complete, check if bbswitch can turn off the discrete GPU or not.
sudo modprobe bbswitch load_state=0
Now check if the discrete GPU is ON or OFF,
If everything was done right, the above command should return OFF.
3. Install Ubuntu nVIDIA drivers from PPA
Next we need to install latest Ubuntu nVIDIA drivers from the graphics-drivers PPA, we can get the latest drivers here, this PPA is very well maintained.
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update to update the software repository and install the nvidia driver, the latest driver version is 378 at the time of writing.
sudo apt-get --no-install-recommends install nvidia-378
As I’m trying to install minimum number of packages, so I’m using the
--no-install-recommends flag, you can exclude it.
In my case, it installed just one package, around 67 MB in size when packed, that all !
4. Install Bumblebee and Pimus
Previously Bumblebee had some problem with latest nVIDIA drivers, version 352 and above.
But this issue is now fixed, bumblebee works out of the box on Ubuntu 16.04.2 and above. But we’ve to enable the xenial-updates repository to get that patched bumblebee.
So, assuming you’re using Ubuntu 16.04 or any later version, and already enabled the updates repo.
sudo apt-get --no-install-recommends install bumblebee primus
That’s all we need to install, and of course we don’t need to install VirtualGL and other stuffs recommended by bumblebee.
5. Configure Bumblebee
We need to configure Bumblebee properly. First take a backup of the default bumblebee configuration, then create a new one.
sudo mv /etc/bumblebee/bumblebee.conf /etc/bumblebee/bumblebee.conf.bac
Now create a new configuration file with your favorite text editor.
sudo nano /etc/bumblebee/bumblebee.conf
Here’s my bumblebee configuration, that works. You may need to adjust it a little according to your system.
[bumblebeed] VirtualDisplay=:8 KeepUnusedXServer=false ServerGroup=bumblebee TurnCardOffAtExit=true NoEcoModeOverride=false Driver=nvidia XorgConfDir=/etc/bumblebee/xorg.conf.d [optirun] Bridge=primus VGLTransport=proxy PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus AllowFallbackToIGC=false [driver-nvidia] KernelDriver=nvidia-378 PMMethod=auto LibraryPath=/usr/lib/nvidia-378:/usr/lib32/nvidia-378 XorgModulePath=/usr/lib/nvidia-378/xorg,/usr/lib/xorg/modules XorgConfFile=/etc/bumblebee/xorg.conf.nvidia [driver-nouveau] KernelDriver=nouveau PMMethod=auto XorgConfFile=/etc/bumblebee/xorg.conf.nouveau
Now restart the bumblebee deamon, it should restart without error if everything is properly configured.
sudo systemctl restart bumblebeed.service
6. Blacklist nvidia kernel modules
Finally we need to blacklist the nvidia kernel modules to prevent auto loading. If these kernel modules loaded, bbswitch will fail to turn off the GPU at startup.
For blacklisting, we’ve to edit the
/etc/modprobe.d/bumblebee.conf file as root and add these few lines listed below.
# nVIDIA 378 blacklist blacklist nvidia_378 blacklist nvidia_378_drm blacklist nvidia_378_modeset blacklist nvidia_378_uvm blacklist nvidiafb
Note that this time the version number is separated by a
_ not a
- . So, if you try to use
- , it won’t work, reason unknown.
7. Fix some issues
Finally we need to reboot the laptop, and check the followings after reboot.
- Is the nVIDIA GPU is turned off ? The answer should be yes.
- Is the nouveau or nvidia kernel module loaded ? This answer should be no.
- Can we run an application with
optiruncommand ? And this answer should be yes too.
I’ve configured bumblebee to run apps with primus by default, as it promises to deliver better performance than VirtualGL.
Next we need to fix some OpenGL related issue. The Ubuntu nVIDIA graphics driver installer overrides the default OpenGL library.
sudo update-alternatives --config x86_64-linux-gnu_gl_conf sudo update-alternatives --config i386-linux-gnu_gl_conf
Run the above commands one by one and select mesa related OpenGL shared library every time, screenshot below.
This OpenGL issue could be fixed by two single commands without selecting the entries manually.
sudo update-alternatives --set x86_64-linux-gnu_gl_conf /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf sudo update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/i386-linux-gnu/mesa/ld.so.conf
And of course, you also need to update the OpenGL_ES library configuration,
x86_64-linux-gnu_egl_conf if you’re using it somewhere.
8. Test Ubuntu nVIDIA Optimus capibility
Now some testing, you can use the
glxgears application for testing.
sudo apt-get install mesa-utils mesa-utils-extra
vblank_mode=0 optirun -vv glxgears
You won’t be able to spot a drastic performance improvement while running
glxgears through the nVIDIA GPU. Lets try some really graphics intensive app like glmark2 or Furmark to test the Ubuntu nvidia optimus capability.
Go to the links above to know more about Furmark on Linux, here’s an example.
optirun ./GpuTest /test=fur /width=800 /height=600 /benchmark
Here’s the result, used primus as bridge by default.
Furmark was able to run the test at 16 to 20 FPS while the Intel HD 3000 GPU stuck at 8–9 FPS.
So, that’s all about how to configure nVIDIA Optimus in Ubuntu, in a minimal way. I hope it’s simple enough to understand.
Though I wrote this tutorial exclusively for Ubuntu, but it should work well on Linux Mint or other Ubuntu derivatives.
I think this NVIDIA Optimus troubleshooting guide could be useful for Ubuntu too, have a look there in case you face a problem or just leave a comment below. Also don’t forget to share this tutorial if you think it’s useful.