Shell – Debian: How to get the current loaded kernel package name

debianlinux-kernelshell

With the following command, I can list all the installed kernel package:

$ dpkg -l | grep linux-image

With the following command, I get for instance the version of the current kernel used:

$ uname -r

However, my needs is to just display in a terminal, the Debian package name corresponding of the current loaded kernel.

As multiples packages names can have the same version, it is difficult to identify uniquely a particular kernel with the previous commands.

So… Do you have an idea to get the package name of the current kernel ?

Best Answer

Use this:

$ dpkg --get-selections | grep -o "^linux-image-$(uname -r)"
linux-image-3.13.0-32-generic

or

$ dpkg -l | grep -o "linux-image-$(uname -r)"
linux-image-3.13.0-32-generic

EDIT: If you have multiple versions of the same kernel release, run the following bash script:

#!/bin/bash
rel="$(uname -r)"
ver="$(uname -v)"
current="${rel%-*}.${ver:1:2}"
echo "$(dpkg -l | grep -Po "linux-image-${rel}(?=\s+${current})")"
Related Question