Available here
Table of Contents
Summary
Based on the tutorial by Clear Linux, I wrote several bash scripts that automate the installation, update, and uninstallation, of NVIDIA proprietary driver.
There’s no need to give them execute permission to make them executable. To run a script, execute bash ./<SCRIPT-NAME>.bash
WITHOUT sudo
.
To install the driver, the user needs to execute pre_install.bash
, install.bash
, and post_install.bash
, in that order, with reboots after executing the first script.
Similarly, to update the driver, the user needs to execute pre_update.bash
, update.bash
, and post_update.bash
, in the same manner.
To uninstall the driver, just execute uninstall.bash
. This script is also helpful when installation/update failed, which helps to restore your system to the initial state.
Note that the uninstall script invokes the official installer to uninstall files from NVIDIA proprietary driver, and it should be sufficient. But incase something is left behind, the cleaning.bash
script is provided, but normally you shouldn’t execute it.
Detailed description for each script
1. pre_install.bash
- For
Intel
system, disablesIOMMU
in the kernel. - Creates a systemd unit that fix problems regarding
libGL
library. - Installs
kernel-native-dkms
orkernel-lts-dkms
bundle based on your kernel type, if not found. - Disables nouveau driver by blacklisting it in
/etc/modprobe.d/disable-nouveau.conf
- Reminds the user to reboot, and to run
install.bash
script to proceed to installation.
Note: After the reboot the GUI desktop environment may not work, then you need press Ctrl+Alt+F2
to enter tty2
, from which you can log-in and proceed to the next step.
2. install.bash
-
Locates NVIDIA driver installer,
NVIDIA-Linux-x86_64-<VERSION>.run
, under current directory.- If there are multiple installers found, chooses the latest.
- If no installer is found, tries to download the latest NVIDIA driver for Linux x86-64 system.
-
Modifies config file for dynamic linker,
/etc/ld.so.conf
, to include libraries of NVIDIA drivers, which are installed under/opt/nvidia/lib
and
/opt/nvidia/lib32
. -
Modifies
Xorg
configuration file,/etc/X11/xorg.conf.d/nvidia-files-opt.conf
, so that it search for additional modules under/opt/nvidia/lib64/xorg/modules
-
Installs the driver with the following options:
--utility-prefix=/opt/nvidia --opengl-prefix=/opt/nvidia --compat32-prefix=/opt/nvidia --compat32-libdir=lib32 --x-prefix=/opt/nvidia --x-module-path=/opt/nvidia/lib64/xorg/modules --x-library-path=/opt/nvidia/lib64 --x-sysconfig-path=/etc/X11/xorg.conf.d --documentation-prefix=/opt/nvidia --application-profile-path=/etc/nvidia/nvidia-application-profiles-rc.d --no-precompiled-interface --no-nvidia-modprobe --no-distro-scripts --force-libglx-indirect --glvnd-egl-config-path=/etc/glvnd/egl_vendor.d --egl-external-platform-config-path=/etc/egl/egl_external_platform.d --dkms --silent
-
Note: In previous version of this script, I removed
--no-nvidia-modprobe
because it’s needed for CUDA toolkit to work properly. I added it back since the official tutorial on CUDA solved this problem.
-
Note: In previous version of this script, I removed
-
Before the actual installation, users will be reminded to run the
post_install.bash
, and they need to press a key to continue installation.
3. post_install.bash
- Checks the NVIDIA kernel modules are correctly loaded on the system, which shall not be empty or otherwise the installation is not successful.
- Prompts the user whether to install a desktop file for
nvidia-settings
.
4. uninstall.bash
- Removes files created for IOMMU and OpenGL workarounds.
- Re-enables nouveau driver by removing
/etc/modprobe.d/disable-nouveau.conf
. - Restores Xorg configuration
- Restores dynamic linker configuration.
- Removes the desktop file for
nvidia-settings
if it was created. - Uninstalls NVIDIA proprietary driver via the official uninstaller,
/opt/nvidia/bin/nvidia-uninstall
. - Reminds the user to reboot.
5. pre_update.bash
- Verifies that NVIDIA proprietary driver is currently installed and displays the current driver version.
- Retrieve the latest driver version and check whether an update is needed.
- If there’s a update and the installer is not downloaded yet, download the installer.
- Temprarily set the boot target to
multi-user.target
. - Remind the user to reboot and execute
update.bash
.
6. update.bash
- Update the driver with the same options as
install.bash
has. - Restore the boot target to
graphical.target
.
7. post_update.bash
- Same as
post_install.bash
that checks NVIDIA kernel moduels are loaded. - Updates
flatpak
runtimes.
8. cleaning.bash
- Sometimes NVIDIA’s official uninstaller still leaves certain files behind and this scripts will remove those files. One possible scenario is when the installer does not succeed.
/opt/nvidia/
-
/usr/src/nvidia*/
, this is directory has source files of NVIDIA DKMS module -
/usr/bin/nvidia-modprobe
, this is installed if the installer was not invoked with--no-modprobe
flag -
/usr/lib/libGL.so.1
, though we specified library prefix, somehow this file exists
Known Issues
- It’s been reported that
gnome-control-center
will not work due to incorrectlibGL
1, but this is fixed by the workarounds provided inpost_install.bash
. - If there is a integrated GPU on Intel Chip-set, the user has to disable the Intel VGA driver, or otherwise he will see the following error message2.
- It’s been reported that compilation of NVIDIA dkms module may fail due to
gcc
error, andthe cause is unknown3this is a known structural issue of NVIDIA driver4. When this happens, the Official uninstaller may left certain files behind. This is taken care bycleaning.bash
.
Footnotes
1 GitHub Issue #791 - 2060 rtx: Black screen after login live usb
2 Clear Linux Forums - Bash scripts to automate installation of NVIDIA proprietary driver
3 GitHub Issue #974 - Error during compilation of NVIDIA dkms module
4 GitHub Issue #1725 - not able to compile nvidia dkms module
This file was last updated on 2020/03/10