NVIDIA Driver Installation for Multiple Linux Kernels on Debian

When managing Linux systems with multiple kernels (e.g., stable and backports versions), a common challenge arises after installing NVIDIA drivers.

The standard installation only targets the currently running kernel, leaving alternative kernels unable to load the graphics driver. This results in a stalled graphical session when booting those kernels.

This article explains why this occurs and provides a comprehensive guide to ensuring your NVIDIA drivers work across all installed kernels, using the official .run installer package. Following these steps will create a consistent driver environment regardless of which kernel you boot.

Problem Explanation

When running the NVIDIA installer, it performs three key operations:

  1. Kernel Detection: Identifies the currently running kernel via uname -r
  2. Module Compilation: Compiles the driver module using that kernel’s headers
  3. Initramfs Update: Rebuilds only the current kernel’s initramfs when prompted

As a result, other installed kernels lack the necessary driver module in /lib/modules/<kernel-version>/kernel/drivers/video/, preventing the graphical system from starting when booting those kernels.

Read: How to display your sound card details on the terminal on Ubuntu 22.04

Prerequisites

Before beginning the installation process, ensure you have:

  1. Kernel Headers: Install headers for all kernels you want to support:
    sudo apt install linux-headers-$(uname -r)
    # Example for additional kernels
    sudo apt install linux-headers-6.7.12+bpo-amd64 linux-headers-6.9.7+bpo-amd64
  2. Downloaded Driver: Get the official NVIDIA driver package from NVIDIA’s website
    chmod +x NVIDIA-Linux-x86_64-*.run
  3. Disabled Nouveau Driver: Ensure the open-source Nouveau driver is blacklisted

Multi-Kernel Installation Methods

Two primary approaches to solving this problem are manual installation for each kernel or DKMS. We’ll cover both.

Method 1: Manual Installation for Each Kernel

The key insight is that you don’t need to reboot between installations. The NVIDIA installer provides flags to target specific kernels that aren’t currently running.

1 Install for the Currently Running Kernel

First, stop your display server:

sudo systemctl isolate multi-user.target

Then run the installer normally:

sudo ./NVIDIA-Linux-x86_64-*.run

When prompted, allow the installer to rebuild the initramfs. This handles your current kernel.

2 Install for Additional Kernels

Next, install the driver for each additional kernel without rebooting:

sudo ./NVIDIA-Linux-x86_64-*.run -K -k <kernel-version>

Replace <kernel-version> with the exact kernel version string (e.g., 6.7.12+bpo-amd64).

For example:

sudo ./NVIDIA-Linux-x86_64-*.run -K -k 6.7.12+bpo-amd64

When prompted, select Yes to rebuild the initramfs for this kernel. This step is critical.

Repeat this step for each additional kernel you want to support.

Flag Explanation:

  • -k: Specifies the target kernel version
  • -K: Skips the interactive compatibility check

Read: How to Fix NVIDIA Installation Conflicts: Disabling the Nouveau Driver on Linux

Method 2: Using DKMS (Dynamic Kernel Module Support)

DKMS provides an automated approach that rebuilds modules automatically when kernels are updated:

  1. Install DKMS package:
    sudo apt install dkms
  2. Run the NVIDIA installer with DKMS support:
    sudo ./NVIDIA-Linux-x86_64-*.run --dkms

With DKMS, the system will automatically rebuild the NVIDIA modules whenever you install a new kernel or update an existing one.

Verification

After completing the installation, verify the driver is correctly installed for each kernel:

Check Module Presence

For the currently running kernel:

ls /lib/modules/$(uname -r)/kernel/drivers/video/ | grep nvidia

For other kernels:

ls /lib/modules/<kernel-version>/kernel/drivers/video/ | grep nvidia

Check Loaded Modules

After booting into each kernel:

lsmod | grep nvidia

Boot Test

The most definitive test is to reboot your system and select different kernels from the GRUB menu to confirm each boots into a graphical session.

Maintenance Considerations

Driver Updates

When updating to a newer NVIDIA driver version:

  1. Install for your current kernel first:
    sudo ./NVIDIA-Linux-x86_64-<new-version>.run
  2. Repeat the installation for each additional kernel:
    sudo ./NVIDIA-Linux-x86_64-<new-version>.run -K -k <kernel-version>

If using DKMS, updates should propagate to all kernels automatically.

New Kernel Installations

When installing a new kernel version:

  1. Install its headers package:
    sudo apt install linux-headers-<new-kernel-version>
  2. Run the NVIDIA installer targeting this kernel:
    sudo ./NVIDIA-Linux-x86_64-*.run -K -k <new-kernel-version>

With DKMS, the module should build automatically for new kernels.

Potential Issues and Solutions

  • Installation Conflicts: If running into conflicts, uninstall existing modules before reinstalling:
    sudo ./NVIDIA-Linux-x86_64-*.run --uninstall
  • Initramfs Failures: If initramfs rebuilding fails, try manually rebuilding:
    sudo update-initramfs -u -k <kernel-version>
  • Deprecated Flags: The installer’s -a option is marked deprecated; stick to -K and -k.

Conclusion

You can achieve consistent driver support across multiple kernels by leveraging the NVIDIA installer’s kernel-selection capabilities. The manual approach gives you precise control over the installation process, while DKMS offers convenient automation for systems with frequent kernel updates.

Either method ensures that every installed kernel can properly load the NVIDIA driver during boot, providing seamless graphics support regardless of which kernel you choose to use.

 

Alex Chen

Alex is a seasoned Linux Systems Administrator and DevOps Engineer with over 12 years of experience architecting and maintaining high-availability infrastructure. He has a deep expertise in kernel tuning, shell scripting, containerization (Docker, Kubernetes), and implementing robust CI/CD pipelines. Alex is passionate about open-source software and finding elegant, automated solutions to complex IT challenges across various distributions.