Tag Archives: how to check kernel version in linux

How to upgrade kernel in RHEL, Suse, Ubuntu Linux

Step by step procedure to upgrade kernel in RHEL, Suse, and Ubuntu Linux along with sample outputs of all the commands.

Upgrade kernel in RHEL, Suse, and Ubuntu Linux

How to check current kernel & patch level in Linux

You can confirm current kernel version & patch level using uname -r and uname -v command.

root@kerneltlks # uname -v
#1 SMP Sun Jul 27 15:55:46 EDT 2014
root@kerneltalks # uname -r
2.6.32-431.29.2.el6.x86_64

-r switch gives you your current kernel version. -v gives you your current patch level. You can see in the above output our RHEL6 system has 2014 (almost 4 years old) patched kernel. We will patch it to the latest one in this article.

How to upgrade the kernel in RHEL

Patching kernel is Linux is the same as upgrading to the latest kernel. Make sure you have yum configured properly to receive the latest packages from trusted repositories. If you do not have/want yum configurations, you can download the latest kernel and its dependencies from the Red Hat portal and keep it ready on the server for installation.

Never replace the existing kernel by updating the package. Always install a new kernel package so that your old kernel still resides on the server and you can boot it if your server/application is not behaving well with the new kernel.

To install the latest kernel, use rpm -ivh <rpm names> or yum install kernel command.

root@kerneltalks # yum install kernel
Loaded plugins: amazon-id, rhui-lb, security
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:2.6.32-696.20.1.el6 will be installed
--> Processing Dependency: dracut-kernel >= 004-408.el6 for package: kernel-2.6.32-696.20.1.el6.x86_64
--> Processing Dependency: kernel-firmware >= 2.6.32-696.20.1.el6 for package: kernel-2.6.32-696.20.1.el6.x86_64
--> Running transaction check
---> Package dracut-kernel.noarch 0:004-336.el6_5.2 will be updated
---> Package dracut-kernel.noarch 0:004-409.el6_8.2 will be an update
--> Processing Dependency: dracut = 004-409.el6_8.2 for package: dracut-kernel-004-409.el6_8.2.noarch
---> Package kernel-firmware.noarch 0:2.6.32-431.29.2.el6 will be updated
---> Package kernel-firmware.noarch 0:2.6.32-696.20.1.el6 will be an update
--> Running transaction check
---> Package dracut.noarch 0:004-336.el6_5.2 will be updated
---> Package dracut.noarch 0:004-409.el6_8.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                        Version                                   Repository                                             Size
========================================================================================================================================================================
Installing:
 kernel                               x86_64                      2.6.32-696.20.1.el6                       rhui-REGION-rhel-server-releases                       32 M
Updating for dependencies:
 dracut                               noarch                      004-409.el6_8.2                           rhui-REGION-rhel-server-releases                      127 k
 dracut-kernel                        noarch                      004-409.el6_8.2                           rhui-REGION-rhel-server-releases                       28 k
 kernel-firmware                      noarch                      2.6.32-696.20.1.el6                       rhui-REGION-rhel-server-releases                       29 M

Transaction Summary
========================================================================================================================================================================
Install       1 Package(s)
Upgrade       3 Package(s)

Total download size: 61 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): dracut-004-409.el6_8.2.noarch.rpm                                                                                                         | 127 kB     00:00
(2/4): dracut-kernel-004-409.el6_8.2.noarch.rpm                                                                                                  |  28 kB     00:00
(3/4): kernel-2.6.32-696.20.1.el6.x86_64.rpm                                                                                                     |  32 MB     00:00
(4/4): kernel-firmware-2.6.32-696.20.1.el6.noarch.rpm                                                                                            |  29 MB     00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    45 MB/s |  61 MB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : dracut-004-409.el6_8.2.noarch                                                                                                                        1/7
  Updating   : dracut-kernel-004-409.el6_8.2.noarch                                                                                                                 2/7
  Updating   : kernel-firmware-2.6.32-696.20.1.el6.noarch                                                                                                           3/7
  Installing : kernel-2.6.32-696.20.1.el6.x86_64                                                                                                                    4/7
  Cleanup    : dracut-kernel-004-336.el6_5.2.noarch                                                                                                                 5/7
  Cleanup    : dracut-004-336.el6_5.2.noarch                                                                                                                        6/7
  Cleanup    : kernel-firmware-2.6.32-431.29.2.el6.noarch                                                                                                           7/7
  Verifying  : kernel-firmware-2.6.32-696.20.1.el6.noarch                                                                                                           1/7
  Verifying  : kernel-2.6.32-696.20.1.el6.x86_64                                                                                                                    2/7
  Verifying  : dracut-kernel-004-409.el6_8.2.noarch                                                                                                                 3/7
  Verifying  : dracut-004-409.el6_8.2.noarch                                                                                                                        4/7
  Verifying  : dracut-004-336.el6_5.2.noarch                                                                                                                        5/7
  Verifying  : kernel-firmware-2.6.32-431.29.2.el6.noarch                                                                                                           6/7
  Verifying  : dracut-kernel-004-336.el6_5.2.noarch                                                                                                                 7/7

