Skip to content

Laptop with Dual GPU Setup Guide

NVIDIA PRIME Render Offload

The official way from NVIDIA

Append these environment variables before running the program

Terminal window
__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia <program>

Steam

Terminal window
__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia %command%

Wrapper script

Arch Linux provides a package called nvidia-prime that helps you set the environment variables above when you run a program, to use it simply execute the following:

Installation of the Wrapper script

Terminal window
sudo pacman -S nvidia-prime

You can use prime-run now.

Terminal window
prime-run <program>

GNOME

As of GNOME 3.38 and later, you can select “Run with Discrete Graphics” from the context menu when you right-click on an application.

Optimus Manager (legacy)

Clever tool for easy switching between a laptop’s integrated GPU and the discrete one.

Modern laptops have two graphics cards, especially if we talk about gaming laptops. iGPU - integrated GPU, longer battery life, and lower performance. dGPU - discrete GPU, higher performance, but it would drain more battery, highly recommended for gaming, rendering, video encoding, NVENC among other demanding tasks.

Windows automatically switches between the iGPU and dGPU depending on the usage. Here is a guide on how to set up the same for CachyOS, especially if you plan to use it for gaming or streaming, 3D development, etc.

Tested on a laptop with an Intel CPU and a NVIDIA GPU, but since release 1.4 Optimus Manager also has support for AMD CPUs.

Preparing iGPU and dGPU for the Linux Kernel

Let’s start by configuring mkinitcpio which loads various kernel modules.

Intel iGPU

Add the following modules i915 intel_agp nvidia to the MODULES section in /etc/mkinitcpio.conf, make sure you don’t insert the same module multiple times:

Terminal window
MODULES=(i915 intel_agp nvidia)

The intel_agp module may cause issues with hibernation on some systems, see https://bbs.archlinux.org/viewtopic.php?id=262043. Try omitting the module if you encounter issues.

AMD iGPU

with AMDGPU driver

Add the following modules amdgpu nvidia to the MODULES section in /etc/mkinitcpio.conf, make sure you don’t insert the same module multiple times:

Terminal window
MODULES=(amdgpu nvidia)

with radeon driver

Add the following modules radeon nvidia to the MODULES section in /etc/mkinitcpio.conf, make sure you don’t insert the same module multiple times:

Terminal window
MODULES=(radeon nvidia)

Enable “Direct Rendering Manager” (DRM KMS)

To enable DRM we need to add the necessary kernel parameter in the bootloader, each bootloader has a different way to do that.

Using GRUB

Add nvidia-drm.modeset=1 to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub, it’ll look something like this:

Terminal window
GRUB_CMDLINE_LINUX_DEFAULT="nvidia-drm.modeset=1 ..."

Now you must use these two commands to save the modification into all the installed kernels and update GRUB.

Terminal window
# run the following commands
sudo mkinitcpio -P
sudo grub-mkconfig -o /boot/grub/grub.cfg

Using systemd-boot

(under development)

Installing Optimus Manager

Installing optimus-manager & Optimus-manager-qt (a system tray for optimus-manager)

Terminal window
sudo pacman -S optimus-manager optimus-manager-qt

The last step, we need to enable and start the service for Optimus manager

Terminal window
sudo systemctl enable --now optimus-manager.service

You can now reboot, after rebooting, you will have a fully working Optimus Manager, which you can find the icon on the bottom right corner of the taskbar.

Congrats! You are now done with the setup.

Optional configuration

Fully power down the GPU when not in use

PCI-Express Runtime D3 (RTD3) Power Management Add these rules into /etc/udev/rules.d/80-nvidia-pm.rules

Terminal window
# Load and unload nvidia-modeset module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-modeset"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-modeset"
# Load and unload nvidia-drm module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-drm"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-drm"
# Load and unload nvidia-uvm module
ACTION=="add", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe nvidia-uvm"
ACTION=="remove", DEVPATH=="/bus/pci/drivers/nvidia", RUN+="/sbin/modprobe -r nvidia-uvm"
# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind
ACTION=="bind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="auto"
# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind
ACTION=="unbind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="on"

The top three ACTION=="add" rules are not needed when running Linux kernel 5.5 and newer, see https://download.nvidia.com/XFree86/Linux-x86_64/530.30.02/README/dynamicpowermanagement.html.

Next add the following text to /etc/modprobe.d/nvidia.conf

options nvidia "NVreg_DynamicPowerManagement=0x02"

To apply these changes right now:

Terminal window
sudo udevadm control --reload
sudo udevadm trigger

Now you need to edit optimus-manager’s configuration file to enable (RTD3) Power Management by adding dynamic_power_management=fine to /etc/optimus-manager/optimus-manager.conf

Using nvidia-persistenced

Enable nvidia-persistenced.service to avoid the kernel tearing down the device state whenever the NVIDIA device resources are no longer in use.

Terminal window
sudo systemctl enable --now nvidia-persistenced.service

And finally, reboot your system. Your laptop’s hybrid mode should now work as it does on Windows!