Nvidia Drivers on Rocky Linux

Preface

An nvidia gpu is one of the common chips in use on almost all operating system platforms. It is generally common for users to install Rocky Linux (or any other Enterprise Linux) or Fedora Linux and then want to install the drivers. There are many guides online and most are conflicting or have information that may not even be needed for the general user.

The goal of this post is to provide the general recommendations and instructions for installing the nvidia driver on a Rocky Linux system.

General Information

There are multiple ways to install the nvidia driver for Rocky Linux. It depends multiple factors such as the major version and your GPU card model. The installation of the drivers relies on dnf repos and avoids the use of the .run installer that nvidia provides.

Current versions this applies to

  • Rocky Linux 8 (latest)
  • Rocky Linux 9 (latest)

Notes on Community Approved Repositories

Rocky Linux has a set of community approved repositories detailed on the wiki. RPMFusion is listed as approved. Nvidia is not listed. Even though this is the case, information on installing the driver from both repositories are provided here, but it should be noted that RPMFusion or ELRepo will always be recommended first when it comes to drivers.

Notes on Secure Boot

Secure boot may be problematic for you when using these drivers. You are (unfortunately) recommended to disable secure boot. You can verify if it is enabled by running mokutil --sb-state.

Notes on why not to use the .run method

The .run installer is never recommended. It is known to overwrite system files and is not sustainable across the life of the distribution’s updates. It is always recommended to use rpm/dnf installation methods.

Installation

Using the RPMFusion driver

RPMFusion is a community approved set of third-party repositories for Fedora and Enterprise Linux systems. RPMFusion contains not just the nvidia driver, but also various multimedia packages and other applications that may be of interest to users.

To install the nvidia drivers, the basic steps come down to:

  • Enabling epel and rpmfusion repositories
  • Installing the driver for your specific card

Initial system setup below.

# rpmfusion-free-release and epel-release are part of extras
% dnf install rpmfusion-free-release epel-release

# rpmfusion-nonfree is currently *not* part of extras
% dnf install --nogpgcheck \
  https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm

# CRB/PowerTools must be enabled
% crb enable

# Perform a dnf update now
% dnf update -y

# Reboot if you had a kernel update
% init 6

While the driver installation is straight forward, it may vary from card to card. If your card does not work and you find that it is no longer supported with the latest driver, you may need an older driver instead. It is highly recommended to review the RPMFusion Wiki for more information to see if your card is supported with another provided driver.

Note: When installing the driver, wait for the transaction to complete. This may take up to 5+ minutes, depending on the driver package you are installing.

# Install the kmod driver
% dnf install kmod-nvidia

# If you wish to use the akmod, the below can be ran instead
% dnf install akmod-nvidia

# Once installation is done, reboot
% init 6

Some users may want cuda support. RPMFusion does provide a cuda subpackage.

% dnf install xorg-x11-drv-nvidia-cuda

If you wish to use the CUDA toolkit from the official nvidia repos with rpmfusion, please see this dedicated page on the topic.

Using the ELRepo driver

ELRepo is a community approved set of third party repositories for Enterprise Linux systems that provides drivers not provided by the stock Red Hat kernel. They also provide long term and main line kernels for users if they are interested.

To install the nvidia drivers from ELRepo, the basic steps come down to:

  • Enabling elrepo repositories
  • Installing the driver for your specific card

As of this writing, ELRepo 9 repositories only contain drivers for recent hardware. If you need to be selective on the driver version you need for your specific hardware, consider using rpmfusion instead.

Initial system setup below.

# elrepo-release and epel-release are part of extras
# epel may not be necessary, but it does not hurt to enable it.
% dnf install elrepo-release epel-release -y

# CRB/PowerTools must be enabled
% crb enable

# Perform a dnf update now
% dnf update -y

# Reboot if you had a kernel update
% init 6

The driver installation is straightforward.

# Install the kmod driver
% dnf install kmod-nvidia

# If you find the driver is not available, enable the testing repository.
% dnf config-manager --enable elrepo-testing

# Once installation is done, reboot
% init 6

Using nvidia’s official repos

Some users may prefer to use the drivers straight from the source. Their use cases may vary, but may come down to (but is not limited to):

  • Users who want their GPU to work on their desktops or workstations
  • Users who want their GPU to work on their servers
  • Users who want their GPU to work in the cloud in whatever form on Rocky Linux

Nvidia’s repositories can be used on Rocky Linux as they provide packages for their drivers for RHEL, thus they will generally work fine on Rocky Linux.

Note: If your card is end of life or is no longer supported by the drivers provided by nvidia, you may want to consider using RPMFusion instead, as they may have support for it.

Initial system setup:

# rpmfusion-free-release and epel-release are part of extras
% dnf install epel-release

# Get the major version and download the repo file
% curver="rhel$(rpm -E %rhel)"
% wget -O /etc/yum.repos.d/cuda-$curver.repo \
  http://developer.download.nvidia.com/compute/cuda/repos/$curver/$(uname -i)/cuda-$curver.repo

# CRB/PowerTools must be enabled
% crb enable

# Perform a dnf update now
% dnf update -y

# Reboot if you had a kernel update
% init 6

Install the necessary driver. You can see what’s available by running dnf module list.

The path of least resistance is their dkms driver. This is not pre-compiled and should generally work.

% dnf module install nvidia-driver:latest-dkms

If you prefer to have the precompiled driver instead, you can install it by choosing another module stream.

% dnf module install nvidia-driver:latest

Troubleshooting nvidia repo drivers

If you find that nouveau and the nvidia driver are at odds with each other, you may need to add blacklists with grubby. This only applies to the nvidia driver from the nvidia repos.

% grubby --update-kernel=ALL --args="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau"
% sed -i -e 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau /g' /etc/default/grub

Uninstalling

RPMFusion

% dnf remove xorg-x11-drv-nvidia\*

nvidia

% dnf remove nvidia-driver

Transitioning from .run to kmod/dkms/back to nouveau

If you used the .run installer and want to transition to kmod/dkms/back to nouveau, there are a few steps you’ll need to take to recover. The rpmfusion wiki explains how to do this here under the “Recover from NVIDIA installer” sections.

2 Likes