How to Roll Back a Kernel Update in Debian 12 Bookworm

This article provides a step-by-step guide on how to roll back a kernel update on a Debian 12 Bookworm system.

Kernel updates in Debian are crucial for security, stability, and performance improvements. However, sometimes a new kernel version can introduce issues such as hardware incompatibility, broken drivers, or unexpected system behavior. In such cases, rolling back to a previous kernel version can help restore system functionality.

In this guide, we will explore different methods to roll back a kernel update on a Debian 12 Bookworm system.


Understanding Debian Kernel Management

Debian typically manages kernels using the package management system APT and the dpkg tool. When a new kernel is installed, older kernels are usually retained unless manually removed. The GRUB bootloader allows users to select an alternative kernel during system startup.

By default, Debian does not automatically remove older kernels, making rollback easier. However, if the previous kernel has been manually removed, you may need to reinstall it before booting into it.


Step 1: Identify Installed Kernels

Before rolling back a kernel update, first, check which kernels are installed on your system.

Run the following command to list all installed kernel versions:

dpkg --list | grep linux-image

This will output a list of installed kernel packages. For example:

rc  linux-image-5.10.0-23-amd64  5.10.179-1   amd64   Linux 5.10 for 64-bit PCs
ii  linux-image-6.1.0-13-amd64   6.1.55-1     amd64   Linux 6.1 for 64-bit PCs
  • ii indicates an installed package.
  • rc means the package has been removed but configuration files remain.

Make a note of the previous kernel version you want to roll back to.


Step 2: Boot into an Older Kernel via GRUB

If the previous kernel is still installed, the easiest rollback method is selecting it from the GRUB bootloader.

Accessing GRUB Menu

  1. Restart your system.
  2. Hold the Shift key (or Esc on some systems) right after the BIOS/UEFI screen to display the GRUB menu.
  3. Use the arrow keys to select “Advanced options for Debian GNU/Linux” and press Enter.
  4. You will see a list of available kernel versions.
  5. Select the previous kernel version and press Enter to boot into it.

Once the system boots successfully, you can remove the problematic kernel to prevent automatic booting into it.


Step 3: Set an Older Kernel as Default

To make an older kernel the default boot option, you need to modify the GRUB configuration.

  1. Open a terminal and edit the GRUB configuration file:

    sudo nano /etc/default/grub
    
  2. Locate the line starting with GRUB_DEFAULT and modify it to specify the older kernel manually.

    GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 5.10.0-23-amd64"
    
  3. Save the file (Ctrl+X, then Y, then Enter).

  4. Update GRUB:

    sudo update-grub
    
  5. Reboot your system:

    sudo reboot
    

Now, your system will automatically boot into the selected kernel version.


Step 4: Remove the Faulty Kernel

If the newer kernel is causing issues and you wish to remove it permanently, use the following steps:

  1. Identify the installed kernels again:

    dpkg --list | grep linux-image
    
  2. Remove the unwanted kernel (replace <kernel-version> with the actual version):

    sudo apt remove --purge linux-image-<kernel-version>
    

    Example:

    sudo apt remove --purge linux-image-6.1.0-13-amd64
    
  3. Remove any unused dependencies:

    sudo apt autoremove
    
  4. Update GRUB again:

    sudo update-grub
    
  5. Reboot the system:

    sudo reboot
    

After rebooting, confirm that your system is running the desired kernel:

uname -r

This command should return the previous kernel version.


Step 5: Prevent Future Kernel Updates (Optional)

If you want to temporarily prevent kernel updates, you can hold the current kernel version using apt-mark.

sudo apt-mark hold linux-image-<kernel-version>

To remove the hold later, use:

sudo apt-mark unhold linux-image-<kernel-version>

Alternatively, configure APT to exclude kernel updates by adding the following line to /etc/apt/preferences.d/no-kernel-upgrade:

Package: linux-image-*
Pin: release *
Pin-Priority: -1

Then, update the package list:

sudo apt update

This will block kernel upgrades until the rule is removed.


Conclusion

Rolling back a kernel update in Debian 12 Bookworm is a straightforward process if an older kernel is still installed. By selecting an older kernel via GRUB, setting it as the default, and removing the faulty update, you can restore system stability. Additionally, you can prevent unwanted kernel upgrades using apt-mark or APT pinning.

It is always recommended to test new kernel updates in a safe environment before deploying them on production systems to avoid unexpected issues.