How to Set Nvidia as Primary GPU on Optimus-based Laptops

Akashdeep Dhar, Jun Aruga, Ankur Sinha Версія F37 Last review: 2022-09-12

This page discusses third-party software sources not officially affiliated with or endorsed by the Fedora Project. Use them at your own discretion. Fedora recommends the use of free and open source software and avoidance of software encumbered by patents.

Introduction

The objective is to enable NVIDIA GPU of an Optimus-based laptop all the time and use it for every single activity. Please do not use this guide if you want to render your desktop using the integrated GPU and specifically select applications to be rendered using the NVIDIA GPU.

The steps listed here have been verified to be working on Fedora 32 Workstation. Please update your installation to include your experiences and any other tweaks that may be needed if you are using any other desktop environments.

Some guides on the internet advise a different approach to installing nVidia drivers on Fedora, such as directly using the binaries provided by nVidia. The Fedora Project cannot ensure these will always work on every Fedora release, and we therefore recommend following the steps in this document instead.

As Prime works less satisfactorily with Wayland server, following the steps provided in this guide would default the server to Xorg.

This guide requires the secure boot to be turned off to load up the unsigned NVIDIA kernel modules.

In order to make all the rendering default to the NVIDIA GPU, you need the follow the steps very carefully.

First, you need to see if you really want to achieve this.

Why would you want to do that?

  • The use of NVIDIA GPU all the time would allow for smoother transitions and richer animation effects. Premium desktop environments like GNOME would benefit a lot from this.

  • Enabling the NVIDIA GPU all the time would lead to lower CPU load and memory consumption which otherwise would have been high due to added in-memory video buffer.

Why would you not want to do that?

  • With the NVIDIA GPU used all the time, there would be a slight increase in battery consumption which should not be a concern if your device is used while being plugged in.

  • Increased generation of heat from the all-the-time enabled NVIDIA GPU can be worrisome. You would not want to play AAA-titles on Proton while placing your laptop on your lap.

Step #1: Update from the existing repositories

Execute

sudo dnf upgrade

once to update all your packages first.

how to set nvidia as primary gpu on optimus based laptops 0

Step #2: Add the RPMFusion repository for NVIDIA drivers

Then you need to add the RPM Fusion repository for NVIDIA drivers. To do that, open up GNOME Software and click on the hamburger menu (three horizontal lines) on the top-right corner. Then click on Software Repositories from the dropdown menu. There you will see this.

how to set nvidia as primary gpu on optimus based laptops 1

Select RPM Fusion for Fedora 32 - Nonfree - NVIDIA Driver and ENABLE it. It requires elevated privileges so enter your password and it will be done.

Step #3: Update from the newly added repositories

Execute

sudo dnf upgrade --refresh

to fetch all available updates from the newly added repository.

how to set nvidia as primary gpu on optimus based laptops 2

Step #4: Install the driver and its dependencies

Execute

sudo dnf install gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686

to get the driver and all necessary dependencies.

how to set nvidia as primary gpu on optimus based laptops 3

Step #5: Wait for the kernel modules to load up

You must wait 5-10 minutes for the kernel modules to load. Please do not proceed to the next steps immediately.

Step #6: Read from the updated kernel modules

Execute

sudo akmods --force
sudo dracut --force

This would force the configuration to be read from the updated kernel modules which now have the NVIDIA drivers in them.

Step #7: Reboot your system

Wait for 3-5 minutes for the changes to take effect and then reboot your system.

Once your system has started, go to the About page in the Settings application. You are likely to see the following output.

how to set nvidia as primary gpu on optimus based laptops 4

This means that the driver installation was successful leading to the detection of two distinct video accelerators - internal and dedicated.

Step #8: Edit the X11 configuration

Please ensure that the xrandr package is installed before proceeding with this step:

sudo dnf install xrandr

Execute the following command to copy the display render details for the X11.

sudo cp -p /usr/share/X11/xorg.conf.d/nvidia.conf /etc/X11/xorg.conf.d/nvidia.conf

Once done, open up the nvidia.conf from the copy destination and edit it to add

Option "PrimaryGPU" "yes"

to the OutputClass section of it.

For example, use nano

sudo nano /etc/X11/xorg.conf.d/nvidia.conf

and make changes.

The file should look like this. Your file should look similar to this.

how to set nvidia as primary gpu on optimus based laptops 5

You can see the additions in both sections.

Save it using [Ctrl]+[S] and exit out using [Ctrl]+[X].

If you are using a display manager other than GDM (the default of Fedora Workstation), you will need to configure it appropriately. Please refer to the Arch wiki for instructions. For SDDM (the KDE spin default) on Fedora32, the Arch wiki is wrong, and you need to edit the /etc/sddm/Xsetup file, not /usr/share/sddm/scripts/Xsetup.

Step #9: Reboot your system

Reboot your system and proceed to the next steps to verify the change in configuration.

Step #10: Verify the configuration

Open a terminal and type in

glxinfo | egrep "OpenGL vendor|OpenGL renderer"

It should show your NVIDIA GPU.

how to set nvidia as primary gpu on optimus based laptops 6

Check on screenfetch.

screenfetch

It should show your NVIDIA GPU under the GPU name.

how to set nvidia as primary gpu on optimus based laptops 7

Check in your Settings application. You would see something like this in the About page.

how to set nvidia as primary gpu on optimus based laptops 8

You can make other configuration changes using NVIDIA X Server Settings application. Also the GPU would show activity in its utilization percentage to signify that it is actually working.

how to set nvidia as primary gpu on optimus based laptops 9

References

Should you face issues while following these steps or if these do not match your use case, feel free to convey your queries on Fedora Forums.

Here are the links you can refer to for obtaining more information.