Prevent Linux Kernel updates on Ubuntu with this trick

Updating your PC on a regular basis is really important if you care about your security, as with newer software you get various bug fixes as well as security fixes. However, sometimes you may want to hold on to those updates, as they might introduce bugs or cause any dependency hell. This is why some people and corporations use the LTS version of the operating systems.

LTS versions of Linux distributions and Linux Kernels receive various security updates and bug fixes for a longer duration when compared to the non-LTS versions. Now, it is important for any Linux distribution to receive these security fixes, as many critical vulnerabilities get fixed via the updates.

Few users may also want to hold on to the Linux kernel they are using. This might be because of requirement of a specific kernel version by any software program, or something else. And in this tutorial, we will learn how to prevent the kernel updates on Ubuntu. We will also demonstrate how can you ‘unhold’ these packages later on, so you can update the Linux Kernel whenever you feel comfortable using the apt command.

Do note that marking several packages to not upgrade can lead to dependency error in the long run. Only do this if you really know what you are doing.

Disable Linux Kernel updates in Ubuntu

First of all, let’s check which version of the Linux kernel you are using. You can do that by simply typing the following commands in your Terminal window:

uname -r

As you can see in the screenshot below, my Ubuntu installation is using the kernel version 6.11.0.8-generic.

Listing Kernel Versions On Ubuntu
Listing Kernel Versions On Ubuntu

Now, let’s check the current installed packages which are related to the Linux kernel, using this command:

dpkg --list | grep linux-image

As you can see below, all the packages related to the kernel are listed, and we have to add all of them to the exclusion list.

List Kernel Related Packages On Ubuntu
List Kernel Related Packages On Ubuntu

Finally, let’s add all the mentioned packages to the exclusion list by typing the following command:

sudo apt-mark hold linux-image-6.11.0-8-generic 
sudo apt-mark hold linux-headers-6.11.0-8-generic
Mark The Kernel Packages To Be On Hold
Mark The Kernel Packages To Be On Hold

You might want to replace the versions of the above packages with the versions which are present on your PC in order to exclude them while updating. Also exclude the following software packages:

sudo apt-mark hold linux-image-generic linux-headers-generic linux-generic

Now, in order to verify that the mentioned packages will indeed not update, you can type the following commands:

apt-mark showhold
Showing All The Held Packages
Showing All The Held Packages

This command will show all the packages which are put on hold and will not update whenever you run the sudo apt update command on Ubuntu.

Unhold the Packages

In case you want to upgrade these kernel packages in the future, you should know how to undo what we did earlier in this tutorial. Simply type the following command:

sudo apt-mark unhold linux-image-6.11.0-8-generic
sudo apt-mark unhold linux-headers-6.11.0-8-generic
sudo apt-mark unhold linux-image-generic linux-headers-generic linux-generic

After running this command, these packages on hold will be updated like any other program on your PC when you run the update command.

Summary

With the help of this tutorial, hopefully you were successfully able to mark the Linux Kernel packages on hold and prevent them from upgrading. You can also use this apt-mark hold to prevent any package from upgrading, however, make sure to mark the dependencies of the software as well otherwise you may encounter several dependency related issues. Do remember to update your Kernel whenever you add any new hardware to your PC, otherwise it may not get recognized by your PC because of the older Linux Kernel.

References

The Apt command guide