I am keeping Secure Boot enabled on my Fedora laptops, even when I need the proprietary NVIDIA driver. Fedora's akmods package can sign the locally built NVIDIA kernel module, but the signing key has to be enrolled as a MOK first.
This is a one-time setup in most cases. After that, akmods rebuilds and signs the driver when Fedora installs a new kernel.
Why NVIDIA needs a MOK with Secure Boot
Fedora's stock kernel is signed by Fedora and can boot with Secure Boot enabled. The NVIDIA module from RPM Fusion is built locally for the installed kernel, so it is not signed by Fedora's key.
With Secure Boot enabled, the kernel runs in lockdown mode. It will reject an unsigned external module, which usually means that nvidia does not load and the system falls back to nouveau or a basic graphical driver.
A Machine Owner Key, or MOK, is a certificate enrolled through shim. The Fedora kernel trusts this key for kernel module signatures. akmods uses its local key to sign the NVIDIA module after it is compiled.
I already use a similar setup on Arch with a Unified Kernel Image. My Arch Linux Secure Boot with systemd-boot, sbctl and a Unified Kernel Image post covers that side of Secure Boot. Fedora is a bit easier here because shim and MOK enrollment are already part of the default boot chain.
Install the RPM Fusion NVIDIA driver
I assume that the RPM Fusion free and nonfree repositories are already enabled. For the normal proprietary driver package I install akmod-nvidia.
# dnf install akmod-nvidia
This pulls in the source package and tools needed to build a module for the installed Fedora kernel. It can take a moment after installation until the module is available.
Do not install
akmod-nvidiaandakmod-nvidia-opentogether. They provide different NVIDIA kernel module variants.
Before rebooting, I create the local akmods signing key. On current Fedora versions the helper is called kmodgenca.
Generate the akmods signing key
The key is stored below /etc/pki/akmods/. The private part stays on the machine and must not be copied somewhere else. The public DER certificate is the file enrolled into MOK.
# kmodgenca -a
# ls -l /etc/pki/akmods/certs/public_key.der
-rw-r--r--. 1 root root 1024 Nov 27 12:20 /etc/pki/akmods/certs/public_key.der
If the key already exists, kmodgenca does not need to create another one. This is important: replacing the key later means enrolling the new public key again.
I like to inspect the certificate before importing it, especially on a machine where I have tested several NVIDIA setups.
$ openssl x509 -inform DER \
-in /etc/pki/akmods/certs/public_key.der \
-noout -subject -fingerprint
subject=CN = akmods
SHA1 Fingerprint=...
The fingerprint is mainly useful to make sure I enroll the expected local key, not a random certificate from another directory.
Enroll the key with mokutil
Now I import the public key into the pending MOK list.
# mokutil --import /etc/pki/akmods/certs/public_key.der
input password:
input password again:
The password here is only used for the next reboot in the MOK Manager screen. It is not your Fedora password and it does not become a permanent disk or firmware password.
Reboot the system after the import.
# systemctl reboot
On the next boot, a blue MOK Manager screen should appear before Fedora starts. The wording varies a little between shim versions, but I use these menu entries:
- Select
Enroll MOK - Select
Continue - Select
Yes - Enter the password set with
mokutil - Select
Reboot
After the reboot, the key is trusted by shim and by the Fedora kernel.
The MOK screen is easy to miss when a laptop boots very fast. If Fedora starts normally and no enrollment happened, run
mokutil --importagain and reboot. Do not just disable Secure Boot to make NVIDIA load.
Build and sign the NVIDIA module
After MOK enrollment I force an akmods build once. Normally this happens automatically, but doing it manually makes troubleshooting much less confusing.
# akmods --force --rebuild
Checking kmods exist for 6.x.x-xxx.fcxx.x86_64 [ OK ]
Building and installing nvidia-kmod [ OK ]
Then I regenerate the initramfs. This makes sure the current boot image contains the newly built module where needed.
# dracut --force
# systemctl reboot
After logging in again, the driver should be active.
$ nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI ... |
+-----------------------------------------------------------------------------+
For my KVM machines I still pay attention to which GPU is used by the host and which one is passed through. Secure Boot signing does not change the usual IOMMU and device binding requirements from my Linux KVM GPU pass-through with identical graphic cards setup.
Verify Secure Boot and module signing
I check Secure Boot status first.
$ mokutil --sb-state
SecureBoot enabled
The enrolled key should also show up in the MOK list.
$ mokutil --list-enrolled | grep -i akmods
The more useful check is the module signer. It must not be empty.
$ modinfo -F signer nvidia
akmods
$ modinfo -F sig_id nvidia
PKCS#7
If modinfo -F signer nvidia returns nothing, the module was built unsigned or an older module is still installed. I rebuild it with akmods --force --rebuild, run dracut --force, and reboot again.
The kernel log is also helpful when something failed early during boot.
$ journalctl -k -b | grep -iE 'nvidia|verification|lockdown'
A message about an unsigned module or a failed signature normally means the MOK was not enrolled, the key files were replaced, or the module build happened before the signing key existed.
After Fedora kernel updates
For normal Fedora updates I do not need to manually sign every new NVIDIA module. akmods detects the new kernel, builds the matching nvidia module, and signs it with the same key from /etc/pki/akmods/.
After a kernel update I usually reboot once the transaction is finished. If the NVIDIA driver does not load on the new kernel, I check the running version and trigger akmods manually.
$ uname -r
6.x.x-xxx.fcxx.x86_64
# akmods --kernels "$(uname -r)" --force
# dracut --force
# systemctl reboot
Do not remove /etc/pki/akmods/ during system cleanup. That directory contains the private key matching the MOK enrolled in firmware. If it is deleted and regenerated, Fedora can still boot, but new NVIDIA modules will be signed by an unknown key and Secure Boot will reject them.
Once this is set up, Fedora updates have been mostly boring for me, which is exactly what I want from a graphics driver.