Installed:
  kernel.x86_64 0:2.6.32-696.20.1.el6

Dependency Updated:
  dracut.noarch 0:004-409.el6_8.2                  dracut-kernel.noarch 0:004-409.el6_8.2                  kernel-firmware.noarch 0:2.6.32-696.20.1.el6

Complete!

If you are on a test system and don’t mind wiping out old kernel then you can directly use yum update kernel or rpm -Uvh <rpms> command and update kernel.

If you observe, yum resolved dependencies too. If you are opting to install from rpm you need to download all dependencies as well. Here is the list of dependencies depending on your RHEL version :

RHEL4 kernel package upgrade dependencies:kernel-smp, kernel-largesmp, kernel-hugemem
RHEL5 kernel package upgrade dependencies:kernel-PAE, kernel-xen
RHEL6 kernel package upgrade dependencies: kernel-firmware
RHEL7 kernel package upgrade dependencies:dracut, dracut-network, dracut-config-rescue

Now, if you observe,/boot/grub/grub.conf your newly installed kernel entry is added before your old kernel entry. This gives new kernel priority to boot when you reboot the system. parameter default=0 says the system needs to be booted from the very first kernel defined below. Kernel entries numbering starts from 0. Make sure this parameter value points to your newly installed kernel and reboot the system.

# cat /boot/grub/grub.conf
default=0
timeout=1
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.32-696.20.1.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-696.20.1.el6.x86_64 console=ttyS0 ro root=UUID=9996863e-b964-47d3-a33b-3920974fdbd9 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 xen_blkfront.sda_is_xvda=1 console=ttyS0,115200n8 console=tty0 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM
        initrd /boot/initramfs-2.6.32-696.20.1.el6.x86_64.img
