Difference between revisions of "NVIDIA Optimus"

From ArchWiki
Jump to navigation Jump to search
m (add the Chinese page)
(→‎Using optimus-manager: remove duplicate mention of optimus-manager-qt)
 
(166 intermediate revisions by 61 users not shown)
Line 1: Line 1:
 
[[Category:Graphics]]
 
[[Category:Graphics]]
[[zh-CN:NVIDIA Optimus]]
+
[[ja:NVIDIA Optimus]]
 +
[[ru:NVIDIA Optimus]]
 +
[[zh-hans:NVIDIA Optimus]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|Bumblebee}}
 
{{Related|Bumblebee}}
 
{{Related|Nouveau}}
 
{{Related|Nouveau}}
 
{{Related|NVIDIA}}
 
{{Related|NVIDIA}}
{{Related|With Xorg 1.17.1}}
+
{{Related|nvidia-xrun}}
 
{{Related articles end}}
 
{{Related articles end}}
  
NVIDIA Optimus is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop. Getting Optimus graphics to work on Arch Linux requires a few somewhat complicated steps, explained below. There are several method available:
+
[[Wikipedia:NVIDIA Optimus|NVIDIA Optimus]] is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop.
  
* disabling one of the devices in BIOS, which may result in improved battery life if the NVIDIA device is disabled, but may not be available with all BIOSes and does not allow GPU switching
+
== Available methods ==
  
* using the official Optimus support included with the proprietary NVIDIA driver, which offers the best NVIDIA performance but does not allow GPU switching and can be more buggy than the open-source driver
+
There are several methods available:
  
