Install NVIDIA Drivers

NVIDIA is a manufacture of graphics processing units (GPU), also known as graphics cards.

NVIDIA devices on Linux have two popular device driver options: the opensource drivers from the nouveau project or the proprietary drivers published by NVIDIA. The nouveau drivers are built into the Clear Linux* OS kernel and are loaded automatically at system boot if a compatible card is detected.

These instructions show how to use the proprietary NVIDIA drivers which require a manual installation.

Note

Software installed outside of swupd is not updated with Clear Linux OS updates and must be updated and maintained manually.

Prerequisites

  • A Clear Linux OS system with a desktop installed
  • A NVIDIA device installed

Install DKMS

The Dynamic Kernel Module System (DKMS) allows the NVIDIA kernel modules to be automatically integrated when kernel updates occur in Clear Linux OS.

Install the appropriate DKMS bundle using the instructions below:

Note

The Long Term Support (LTS) kernel variant is more likely to remain compatible between updates with NVIDIA drivers.

The kernel-native-dkms bundle provides the dkms program and Linux kernel headers, which are required for compiling kernel modules.

The kernel-native-dkms bundle also:

  • Adds a systemd update trigger (/usr/lib/systemd/system/dkms-new-kernel.service) to automatically run DKMS to rebuild modules after a kernel upgrade occurs with swupd update .
  • Disables kernel module signature verification by appending a kernel command-line parameter ( module.sig_unenforce ) from the /usr/share/kernel/cmdline.d/clr-ignore-mod-sig.conf file.
  • Adds a notification to the Message of the Day (MOTD) indicating kernel module signature verification is disabled.

Warning

We recommend that you always review the swupd update output to make sure kernel modules were successfully rebuilt against the new kernel. This is especially important for systems where a successful boot relies on a kernel module.

Install the kernel-native-dkms or kernel-lts-dkms bundle:

  1. Determine which kernel variant is running on Clear Linux OS. Only the native and lts kernels are enabled to build and load out-of-tree kernel modules with DKMS.

$ uname -r 5.XX.YY-ZZZZ.native

Ensure .native or .lts is in the kernel name.
2. Install the DKMS bundle corresponding to the installed kernel. Use kernel-native-dkms for the native kernel or kernel-lts-dkms for the lts kernel.

sudo swupd bundle-add kernel-native-dkms

or

sudo swupd bundle-add kernel-lts-dkms

  1. Update the Clear Linux OS bootloader and reboot.

sudo clr-boot-manager update reboot

Download and install the NVIDIA Drivers

Download the NVIDIA Drivers for Linux

  1. Identify the model of NVIDIA GPU that is installed.

sudo lshw -C display

  1. Go to the NVIDIA Driver Downloads website . Search for and download the appropriate driver based on the model of NVIDIA GPU you have with Linux 64-bit selected as the Operating System .
  2. Open a terminal and navigate to where the NVIDIA-Linux-x86_64-.run file was saved. In this example, it was saved in the Downloads folder.

cd ~/Downloads/

  1. Make the NVIDIA-Linux-x86_64-.run file executable.

