NVIDIA Driver with Optimus Laptops

From Gentoo Wiki
Jump to: navigation, search

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.

Note
This article is about native Optimus support using the official Nvidia drivers (x11-drivers/nvidia-drivers) – it is not about bumblebee; bumblebee is not used in the following configuration.

Installation

Kernel

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

KERNEL
DeviceDrivers  --->
    Graphics Support  --->
        Direct Rendering Manager  --->
            Direct Rendering Manager (Xfree86 4.1.0 and higher DRI support)   --->
                <*> Intel 8xx/9xx/G3x/G4x/HD Graphics
                [*]   Enable modesetting on intel by default
Important
In the case that something should go wrong, it is recommended to have live media to assist in reverting any changes. Having a Gentoo Minimal Install CD, SystemRescueCD (which is a Gentoo based recovery image), or a LiveUSB around work nicely for this purpose. If you choose to proceed without having a "just in case" alternative boot method proceed with extreme caution!
Note
At the time this article was written version 343.36 of x11-drivers/nvidia-drivers was the most recent (stable) version of the driver in the Portage tree, therefore examples that reference a specific version will presume version 343.36 is being used. When a newer version of the driver is released, or if an older version is selected, simply substitute 343.36 for the desired version.

USE flags

Optional USE flags for x11-drivers/nvidia-drivers:
USE flag (what is that?) Default Recommended Description
X Yes Yes Controls whether the X.org driver, OpenGL libraries, XvMC libraries, and VDPAU libraries are installed
acpi Yes Yes Add support for Advanced Configuration and Power Interface
gtk2 No Install nvidia-settings with support for GTK
gtk3 Yes Install nvidia-settings with support for GTK
multilib Yes Yes On 64bit systems, if you want to be able to compile 32bit and 64bit binaries
pax_kernel No PaX patches from the PaX project
tools Yes Yes Installs additional tools such as nvidia-settings
uvm Yes Yes Install the Unified Memory kernel module (nvidia-uvm) for sharing memory between CPU and GPU in CUDA programs

Emerge

Installing Nvidia drivers is easy, run the following:

root #emerge --ask x11-drivers/nvidia-drivers

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.

xorg.conf configuration

The best way to set the system's xorg.conf 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 /usr/share/doc/nvidia-drivers-343.36/README.bz2.

Example: Use the less command to read the local documentation:

user $less /usr/share/doc/nvidia-drivers-343.36/README.bz2

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

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 read-edid utility.

root #emerge --ask x11-misc/read-edid
root #get-edid > /lib/firmware/edid/1920x1080_Clevo_W670SR.bin

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

drm_kms_helper.edid_firmware=edid/1920x1080_clevo_W670SR.bin

If the GRUB2 bootloader is being used, this can be configured in the file /etc/default/grub

FILE /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="drm_kms_helper.edid_firmware=edid/1920x1080_clevo_W670SR.bin"
GRUB_GFXMODE=1920x1080

Note: If using Sabayon Linux, the kernel boot parameters should be specified in the /etc/default/sabayon-grub file instead of /etc/default/grub file.

Example xorg.conf for EDID

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

Before starting X

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

CODE XRandR commands:
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

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.

Warning
The xrandr commands must be added to the system's X session start up scripts (such as ~/.xinitrc) in order for the X display to start using modesetting. Failure to do so will result in a black screen.

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 xrandr command to find the appropriate graphics device:

root #xrandr --listproviders

Display manager configuration

Qingy

root #emerge --ask sys-apps/qingy
For menu option (A) KDE-4

Add the xrandr commands to the end of the /etc/X11/Sessions/KDE-4 file:

FILE /etc/X11/Sessions/KDE-4KDE-4's X session file
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
For menu option (B) your .xsession

Add the xrandr commands to the end of the ~/.xsession file.

Qingy DirectFB

In the /etc/directfbrc configuration file. It is necessary to set the busid parameter to the BusID of the Intel graphics card as reported by the lspci command:

root #lspci

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

FILE /etc/directfbrc
busid=0:02:0

The Console Display Manager (CDM)

root #emerge --ask x11-misc/cdm

Add the xrandr commands to ~/.xinitrc file:

KDE Display Manager (KDM)

root #emerge --ask kde-base/kdm

Add the xrandr commands to the /usr/share/config/kdm/Xsetup file.

Mint Desktop Manager (MDM)

For Mint Desktop Manager fetch the ebuild and install gnome-base/mdm:

root #emerge --ask gnome-base/mdm

Add the xrandr commands to the /etc/X11/mdm/Init/Default file:

X Display Manager (XDM)

Add the xrandr commands to the /usr/lib/X11/xdm/Xsetup_0 file:

If the system is a 32-bit system, add the commands to the /usr/lib64/X11/xdm/Xsetup_0 file.

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

CODE X Display Manager Example
DisplayManager._0.setup: /usr/lib/X11/xdm/Xsetup_0

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 dmesg (/var/log/dmesg) and Xorg (/var/log/Xorg.0.log) 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 /etc/default/grub, the Xorg's /etc/X11/xorg.conf 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.

Note
When viewing /var/log/Xorg.0.log using a text editor such as app-editors/vim, search for (EE) to quickly find errors. This will speed up debugging time considerably.

To aid in distinguishing between important and unimportant messages in /var/log/dmesg and /var/log/Xorg.0.log files, working examples have been provided at these sub-articles:

D-Bus

Xorg

See also

External resources