How to check if a specific kernel version is running in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the version of the Linux kernel running on your system. The kernel is a fundamental part of the operating system, and knowing its version is essential for various tasks, including troubleshooting, software compatibility, and security.

You will begin by using the uname -r command, the most common method for quickly displaying the kernel release. Next, you will explore the /proc/version file within the virtual /proc filesystem to find more detailed information about the kernel. Finally, you will inspect the boot logs using the dmesg command to see kernel-related messages generated during system startup. By completing these steps, you will gain practical skills in identifying and understanding your Linux kernel version.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/BasicFileOperationsGroup -.-> linux/less("File Paging") linux/BasicFileOperationsGroup -.-> linux/more("File Scrolling") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") linux/SystemInformationandMonitoringGroup -.-> linux/uname("System Information Displaying") subgraph Lab Skills linux/cat -.-> lab-558760{{"How to check if a specific kernel version is running in Linux"}} linux/less -.-> lab-558760{{"How to check if a specific kernel version is running in Linux"}} linux/more -.-> lab-558760{{"How to check if a specific kernel version is running in Linux"}} linux/grep -.-> lab-558760{{"How to check if a specific kernel version is running in Linux"}} linux/uname -.-> lab-558760{{"How to check if a specific kernel version is running in Linux"}} end

Check kernel version with uname -r

In this step, you will learn how to check the Linux kernel version using the uname command. The kernel is the core of the operating system, managing the system's resources and providing a bridge between the hardware and the software. Knowing the kernel version is often important for troubleshooting or installing specific software.

The uname command is used to display system information. By default, it shows the kernel name. To get more specific information, you can use options.

The -r option tells uname to print the kernel release. This is the most common way to check the kernel version.

Open your terminal if it's not already open. You can do this by clicking the Xfce Terminal icon on the left side of the desktop.

Now, type the following command into the terminal and press Enter:

uname -r

You should see output similar to this, though the exact version numbers might differ:

5.15.0-XX-generic

This output tells you the specific release number of the Linux kernel running on your system. The numbers and letters represent different aspects of the kernel version, including the major version, minor version, patch level, and potentially information about the build or distribution.

Understanding your kernel version is a fundamental skill in Linux system administration and development. It helps you determine compatibility with hardware and software, and is crucial for security updates.

Now that you've successfully checked the kernel version, click Continue to proceed to the next step.

Verify kernel details in /proc/version

In this step, you will explore the /proc filesystem, which is a virtual filesystem in Linux that provides information about processes and other system information. Specifically, we will look at the /proc/version file, which contains detailed information about the running kernel.

The /proc filesystem is a powerful tool for understanding what's happening inside your Linux system. Files within /proc are not stored on disk like regular files; they are generated on the fly by the kernel when you access them.

The /proc/version file contains a string that includes the kernel version, the GCC version used to compile the kernel, and other build information.

To view the contents of this file, we can use the cat command, which is commonly used to display the content of files.

Type the following command into your terminal and press Enter:

cat /proc/version

You should see output similar to this:

Linux version 5.15.0-XX-generic (...) (gcc (Ubuntu XX.X.X-XubuntuX) X.X.X) #XX-Ubuntu SMP ...

Let's break down the output:

  • Linux version 5.15.0-XX-generic: This confirms the kernel version, similar to what you saw with uname -r.
  • (gcc (Ubuntu XX.X.X-XubuntuX) X.X.X): This shows the version of the GCC compiler that was used to build the kernel.
  • #XX-Ubuntu SMP ...: This part provides information about the specific build, including the build number and whether it's a Symmetric Multiprocessing (SMP) kernel, which is common for modern multi-core processors.

Examining /proc/version gives you a more comprehensive view of the kernel's origin and build environment compared to just the release number from uname -r.

Click Continue to move on to the next step.

Inspect boot logs with dmesg

In this step, you will learn how to use the dmesg command to view the kernel ring buffer. The kernel ring buffer stores messages from the kernel, including information about hardware detection, device drivers, and system events that occur during the boot process.

The dmesg command is invaluable for diagnosing hardware issues or understanding how the kernel interacts with your system's components. When your system boots, the kernel initializes hardware and loads drivers, and it logs these actions to the ring buffer.

To view the entire contents of the kernel ring buffer, simply type dmesg in your terminal and press Enter:

dmesg

You will likely see a large amount of output scrolling by. This output contains messages from the kernel since the system started.

Since the output can be quite long, it's often useful to pipe the output of dmesg to a pager like less or more to view it screen by screen. This allows you to scroll up and down through the messages.

Let's try piping the output to less:

dmesg | less

Now you can use the arrow keys to scroll through the output. Press the spacebar to go to the next page, and press q to exit less.

You can also filter the output of dmesg using tools like grep to search for specific keywords. For example, to see messages related to USB devices, you could use:

dmesg | grep -i usb

The -i option makes the search case-insensitive.

Exploring the dmesg output can provide deep insights into your system's boot process and hardware.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check the Linux kernel version using the uname -r command, which provides the kernel release number. You also explored the /proc filesystem and specifically the /proc/version file to verify detailed information about the running kernel. Finally, you inspected boot logs using the dmesg command to gain further insights into the kernel's initialization process.