hmod +x :file:`NVIDIA-Linux-x86_64-.run

Disable the nouveau Driver

The proprietary NVIDIA driver is incompatible with the nouveau driver and needs to be disabled before installation can continue.

  1. Disable the nouveau driver by creating a blacklist file under /etc/modprobe.d and reboot.

sudo mkdir /etc/modprobe.d printf "blacklist nouveau \noptions nouveau modeset=0 \n" | sudo tee --append /etc/modprobe.d/disable-nouveau.conf

  1. Reboot the system and log back in. It is normal for the graphical environment to not start with no NVIDIA driver loaded.

Configure the Dynamic Linker

The NVIDIA installer will be directed to install files under /opt/nvidia as much as possible to keep its contents isolated from the rest of the Clear Linux OS system files under /usr. The dynamic linker will need to be configured to use the NVIDIA-provided libraries.

  1. Configure the dynamic linker to look for and cache shared libraries under /opt/nvidia/lib and /opt/nvidia/lib32.

echo "include /etc/ld.so.conf.d/*.conf" | sudo tee --append /etc/ld.so.conf sudo mkdir /etc/ld.so.conf.d printf "/opt/nvidia/lib \n/opt/nvidia/lib32 \n" | sudo tee --append /etc/ld.so.conf.d/nvidia.conf

Install the NVIDIA Drivers

  1. A terminal not running on /dev/tty1 is useful to view uninterrupted installation progress. Switch to a secondary virtual terminal by pushing CTRL + ALT + F2 or remotely login over SSH.
  2. Navigate into the directory where the NVIDIA installer was downloaded.

cd ~/Downloads/

  1. Run the installer with the advanced options below.

sudo ./NVIDIA-Linux-x86_64-<VERSION>.run \ --utility-prefix=/opt/nvidia \ --opengl-prefix=/opt/nvidia \ --compat32-prefix=/opt/nvidia \ --compat32-libdir=lib32 \ --x-prefix=/opt/nvidia \ --documentation-prefix=/opt/nvidia \ --no-precompiled-interface \ --no-nvidia-modprobe \ --no-distro-scripts \ --force-libglx-indirect \ --dkms \ --silent

  1. The graphical interface may automatically start after the NVIDIA driver is loaded. Return to the working terminal and log back in if necessary.
  2. Validate the nvidia kernel modules are loaded.

lsmod | grep ^nvidia

  1. Run a Clear Linux OS system verification to restore files that the NVIDIA installer likely deleted.

sudo swupd verify --quick --fix --bundles=lib-opengl

Note

The NVIDIA software places some files under the /usr subdirectory which are not managed by Clear Linux OS and conflict with the Clear Linux OS stateless design. Although a limited version of swupd verify ā€“fix is ran above, other uses of the swupd verify ā€“fix command should be avoided with the proprietary NVIDIA drivers installed.

Updating the NVIDIA Drivers

The proprietary NVIDIA drivers are installed manually outside of swupd and must be updated manually when needed.

Updating the NVIDIA drivers follows the same steps as initial installation, however the desktop environment must first be stopped so that the drivers are not in use.

  1. Follow the steps in Download the NVIDIA Drivers for Linux section to get the latest NVIDIA drivers.
  2. Temporarily set the default boot target to the multi-user which is a non-graphical runtime.

sudo systemctl set-default multi-user.target

  1. Reboot the system and log back in. It is normal for the graphical environment to not start.
  2. Follow the steps in Install the NVIDIA Drivers section to update the NVIDIA drivers. This installation will overwrite the previous NVIDIA drivers and files.
  3. Set the default boot target back to the graphical target.

sudo systemctl set-default graphical.target

  1. Reboot the system and log back in.
  2. Trigger a flatpak update which will download the runtime corresponding with the new NVIDIA drivers for flatpak apps requiring it.

flatpak update

Uninstalling the NVIDIA Drivers

The NVIDIA drivers and associated software can be uninstalled and nouveau driver restored by:

  1. Remove the previously created file /etc/modprobe.d that prevents nouveau from loading.

sudo rm /etc/modprobe.d/disable-nouveau.conf

  1. Run the sudo /opt/nvidia/bin/nvidia-uninstall
  2. Follow the prompts on the screen and reboot the system.

Debugging Installation of NVIDIA Drivers

  • The NVIDIA driver places installer and uninstaller logs under /var/log/nvidia-install and /var/log/nvidia-uninstall.
  • NVIDIA-Linux-x86_64-.run --advanced-options shows many parameters to control installation behavior.
  • NVIDIA-Linux-x86_64-.run --extract-only extracts installation files into a directory namedNVIDIA-Linux-x86_64-.

Additional resources

4 Likes

I followed the above instructions and once I installed the Nvidia drivers with the options it restarted but only to a flashing cursor and not a bash prompt or the Clear Linux desktop. It doesnā€™t allow any input from the keyboard etc. Not sure if there is any option to recover other than to do a clean install?

There is a recovery mode in the installer. @miguelinux can you help here, please?

After powering on, press and hold space bar until the boot menu of systemd-boot appear, press e and add the following to the end of the cmdline

systemd.unit=rescue.target

Press enter and you should be brought to rescue mode where you can log in as root user and then you can uninstall the NVIDIA driver.

2 Likes

Thanks, Iā€™ll give that a go when I get home.

Also you can use swupd to fix your system.

I created a script that can be used from the CL installer ISO.
Boot with CL installer and open a terminal, and firefox to go here and copy the URL.

You can get the script with:

curl -LO https://raw.githubusercontent.com/miguelinux/fix-clr/master/fix-clr.sh
chmod 755 fix-clr.sh
fix-clr.sh <path-to-your-root-device_eg:/dev/sda3>

You can modify the script as you convenience:
The source is at: GitHub - miguelinux/fix-clr

Iā€™ll paste the script as a reference here:

#!/bin/bash

CL_ROOTFS=${1-/dev/sda3}
MOUNT_POINT=/mnt/my-cl

sudo mkdir ${MOUNT_POINT}
sudo mount ${CL_ROOTFS} ${MOUNT_POINT}
sudo mkdir -p  ${MOUNT_POINT}/var/lib/swupd
sudo chmod 700 ${MOUNT_POINT}/var/lib/swupd

# Get VERSION_ID from
source ${MOUNT_POINT}/usr/lib/os-release

sudo swupd repair --picky --version=${VERSION_ID} \
    --path=${MOUNT_POINT} \
    --statedir ${MOUNT_POINT}/var/lib/swupd \
    --no-scripts \
    --no-boot-update

sudo umount ${MOUNT_POINT}
sudo rmdir  ${MOUNT_POINT}

2 Likes

Thanks @miguelinux, Iā€™ve got Clear Linux running again.

It appears the issue I had with installing the NVIDIA Drivers was that my motherboard also had a GPU, which it must have defaulted to.

I got some good help from the Community at here: https://community.clearlinux.org/t/bash-scripts-to-automate-installation-of-nvidia-proprietary-driver

1 Like

CL Docs just published a revised tutorial on installing NVIDIA Drivers on Clear Linux OS, thanks to @puneetse.
Check out the added sections on driver selection (nouveau drivers), installation and config., and a new Troubleshooting section.

1 Like

Finaly got it to work!
Iā€™m a beginner but the following worked on my system intel i5 with geforce gtx 1060

Check if you have lts or native
uname -r

I have native so:
sudo swupd bundle-add kernel-native-dkms

Check which gpu i had
sudo lshw -C display

I have a geforce 1060 so i downloaded it from the nvidia website Official Drivers | NVIDIA

Make executable
cd ~/Downloads/
chmod +x NVIDIA-Linux-x86_64-440.44.run (your filename can be different)

sudo clr-boot-manager update
reboot

Disable nouveau driver
sudo mkdir /etc/modprobe.d
printf ā€œblacklist nouveau \noptions nouveau modeset=0 \nā€ | sudo tee --append /etc/modprobe.d/disable-nouveau.conf

sudo nano /etc/modprobe.d/disable-nouveau.conf

Check if file contains the following:
blacklist nouveau
options nouveau modeset=0

ctrl+X to exit

Restart without graphical environment
reboot

After login type
echo ā€œinclude /etc/ld.so.conf.d/*.confā€ | sudo tee --append /etc/ld.so.conf

Check with if the file contains: include /etc/ld.so.conf.d/*.conf
sudo nano /etc/ld.so.conf
ctrl+X to exit

sudo mkdir /etc/ld.so.conf.d
printf ā€œ/opt/nvidia/lib \n/opt/nvidia/lib32 \nā€ | sudo tee --append /etc/ld.so.conf.d/nvidia.conf

Check if the file contains:
/opt/nvidia/lib
/opt/nvidia/lib32
sudo nano /etc/ld.so.conf.d/nvidia.conf

Switch to tty2
CTRL + ALT + F2

Install nvidia driver
cd ~/Downloads/

sudo ./NVIDIA-Linux-x86_64-440.44.run \ ā€“utility-prefix=/opt/nvidia \ ā€“opengl-prefix=/opt/nvidia \ ā€“compat32-prefix=/opt/nvidia \ ā€“compat32-libdir=lib32 \ ā€“x-prefix=/opt/nvidia \ ā€“documentation-prefix=/opt/nvidia \ ā€“no-precompiled-interface \ ā€“no-nvidia-modprobe \ ā€“no-distro-scripts \ ā€“force-libglx-indirect \ ā€“dkms \ ā€“silent

On my system the grapical interface started automatically, check if nvidia is running:
lsmod | grep ^nvidia

Repair files that Nvidia deleted:
sudo swupd verify --quick --fix --bundles=lib-opengl

Create a link for the nvidia-settings desktop entry
ln -sv /opt/nvidia/share/applications/nvidia-settings.desktop $HOME/.local/share

Hope this helps someone, feel free to correct me, iā€™m just a beginner.

Best regards
Bram

2 Likes

Hey @bram. Welcome to the Forum. Thanks for sharing your experience in such detail.

1 Like

Iā€™ve been following the guide, but the Nvidia installer script fails because the build directory is missing:

`
$ ls /usr/lib/modules/$(uname -r)/build
ls: cannot access ā€˜/usr/lib/modules/5.4.30-25.lts2019/buildā€™: No such file or directory

