Skip to content

Instantly share code, notes, and snippets.

@gerarldlee
Created March 1, 2017 18:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gerarldlee/b593f31f12aebb2339ef5fd09c3b8848 to your computer and use it in GitHub Desktop.
Save gerarldlee/b593f31f12aebb2339ef5fd09c3b8848 to your computer and use it in GitHub Desktop.
Bumblebee on Ubuntu 16.04
Remove the default Nvidia driver:
sudo apt-get remove xserver-xorg-video-nouveau
Install Bumblebee, primus, and nvidia drivers
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install bumblebee bumblebee-nvidia bbswitch-dkms nvidia-375 nvidia-375-dev libcuda1-375 nvidia-opencl-icd-375 nvidia-prime primus
Blacklist NVidia Drivers
Do not reboot until you have done this. Rebooting after installing drivers but before blacklisting them will result in a black-screen and you'll have to enter through recovery mode to blacklist them. In fact, don't reboot unless it explicitly says to.
Modify /etc/modprobe.d/bumblebee.conf
# 375
blacklist nvidia-375
blacklist nvidia-375-updates
blacklist nvidia-experimental-375
Modify the /etc/bumblebee/bumblebee.conf to point to the new driver
# The Driver used by Bumblebee server. If this value is not set (or empty),
# auto-detection is performed. The available drivers are nvidia and nouveau
# (See also the driver-specific sections below)
Driver=nvidia
[optirun]
# Acceleration/ rendering bridge, possible values are auto, virtualgl and
# primus.
Bridge=primus
[driver-nvidia]
# Module name to load, defaults to Driver if empty or unset
KernelDriver=nvidia-375
PMMethod=auto
# colon-separated path to the nvidia libraries
LibraryPath=/usr/lib/nvidia-375:/usr/lib32/nvidia-375
# comma-separated path of the directory containing nvidia_drv.so and the
# default Xorg modules path
XorgModulePath=/usr/lib/nvidia-375/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia
Modify the /etc/bumblebee/xorg.conf.nvidia
Section "Device"
Identifier "DiscreteNvidia"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BusID "PCI:01:00:0"
Option "ProbeAllGpus" "false"
Option "NoLogo" "true"
Option "UseEDID" "false"
Option "UseDisplayDevice" "none"
Option "RegistryDwords" "PerfLevelSrc=0x2222"
EndSection
Select Intel as your primary video driver
sudo prime-select intel
OPTIONAL: Select Mesa as your GL Provider for your Intel driver
sudo update-alternatives --config i386-linux-gnu_gl_conf
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia-361/alt_ld.so.conf 8604 auto mode
1 /usr/lib/i386-linux-gnu/mesa/ld.so.conf 500 manual mode
2 /usr/lib/nvidia-361-prime/alt_ld.so.conf 8603 manual mode
* 3 /usr/lib/nvidia-361/alt_ld.so.conf 8604 manual mode
sudo update-alternatives --config x86_64-linux-gnu_egl_conf
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia-361/ld.so.conf 8604 auto mode
1 /usr/lib/nvidia-361-prime/ld.so.conf 8603 manual mode
2 /usr/lib/nvidia-361/ld.so.conf 8604 manual mode
* 3 /usr/lib/x86_64-linux-gnu/mesa-egl/ld.so.conf 500 manual mode
sudo update-alternatives --config x86_64-linux-gnu_gl_conf
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia-361/ld.so.conf 8604 auto mode
1 /usr/lib/nvidia-361-prime/ld.so.conf 8603 manual mode
2 /usr/lib/nvidia-361/ld.so.conf 8604 manual mode
* 3 /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf 500 manual mode
Install latest VirtualGL Package from https://sourceforge.net/projects/virtualgl/files/
sudo ln -s /opt/VirtualGL/bin/glxspheres64 /usr/bin/glxspheres
Reboot
sudo reboot
OPTIONAL: Disable gpu-manager
The ubuntu-drivers-common package installs this thing called gpu-manager. It's started by /etc/init/gpu-manager.conf, which is run by upstart, but what it does is actually creates a new /etc/X11/xorg.conf every time you shut-down/reboot your laptop. We need to disable it, because the xorg.conf it creates will break our setup. Add nogpumanager to your /etc/default/grub file.
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="nogpumanager"
$ sudo update-grub
Re-build the bbswitch and nvidia modules.
sudo dpkg-reconfigure bbswitch-dkms
sudo dpkg-reconfigure nvidia-375
Reboot
sudo reboot
Run GLX* programs to test the Intel and NVidia GPUs
Using Intel graphics:
$ glxspheres
$ glxinfo
$ glxgears
Using Nvidia graphics:
$ optirun glxspheres
$ optirun glxinfo
$ primusrun glxgears
Note: Black Screen, Xorg not Starting.
If the next time you reboot you get a black screen, or Xorg doesn't start and drops you shell, or the screen is flickering between the console and a black screen, then chances are the gpu-manager has created an /etc/X11/xorg.conf. Just enter the recovery mode in the GRUB menu, and delete (rm) the file.
OPTIONAL: Configure Steam Games to Use NVidia GPU
Steam applications must be launched using a special pre-load command to use the NVidia GPU. When looking at your steam library, Right-Click the game you want to run with the NVidia GPU and select the ‘Properties’ option. On the window that opens, select ‘Set Launch Options…’.
LD_PRELOAD="libpthread.so.0 libGL.so.1" __GL_THREADED_OPTIMIZATIONS=1 optirun %command%
OPTIONAL: Configure NVidia GPU to Enable FXAA for all Applications
Many applications do not have an option to enable Anti-Aliasing within the applications settings. You can enable FXAA (Fast Approximate Anti-Aliasing, a low cost implementation of AA) for all applications in the nvidia-settings application. This will apply Anti-Aliasing at the driver level and provides it to all applications run using the NVidia GPU.
The nvidia-settings application must be launched using the optirun command so that the driver can access the NVidia GPU. By default bumblebee uses the 8th screen for the NVidia GPU, so use the -c :8 flag to specify which screen nvidia-settings should use.
$ optirun nvidia-settings -c :8
Under Anti-Aliasing Settings > Override Application Settings
Click Enable FXAA
@catalinolaru1
Copy link

I love you, dude!

@ak2766
Copy link

ak2766 commented Oct 15, 2018

I love you more than catalinolaru1, dude!

I hate myself though for not having found this sooner! I had resigned to using prime-select to change devices and then simply systemctl restart lightdm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment