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.
Contents
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, Alt
+ Ctrl
+ F1
.
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,
cat /proc/acpi/bbswitch
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
Again run 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 Primus
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
optirun
command ? 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.
9. Conclusion
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.
Paul says
Hi !
All the steps work good excepted when I run the command :
sudo update-alternatives --config x86_64-linux-gnu_gl_conf
The output is :
update-alternatives: error: no alternatives for gl_conf
For information, I have Ubuntu 18.04.1. I did not find the nvidia-378 so I installed nvidia-390 and I modified the configuration files accordingly.
Thanks for your time.
Arnab Satapathi says
Yeah,
x86_64-linux-gnu_gl_conf
is not necessary.As I had both 64 bit and 32 bit libraries installed, so it was needed.
Aditya says
I was not able to use my graphics card on my Asus Notebook, but now I am able to. Thanks for the kickstart.
I did face a problem in setting the library path in bumblebee.conf [driver nvidia] section. because the directory of those files has been changed.
new library path settings are
LibraryPath=/usr/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu
XorgModulePath=/usr/lib/x86_64-linux-gnu/nvidia/xorg,/usr/lib/xorg/modules,/usr/lib/xorg/modules/input
Also the update-alternatives for 'sudo update-alternatives --config x86_64-linux-gnu_gl_conf' was not working in ubuntu 18.04
Thanks a ton for this article!
Now I can use my graphics card for ML!
opentux says
Hi.
I do not understand, or I made a mistake
i am only on nvidia drivers, bumblebeed services is status=1/FAILLURE
but i am à good perf on glxgears with the nvidia driver.
?? Why ??
thanks in advance.
i am on ubuntu 18.04
Arnab Satapathi says
Bumblebee behaving weird with Ubuntu 18.04, I've to manually turn off the GPU.
What's the status of bbswitch?
/proc/acpi/bbswitch
Plazma says
Great tutorial, will you add for 18.04 bumblebee installation guide too ?
Arnab Satapathi says
It will be almost identical, I'll nvidia optimus on Ubuntu 18.04 and add it to the guide.
plazma says
Ty for quick answer, its not workin on 18.04 disable nouveau but i can find a way:
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
$ sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
you can check
cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf
blacklist nouveau
options nouveau modeset=0
if you see its ok than:
sudo update-initramfs -u
sudo reboot
Arnab Satapathi says
I'll include that in this tutorial.
libre says
Thanks for your guide !
Im running into an issue, after following all steps here when trying to restart bumblebeed service. The system hangs up, I cannot open any tty session more and cannot cancel the command. I had to make a hard reboot and the system just refuses to boot normally then.
Now Im just unable to start the system again except in failsafe mode where I can have a terminal with root access.
I have a MSI laptop with GTX 1050 and Ubuntu Xenial 16.04.4
Thanks for your help and your article !
Arnab Satapathi says
May be you need to add these two Boot time kernel parameters,
nouveau.modeset=0
andnvidia.modeset=0
.Hope this helps.
enes behlul says
sudo apt-get --no-install-recommends install nvidia-378 when i try this instruction the output is there is no nvidia 378 installation package. what should i do.
i am on mint 18.3 xcfe
Arnab Satapathi says
You can press the Tab key to get visual feedback. Something like below.
sudo apt-get --no-install-recommends install nvidia- [Tab Tab ... ]
Or use apt-cache to get the list of available packages.
sudo apt-cache search nvidia
Andrzej Mendel-Nykorowycz says
I must say this is a great HOWTO - well written, I knew what I was doing and why and now nVidia Optimus works! This is so much better than most HOWTOs which are just a bunch of commands slapped together with little to no comment.
Step 7 can be eliminated - installing package 'bumblebee-nvidia' takes care of keeping the default OpenGL library in place. 'bumblebee-nvidia' depends on package 'bumblebee', which in turn depends on 'primus' so you can just swap 'apt-get install bumblebee primus' with 'apt-get install bumblebee' in step 4 and get rid of step 7. But that is just a cosmetic tweak.
In any case, drop me a line if you are ever in Poland because I owe you a beer (or any other refreshment of your choice)!
P.S. This is on Ubuntu 17.10 with nvidia-384
Arnab Satapathi says
Yeah, those two steps could be merged together, I just wanted to elaborate things a little more.
Thankkssss for the kind offer, surely I'll like to taste the Polish beer 🙂
Anon says
FYI .. then you've to log out You've is the abbreviation for "you have" but not in this case, please check your abbreviations to ensure you are using it properly. You've is a pronoun that should be used like:
You've changed
You've been to a city
You've won something
Arnab Satapathi says
Thanks for pointing me out. Though all the doubts are not cleared, I appreciate such helps very much.
Gabriel says
Hi thanks for the guide!
I did everything and is working fine
the only problem that i have is that after running some software with optirun, the nvidia card doesn't turn off automatically. Idk if this is normal... i need to reboot to turn it off again, and sometimes the fans are running at max all the time.
I have a very old notebook with a GT335M
Thanks again for your help!
Arnab Satapathi says
Which release of Ubuntu and what's the NVIDIA driver version ? Better to stick with 378 till now.
I've noticed the exact same problem on Debian long time ago, you can manually remove every nvidia related kernel module with rmmod command and use echo 'OFF' > /proc/acpi/bbswitch command to turn it off.
In my case, it was solved by running sudo apt-get update && sudo apt-get upgrade after few days.
Gabriel says
i have the latest ubuntu 17.10 ... and the only nvidia drvier that work was the 340 version
but its weird... sometimes comeback to the intel graphics.
well i'm just trying to recovery this old laptop.
Thanks anyways !
Sathya says
Thanks, awesome step by step guide.
Worked perfectly on my Dell inspiron 5558 with nvidia 920M GPU, running Ubuntu 17.10
Arnab Satapathi says
You're most welcome! And thanks for the feedback.
danirosan says
oh well, forget it, i updated the system and now it worked just fine! ty!
Arnab Satapathi says
Glad to know !
danirosan says
man, i love you for this guide, the only one i could follow and worked in the first try!
i just had some trouble with this command
sudo update-alternatives --set i386-linux-gnu_gl_conf /usr/lib/i386-linux-gnu/mesa/ld.so.conf
i don't seem to have mesa for i386 architecture or am i wrong?
kyler clonts says
Only thing that finally got my graphics working correctly! Thank you.
Small bug in your instructions though, instruction 4 has a spelling error, your forgot the 'r' in primus and spelled it 'pimus'
Thanks again
Arnab Satapathi says
Also thanks to you for pointing out the spelling mistake. Fixed it.
Mark Ackerman says
Thanks
and I was sick of screen tearing so I revisited Bumblebee and optirun
and this guide actually seems to work
interestingly optirun glxgears sucks at 20 fps
but
vblank_mode=0 optirun -vv glxgears
results in over 1,000 fps so i guess it is now kinda solved
Cheers, Mark
Arnab Satapathi says
You're most welcome ! Glad to know it worked.