How To Get Linux Kernel Version

How To Get Linux Kernel Version

Reading time1 min
#Linux#Kernel#OpenSource#LinuxKernel#SysAdmin#Troubleshooting

How to Get Your Linux Kernel Version—Fast, and Why This Matters

Working with hardware drivers, deploying kernel modules, or troubleshooting system bugs? Kernel release versions matter. Compatibility issues, CVE patch validation, or initrd/module mismatches can all be traced back to running the wrong kernel—or not knowing which kernel is currently active.

Quick Reference: Kernel Version Checks

Most direct:

uname -r

Typical output:

5.15.0-70-generic

Interpreted as:

  • 5 (major),
  • 15 (minor),
  • 0 (patch),
  • 70-generic (build & packaging info; distribution-specific)

It’s fast, reliable, works on every major distro (Ubuntu, RHEL, SUSE, Arch).

Extended Details (uname -a)

uname -a

Sample output:

Linux node01 5.15.0-70-generic #77-Ubuntu SMP Fri Mar 24 13:00:05 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Includes architecture, hostname, kernel release, and full build string. Useful for support cases where vendor build or exact architecture is needed (e.g., cross-compiled images on ARM vs x86_64).

/proc/version: Forensic Kernel Provenance

Use:

cat /proc/version

You’ll get compiler flags, builder info, and build tool versions:

Linux version 5.15.0-70-generic (buildd@lcy02-amd64-037) (gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0, GNU ld (GNU Binutils for Ubuntu) 2.40) #77-Ubuntu SMP Fri Mar 24 13:00:05 UTC 2024

Side note: If debugging a failed kernel module build (invalid format errors, symbol mismatches), cross-check gcc version here. Modules built with mismatched toolchains or different CONFIG_* options often fail silently.

systemd-based Systems: hostnamectl

On systems running systemd (e.g., Ubuntu 20.04+, CentOS 8+):

hostnamectl | grep Kernel

Returns:

Kernel: Linux 5.15.0-70-generic

Handy when scripting automated inventory or when issuing remote (SSH) queries across fleet nodes.


Table: Command Comparison

CommandOutput DetailUseful For
uname -rKernel release shortQuick checks, scripting
uname -aFull system/kernel infoSupport, bug reports
cat /proc/versionBuild/compiler infoDebugging, compiling modules
hostnamectlUser-friendly, one-linerInventory, dashboards

Additional Insights and Reality-based Tips

  • Installed vs. Running Kernels:
    Vendors ship multiple kernels with OS updates. dpkg --list | grep linux-image (Debian/Ubuntu) lists all installed kernel images:

    ii  linux-image-5.15.0-70-generic  5.15.0-70.77~20.04.1   amd64  Signed kernel image generic
    

    Gotcha: After apt upgrade, the newest kernel is installed but not always active until reboot. uname -r shows only the currently running kernel.

  • Kernel Headers:
    Required for building out-of-tree modules. Check with:

    dpkg -l | grep linux-headers
    

    If you see errors like

    ERROR: missing kernel headers
    

    during dkms or make, mismatched or missing kernel headers are likely.

  • Advanced (Not Obvious): Check /lib/modules/$(uname -r)/build
    Symlink should point to the matching headers. If absent or broken, module builds for drivers (NVIDIA, ZFS, wireguard) will fail.

  • Source Tree Versions:
    If you're deep debugging (e.g., patching drivers), inspect /usr/src/linux-headers-$(uname -r)/Makefile for the exact VERSION, PATCHLEVEL, and SUBLEVEL.

Known Issue

On certain containerized environments (Alpine, minimal Docker images), /proc/version or even uname may not reflect the host kernel correctly due to namespaces or image limitations. In these cases, bind-mount /proc or check the orchestrator’s capabilities.

Practical Example: Diagnosing a Driver Failure

You see:

modprobe: ERROR: could not insert 'v4l2loopback': Invalid module format
dmesg | tail
... v4l2loopback: version magic '5.15.0-72-generic SMP mod_unload ' should be '5.15.0-70-generic SMP mod_unload '

Mismatch in module build and running kernel. Solution:

  • Confirm with uname -r
  • Rebuild the module against the active kernel

Summary

For Linux system troubleshooting, rapid identification of the active kernel version is non-negotiable. Rely on uname -r for most tasks, escalate to /proc/version or dpkg for module/driver debugging or when verifying installed but inactive kernels. Don’t trust post-upgrade states without a reboot. And on clusters, automate this as part of your node health checks—unexpected kernel drift causes subtle bugs.

Some things never change: Kernel details are still the cornerstone of reliable Linux system administration.