1214xx

Switch Intel and NVIDIA GPUs in Arch Linux

Written on 2019-05-12


There are a lot of laptops nowadays that use both an Intel integrated GPU and a discrete NVIDIA GPU. NVIDIA developed a technology that manages such setups. From the Arch Linx wiki:

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.

The wiki describes how to take setup OPTIMUS graphics using different methods. I'm going to show you how to toggle the active video card. In a perfect world, we would have dinamically switching for GPUs for both the open-source and the proprietary NVIDIA drivers, but until now, only the nouveau drivers can do this using a technology called PRIME. That's why people like me, who want to use the proprietary drivers to achieve better performance, need to use other methods, such as manual GPU switching.

There is actually a way to run programs using the NVIDIA card with proprietary drivers while anything else is working on the Intel one but it involves using Bumblebee which has no support for Vulkan.

optimus-manager

optimus-manager is a program that intends to port the functionality of prime-select from Ubuntu-based distros. Here's how it works when you switch from the NVIDIA GPU to the Intel GPU:

  1. You are automatically logged out from your session, which also stops the X server (warning : this closes all opened applications)
  2. The Nvidia modules are unloaded and either bbswitch or nouveau are loaded instead. bbswitch is used to turn off the card on machines which do not support power management from the kernel, while nouveau is the open-source driver for Nvidia cards, which allows you to use external outputs even in Intel mode.
  3. The configuration for X and your login manager is updated (note that the configuration is saved to dedicated files, this will not overwrite any of your own configuration files)
  4. The login manager restarts a X server running on the proper GPU.

I'm going to cover the installation and usage of optimus-manager under i3 with no display manager, because this is what I use and it seems the hardest config of them all (but is still pretty simple). Instructions for other configs are available in the README and on the project's wiki (be sure to check out the FAQ too).

Installation

At the time of writing the 1.0 version is not yet released, but you can install it from the AUR:

sudo yay -S optimus-manager-git

If you want the latest stable version, install optimus-manager instead.

Add exec /usr/bin/prime-offload to your .xinitrc, after exec i3.

Usage

Switch your active GPU with:

optimus-manager --switch 
where <mode> is either nvidia or intel.

End your X session to kill the X server (default shortcut is $mod+shift+e).

Run sudo /usr/bin/prime-switch. This command must be run as root.

Restart your X server with startx. You should be now using the selected GPU. You can check which card is running with optimus-manager --print-mode.