Check Kernel Version in Linux

10 Ways to Check Kernel Version in Linux

The Linux kernel is the core component of the Linux operating system, responsible for managing hardware resources, processes, and memory.

Checking the kernel version is essential for ensuring compatibility with software and hardware, maintaining system security and stability, troubleshooting issues, and accessing relevant support resources.

Here are the most used methods to Check Kernel Version in Linux that help ensure compatibility, security, stability, and aids in troubleshooting:

  • uname Command: Directly prints the kernel release version.
  • hostnamectl Command: Displays the kernel version in the “Kernel” line.
  • dmesg Command: Reveal the kernel version in boot messages.
  • dpkg Command: Provide clues about the kernel version.
  • /proc/version File: Shows detailed information about the running kernel, including the version.
  • ls Command: Lists files related to the kernel, such as those in the /proc directory.

Prerequisites to Find the Linux kernel Version [Using CLI]

Provide the options below to let this tutorial work correctly and move on.

  • A Linux VPS plan running one of Linux distributions.
  • A non-root user with sudo privileges.
  • Access to the Terminal.

10 Methods to Check Kernel Version in Linux

If what is my kernel version Linux is your question, let’s go through the examples of this guide to review how to check kernel version in Linux.

In the end, you are ready to use one of the methods to find kernel version Linux.

1. uname Command

The uname command is designed to display system information. When used with the -r option, it specifically focuses on the kernel release version.

The output is typically a string of numbers and possibly letters, representing the kernel’s major, minor, and patch level.

  • Example 1:
uname -r
5.15.0-57-generic

In this example, the output indicates that the kernel version is 5.15.0-57-generic.

  • 5.15.0: This is the major, minor, and patch level of the kernel.
  • -57: This signifies a specific build or release within the 5.15.0 series.
  • generic: This might indicate a generic or common kernel configuration.

Other components in the output depending on your distribution and kernel configuration might display.

For instance:

  • -generic or -rt: These might indicate specific kernel configurations or optimizations.
  • -pae or -smp: These could refer to hardware-specific features or capabilities.

Example 2:

You can also use uname with -a option that provides a detailed overview of system information, including the kernel version:

uname -a

The output is typically formatted as follows:

Linux hostname 5.15.0-57-generic SMP PREEMPT RT x86_64 GNU/Linux
  • Linux: The operating system name.
  • hostname: The system’s hostname.
  • 5.15.0-57-generic: The kernel version, including major, minor, patch level, and build information.
  • SMP: Indicates Symmetric Multiprocessing support.
  • PREEMPT RT: Indicates Real-Time Preemption support.
  • x86_64: The CPU architecture.
  • GNU/Linux: The distribution of Linux.

To extract just the kernel version from the output, you can use grep command:

uname -a | grep "Linux version"

This will output the line containing the kernel version.

2. hostnamectl Command

While primarily designed for managing hostname information, hostnamectl can also provide valuable details about the kernel version.

  • To retrieve the kernel version using hostnamectl, simply execute the command without any additional options:
hostnamectl

This will display a comprehensive overview of system information, including the kernel version.

Look for the line labeled “Kernel” to find the specific version number:

  • Example:
Static hostname: my-hostname
   Icon hostname: my-hostname
   Chassis: desktop
   Boot ID: 5200
   Operating System: Ubuntu 22.04.2 LTS
   Kernel: 5.15.0-57-generic
   Architecture: x86_64

As you see in this example, the kernel version is 5.15.0-57-generic.

Note:

While uname -r is often the go-to method for checking the kernel version, hostnamectl provides a more versatile option, especially when you need additional system details in a single command.

3. dmesg Command

dmesg is a powerful command-line tool in Linux that displays kernel messages.

While not directly designed for kernel version checking, it can indirectly help you identify the kernel version by examining specific messages.

  • Basic Usage:
dmesg

This will display all kernel messages since the system was booted.

  • Filtering Messages:

To filter messages based on specific criteria, use the -l option to specify a log level:

dmesg -l 3

This will display messages with a log level of 3 (warning) or higher.

  • Searching for Specific Messages:

Use the -n option to specify the number of lines to display:

dmesg -n 100

This will show the last 100 lines of kernel messages.

  • Grepping for Keywords:

Combine dmesg with grep to search for specific keywords:

dmesg | grep "kernel version"

This will search for messages containing the phrase “kernel version.”

Example:

