For a DevOPS script, after upgrading a Debian system I need to check the currently latest installed Linux kernel version on Debian, and compare it to the running version (uname -r).

What is the simplest way to figure this out?

How do I automatically reboot the system if necessary?

2 Answers 2


As noted in the question, the currently running kernel can be obtained via:

uname -r

The output looks like this:


In contrast, the version of the latest kernel package needs to be taken from the package manager. Assuming an amd64 architecture and a standard installation, we can check the dependencies of the linux-image-amd64 meta-package, which always points to the latest kernel package:

dpkg-query -f '${Package}: ${Depends}\n' -W linux-image-amd64

The output looks like this:

linux-image-amd64: linux-image-4.19.0-8-amd64

To put this into a shell script, two extra steps are needed. First, we should determine the architecture automatically via:

dpkg --print-architecture

The output looks like this:


Second, we need to strip the linux-image- prefix from the kernel package name:

echo linux-image-4.19.0-8-amd64 | sed s/^linux-image-//

The output looks like this:


Putting this all together and adding proper shell script quoting, we arrive at:

if [ "$(uname -r)" != "$(dpkg-query -f '${Depends}' -W "linux-image-$(dpkg --print-architecture)" | sed s/^linux-image-//)" ]; then

Best way to do this in a generic way is explained in this comment.

Copy and paste this script, make is executable and run it will give you expected result.

  • Thanks for the hint to that related question!
    – vog
    Commented Nov 24, 2023 at 21:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .