Press "Enter" to skip to content

Manually upgrade to the latest Debian kernel

I recently ran into quite a few problems with one of my Debian servers attributed to an outdated kernel. For whatever reason, the specific set of software I was using had gotten updated, and that update forced a kernel level that unless met, would produce tons of issues. Needless to say, I needed to upgrade my Debian installation to a kernel version higher than what was available in the default repositories.

Using the following few commands (plus one custom command I wrote) you can easily get your Debian server on the absolute latest Linux Kernel available.

The first command is going to add the Stretch backports into our repo list.

echo "deb stretch-backports main" | sudo tee -a /etc/apt/sources.list > /dev/null

Issue the next command to go ahead and upgrade all packages on your system using the backports repo so that nothing is broken by moving up to the latest kernel.

apt-get update && apt-get -t stretch-backports upgrade

As of this writing, the latest kernel version available to my server installation is 4.18.0-0. You can, however, search for the latest kernel version by issuing the following command:

apt-cache search linux-image-*

You’ll get a list that looks something like this:

Using this screenshot, you should try and go for the image with the filename structured like “linux-image-4.18.0-0.bpo.1-amd64.” To install the latest kernel, issue the following command:

apt-get -t stretch-backports install linux-image-4.18.0-0.bpo.1-amd64

Once the installation is complete, reboot your server. When it begins to start up, ensure the latest kernel is selected in grub. Once you are logged back into the command line we want to make sure you are using the latest kernel by issuing the following command:

uname -r

If that outputs a line that looks like “linux-image-4.18.0-0.bpo.1-amd64” (or whatever kernel you just installed) that means you are using the latest kernel and everything went well.

The next bit of instruction I’m going to provide to you should not be issued unless you are completely certain your server has been backed up and those backups are functioning. I have a custom command that will go through all of the old kernels in your system and uninstall them, saving disk space and making sure grub doesn’t try booting up with an outdated kernel. This command will 100% uninstall¬†all of your old kernels. You should, however, look at installing at least one officially stable kernel from the repos to use as a fallback should anything weird happen with the bleeding-edge latest kernel you just installed.

Enough talking. Issue the following command to completely uninstall all kernels currently not in use:

uname -r && dpkg --list | grep 'linux-image' | awk '{ print $2 }' | grep -v $(uname -r) | xargs sudo apt-get purge

What this does is issues uname -r to the command line so that you can see what you are currently running. It then takes a full list of installed packages with dpkg –list. The next grep command only accepts packages with “linux-image” in the title. The next command sorts the results. The next grep command removes the currently installed kernel name from the list of names obtained from the previous pipes. The final command will take each line of kernel names and issue them as arguments against the “apt-get purge” command, meaning they will be completely uninstalled and forgotten about.

This is a completely automated solution, and I do not recommend using it unless you are willing to accept what happens if it ends up wiping out your currently active kernel. If you can accept the fate of your system blowing up and being able to restore from backups, just in case something goes wrong, feel free to give it a shot. I can tell you that I have used these exact instructions on seven different virtual Debian servers and I have had zero issues. Your mileage, though, may vary.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *