Linux - uname in chroot

By xngo on March 2, 2019

When building a new Linux kernel version in chroot environment, don't use uname -r because it will return the kernel version of the running system, not the chroot. Instead, use

dpkg-query -W -f='${binary:Package}\n' linux-image-* | head -n 1 | sed 's/linux-image-//'

dpkg-query will return the kernel that was installed and then you extract the version using head and sed commands.

The command above is useful in the situation where you are running linux-image-3.16.0-4-amd64 and you want to build a new system with the latest kernel(e.g. linux-image-4.5.0-0.bpo.1-amd64) from jessie-backports repository.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.