$ ls -lah /usr/lib/modules/$(uname -r)/
total 3.8M
drwxr-xr-x 3 root root 4.0K Apr 4 21:31 .
drwxr-xr-x 5 root root 4.0K Apr 4 21:46 ā€¦
drwxr-xr-x 12 root root 4.0K Apr 4 20:38 kernel
-rw-rā€“r-- 1 root root 929K Apr 4 21:31 modules.alias
-rw-rā€“r-- 1 root root 905K Apr 4 21:31 modules.alias.bin
-rw-rā€“r-- 1 root root 13K Mar 31 19:35 modules.builtin
-rw-rā€“r-- 1 root root 16K Apr 4 21:31 modules.builtin.bin
-rw-rā€“r-- 1 root root 92K Apr 4 20:38 modules.builtin.modinfo
-rw-rā€“r-- 1 root root 359K Apr 4 21:31 modules.dep
-rw-rā€“r-- 1 root root 498K Apr 4 21:31 modules.dep.bin
-rw-rā€“r-- 1 root root 240 Apr 4 21:31 modules.devname
-rw-rā€“r-- 1 root root 124K Mar 31 19:35 modules.order
-rw-rā€“r-- 1 root root 480 Apr 4 21:31 modules.softdep
-rw-rā€“r-- 1 root root 403K Apr 4 21:31 modules.symbols
-rw-rā€“r-- 1 root root 491K Apr 4 21:31 modules.symbols.bin`

It seems like I need to build something, but Iā€™m lost.

FWIW, The Nouveau driver seems to be unstable with my GTX 1650 Super (glitchy/black screens), so Iā€™m hoping this will make the GUI more reliable.

@jonahbron Is your issue related to this?

Does my script fail?

@doct0rHu Iā€™m on lts2019, so I added it to the script and PRā€™d. I run into the same problem, though.

Your kernel headers for kernel 5.4.30-25.lts2019 cannot be found at
   /lib/modules/5.4.30-25.lts2019/build or /lib/modules/5.4.30-25.lts2019/source.

Thereā€™s no kernel-lts2019-dkms module now. You can follow this issue

I will merge you PR once this bundle is available.

1 Like

I read through that issue earlier. So that bundle would fix the missing build directory once itā€™s available?

If you desperately want to install the driver you can install kernel-native-dkms now. That should work.

Thanks for your help. This is a fresh install, and I was only using LTS because the guide said it would likely be more stable with proprietary drivers.

Noob question: Iā€™ve installed the native kernel bundle. Can I switch kernels or do I need to reinstall CL?

1 Like

clr-boot-manager manages kernels. You can set your default kernel with it.

After switching to native, your scripts werked flawlessly.

1 Like