Pinning the NVIDIA Driver on Ubuntu 24.04 to Avoid Kernel Update Breakage

Why Pinning the NVIDIA Driver Matters on Ubuntu 24.04

Kernel updates are a blessing and a curse. They bring new features, hardware support, and security patches, but they also can break proprietary modules that depend on a specific ABI. The NVIDIA driver is a prime example: a new kernel may require a new driver build, and if you’re running a GPU‑heavy workload or a GPU‑accelerated service, an unexpected reboot or a “module not found” error can be costly.

Ubuntu 24.04 ships with a 6.8‑series kernel and a default NVIDIA driver (currently 535.x). If you’re on a workstation, a home lab, or a self‑hosted GPU service, you’ll often want to lock the driver to a known‑good version and, optionally, lock the kernel to avoid breakage. Below is a step‑by‑step guide to pinning the driver, the kernel, and the associated modules, with an eye toward security and operational stability.


1. Identify the Exact Driver and Kernel You Need

# Show the current driver
nvidia-smi --query-gpu=driver_version --format=csv,noheader
# Example output: 535.54.05

# Show the running kernel
uname -r
# Example output: 6.8.0-24-generic

If you’re using a different GPU or a different Ubuntu release, the numbers will change. Keep them handy; they’re the keys to the next steps.


2. Pin the NVIDIA Driver in APT

The easiest way to keep the driver at a specific version is to use APT pinning. Create a file under /etc/apt/preferences.d/:

sudo tee /etc/apt/preferences.d/nvidia-driver-pin <<EOF
Package: nvidia-driver-535
Pin: version 535.54.05-*
Pin-Priority: 1001
EOF

The Pin-Priority of 1001 forces APT to keep that exact version even if newer ones appear in the archive. If you’re using a different driver package (e.g., nvidia-driver-525), adjust the package name and version accordingly.

After that, run:

sudo apt update
sudo apt upgrade

APT will now refuse to upgrade the NVIDIA driver unless you explicitly remove the pin or override it.


If you’re running GPU‑intensive workloads, you might also want to freeze the kernel. This is a bit more involved because the kernel is a core component, but it’s doable.

  1. Create a pin for the kernel package:

    sudo tee /etc/apt/preferences.d/kernel-pin <<EOF
    Package: linux-image-6.8.0-24-generic
    Pin: version 6.8.0-24*
    Pin-Priority: 1001
    EOF
    
  2. Prevent the generic meta‑package from pulling a newer kernel:

    sudo tee /etc/apt/preferences.d/linux-generic-pin <<EOF
    Package: linux-generic
    Pin: release n=24.04
    Pin-Priority: -1
    EOF
    
  3. Re‑install the exact kernel you pinned (if you’re not already on it):

    sudo apt install linux-image-6.8.0-24-generic linux-headers-6.8.0-24-generic
    
  4. Reboot into the pinned kernel:

    sudo reboot
    

After reboot, run uname -r again to confirm you’re on the expected version.


4. Make Sure the NVIDIA Modules Are Loaded Correctly

Sometimes a pinned driver can still fail to load if the kernel modules don’t match. The easiest check:

sudo modprobe nvidia

If you get an error like “module not found” or “invalid module format”, you’ll need to rebuild the module against the current kernel:

sudo dkms install -m nvidia -v 535.54.05

If you’re using the proprietary driver from NVIDIA’s own .run installer, run it again after the kernel change; it will rebuild the modules automatically.


5. Verify Everything Is Working

nvidia-smi

You should see the GPU status, driver version, and a clean output. If you see “driver not loaded” or an error, double‑check the module load step above.


6. Keep the System Secure

Even with pinned components, you still want to stay on top of security updates for the rest of the system. The best practice is to:

  • Update non‑GPU packages regularly:

    sudo apt update && sudo apt upgrade
    
  • Only re‑apply the pin when you’re ready to upgrade the driver:

    Remove the pin file and let APT install the new driver:

    sudo rm /etc/apt/preferences.d/nvidia-driver-pin
    sudo apt update && sudo apt upgrade
    
  • Use unattended-upgrades for critical security patches, but exclude the GPU driver and kernel packages:

    Edit /etc/apt/apt.conf.d/50unattended-upgrades and add:

    Unattended-Upgrade::Package-Blacklist {
        "nvidia-driver-535",
        "linux-image-6.8.0-24-generic",
        "linux-headers-6.8.0-24-generic"
    };
    

7. Rollback If Something Goes Wrong

If you accidentally upgrade the driver or kernel and the system becomes unstable, you can roll back:

sudo apt install nvidia-driver-535=535.54.05-*
sudo apt install linux-image-6.8.0-24-generic=6.8.0-24*
sudo reboot

Because the pin files are still in place, APT will keep those exact versions until you remove the pins.


TL;DR

StepWhat you doWhy
Pin driverAPT preferences filePrevent accidental upgrade
Pin kernelAPT preferences fileKeep ABI stable
Load modulesmodprobe or dkmsEnsure driver works with kernel
Verifynvidia-smiQuick sanity check
Secureunattended-upgrades blacklistKeep rest of system up‑to‑date

TAGS: ubuntu, nvidia, driver, kernel, pinning


See also