$ dmesg | grep "kernel version"
[    0.000000] Linux version 5.15.0-57-generic (build: #58-Ubuntu SMP PREEMPT RT, preempt=RT)

In this example, the kernel version is clearly stated in the message.

4. dpkg Command

While dpkg is primarily a package manager (installing, configuring, and removing packages) for Debian-based systems, it can be used indirectly to gather clues about the kernel version.

By examining the installed packages and their dependencies, you can sometimes infer the kernel version:

  • List Installed Packages:
dpkg -l

This will list all installed packages, including their names, versions, and status.

  • Search for Kernel-Related Packages:

Look for packages related to the kernel, such as:

  • linux-image-generic
  • linux-headers-generic
  • linux-modules-extra

The versions of these kernel-related packages can often provide clues about the kernel version.

For example, if linux-image-generic is version 5.15.0-57-generic, it’s likely that the kernel version is 5.15.0-57-generic.

5. /proc/version File

The /proc/version file is a pseudo-file system entry that provides detailed information about the running Linux kernel.

It’s a reliable and straightforward method to retrieve the kernel version that provides direct access to the kernel version information.

The /proc/version file contains several pieces of information about the kernel, including:

  1. Kernel Version.
  2. Build Information.
  3. Compiler Information.
  4. Configuration Options.
  • Accessing the File:

To view the contents of the /proc/version file, you can use any text editor or the cat command:

cat /proc/version

Example Output:

Linux version 5.15.0-57-generic (build: #58-Ubuntu SMP PREEMPT RT, preempt=RT)

In this example, the kernel version is 5.15.0-57-generic.

  • Extracting Specific Information:

If you only need the kernel version number, you can use the grep command to extract it:

cat /proc/version | grep "Linux version"

This will output the line containing the kernel version.

6. ls Command

This method is not a direct way to check the kernel version since ls command isn’t primarily designed for checking kernel versions.

It can only be used indirectly to gather clues about the kernel. So, for a more direct and reliable approach, refer to the previous solutions.

Using ls to List Files:

To list the contents of these directories and potentially identify relevant files, use the ls command:

ls /proc/modules
ls /proc/kcore

While the contents of these files might not directly reveal the kernel version, they can provide clues.

For example, if specific modules are present or absent, it might indicate compatibility with certain kernel versions.

List kernel image files:

ls vmlinuz-

Files starting with ‘vmlinuz-‘ are listed by this command. Often, kernel images are included in these files. Usually, the filename itself contains the version information.

Output:

vmlinuz-5.15.0-52-generic  vmlinuz-5.15.0-52-generic.old

Which shows two kernel images:

  1. `vmlinuz-5.15.0-52-generic`
  2. `vmlinuz-5.15.0-52-generic.old`

7. Using System Information Tools

This is also another method to Check Kernel Version in Linux:

  • neofetch: This tool provides a visually appealing overview of your system, including the kernel version.
  • htop: The interactive process viewer can also display the kernel version in its header.
  • inxi: A versatile system information tool that provides detailed information, including the kernel version.

8. Using Package Managers

Here’s a method that helps you to check Linux kernel version:

  • yum (RPM-based systems): Use yum info kernel to get information about the installed kernel package, including its version.
  • pacman (Arch Linux): Use pacman -Qi Linux to query the Linux package for version details.

9. Using Bootloader Configuration Files

  • GRUB: In the GRUB configuration file (/boot/grub/grub.cfg), look for lines like kernel /vmlinuz-X.Y.Z to identify the kernel version.
  • systemd-boot: Check the boot/loader/entries/ directory for entries that reference kernel images, such as linux.conf.

10. Using Kernel Documentation

To use this method, refer to the kernel documentation (often available online or in /usr/share/doc/linux-headers-X.Y.Z) for specific details about the kernel version and its features.

How Essential is Checking Linux Kernel Version?

Checking the Linux kernel version is essential for several reasons:

  • Compatibility: Different software and hardware may require specific kernel versions for optimal performance.
  • Security: Ensuring your kernel is up-to-date helps protect your system from vulnerabilities.
  • Troubleshooting: Knowing the kernel version can aid in diagnosing and resolving system issues.

My kernel version is outdated. What should I do?

Update your system using the appropriate package manager (e.g., apt, yum, pacman).

How can I find the kernel version for a previous boot?

Examine the system logs or use tools like journalctl to find older kernel boot messages.

Conclusion

Check kernel version Linux is easily possible using the methods we explained in this tutorial. Ensuring your kernel is up-to-date helps protect your system from vulnerabilities.

Knowing the kernel version can aid in diagnosing and resolving system issues and making informed decisions about updating your system, troubleshooting problems, and ensuring optimal performance.

Leave a Reply

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