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
|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|
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.
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
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
mhwd or MSM to install the
nvidia driver in the normal way.
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
/etc/X11/xorg.conf.d/90-mhwd.conf and replace it with:
Section "Module" Load "modesetting" EndSection Section "Device" Identifier "nvidia" Driver "nvidia" BusID "PCI:1:0:0" Option "AllowEmptyInitialConfiguration" EndSection
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
To remove the existing blacklist, edit, move or remove any related
mhwd-* files in
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
blacklist nouveau blacklist nvidiafb blacklist rivafb
Step 4: enable
Create a new file,
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.
Create a new file with the following content:
#!/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
Create a new file,
[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 above script,
[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.
Create a new file,
xrandr --setprovideroutputsource modesetting NVIDIA-0 xrandr --auto
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