Linus Torvalds has previously had some very choice words to say about NVidia with regards their interaction with open source and Linux. I've spent much of my career using (and battling with) the NVidia drivers on my Linux laptop and these are my notes that make life a little easier and better. For me, NVidia drivers at home on a PC work pretty well. They work less well on a laptop where things are a bit more complicated with external screens, hot plugging of screens, suspend, etc. I've tried the open source alternatives and they really just don't work as well in terms of stability (not that I find the NVidia proprietary Linux drivers especially stable, especially on a modern desktop under Wayland) but also in terms of power management and graphical performance. Hence, I've always concluded I'm better off running the proprietary drivers. If it weren't for the fact that the Lenovo Laptops I use at work have their external monitor connections hard wired to the NVidia card then I would probably just turn off the GPU entirely and rely on the embedded Intel GPU.
Installation
Thankfully, this is pretty simple on Fedora due to the packaging at RPM Fusion. Hence, I think the best way to install the NVidia driver on Fedora is to use the RPM Fusion repository, as follows:
- Follow the guide at https://rpmfusion.org/Configuration to install both the free and non-free RPM Fusion repositories
- Install the NVidia drivers (see https://rpmfusion.org/Howto/NVIDIA)
It is also best to set your GPU to "discrete only" mode in your UEFI/BIOS.
Note: there is a highly viable alternative repository that also I've run very successfully at Negativo17 and you can, of course, grab the drivers directly from NVidia via their unix downloads page.
Re-Build the NVidia Kernel Module
There are instances where manually kicking off the re-building of the NVidia kernel module can be useful. This can be done very easily as follows:
$ akmodsbuild --kernels $(uname -r) /usr/src/akmods/nvidia-kmod.latest
$ sudo dnf reinstall <name-of-the-output-rpm-from-above>
Note that the above will rebuild the NVidia kernel module for the current running kernel. You can swap out the $(uname -r)
piece of the command for the version string of any of your installed
kernel modules to build for a different kernel that you have.
Create a file /etc/modprobe.d/nvidia.conf
with the following content:
options nvidia NVreg_PreserveVideoMemoryAllocations=1
options nvidia NVreg_TemporaryFilePath=/var/tmp
options nvidia_drm modeset=1
These should already be on your system after installation but just in case, make sure you have the following RPMs installed by running:
$ sudo dnf install xorg-x11-drv-nvidia-power nvidia-modprobe
Ensure the nvidia suspend/resume services are enabled:
$ sudo systemctl enable nvidia-suspend.service nvidia-hibernate.service nvidia-resume.service
Note: do not enable the nvidia-persistenced.service as this can cause issues on a single GPU machine such as a laptop
Often, the installation of the NVidia driver can cause the LUKS password prompt to drop back to text mode. This isn't a problem from a functional point of view but it's not so nice to look at as the graphical prompt. If you want to restore the graphical prompt you need to ensure that the NVidia driver is built into your ram disk image. This can be achieved fairly simply, as follows:
Create a file /etc/dracut.conf.d/nvidia.conf
and add these lines (note the spaces are required in the quoted strings so that's not a mistake):
add_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm "
install_items+=" /etc/modprobe.d/nvidia.conf "
With that file in place, you can re-generate your ram disk image by running:
$ sudo dracut -f
Not strictly an NVidia related thing but while I'm on the topic of displays, on HiDPI/4k laptop screens, the console font (seen during the boot process if things go wrong) can be nearly impossible to read as it's far too small. You can resolve this issue by switching your console font to a larger font size.
First, make sure you have the relevant console font(s) installed:
$ sudo dnf install kbd-misc
Next, edit the file /etc/vconsole.conf
and change the "FONT=" line to a larger font e.g.
FONT="latarcyrheb-sun32"