[HowTo] Set up PRIME with NVIDIA proprietary driver

The latest versions of Xorg, kernel, and NVIDIA driver all support PRIME output but setting this up is a bit of a faff. What follows is a method to get this working on an Optimus-enabled laptop.

Note: Fermi-based GPUs should use nvidia-390xx instead of nvidia.

Method Advantages Disadvantages
bumblebee, using "render offload" Uses the dGPU only when requested, allows power saving, is the Manjaro default Some overhead so lower raw performance
PRIME, using "output offload" Uses the dGPU directly, better raw performance dGPU and iGPU both powered on constantly, needs manual configuration
optimus-manager Easy switch between iGPU and dGPU usage Very much pre-release and under rapid development

Note: The easiest way to switch to the dGPU is to disable the iGPU in your BIOS. If that option is available all of this is unnecessary and you can just go ahead and use the NVIDIA driver.

Note 2: While the package optimus-manager offers a semi-automated way of switching configuration between iGPU and dGPU, as of 2018-12-15T00:00:00Z it is still under heavy development.

Disclaimer: NVIDIA's support for Optimus under Linux is a right mess. There are many different hardware configurations so while this approach works for many it may not work for you. Read the Arch wiki for some options.

Step 1: remove bumblebee

If you installed with the non-free driver option mhwd will have set up bumblebee for you. This will get in the way so the first step is to remove it. Use the mhwd command-line or simply remove it via Manjaro Settings Manager.

Step 2: install the NVIDIA driver

Use mhwd or MSM to install the nvidia driver in the normal way.

Step 3: break fix mhwd's configuration

mhwd does the sensible thing and puts configuration in place as though the NVIDIA GPU was the only device available. We need to change this setup so PRIME will work.

Step 3.1: set up a new Xorg configuration

Firstly, remove /etc/X11/xorg.conf.d/90-mhwd.conf and replace it with:

/etc/X11/xorg.conf.d/optimus.conf
Section "Module"
    Load "modesetting"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
    Option "AllowEmptyInitialConfiguration"
EndSection

While the BusID value above should be correct for most Optimus laptops you should check your values with lspci | grep -E "VGA|3D" .

Step 3.2: Refine blacklisting

PRIME relies on nvidia-drm and mhwd puts it in a blacklist by default, but to ensure the nvidia kernel module will load we still need to blacklist certain other modules. Therefore, you'll have to do some editing of the files in /etc/modprobe.d.

To remove the existing blacklist, edit, move or remove any related mhwd-* files in /etc/modprobe.d/, e.g.

ls /etc/modprobe.d/mhwd*
sudo rm /etc/modprobe.d/mhwd-gpu.conf
sudo rm /etc/modprobe.d/mhwd-nvidia.conf

The end result must include a blacklist of the following modules, e.g. in /etc/modprobe.d/nvidia.conf:

blacklist nouveau
blacklist nvidiafb
blacklist rivafb

Step 4: enable nvidia-drm.modeset

Create a new file,

/etc/modprobe.d/nvidia-drm.conf
options nvidia_drm modeset=1

Step 5: Set the output source for your DM.

This is the most complicated part and the one which will take longest to get right. If you reboot now, your DM will load but display on the wrong output; the laptop display will be entirely blank (powered off).

We need to set a startup script to load the correct settings while the DM is loading.

NOTE: Use only the part which matches your current DM. You don't need to do all of these.

For LightDM

e.g. Xfce edition

Create a new file with the following content:

/usr/local/bin/optimus.sh
#!/bin/sh

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Make sure to set it world read-execute, chmod a+rx /usr/local/bin/optimus.sh.

Now you have to get this to load in LightDM's startup sequence, so edit /etc/lightdm/lightdm.conf and set this at the [Seat:*] section

display-setup-script=/usr/local/bin/optimus.sh

For GDM

e.g. GNOME edition

Create a new file,

/usr/local/share/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

Or using the same script as above ("for LightDM"),

