Knowing the exact kernel version or OS version is sometimes necessary while troubleshooting an issue or providing information to the support team. This post will assist you to determine the OS and kernel version of the CentOS or RHEL system you are running.
There are 2 major things to check when it comes to finding the version of any Linux system. They are
1. Check the OS Update Level
2. Check the running kernel version
1. Check the CentOS/RHEL OS Update Level
The 4 files shown below provides the update version of the CentOS/Redhat OS.
- /etc/centos-release
- /etc/os-release
- /etc/redhat-release
- /etc/system-release
The content of each of the above files from a CentOS 7.4 system is shown below.
# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)
# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)
# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
# cat /etc/system-release CentOS Linux release 7.4.1708 (Core)
The above 4 files are provided by the package centos-release.
# rpm -ql centos-release | grep release$ /etc/centos-release /etc/os-release /etc/redhat-release /etc/system-release
You can find out release information by checking the versioning reported the rpm database. For example:
# rpm -qf /etc/redhat-release centos-release-7-4.1708.el7.centos.x86_64
2. Check the Running Kernel version
You can find out which CentOS kernel version and architecture you are using with the uname command. Do “man uname” for details of the uname command.
Examples:
# uname -s -r Linux 3.10.0-693.21.1.el7.x86_64
# uname -a Linux geeklab 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Check kernel compile time (uname -v) and compare with known value:
# uname -v #1 SMP Wed Mar 7 19:03:37 UTC 2018
You can also Verify the kernel package using the rpm command. The command would produce an output only if there is any issue with the installed kernel.
# rpm -q --verify kernel-3.10.0-693.21.1.el7.x86_64
Checking CentOS 7 version
Apart from all the above commands, you can also use the command “hostnamectl” to find OS version information in CentOS 7 systems. For example:
# hostnamectl Static hostname: geeklab Icon name: computer-vm Chassis: vm Machine ID: f9afeb75a5a382dce8269887a67fbf58 Boot ID: 668b5c55c6b9438b9356438d8beceec6 Virtualization: xen Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-693.21.1.el7.x86_64 Architecture: x86-64
Checking the LSB version
Another way to check the centOS version is using the “lsb_release” command. The lsb_release command is provided by the package “redhat-lsb”. This package may not be present by default on the system and you may need to install it first.
# yum install redhat-lsb
Examples of lsb_release command:
# lsb_release -d Description: CentOS Linux release 7.4.1708 (Core)
# lsb_release -r Release: 7.4.1708
# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 7.4.1708 (Core) Release: 7.4.1708 Codename: Core
Check OS version with GRUB configuration files
Using the GRUB configuration file is not a recommended way of checking the OS version, but I would still like to mention this method here for your information. Search for the “menuentry” (For CentOS 7) and “title” (For CentOS 6) in the GRUB configuration file to find the OS version.
CentOS 7 Example
# cat /boot/grub2/grub.cfg | grep -w menuentry menuentry 'CentOS Linux (3.10.0-693.21.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.21.1.el7.x86_64-advanced-0f790447-ebef-4ca0-b229-d0aa1985d57f' { menuentry 'CentOS Linux (3.10.0-693.17.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.17.1.el7.x86_64-advanced-0f790447-ebef-4ca0-b229-d0aa1985d57f' {
In case of CentOS 7, you can also get the current kerel version from the file /boot/grub2/grubenv. For example:
# grep saved_entry /boot/grub2/grubenv saved_entry=CentOS Linux (3.10.0-693.21.1.el7.x86_64) 7 (Core)
CentOS 6 Example
# cat /boot/grub/grub.conf | grep title title CentOS (2.6.32-696.20.1.el6.x86_64) title CentOS (2.6.32-696.18.7.el6.x86_64)