Skip to content

A simple shell script to switch between Intel/NVIDIA graphics

License

Notifications You must be signed in to change notification settings

manu-mannattil/gpu-select

Repository files navigation

gpu-select

gpu-select is a simple shell script to switch between Intel/NVIDIA graphics on PRIME systems. It's similar in functionality to Ubuntu's prime-select command.

Installation

gpu-select requires bbswitch (Debian package bbswitch-dkms) from the Bumblebee Project. To install gpu-select, clone this repository and run make install as root.

The X configuration files that gpu-select uses are installed in /etc/gpu-select. Intel and NVIDIA specific configuration are kept in the files intel.conf and nvidia.conf of that directory. One should ensure that the correct bus ID for the devices have been set in the configuration files. To find the bus ID, see lspci's output, e.g.,

$ lspci | grep -E '3D|VGA'
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (Whiskey Lake) (rev 02)
3c:00.0 3D controller: NVIDIA Corporation Device 1d34 (rev a1)

X requires decimal bus IDs (as opposed to the hexadecimal bus IDs that lspci shows) in its configuration files. Since 3c is 60 in decimal, the decimal bus ID of the NVIDIA device in the above example is 60:0:0.

Usage

The basic usage is

gpu-select intel|hybrid|nvidia|query

The options nvidia and intel turn the GPU on/off and configures X to run on the NVIDIA GPU/Intel graphics. The option hybrid turns on the GPU, but configures X to run on Intel graphics. (Depending on the supplied option, the appropriate X configuration file is copied from /etc/gpu-select to the xorg.conf.d directory.) And finally, the option query reports the state, which can also be read from the file /etc/gpu-select/state.

Note that the installation blacklists all NVIDIA drivers by default. This means that even if the discrete GPU is selected, the system reverts back to Intel graphics and powers down the GPU on reboot.

Also, gpu-select doesn't configure xinit for you. Hence, one should check if the discrete GPU is turned on before starting X and run the appropriate xrandr call, e.g., by adding the following snippet in ~/.xinitrc:

#!/usr/bin/env bash
# ~/.xinitrc

gpu=$(</etc/gpu-select/state)
if [[ "$gpu" == "nvidia" ]]
then
  xrandr --setprovideroutputsource modesetting NVIDIA-0
  xrandr --auto
fi

# rest of ~/.xinitrc

Issues

Sometimes, bbswitch fails to turn the GPU off, e.g.,

$ echo "OFF" >/proc/acpi/bbswitch
$ cat /proc/acpi/bbswitch
0000:3c:00.0 ON

On some Lenovo ThinkPads (e.g., P53s, P43s, T490, etc.) this issue can be fixed by passing acpi_osi='!Linux-Lenovo-NV-HDMI-Audio' to the kernel parameters (see here and here).

Some laptops may also require adding pcie_port_pm=off to the kernel parameters for bbswitch to work. However, note that pcie_port_pm=off disables PCIe port power management, which almost always will result in poor battery life.

If modprobe refuses to remove the nvidia module and says that it's in use, check the processes using it:

lsof -n -w -t /dev/nvidia*

gpu-select has been most recently tested with bbswitch 0.8-10 and NVIDIA drivers 460.91 on Debian 11.1.

License

Public domain. See the file UNLICENSE for more details.

About

A simple shell script to switch between Intel/NVIDIA graphics

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published