title Red Hat Enterprise Linux (2.6.32-431.29.2.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-431.29.2.el6.x86_64 console=ttyS0 ro root=UUID=9996863e-b964-47d3-a33b-3920974fdbd9 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 xen_blkfront.sda_is_xvda=1 console=ttyS0,115200n8 console=tty0 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_LVM rd_NO_DM
        initrd /boot/initramfs-2.6.32-431.29.2.el6.x86_64.img

After rebooting, you can see your system is running with a new updated kernel!

root@kerneltalks # reboot

Broadcast message from root@kerneltalks
        (/dev/pts/0) at 2:14 ...

The system is going down for reboot NOW!

root@kerneltalks # uname -r
2.6.32-696.20.1.el6.x86_64
root@kerneltalks # uname -v
#1 SMP Fri Jan 12 15:07:59 EST 2018

You can see kernel is upgraded from 2.6.32-431.29.2.el6.x86_64 to 2.6.32-696.20.1.el6.x86_64. And patch level from July 2014 to Jan 2018.

How to upgrade the kernel in Suse Linux

Let’s start with checking current kernel version and patch info.

root@kerneltalks # uname -r
3.0.101-108.21-default
root@kerneltalks # uname -v
#1 SMP Fri Dec 29 10:25:37 UTC 2017 (5f5299b)

Perform kernel upgrade with zypper or if you have kernel rpm package with you, you can use rpm -ivh <kernel_rpm_path> to perform the multi-kernel install (not update)

You have an option to perform distribution upgrade using zypper dup as well which includes updating all packages to available updates. But most of the cases it’s not recommended.

# zypper up kernel-default
Refreshing service 'cloud_update'.
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following packages are going to be upgraded:
  kernel-default kernel-default-base

2 packages to upgrade.
Overall download size: 40.2 MiB. After the operation, additional 1.2 MiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package kernel-default-base-3.0.101-108.35.1.x86_64 (1/2), 15.7 MiB (23.2 MiB unpacked)
Retrieving: kernel-default-base-3.0.101-108.35.1.x86_64.rpm [done]
Retrieving package kernel-default-3.0.101-108.35.1.x86_64 (2/2), 24.5 MiB (86.1 MiB unpacked)
Retrieving: kernel-default-3.0.101-108.35.1.x86_64.rpm [done]
Installing: kernel-default-base-3.0.101-108.35.1 [done]
Additional rpm output:

Kernel image:   /boot/vmlinuz-3.0.101-108.35-default
Initrd image:   /boot/initrd-3.0.101-108.35-default
Root device:    /dev/hda1 (mounted on / as ext3)
Kernel Modules: xen-platform-pci xen-vbd-upstream xen-vbd xen-balloon xen-vnif scsi_mod libata ata_piix jbd mbcache ext3 edd usb-common usbcore ehci-hcd ohci-hcd uhci-hcd xhci-hcd crc-t10dif sd_mod
Features:       acpi fv_guest block resume.userspace resume.kernel
32723 blocks


Installing: kernel-default-3.0.101-108.35.1 [done]
Additional rpm output:

Kernel image:   /boot/vmlinuz-3.0.101-108.35-default
Initrd image:   /boot/initrd-3.0.101-108.35-default
Root device:    /dev/hda1 (mounted on / as ext3)
Kernel Modules: hwmon thermal_sys thermal processor fan xen-platform-pci xen-vbd-upstream xen-vbd xen-balloon xen-vnif scsi_mod libata ata_piix ata_generic jbd mbcache ext3 edd usb-common usbcore ehci-hcd ohci-hcd uhci-hcd xhci-hcd hid usbhid crc-t10dif sd_mod
Features:       acpi fv_guest block usb resume.userspace resume.kernel
33630 blocks

# reboot
Broadcast message from root (pts/0) (Sat Mar  3 04:47:12 2018):

The system is going down for reboot NOW!

Reboot the system and then check new kernel version.

# uname -r
3.0.101-108.35-default
# uname -v
#1 SMP Mon Feb 19 21:13:08 UTC 2018 (251ec24)

You can see the kernel is upgraded from 3.0.101-108.21-default to 3.0.101-108.35-default. And patch date from Dec 2017 to Feb 2018!

How to upgrade the kernel in Ubuntu Linux

Start with checking your current kernel version and patching date

# uname -v
#16-Ubuntu SMP Fri Jan 20 15:31:12 UTC 2017
# uname -r
4.9.0-15-generic

Now visit the Ubuntu Kernel page and download the kernel of your choice which is matching with your server arch using wget. We chose to upgrade to 4.10 kernel. Since we have generic kernel we downloaded generic kernel files from 4.10 directory.

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
--2018-03-03 05:03:15--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 659514 (644K) [application/x-debian-package]
Saving to: ‘linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’

linux-headers-4.10.1-041001-generic_4.10. 100%[=====================================================================================>] 644.06K  1.32MB/s    in 0.5s

2018-03-03 05:03:16 (1.32 MB/s) - ‘linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’ saved [659514/659514]

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
--2018-03-03 05:03:24--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 59573112 (57M) [application/x-debian-package]
Saving to: ‘linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’

linux-image-4.10.1-041001-generic_4.10.1- 100%[=====================================================================================>]  56.81M   744KB/s    in 2m 40s

2018-03-03 05:06:05 (363 KB/s) - ‘linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb’ saved [59573112/59573112]

root@kerneltalks # wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
--2018-03-03 05:06:10--  http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.10.1/linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb
Resolving kernel.ubuntu.com (kernel.ubuntu.com)... 91.189.94.216
Connecting to kernel.ubuntu.com (kernel.ubuntu.com)|91.189.94.216|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10345532 (9.9M) [application/x-debian-package]
Saving to: ‘linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb’

linux-headers-4.10.1-041001_4.10.1-041001 100%[=====================================================================================>]   9.87M   932KB/s    in 14s

2018-03-03 05:06:24 (739 KB/s) - ‘linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb’ saved [10345532/10345532]

Now install these kernel packages using dpkg command with -i switch.

root@kerneltalks # dpkg -i *.deb
Selecting previously unselected package linux-headers-4.10.1-041001.
(Reading database ... 56103 files and directories currently installed.)
Preparing to unpack linux-headers-4.10.1-041001_4.10.1-041001.201702260735_all.deb ...
Unpacking linux-headers-4.10.1-041001 (4.10.1-041001.201702260735) ...
Selecting previously unselected package linux-headers-4.10.1-041001-generic.
Preparing to unpack linux-headers-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb ...
Unpacking linux-headers-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Selecting previously unselected package linux-image-4.10.1-041001-generic.
Preparing to unpack linux-image-4.10.1-041001-generic_4.10.1-041001.201702260735_amd64.deb ...
Done.
Unpacking linux-image-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Setting up linux-headers-4.10.1-041001 (4.10.1-041001.201702260735) ...
Setting up linux-headers-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Setting up linux-image-4.10.1-041001-generic (4.10.1-041001.201702260735) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
update-initramfs: Generating /boot/initrd.img-4.10.1-041001-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
run-parts: executing /etc/kernel/postinst.d/x-grub-legacy-ec2 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.9.0-15-generic
Found kernel: /boot/vmlinuz-4.10.1-041001-generic
Found kernel: /boot/vmlinuz-4.9.0-15-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done

run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.10.1-041001-generic /boot/vmlinuz-4.10.1-041001-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.10.1-041001-generic
Found initrd image: /boot/initrd.img-4.10.1-041001-generic
Found linux image: /boot/vmlinuz-4.9.0-15-generic
Found initrd image: /boot/initrd.img-4.9.0-15-generic
done

After a successful install, reboot the system and check new kernel version.

root@kerneltalks # reboot

root@kerneltalks # uname -v
#201702260735 SMP Sun Feb 26 12:36:48 UTC 2017
root@kerneltalks # uname -r
4.10.1-041001-generic

You can see kernel is upgraded to 4.10.1-041001-generic from 4.9.0-15-generic. And patch date from Jan 2017 to Feb 2017.