NVIDIA/Optimus

Laptops with Nvidia graphics cards using Nvidia Optimus can be configured to render scenes on the discrete Nvidia GPU (Graphics Processing Unit) card using and copy the rendered scenes to the Intel GPU using XRandR.

Kernel
Since Nvidia Optimus will be using the integrated Intel graphics for modesetting, the following kernel options will need to be enabled:

Emerge
Installing Nvidia drivers is easy, run the following:

Configuration
Configuring a system to use Nvidia's proprietary driver is not easy as the installation. There are several configuration files that will need to be modified in order for a system to work properly.

Kernel modules
If the user has chosen to not use built-in modules, then the init system should load the necessary modules on system boot. If is available, this can verified by running the following command:

If the output returns CONFIG_MODULES set to, then the kernel will need recompiled with support to load modules. Information about that can be found over here. After module loading support has been added, return to this article and continue reading.

Create a new file called in the  directory. It should contain the nvidia module name:

OpenRC
Verify the modules init script has been added to the boot runlevel (it should be by default, but double check):

The output should look like: * rc-update: modules already installed in runlevel `boot'; skipping

Systemd
Check the status of the systemd-modules-load.service to verify things are running smoothly. If issues arise this service unit will be the place to check:

xorg.conf
The best way to set the system's correctly would be to read the documentation Nvidia has provided. The documentation can be found in a couple of locations. To save time, consider reading only the pages on Optimus and XRandR, as they are vital to correct configuration. If the driver has already been emerged (done in the installation step above), the documentation can be found locally at.

Example: Use the command to read the local documentation:

It is also possible to read the documentation at Nvidia's website by following these (external) links:

http://us.download.nvidia.com/XFree86/Linux-x86_64/343.36/README/optimus.html

http://us.download.nvidia.com/XFree86/Linux-x86_64/343.36/README/randr14.html

Replace 343.36 with your version of nvidia-drivers e.g. 390.42 to get the most suitable configuration.

For a quick example here on the wiki, view this xorg.conf file.

How to find the busid

How to find BusID
Invoke  the BusID is at the beginning of each device:

01:00.0 3D controller: NVIDIA Corporation GK104M [GeForce GTX 870M] (rev a1)

Where  is BusID.

Using a specific monitor via EDID
It is probably best to first try a simple configuration first like described in the Nvidia driver manual:

http://us.download.nvidia.com/XFree86/Linux-x86_64/346.22/README/randr14.html

Saving the monitor's EDID
Some laptops/notebooks may benefit from saving the EDID screen information to a file so it can be passed to the Intel modesetting driver. The EDID information can be saved using the utility.

The EDID information is provided to the Intel GPU (Graphics Processing Unit) by specifying its location in the kernel boot parameter:

If the GRUB2 bootloader is being used, this can be configured in the file

Note: If using Sabayon Linux, the kernel boot parameters should be specified in the file instead of file.

Example xorg.conf for EDID
See EDID xorg.conf Example to view an example  using an EDID for a specific monitor.

Before starting X
Per Nvidia's instructions, the following commands are required before starting X:

This is to say any Display Manager that starts X-Windows then asks the user to log in will result in a black screen unless the above commands are run before asking the user to log in.

NOTE: If you get a black screen with no back-lighting from the previous steps, creating .xsessionrc and placing the xinitrc commands in there COULD fix it.

Use the command to find the appropriate graphics device:

Display manager configuration
The following shows a list of where to add the required xrandr commands, sorted by desktop.

For menu option (A) KDE-4
Add the commands to the end of the  file:

For menu option (B) your .xsession
Add the commands to the end of the  file.

Qingy DirectFB
In the configuration file. It is necessary to set the  variable to the BusID of the Intel graphics card as reported by the  command:

For example, if says the Intel graphics card is on BusID 00:02.0, then add the following line to

The Console Display Manager (CDM)
Add the  commands to file:

KDE Display Manager (KDM)
Add the commands to the  file and protect them like described above.

Simple Desktop Display Manager (SDDM)
Add the commands to the  file and protect them like described above.

Mint Desktop Manager (MDM)
Add the commands to the  file:

X Display Manager (XDM)
Add the commands to the  file and protect them like described above.

NOTE: if the system is a 32-bit system, add the commands to the file.

If using a 64-bit system, edit the configuration file and change the following line to point to the  file created above:

LXDE Display Manager (LXDM)
Add the following lines to :

Gnome Display Manager (GDM)
Create two .desktop files:

Make sure that GDM uses X as default backend (this does only affect . will still use wayland when USE="wayland" is enabled):

Troubleshooting
Since there are many files to configure and because the Nvidia's proprietary support for Optimus in Linux is buggy, it is rather easy to create a faulty Optimus configuration. It is possible something was typed incorrectly, or a certain configuration was not compatible with the hardware being used. Whatever the case, a broken configuration means that debugging is required.

To debug, carefully read the logs from  and Xorg  with a favorite text editor; they are the best indicators to find issues. If something irregular is discovered, make changes to the respective configuration files. Other areas to inspect for debugging include any of the configuration files that were modified through the course of this article (the kernel's {Path|.config}}, kernel boot parameters passed at, the Xorg's file, etc.). Continue checking the files as necessary then reboot the system and try again. Many attempts may be required in order to obtain a working configuration! It is not exciting process; time could be spent on something more interesting, but if debugging is required in order to get Optimus working then it needs to happen.

To aid in distinguishing between important and unimportant messages in and  files, working examples have been provided at these sub-articles:

Specific models

 * Lenovo Thinkpad W530 - In short, for all the screens to work, set the configuration to discrete mode in the motherboard firmware.

D-Bus

 * Troubleshooting D-Bus

Xorg

 * Troubleshooting Xorg

External resources

 * Official Nvidia website