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 x11-drivers/nvidia-drivers and copy the rendered scenes to the Intel GPU using XRandR.

Installation
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 Configuration
Since NVIDIA Optimus will be using the integrated Intel graphics for modesetting, the following kernel options will need to be enabled:

Xorg.conf Configuration
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 less 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/346.22/README/optimus.html

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

Using 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 NVIDIA and Intel modesetting drivers. The EDID information can be saved using the read-edid 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 Xorg.conf using an EDID for a specific monitor.

Configuration Prior to 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 xrandr commands are run before asking the user to log in.

Use the xrandr command to find the appropriate graphics device:

For Menu Option (A) KDE-4
Add the xrandr commands to the end of the file:

For Menu Option (B) Your .xsession
Add the xrandr commands to the end of the file.

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

For example, if lspci says the Intel graphics card is on BusID 00:02.0, then add the following line to {{Path}/etc/directfbrc}}

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

KDE Display Manager (KDM)
Add the xrandr commands to the file.

Mint Desktop Manager (MDM)
For Mint Desktop Manager fetch the ebuild and install :

Add the xrandr commands to the file:

X Display Manager (XDM)
Add the xrandr commands to the file:

If the system is a 32-bit system, add the commands to the file.

If a using a 64-bit system, then add the commands to Then edit the following line to point to another script that will run the xrandr commands:

Debugging
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 dmesg 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:

Debugging D-Bus
Debugging D-Bus

Debugging Xorg
Debugging Xorg