* using the PRIME functionality of the open-source nouveau driver, which allows GPU switching but offers poor performance compared to the proprietary NVIDIA driver and does not currently implement any powersaving
+
* [[#Use Intel graphics only]] - saves power, because NVIDIA GPU will be completely powered off.
 +
* [[#Use NVIDIA graphics only]] - gives more performance than Intel graphics, but drains more battery (which is not welcome for mobile devices). This utilizes the same underlying process as the [[#Using optimus-manager|optimus-manager]] and [[#Using nvidia-xrun|nvidia-xrun]] options, it should be utilized for troubleshooting and verifying general functionality, before opting for one of the more automated approaches.
 +
* Using both (use NVIDIA GPU when needed and keep it powered off to save power):
 +
** [[#Using PRIME render offload]] - official method supported by NVIDIA.
 +
** [[#Using optimus-manager]] - switches graphics with a single command (logout and login required to take effect). It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
 +
** [[#Using nvidia-xrun]] - run separate X session on different TTY with NVIDIA graphics. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
 +
** [[#Using Bumblebee]] - provides Windows-like functionality by allowing to run selected applications with NVIDIA graphics while using Intel graphics for everything else. Has significant performance issues.
 +
** [[#Using nouveau]] - offers poorer performance (compared to the proprietary NVIDIA driver) and may cause issues with sleep and hibernate. Does not work with latest NVIDIA GPUs.
  
* using the third-party Bumblebee program to implement Optimus-like functionality, which offers GPU switching and powersaving but requires extra configuration
+
{{Note|All of these options are mutually exclusive, if you test one approach and decide for another, you must ensure to revert any configuration changes done by following one approach before attempting another method, otherwise file conflicts and undefined behaviours may arise.}}
  
These options are explained in detail below.
+
== Use Intel graphics only ==
  
== Disabling switchable graphics ==
+
If you only care to use a certain GPU without switching, check the options in your system's BIOS. There should be an option to disable one of the cards. Some laptops only allow disabling of the discrete card, or vice-versa, but it is worth checking if you only plan to use just one of the cards.
  
If you only care to use a certain GPU without switching, check the options in your system's BIOS. There should be an option to disable one of the cards. Some laptops only allow disabling of the discrete card, or vice-versa, but it is worth checking if you only plan to use one of the cards. If you want to use both cards, or cannot disable the card you do not want, see the options below.
+
If your BIOS does not allow to disable Nvidia graphics, you can disable it from the Linux kernel itself. See [[Hybrid graphics#Fully Power Down Discrete GPU]].
  
== Using nvidia ==
+
== Use NVIDIA graphics only ==
  
The [[NVIDIA|proprietary NVIDIA driver]] does not support dynamic switching like the nouveau driver (meaning it can only use the NVIDIA device). It also has notable screen-tearing issues that NVIDIA recognizes but has not fixed. However, it does allow use of the discrete GPU and has (as of October 2013) a marked edge in performance over the nouveau driver.
+
The proprietary NVIDIA driver can be configured to be the primary rendering provider. It also has notable screen-tearing issues unless you enable prime sync by enabling [[NVIDIA#DRM kernel mode setting]], see [https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/] for further information. It does allow use of the discrete GPU and has (as of [https://www.phoronix.com/scan.php?page=article&item=nouveau-410-blob&num=1 January 2017]) a marked edge in performance over the nouveau driver.
  
{{Poor writing|Does not comply with [[Help:Style#Package management instructions]].}}
+
First, [[install]] the [[NVIDIA]] driver and {{Pkg|xorg-xrandr}}. Then, configure {{ic|/etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf}} the options of which will be combined with the package provided {{ic|/usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf}} to provide compatibility with this setup.
  
First install the nvidia drivers:
+
{{Note|On some setups this setup breaks automatic detection of the values of the display by the nvidia driver through the EDID file. As a work-around see [[#Resolution, screen scan wrong. EDID errors in Xorg.log]]. }}
  
# pacman -S nvidia
+
{{hc|/etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf|
 
+
Section "OutputClass"
Then install {{ic|xrandr}}:
+
     Identifier "intel"
 
+
     MatchDriver "i915"
# pacman -S xorg-xrandr
+
     Driver "modesetting"
 
 
Next, you must create a custom {{ic|xorg.conf}}. You will need to know the PCI address of the NVIDIA card, which you can find by issuing
 
 
 
$ <nowiki>lspci | grep -E "VGA|3D"</nowiki>
 
 
 
The PCI address is the first 7 characters of the line that mentions NVIDIA. It will look something like {{ic|01:00.0}}. In the {{ic|xorg.conf}}, you will need to format it as {{ic|#:#:#}}; e.g. {{ic|01:00.0}} would be formatted as {{ic|1:0:0}}.
 
 
 
{{hc|# nano /etc/X11/xorg.conf|
 
Section "ServerLayout"
 
     Identifier "layout"
 
     Screen 0 "nvidia"
 
     Inactive "intel"
 
 
EndSection
 
EndSection
  
Section "Device"
+
Section "OutputClass"
 
     Identifier "nvidia"
 
     Identifier "nvidia"
 +
    MatchDriver "nvidia-drm"
 
     Driver "nvidia"
 
     Driver "nvidia"
    BusID "PCI:''PCI address determined earlier''"
 
    # e.g. BusID "PCI:1:0:0"
 
EndSection
 
 
Section "Screen"
 
    Identifier "nvidia"
 
    Device "nvidia"
 
 
     Option "AllowEmptyInitialConfiguration"
 
     Option "AllowEmptyInitialConfiguration"
 +
    Option "PrimaryGPU" "yes"
 +
    ModulePath "/usr/lib/nvidia/xorg"
 +
    ModulePath "/usr/lib/xorg/modules"
 
EndSection
 
EndSection
  
Section "Device"
+
}}
    Identifier "intel"
 
    Driver "modesetting"
 
    Option "AccelMethod"  "none"
 
EndSection
 
 
 
Section "Screen"
 
    Identifier "intel"
 
    Device "intel"
 
EndSection}}
 
  
 
Next, add the following two lines to the beginning of your {{ic|~/.xinitrc}}:
 
Next, add the following two lines to the beginning of your {{ic|~/.xinitrc}}:
  
{{hc|$ nano ~/.xinitrc|
+
{{hc|~/.xinitrc|
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto}}
+
xrandr --auto
 +
}}
  
 
Now reboot to load the drivers, and X should start.
 
Now reboot to load the drivers, and X should start.
  
If you get a black screen when starting X, make sure that there are no ampersands after the two {{ic|xrandr}} commands in {{ic|~/.xinitrc}}; if there are ampersands, it seems that the window manager can run before the {{ic|xrandr}} commands finish executing, leading to the black screen.
+
If your display dpi is not correct add the following line:
 +
 
 +
xrandr --dpi 96
 +
 
 +
If you get a black screen when starting X, make sure that there are no ampersands after the two {{ic|xrandr}} commands in {{ic|~/.xinitrc}}. If there are ampersands, it seems that the window manager can run before the {{ic|xrandr}} commands finish executing, leading to a black screen.  
  
=== Display Managers ===
+
=== Display managers ===
  
 
If you are using a display manager then you will need to create or edit a display setup script for your display manager instead of using {{ic|~/.xinitrc}}.
 
If you are using a display manager then you will need to create or edit a display setup script for your display manager instead of using {{ic|~/.xinitrc}}.
Line 93: Line 83:
 
For the [[LightDM]] display manager:
 
For the [[LightDM]] display manager:
  
{{hc|# nano /etc/lightdm/display_setup.sh|
+
{{hc|/etc/lightdm/display_setup.sh|
 +
#!/bin/sh
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto}}
+
xrandr --auto
 +
}}
  
 
Make the script executable:
 
Make the script executable:
Line 101: Line 93:
 
  # chmod +x /etc/lightdm/display_setup.sh
 
  # chmod +x /etc/lightdm/display_setup.sh
  
Now configure lightdm to run the script by editing the {{ic|[SeatDefaults]}} section in {{ic|/etc/lightdm/lightdm.conf}}:
+
Now configure lightdm to run the script by editing the {{ic|[Seat:*]}} section in {{ic|/etc/lightdm/lightdm.conf}}:
  
{{hc|# nano /etc/lightdm/lightdm.conf|output=
+
{{hc|/etc/lightdm/lightdm.conf|output=
[SeatDefaults]
+
[Seat:*]
display-setup-script=/etc/lightdm/display_setup.sh}}
+
display-setup-script=/etc/lightdm/display_setup.sh
 +
}}
  
 
Now reboot and your display manager should start.
 
Now reboot and your display manager should start.
  
 
==== SDDM ====
 
==== SDDM ====
For the [[SDDM]] display manager:
+
For the [[SDDM]] display manager (SDDM is the default DM for [[KDE]]):
  
{{hc|# nano /usr/share/sddm/scripts/Xsetup|
+
{{hc|/usr/share/sddm/scripts/Xsetup|
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
 
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto}}
+
xrandr --auto
 +
}}
 +
 
 +
==== GDM ====
 +
 
 +
For the [[GDM]] display manager create two new .desktop files:
  
==== KDM ====
+
{{hc|/usr/share/gdm/greeter/autostart/optimus.desktop
 +
/etc/xdg/autostart/optimus.desktop|
 +
<nowiki>[Desktop Entry]
 +
Type=Application
 +
Name=Optimus
 +
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
 +
NoDisplay=true
 +
X-GNOME-Autostart-Phase=DisplayServer</nowiki>
 +
}}
  
For KDE's [[KDM]], add the xrandr lines into {{ic|/usr/share/config/kdm/Xsetup}}.
+
Make sure that GDM use [[GDM#Use_Xorg_backend|X as default backend]].
  
 
=== Checking 3D ===
 
=== Checking 3D ===
Line 124: Line 130:
 
You can check if the NVIDIA graphics are being used by installing {{Pkg|mesa-demos}} and running
 
You can check if the NVIDIA graphics are being used by installing {{Pkg|mesa-demos}} and running
  
  $ glxinfo <nowiki>|</nowiki> grep NVIDIA
+
  $ glxinfo | grep NVIDIA
  
 
=== Further Information ===
 
=== Further Information ===
  
For more information, look at NVIDIA's official page on the topic [http://http.download.nvidia.com/XFree86/Linux-x86_64/340.32/README/randr14.html].
+
For more information, look at NVIDIA's official page on the topic [http://us.download.nvidia.com/XFree86/Linux-x86/370.28/README/randr14.html].
  
 
== Troubleshooting ==
 
== Troubleshooting ==
 +
 +
{{Style|If this is relevant only for [[#Use NVIDIA graphics only]], it should be a subsection. Otherwise it should be the last section on the page.}}
 +
 +
=== Tearing/Broken VSync ===
 +
 +
This requires {{pkg|xorg-server}} 1.19 or higher, {{pkg|linux}} kernel 4.5 or higher, and {{pkg|nvidia}} 370.23 or higher. Then enable [[NVIDIA#DRM_kernel_mode_setting|DRM kernel mode setting]], which will in turn enable the PRIME synchronization and fix the tearing.
 +
 +
You can read the official [https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/ forum thread] for details.
 +
 +
It has been [https://bbs.archlinux.org/viewtopic.php?id=251032 reported] that {{pkg|linux}} kernel 5.4 breaks PRIME synchronization.
  
 
=== Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!) ===
 
=== Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!) ===
  
Add {{ic|1=rcutree.rcu_idle_gp_delay=1}} to the kernel parameters. Original topic can be found [https://bbs.archlinux.org/viewtopic.php?id=169742 here].
+
Add {{ic|1=rcutree.rcu_idle_gp_delay=1}} to the kernel parameters. Original topic can be found in [https://github.com/Bumblebee-Project/Bumblebee/issues/455#issuecomment-22497464] and [https://bbs.archlinux.org/viewtopic.php?id=169742].
 +
 
 +
=== Resolution, screen scan wrong. EDID errors in Xorg.log ===
 +
 
 +
This is due to the NVIDIA driver not detecting the EDID for the display. You need to manually specify the path to an EDID file or provide the same information in a similar way.
 +
 
 +
To provide the path to the EDID file edit the Device Section for the NVIDIA card in Xorg.conf, adding these lines and changing parts to reflect your own system:
 +
 
 +
{{hc|/etc/X11/xorg.conf|
 +
Section "Device"
 +
      Option "ConnectedMonitor" "CRT-0"
 +
      Option "CustomEDID" "CRT-0:/sys/class/drm/card0-LVDS-1/edid"
 +
Option "IgnoreEDID" "false"
 +
Option "UseEDID" "true"
 +
EndSection
 +
}}
 +
 
 +
If Xorg wont start try swapping out all references of CRT to DFB.
 +
card0 is the identifier for the intel card to which the display is connected via LVDS. The edid binary is in this directory. If the hardware arrangement is different, the value for CustomEDID might vary but yet this has to be confirmed. The path will start in any case with /sys/class/drm.
 +
 
 +
Alternatively you can generate your edid with tools like {{Pkg|read-edid}} and point the driver to this file. Even modelines can be used, but then be sure to change "UseEDID" and "IgnoreEDID".
 +
 
 +
=== Wrong resolution without EDID errors ===
 +
Using ''nvidia-xconfig'', incorrect information might be generated in Xorg.conf and in particular wrong monitor refresh rates that restruct the possible resolutions. Try commenting out the {{ic|HorizSync}}/{{ic|VertRefresh}} lines. If this helps, you can probably also remove everything else not mentioned in this article.
 +
 
 +
=== Lockup issue (lspci hangs) ===
 +
Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.
 +
 
 +
Applies to: newer laptops with GTX 965M or alike when bbswitch (e.g. via Bumblebee) or nouveau is in use.
 +
 
 +
When the dGPU power resource is turned on, it may fail to do so and hang in ACPI code ([https://bugzilla.kernel.org/show_bug.cgi?id=156341 kernel bug 156341]).
 +
 
 +
When using nouveau, disabling runtime power-management stops it from changing the power state, thus avoiding this issue.
 +
To disable runtime power-management, add {{ic|1=nouveau.runpm=0}} to the kernel parameters.
 +
 
 +
For known model-specific workarounds, see [https://github.com/Bumblebee-Project/Bumblebee/issues/764#issuecomment-234494238 this issue].
 +
In other cases you can try to boot with {{ic|1=acpi_osi="!Windows 2015"}} or {{ic|1=acpi_osi=! acpi_osi="Windows 2009"}} added to your [[Kernel parameters]]. (Consider reporting your laptop to that issue.)
 +
 
 +
=== No screens found on a laptop/NVIDIA Optimus ===
 +
 
 +
Check if {{ic|<nowiki>$ lspci | grep VGA</nowiki>}}
 +
outputs something similar to:
 +
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
 +
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)
 +
 
 +
NVIDIA drivers now offer Optimus support since 319.12 Beta [http://www.nvidia.com/object/linux-display-amd64-319.12-driver.html] with kernels above and including 3.9.
 +
 
 +
Another solution is to install the [[Intel]] driver to handle the screens, then if you want 3D software you should run them through [[Bumblebee]] to tell them to use the NVIDIA card.
 +
 
 +
== Use switchable graphics ==
 +
 
 +
=== Using PRIME render offload ===
 +
 
 +
This is the official NVIDIA method to support switchable graphics.
 +
 
 +
See [[PRIME#PRIME render offload]] for details.
 +
 
 +
=== Using nouveau ===
 +
 
 +
See [[PRIME]] for graphics switching and [[nouveau]] for open-source NVIDIA driver.
 +
 
 +
=== Using Bumblebee ===
 +
 
 +
See [[Bumblebee]].
 +
 
 +
=== Using nvidia-xrun ===
 +
 
 +
See [[nvidia-xrun]].
 +
 
 +
=== Using optimus-manager ===
 +
 
 +
[https://github.com/Askannz/optimus-manager Optimus-manager] is one of the easiest solutions for graphics switching between NVIDIA and Intel with a single command.
 +
 
 +
==== Installation ====
 +
 
 +
Install the required [[NVIDIA]] driver and {{AUR|optimus-manager}}. Optionally, install {{AUR|optimus-manager-qt}} for a system tray applet.
 +
 
 +
Also [[Systemd#Using_units|start and enable]] {{ic|optimus-manager.service}}.
 +
 
 +
{{Note|By default, optimus-manager only changes which graphics driver is active; it does not automatically turn off the NVIDIA GPU when not in use. To enable power management, see the [https://github.com/Askannz/optimus-manager/wiki/A-guide--to-power-management-options upstream guide]. Configurations that include a Turing architecture (or newer) GPU and an Intel Coffee Lake (or newer) CPU can use power management features built into the proprietary [[NVIDIA]] driver; see [http://download.nvidia.com/XFree86/Linux-x86_64/435.17/README/dynamicpowermanagement.html] for setup instructions.}}
 +
 
 +
{{Expansion|Mention {{Pkg|bbswitch}} for power management of older hardware, if it works.}}
 +
 
 +
==== Usage ====
  
== Using nouveau ==
+
{{Note|Switching graphics will log you out automatically. Log in again to use selected graphics.}}
  
The open-source [[nouveau]] driver ({{Pkg|xf86-video-nouveau}}) can dynamically switch with the Intel driver ({{Pkg|xf86-video-intel}}) using a technology called PRIME. For more information, see the wiki article on [[PRIME]].
+
Use below commands to switch graphics:
 +
$ optimus-manager --switch intel    # Use Intel graphics
 +
$ optimus-manager --switch nvidia  # Use NVIDIA graphics
 +
$ optimus-manager --switch hybrid  # Use hybrid graphics (Requires a patch to xorg-server)
 +
$ optimus-manager --switch auto    # Switch to different graphics (from what is used now)
  
== Using Bumblebee ==
+
Also specify which graphics to use on boot:
 +
$ optimus-manager --set-startup intel
 +
$ optimus-manager --set-startup nvidia
 +
$ optimus-manager --switch hybrid  # Use hybrid graphics (Requires a patch to xorg-server)
  
If you wish to use Bumblebee, which will implement powersaving and some other useful features, see the wiki article on [[Bumblebee]].
+
For more information and troubleshooting, see [https://github.com/Askannz/optimus-manager/blob/master/README.md upstream documentation].

Latest revision as of 13:15, 8 February 2020

NVIDIA Optimus is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop.

Available methods

There are several methods available:

  • #Use Intel graphics only - saves power, because NVIDIA GPU will be completely powered off.
  • #Use NVIDIA graphics only - gives more performance than Intel graphics, but drains more battery (which is not welcome for mobile devices). This utilizes the same underlying process as the optimus-manager and nvidia-xrun options, it should be utilized for troubleshooting and verifying general functionality, before opting for one of the more automated approaches.
  • Using both (use NVIDIA GPU when needed and keep it powered off to save power):
    • #Using PRIME render offload - official method supported by NVIDIA.
    • #Using optimus-manager - switches graphics with a single command (logout and login required to take effect). It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
    • #Using nvidia-xrun - run separate X session on different TTY with NVIDIA graphics. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
    • #Using Bumblebee - provides Windows-like functionality by allowing to run selected applications with NVIDIA graphics while using Intel graphics for everything else. Has significant performance issues.
    • #Using nouveau - offers poorer performance (compared to the proprietary NVIDIA driver) and may cause issues with sleep and hibernate. Does not work with latest NVIDIA GPUs.
Note: All of these options are mutually exclusive, if you test one approach and decide for another, you must ensure to revert any configuration changes done by following one approach before attempting another method, otherwise file conflicts and undefined behaviours may arise.

Use Intel graphics only

If you only care to use a certain GPU without switching, check the options in your system's BIOS. There should be an option to disable one of the cards. Some laptops only allow disabling of the discrete card, or vice-versa, but it is worth checking if you only plan to use just one of the cards.

If your BIOS does not allow to disable Nvidia graphics, you can disable it from the Linux kernel itself. See Hybrid graphics#Fully Power Down Discrete GPU.

Use NVIDIA graphics only

The proprietary NVIDIA driver can be configured to be the primary rendering provider. It also has notable screen-tearing issues unless you enable prime sync by enabling NVIDIA#DRM kernel mode setting, see [1] for further information. It does allow use of the discrete GPU and has (as of January 2017) a marked edge in performance over the nouveau driver.

First, install the NVIDIA driver and xorg-xrandr. Then, configure /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf the options of which will be combined with the package provided /usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf to provide compatibility with this setup.

Note: On some setups this setup breaks automatic detection of the values of the display by the nvidia driver through the EDID file. As a work-around see #Resolution, screen scan wrong. EDID errors in Xorg.log.
/etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf
Section "OutputClass"
    Identifier "intel"
    MatchDriver "i915"
    Driver "modesetting"
EndSection

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "PrimaryGPU" "yes"
    ModulePath "/usr/lib/nvidia/xorg"
    ModulePath "/usr/lib/xorg/modules"
EndSection

Next, add the following two lines to the beginning of your ~/.xinitrc:

~/.xinitrc
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Now reboot to load the drivers, and X should start.

If your display dpi is not correct add the following line:

xrandr --dpi 96

If you get a black screen when starting X, make sure that there are no ampersands after the two xrandr commands in ~/.xinitrc. If there are ampersands, it seems that the window manager can run before the xrandr commands finish executing, leading to a black screen.

Display managers

If you are using a display manager then you will need to create or edit a display setup script for your display manager instead of using ~/.xinitrc.

LightDM

For the LightDM display manager:

/etc/lightdm/display_setup.sh
#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Make the script executable:

# chmod +x /etc/lightdm/display_setup.sh

Now configure lightdm to run the script by editing the [Seat:*] section in /etc/lightdm/lightdm.conf:

/etc/lightdm/lightdm.conf
[Seat:*]
display-setup-script=/etc/lightdm/display_setup.sh

Now reboot and your display manager should start.

SDDM

For the SDDM display manager (SDDM is the default DM for KDE):

/usr/share/sddm/scripts/Xsetup
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

GDM

For the GDM display manager create two new .desktop files:

/usr/share/gdm/greeter/autostart/optimus.desktop
/etc/xdg/autostart/optimus.desktop
[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer

Make sure that GDM use X as default backend.

Checking 3D

You can check if the NVIDIA graphics are being used by installing mesa-demos and running

$ glxinfo | grep NVIDIA

Further Information

For more information, look at NVIDIA's official page on the topic [2].

Troubleshooting

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements. See Help:Style for reference.Tango-edit-clear.png

Reason: If this is relevant only for #Use NVIDIA graphics only, it should be a subsection. Otherwise it should be the last section on the page. (Discuss in Talk:NVIDIA Optimus#)

Tearing/Broken VSync

This requires xorg-server 1.19 or higher, linux kernel 4.5 or higher, and nvidia 370.23 or higher. Then enable DRM kernel mode setting, which will in turn enable the PRIME synchronization and fix the tearing.

You can read the official forum thread for details.

It has been reported that linux kernel 5.4 breaks PRIME synchronization.

Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!)

Add rcutree.rcu_idle_gp_delay=1 to the kernel parameters. Original topic can be found in [3] and [4].

Resolution, screen scan wrong. EDID errors in Xorg.log

This is due to the NVIDIA driver not detecting the EDID for the display. You need to manually specify the path to an EDID file or provide the same information in a similar way.

To provide the path to the EDID file edit the Device Section for the NVIDIA card in Xorg.conf, adding these lines and changing parts to reflect your own system:

/etc/X11/xorg.conf
Section "Device"
       	Option		"ConnectedMonitor" "CRT-0"
       	Option		"CustomEDID" "CRT-0:/sys/class/drm/card0-LVDS-1/edid"
	Option		"IgnoreEDID" "false"
	Option		"UseEDID" "true"
EndSection

If Xorg wont start try swapping out all references of CRT to DFB. card0 is the identifier for the intel card to which the display is connected via LVDS. The edid binary is in this directory. If the hardware arrangement is different, the value for CustomEDID might vary but yet this has to be confirmed. The path will start in any case with /sys/class/drm.

Alternatively you can generate your edid with tools like read-edid and point the driver to this file. Even modelines can be used, but then be sure to change "UseEDID" and "IgnoreEDID".

Wrong resolution without EDID errors

Using nvidia-xconfig, incorrect information might be generated in Xorg.conf and in particular wrong monitor refresh rates that restruct the possible resolutions. Try commenting out the HorizSync/VertRefresh lines. If this helps, you can probably also remove everything else not mentioned in this article.

Lockup issue (lspci hangs)

Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.

Applies to: newer laptops with GTX 965M or alike when bbswitch (e.g. via Bumblebee) or nouveau is in use.

When the dGPU power resource is turned on, it may fail to do so and hang in ACPI code (kernel bug 156341).

When using nouveau, disabling runtime power-management stops it from changing the power state, thus avoiding this issue. To disable runtime power-management, add nouveau.runpm=0 to the kernel parameters.

For known model-specific workarounds, see this issue. In other cases you can try to boot with acpi_osi="!Windows 2015" or acpi_osi=! acpi_osi="Windows 2009" added to your Kernel parameters. (Consider reporting your laptop to that issue.)

No screens found on a laptop/NVIDIA Optimus

Check if $ lspci | grep VGA outputs something similar to:

00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)

NVIDIA drivers now offer Optimus support since 319.12 Beta [5] with kernels above and including 3.9.

Another solution is to install the Intel driver to handle the screens, then if you want 3D software you should run them through Bumblebee to tell them to use the NVIDIA card.

Use switchable graphics

Using PRIME render offload

This is the official NVIDIA method to support switchable graphics.

See PRIME#PRIME render offload for details.

Using nouveau

See PRIME for graphics switching and nouveau for open-source NVIDIA driver.

Using Bumblebee

See Bumblebee.

Using nvidia-xrun

See nvidia-xrun.

Using optimus-manager

Optimus-manager is one of the easiest solutions for graphics switching between NVIDIA and Intel with a single command.

Installation

Install the required NVIDIA driver and optimus-managerAUR. Optionally, install optimus-manager-qtAUR for a system tray applet.

Also start and enable optimus-manager.service.

Note: By default, optimus-manager only changes which graphics driver is active; it does not automatically turn off the NVIDIA GPU when not in use. To enable power management, see the upstream guide. Configurations that include a Turing architecture (or newer) GPU and an Intel Coffee Lake (or newer) CPU can use power management features built into the proprietary NVIDIA driver; see [6] for setup instructions.

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Mention bbswitch for power management of older hardware, if it works. (Discuss in Talk:NVIDIA Optimus#)

Usage

Note: Switching graphics will log you out automatically. Log in again to use selected graphics.

Use below commands to switch graphics:

$ optimus-manager --switch intel    # Use Intel graphics
$ optimus-manager --switch nvidia   # Use NVIDIA graphics
$ optimus-manager --switch hybrid   # Use hybrid graphics (Requires a patch to xorg-server)
$ optimus-manager --switch auto     # Switch to different graphics (from what is used now)

Also specify which graphics to use on boot:

$ optimus-manager --set-startup intel
$ optimus-manager --set-startup nvidia
$ optimus-manager --switch hybrid   # Use hybrid graphics (Requires a patch to xorg-server)

For more information and troubleshooting, see upstream documentation.