[Desktop Entry]
Type=Application
Name=Optimus
Exec=/usr/local/bin/optimus.sh
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer

and link it into place so it starts with GDM and on login

sudo ln -s /usr/local/share/optimus.desktop /usr/share/gdm/greeter/autostart/optimus.desktop
sudo ln -s /usr/local/share/optimus.desktop /etc/xdg/autostart/optimus.desktop

You'll also have to use X, not Wayland.

For SDDM

e.g. KDE edition

Create a new file,

/usr/share/sddm/scripts/Xsetup
#!/bin/sh

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

and make it executable.

Step 6: reboot

If everything is set correctly, when you reboot your DM will load, you can log in, and:

$ glxinfo | grep -i vendor
server glx vendor string: NVIDIA Corporation
client glx vendor string: NVIDIA Corporation
OpenGL vendor string: NVIDIA Corporation

Hooray! You're running X via the dGPU not the iGPU!

If you have multiple displays you may have to configure their layout again in the normal way.

References and reading

62 Likes
Impossible to boot after installing Nvidia drivers (gtx1060 laptop)
Nvidia non-free driver prevents me from loading Manjaro
Performance regression with NVIDIA 390.25
GNOME freezing waking up from suspend, now even after restart GUI wont start
KMail corrupt after upgrades
Using Only Nividia Card on Optimus System
No display after installation on Nvidia drivers
Issues Installing Proprietary Nvidia drivers
HDMI port not working on Dell Inspiron 7567
Bumblebee suddenly stopped working.
[Solved] Window trails and general glitchyness of Gnome Desktop after setting up NVIDIA Prime
Deepin Manjaro wireless card and Nvidia driver problem!
Blank Screen after login in gaming laptop with Nvidia GPU
Blank Screen after login in gaming laptop with Nvidia GPU
Driver Issue? Unsure - some programs not opening, hangs on shutdown
Can't get nvidia drivers to work
Switching from propietrary/nonfree drivers to free drivers when switching computers (booting from an external ssd)
Manjaro Setting Manager - Hardware Configuration shows no installed display controller
Steam Failed to load steamui.so on bumblebee
Nvidia drivers don't work
Xbacklight not working after setting up proprietary Nvidia drivers
Setting up VGA passthrough on my laptop
Nvidia Proprietary Drivers on 1660Ti
How often do you update your manjaro ?
How can I activate my Nvidia card ?
Low resolution after installing Nvidia Prime
NVIDIA PRIME and Manjaro
NVIDIA PRIME and Manjaro
Manjaro XFCE Stable Fresh Install Random Freeze Problems
Using a Second Monitor with Gnome
Using a Second Monitor with Gnome
Installing Nvidia Prime breaks the brightness controls on my macbook pro Mid 2012.
Vulkan issues (?) with Witcher 3 (GOG) + wine + dxvk + Optimus Nvidia
accidentally (?) deleted graphics driver.. blank screen..arrghh (wants walkthrough for driver reinstallation)
nvidia - unable to make driver work properly
nvidia - unable to make driver work properly
[SOLVED] OS temporary freezes before shutting down
Intel and Nvidia GTX 1050ti drivers problems on DELL G7 15 7588
Integrated graphics laptop - any walkthrough for non-technical users?
60p youtube videos are choppy when using proprietary Nvidia drivers
Trying to reinstall free graphics (moving away from PRIME)
[Asus FX504GD] Issues with nvidia proprietary drivers standalone / bumblebee
SDDM doesnt start on boot, works with startx
Gaming-related system crashes
Frame drops when using Nvidia Prime
System freezes when launching apps with NVIDIA Prime, but not with bumblebee
Bumblebee is not able to activate NVIDIA GPU
Nvidia Optimus
Shutdown problems, desktop freezing
keyboard layout does not persist on reboot, even after configuring xorg manually.
Wrong display scaling/DPI after setting up Nvidia Prime
KDE composer with nvidia
Unable to boot after nvidia-prime-select install
Latest resort nvidia drivers
[Solved]nvidia kernel module not loading without force loading it
Thinkpad T430s Grafiktreiber
Latest resort nvidia drivers
Failed to start Load Kernel Modules.
Nvidia drivers are not loaded and external monitor not recognized
Desktop(Gnome) frequently get frozen few seconds and works again.
Pantalla negra no funciona servicio light display manager. [Solucionado]
Setting primary card in dual card NVIDIA and Intel.
Intel for display, Nvidia for CUDA?
How To Install NVIDIA Drivers
Не получается запустить игры в steam с дискретной видеокартой.
Unable to boot after nvidia-prime-select install
Can't reinstall Manjaro
Screen tearing appears after watching movies on VLC or using Simplescreenrecorder | SOLVED
Screen tearing appears after watching movies on VLC or using Simplescreenrecorder | SOLVED
configuration of my graphic card is correct?
User experience degraded when laptop is on battery
Restore nvidia settings
System cannot boot after updating to kernel 4.19.30-1
Problemas para Suspender e Hibernar
No gaming for me
Stable but battery efficient GPU option
I3 Nvidia screen tear | SOLVED
Overall Graphics Problem with HP Omen Laptop
Gnome black screen after installing Nvidia Proprietary drivers + Prime
Low screen resolution after installing nvidia driver
Graphics issue
Upgrade to kernel 5.0 broke display
Nvidia "Prime Profiles" Not Show
Nvidia "Prime Profiles" Not Show
Using something else than FOSS gfx driver in macBook Pro
Installing video-nvidia using mhwd always leads to Failed to start load kernel modules
Live USB not booting on XPS 15 9560
Nvidia M150 Issues On Xiaomi Mi Notebook Pro
Nvidia M150 Issues On Xiaomi Mi Notebook Pro
[Testing Update] 2019-03-11 - KDE Frameworks, AMDVLK, LXDE, Glib2
Manjaro has ceased working on my new laptop
GDM becoming unstable after switching to Nvidia-driver
SOLVED - KDE compositing not working after enabling PRIME
Optimus + Ultra Wide monitor + i3
Unreasonably bad performance on RTX 2060 (mobile)
Nvidia nonfree driver install program
Installing Manjaro on HD630 and GTX1050Ti makes me crazy
Setting up nvidia optimus; nvidia not detected
[Steam] Recently Civ VI stops to launch
Laptop not booting after installing proprietary drivers
Nvidia drivers not working in fresh install
Vetzki's PRIME tutorial discussion
System crashes on reboot or poweroff
Options for Nvidia Optimus graphics
How can I make Manjaro like my optimus hardware?
Manjaro not booting into kde environment
Manjaro XFCE keeps getting stuck
How to install nvidia driver for secondary GPU on laptop
How to install nvidia driver for secondary GPU on laptop
How to install nvidia driver for secondary GPU on laptop
Issues with gaming on Manjaro i3 with Optimus
No more Login screen and xorg got deleted after uninstalling libinput drivers
Did anyone installed drivers for Nvidia GTX1070?
Need help setting up Nvidia Optimus: Bumblebee / Prime?
Optimus laptop issues
Manjaro KDE and Nvidia
[SOLVED] NVIDIA PRIME synchronization
Nvidia GPU driver (bumblebee) doesn't install correctly
NVIDIA Optimus problematic
How do I use only nvidia and not use intel graphics?
Hardware configuration hangs out
Trying to understand my setup
Nvidia Drivers with Intel Integrated Graphics - Current Status?
HDMI port not recognized on Acer Nitro V
Extreme difficulties with GTX 1050ti/intel 630 hybrid graphics [SOLVED]
Trying to understand my setup
Manjaro KDE and Nvidia
Cannot enable nvidia gpu for bumblebee XPS 15 9550
Poweroff doesn't work after install
Manjaro KDE works perfectly live but freezes once installed
940MX Geforce Nvidia
Manjaro Deepin on an Asus FX504G laptop
Dual monitors Nvidia graphics (not Nouveau)
No possibility to get Nvidia GT 610M working
Manjaro boot stuck at 'started Network Manager script dispatcher service'
Bumblebee fullscreen problem
NVIDIA driver not working properly (+ poor rendering performance in Chrome)
Can't detect HDMI cable for another monitor when using bumblebee
I3 Manjaro - unable to detect secondary monitor
Manjaro Wiki sanitization - report dangerously outdated articles here!
Acer V5 573G Default PrtScSysRq Screenshot Error
KDE + NVidia lag and jankiness (Solved)
Your 2019 hopes for and from Manjaro?
After install video-nvidia manjaro can't boot
Free or non free for Nvidia GTX960?
NVIDIA Driver disappears after roboot
Installing nvidia and intel driver problem
After install video-nvidia manjaro can't boot
Unable to detect GPU - Dell XPS 9570
Optirun problem on Manjaro KDE
CSGO is Not working on Nvidia Bumblebee (Only Getting 30 fps)
Manjaro KDE after update Black screen
Nvidia Prime vs Optimus-manager
Unable to detect second display
Low resolution after update
Low resolution after update
NVIDIA GeForce GTX 1060 not starting on Dell G5 laptop
Can't make Manjaro boot with bumblebee drivers in HP Omen 15-DC0053la
Lenovo Ideapad 330-17IKB randomly freezes
Artifact card game on dedicated graphics
[bumblebee, opti/primusrun] error: [XORG] (EE) kbd: <default keyboard>: failed to set us as foreground pgrp (Inappropriate ioctl for device)
Where to find resources for newbies?
Where to find resources for newbies?
Nvidia prime leads to black screen
Nvidia prime leads to black screen
[SOLVED] Issue with Nvidia Graphics
Hardware Detection Issue
XCOM 2 not using NVIDIA Drivers
Dell XPS 15 9570 with PRIME -> OS Freezes on wake up
Hardware Detection Issue
How to install nvidia drivers only?
How to install nvidia drivers only?
Unable to boot into system after installation
Optimus setup with nouveau works perfectly on live ISO but doesn't work on a fresh installation
Cannot install Manjaro with the "nonfree" driver option
Subpar browser experience
Second monitor does not work Alienware 13 i3 nvidia / intel
Dell XPS 15 (9550) Suspend to ram once; but not a second time
Multiple monitor dual gpu issues
Dell G7 i7 w GTX1060 6gb
Enabling GPU in Steam Games - Crash on Startup
Need help with my laptop's recovery and driver installation
Dell G7 i7 w GTX1060 6gb
Issues setting up PRIME on a laptop
Random crashes w/flickering black bars
Bad Hardware Support for new devices (laptops) and nVidia cards (mobile variant)
Nvidia proprietary drivers not installable
Install Works, but black screen after login
Bad Hardware Support for new devices (laptops) and nVidia cards (mobile variant)
Black screen after login each time after installing nvidia driver
Dell XPS 15 9570 Discrete Graphics
Unable to install Manjaro, problem with dual graphics
Lock Screen Freeze Manjaro 18 XFCE with Nvidia Prime
Nvidia driver problems
Is it possible to use Prime like in Ubuntu?
[SOLVED] System hang when using mhwd on Entroware Kratos
Optimus laptops & Steam Play (Proton), any news?
[Steam][Bumblebee] Cs:go/dota2 MX940
Manjaro uses integrated graphics card instead of dedicated
[Testing Update] 2018-02-14 - Kernels, Plasma, KDE Framework, Themes
When will PRIME support be added to mhwd?
Cannot manage to have a external monitor and laptop display working at the same time
Installing manjaro linux to external hdd
[Solved] Open GLX Extention not supported by display
System76 & Manjaro
HDMI port not working on Dell Inspiron 7567
[Solved] "NVIDIA X driver not loaded" when running nvidia-settings
[SOLVED] Nvidia Prime Issue With Inspiron 15 GTX 1050TI
[SOLVED] Nvidia Prime Issue With Inspiron 15 GTX 1050TI
NVIDIA Setting Restore on Boot
[SOLVED] Nvidia Prime Issue With Inspiron 15 GTX 1050TI
BIOS allows discrete and hybrid nvidia, but how does manjaro swap?
BIOS allows discrete and hybrid nvidia, but how does manjaro swap?
NVIDIA-bumblebee stops working, needs to be reinstalled
Nvidia-intel hybrid performance issue
Nvidia-prime - manjaro
Dell laptop -- hybrid Intel/nVidia 1050Ti -- dual-monitor issues
Dell laptop -- hybrid Intel/nVidia 1050Ti -- dual-monitor issues
Dell laptop -- hybrid Intel/nVidia 1050Ti -- dual-monitor issues
Intel HD 630 and Nvidia problem
NVIDIA issue (hybrid graphics and non-free driver)
Primusrun very slow?
Trouble installing Manjaro on System with Nvidia GTX 1050 Ti
[SOLVED] Bad performance with Steam game using Nvidia bumblebee
Getting stuck after entering login details
GDM + Bumblebee = black login screen
Can't make Intel + Nvidia gpu's works
Can't boot to manjaro after installing NVIDIA drivers
Fragen zu Intel/Nvidia Hybrid Grafik und nonfree Treiber
Only boot on dual screen
External monitor does not work (hdmi)
(940mx + intel ) Nonfree driver issue ! Looking for helps :(
[SOLVED] UI of some apps not responding but I know they're working and "could not enable discrete graphics"
Manjaro stopped booting
Xorg can't find GLX for Nvidia
[求助]无法安装intel+nVidia混合驱动
Multiple issues with laptop's GPU
MCE and other problems
[SOLVED] New laptops i7-8750
Deepin Screen Tearing with NVIDIA Drivers - HP Envy
Start with black screen after non-free nvidia-driver installation
Boot Stuck at TPM Error
Start with black screen after non-free nvidia-driver installation
Video-Hybrid-Intel-Nvidia-Bublebee External Display
Video-Hybrid-Intel-Nvidia-Bublebee External Display
Dell XPS 15 9560 - Dual Display (HDMI Out, USB-C to HDMI Adapter Out)
[SOLVED] OpenGL not detected with primusrun and NVIDIA 390xx
Old desktop (6 years) and nvidia GeForce GT 730
[TOC] Nvidia GPU related Tutorials
Nvidia prime fail to load nouveau driver
Setting up PRIME reduces resolution to 960x540 (16:9)
Prime profiles missing?
Use so called prime instead of bumblebee for nvidia optimus based laptops
Problem with Manjaro on MSI GP72MVR 7RFX gaming laptop
A question about this tutorial (prime with nvidia driver)
How to only use Nvidia drivers?
Fan at maximum speed
Problem installing NVIDIA Drivers - without NVIDIA Optimus
Need help for Nvidia Prime setup
OS not booting. Lighted black screen with white underscore
OS not booting. Lighted black screen with white underscore
Running dedicated GPU Card in my laptop
Manjaro hangs after login on MSI GS63VR
Black screen after installing nvidia drivers - laptop dont work with nvidia drivers only!
Which GPU driver should I use?
Bumblebee: optirun working, primusrun not working
Unreal Engine crashes on Manjaro on Vulkan and too slow on OpenGL
Asus Nvidia GTX1050M, Drivers keeps crashing
Hybrid laptop - Intel + Nvidia GPU
NVIDIA 435.17 driver looks exciting
Nvidia render offloading
Trouble with Steam -- hangs on "installing breakpad exception" -- suspect issue with drivers
Monitor detection lost after install Nvidia driver
Could not load GPU driver
How to properly disable intel GPU (hybrid GPU notebook)
There is a problem with the dual screen display when installing the NVIDIA driver prime?
An option for an MX150 GPU?
blank screen when booting nvidia driver
Installing Nvidia drivers
No sound over HDMI - Nvidia Prime setup
Primary laptop display (eDP1) not detected/connected after upgrade
Video drivers on Asus Zenbook Pro
Primary laptop display (eDP1) not detected/connected after upgrade

Fantastic writeup! More people should be aware of the advantages. Once you leave bumblebee behind you never look back.

1 Like

A bit off-topic, any idea when 390 will hit Stable branch?

With the next stable update. :wink:

Nice.

Will boot parameters replace the need for a startup script and modprobe configuration?

GRUB_CMDLINE_LINUX_DEFAULT= "nvidia-drm.modeset=1

No.

Yes. It’s a different way of setting the same option.

Are these extensions enabled by default? Are they even necessary?

Section "Extensions"
    Option "Composite" "Enable"
    Option "RENDER" "Enable"
EndSection

you can try (“Composite” “Enable” should work) and check xorg.log, it will say enabled or unknown option or something like that

e.g:

grep Composite .local/share/xorg/Xorg.0.log
[    12.470] (**) Extension "Composite" is enabled
[    12.803] (II)         Composite (RENDER acceleration)

be aware that xorg.log could be either in .local or in /var (depends if started as user or with root permissions)
if unsure check timestamp

1 Like

I was curious if these options are already on default and if setting through the extensions section is redundant. Also, for a compositing window manager like Cinnamon, would it even have an effect to enable through Xorg?

I have it set to run as root to ensure KMS is active.

remove it and check xorg.log if its still enabled
(or xdpyinfo|grep Composite)

I really dont know

So, according to arch wiki Composite isn’t needed for window managers that already include. I assume that means Damage and Render extensions are redundant also.

ARCHWIKI: Some window managers (e.g. Compiz, Enlightenment, KWin, Marco, Metacity, Muffin, Mutter, Xfwm) do compositing on their own. For other window managers, a standalone composite manager can be used.

A post was split to a new topic: When will PRIME support be added to mhwd?

Can you please explain why you say so? :thinking:
From what I see in OP’s table both gpus are enabled all the time, so I assume this is a PC only solution?

That’s about it.

What kind of difference are we talking about? As far as I have read it is said that bumblebee is not reducing performance. So I am really curious.

Also, I assume on laptop it is a battery draining solution?

It’s all hardware-dependent. The only way to see if it works better for you is to try it.

The point of the OP was not to discuss the relative merits, but the method of switching from render offload to display offload, only including a brief overview of the differences in the introduction.

There is a small mistake here the option requires a boolean as it is presented here it will hang the system.

Reference:

Option "AllowEmptyInitialConfiguration" "boolean"

    Normally, the NVIDIA X driver will fail to start if it cannot find any display devices connected to the NVIDIA GPU. AllowEmptyInitialConfiguration overrides that behavior so that the X server will start anyway, even if no display devices are connected.

    Enabling this option makes sense in configurations when starting the X server with no display devices connected to the NVIDIA GPU is expected, but one might be connected later. For example, some monitors do not show up as connected when they are powered off, even if they are physically connected to the GPU.

    Another scenario where this is useful is in Optimus-based laptops, where RandR 1.4 display offload (see Chapter 32, Offloading Graphics Display with RandR 1.4) is used to display the screen on the non-NVIDIA internal display panel, but an external display might be connected later.

    Default: off. The driver will refuse to start if it can't find at least one connected display device.

@jonathon following this tutorial using my modification did work here but the system started to overheat and I had to manually run the whole startkde to the gpu which was bad. I remmember I did not have to do it on my good setup so I dont know what I did have that differs from this that you posted

According to the NVIDIA driver documentation it does not require a boolean.

You might want to link to your source.

http://us.download.nvidia.com/XFree86/Linux-x86/390.48/README/xconfigoptions.html

if its working without should be logged in xorg.log