NVIDIA/Bumblebee

This is a guide to configuring a Gentoo system to make use of Hybrid Graphics using:
 * The proprietary NVIDIA graphics drivers
 * The Intel iGPU drivers
 * Bumblebee
 * bbswitch for hardware switching
 * Primus for bridging

This configuration prefers Primus over Optirun/VGL.

NVIDIA Optimus support
This is pretty much straightforward. If you have an Intel processor (2nd Gen +) and a NVIDIA GPU, then you probably have Optimus on your laptop. To check for sure, run

and look for VGA or 3D controllers to see your present GPUs. If you don't have an Optimus system, this guide will do nothing for you.

NVIDIA drivers
First configure your system to use NVIDIA's proprietary drivers instead of the open source Nouveau drivers and install the drivers. This is already detailed elsewhere on the wiki and is not repeated here.

Intel drivers
Also configure and install the Intel drivers according to the wiki. DDX or modesetting both ought to work.

Kernel
Ensure that you system can load and unload modules:

Video cards
Set your video card variables like so:

USE flags
In order to allow easy enabling and disabling of the NVIDIA drivers, we need to disable the  and   USE flags for the NVIDIA drivers:

Now update your set:

Then reboot your system

Installing Bumblebee, bbswitch, Primus
Emerge the packages:

User access to Bumblebee
Make sure to add your user to the and  groups to allow use of bumblebee:

(Replacing USER with your username)

Configuring /etc/init.d/bumblebee
By default, the OpenRC bumblebee module is set to depend on VGL and XDM. We are using primus over VGL. The XDM dependency can cause problems if this configuration is being setup prior to the X server. Remove the following lines (which should be near the start of the file):

Your final file should look something like this:

The important part is that it no longer has any dependencies.

Configuring /etc/bumblebee/bumblebee.conf
The following settings need to be present in the file.

OpenRC
Now enable Bumblebe to load at runlevel

And once again, reboot the system:

Configuring /etc/modprobe.d/nvidia-rmmod.conf
Earlier, we disabled the  and   USE flags for the NVIDIA drivers. This means we should only have the module  present and not ,  , or. In order that functions correctly, we need it to remove only   and nothing else. Remove all other modules from so that it changes from looking like this:

to this:

OpenGL
We need to ensure OpenGL is set to use  instead of  :

Using glxgears
Install the package to access :

Before we run our test, make sure the  module is not loaded:

And check the status of bbswitch using:

As you can see:


 * bbswitch is loaded
 * The  module is not loaded
 * The NVIDIA GPU (at PCI location 01:00.0) is off

Now let’s check if the NVIDIA card will be switched on and the  module will be loaded once / are executed, and if it’ll switch off and the   module will be unloaded once / finish executing.

From within an Xorg Session:

or (but not both at once):

A window showing should open. While it's running, check:

This shows that the NVIDIA GPU is now on, its module loaded, and OpenGL is using it as expected. Once you end the or  command and exit, the previous checks run again should show the GPU off and the module unloaded.

Using glxinfo
Alternatively, can be used to see if bumblebee is working:

As you can see, running the command without runs with the iGPU but with  runs with the NVIDIA GPU.

Building with KMS and UVM
Users who want to use CUDA or offloading with their NVIDIA GPU will want to use KMS and UVM. To do this, first follow the guide above to install without KMS and UVM. This provides a good starting point because if it doesn't work with that setup, it will not work with this one.

First, stop the Bumblebee daemon:

Then unmount the module and remount  module:

Next, change your use flags to include  and  :

and update your set:

Next, enable the overlay with  or :

or

and install the patched version of bumblebee (which is capable of removing all of the NVIDIA drivers):

Edit the to unload the relevant drivers in the right order:

Change your kernel module parameter in your file to

Now reboot your system.

Using Bumblebee with Steam games
In order to run a Steam game with or, you need to
 * right click on the game within steam
 * select "properties"
 * "Set Launch Options"
 * add either  or   to the text field.

Using the Bumblebee overlay
Some users cannot get this configuration to work and it is suggested to use the Bumblebee Overlay to emerge Bumblebee and Primus.

First add the bumblebee overlay via eselect repository or layman:

or

Then unmask Bumblebee and Primus:

And mask the official Portage tree:

Then emerge Primus:

Configuring Xorg
Some systems require Xorg to be configured to use the Intel drivers. Do this according to the Gentoo Intel Wiki Page.

bbswitch refuses to turn off card
Try adding:

to your kernel command-line (this has worked for a couple of users, especially those with Thinkpads and Lenovo laptops).

Manual unloading
If the NVIDIA drivers are built with  and/or   and a patched version of bumblebee then the bumblebee module will not be able to unload the   module as it will be in use by the   module which is itself in use by the   module. However, the modules cat be unloaded manually (using ) and the relevant changes to. The GPU can then be turned off using. Some users have these two commands in a script accessible through a key command in their WM.

System freezes when starting Xorg server
On some systems, it may be necessary to start Xorg with the  module loaded and the discrete GPU turned on or else the system will hang. The module can then be unloaded and the GPU switched off. In order to manually load the module, add  to your modules configuration file:

The  module must not be blacklisted.

Bumblebee daemon doesn't start on boot
First check that bumblebee is configured in OpenRC: Now enable Bumblebee to load at runlevel

If you still get errors indicating that the Bumblebee Daemon is not running when you attempt and  commands, it may be necessary to start the daemon manually on log-in. Put  into a suitable configuration file so that it will be automatically run when you start your X server. This might be in your or window manager (such as i3) config file depending on your setup.

GPU doesn't automatically turn off for the first time
Some users may experience their bumblebee setup working in every respect except for that the GPU remains on until the first time a or  command is run. A workaround for this is to add  to your  or other initializing config file (like your i3 config file).

System hangs on any PCI call when the GPU is off
Some users may find that their setup works well but will experience random kernel crashes characterized by a complete system hang with no errors in any log files generated. If this is the case, it may be necessary to trick the acpi kernel module into thinking that the system is an earlier version of Windows by editing your grub configuration:

The parameters,  , and   may also be necessary.

Then regenerate your grub config file:

Blacklisting the NVIDIA modules
On some systems it may be necessary to blacklist the  modules. Edit your blacklist file as necessary:

Could not load GPU driver
If you tested with to see if Bumblebee is working and got the following output:

Restarting the GUI by using should fix the issue.

libGL error: failed to load driver: swrast
If you get the following error when you run :

The issue could be that Bumblebee cant find the NVIDIA libraries. Changing the  in  can fix the issue.

Specific use cases
The following Wiki Pages make reference to Bumblebee and/or Bumblebee configurations:


 * Lenovo ThinkPad T440s
 * Clevo P650HS-G
 * Dell XPS 15z
 * Toshiba Satellite P70-A
 * Dell XPS 15 9560