Upgrade Your Linux Kernel on CentOS 7 and Ubuntu 16.04 in Simple Steps
This guide walks through checking the current kernel version, adding the ELRepo repository, listing and installing newer kernels on CentOS 7, configuring GRUB to boot the new kernel, and then provides a parallel step‑by‑step process for upgrading the kernel on Ubuntu 16.04, including troubleshooting dependency issues.
1. Upgrade Kernel on CentOS 7
1.1 Check Installed Kernel Version
To display the currently installed kernel version, run:
# uname -sr
Linux 3.10.0-862.el7.x86_64The latest kernel on kernel.org at the time of writing is 5.12. Consider the kernel lifecycle when choosing a version.
1.2 Upgrade Kernel
CentOS can use the third‑party ELRepo repository to obtain newer kernels. Enable ELRepo with:
# Import ELRepo public key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# Install ELRepo yum repository
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm1.3 List Available Kernel Packages
After enabling the repository, list the kernel packages you can install:
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available1.4 Install Latest Kernel
For CentOS, using yum to install the RPM avoids many dependency issues. By default it installs the newest kernel version available in ELRepo.
# Install the mainline kernel from ELRepo
yum -y --enablerepo=elrepo-kernel install kernel-ml1.5 Set GRUB Default Kernel Version
After installation, set the new kernel as the default boot entry.
List All Available Kernels
# sudo awk -F' ' '$1=="menuentry " {print i++ ": " $2}' /etc/grub2.cfg
0 : CentOS Linux 7 Rescue 8916e15095f33283a3b46d8f9ac7c654 (5.12.1-1.el7.elrepo.x86_64)
1 : CentOS Linux (5.12.1-1.el7.elrepo.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-ea3169a040da42e0b632f72ceb5abd82) 7 (Core)Set New Kernel as GRUB Default
Use grub2-set-default 0 or edit /etc/default/grub to set the default entry.
# Set GRUB_DEFAULT=0 so the first entry becomes the default
grub2-set-default 0Generate GRUB Config and Reboot
# Recreate GRUB configuration file
grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.12.1-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.12.1-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-8916e15095f33283a3b46d8f9ac7c654
Found initrd image: /boot/initramfs-0-rescue-8916e15095f33283a3b46d8f9ac7c654.img
Found linux image: /boot/vmlinuz-0-rescue-ea3169a040da42e0b632f72ceb5abd82
Found initrd image: /boot/initramfs-0-rescue-ea3169a040da42e0b632f72ceb5abd82.img
doneVerify
# reboot
# uname -r
5.12.1-1.el7.elrepo.x86_64Upgrade successful.
Side Note
Creating Offline Kernel Upgrade Packages Without Internet
# Install tools for creating a repository
yum -y install yum-utils
yum -y install createrepo
# Download required packages (example for httpd)
repotrack httpd -p ./httpds/ # or yumdownloader --resolve --destdir /tmp/ansible ansible
# Create offline kernel package directory
repotrack kernel-ml.x86_64 -p ./kernel-ml.x86_64/ # or yumdownloader --resolve --destdir ./kernel-ml.x86_64 kernel-ml.x86_64
# Copy the ./kernel-ml.x86_64 directory to the target machine and installRemove Old Kernels
List all installed kernel packages:
# rpm -qa | grep kernel
kernel-headers-3.10.0-957.27.2.el7.x86_64
kernel-tools-3.10.0-862.el7.x86_64
kernel-debug-devel-3.10.0-957.27.2.el7.x86_64
kernel-ml-5.12.1-1.el7.elrepo.x86_64
kernel-3.10.0-862.el7.x86_64
kernel-tools-libs-3.10.0-862.el7.x86_64Method 1: remove specific old kernel RPMs with yum remove.
Method 2: use yum-utils to clean up old kernels automatically when more than three are installed:
# yum install -y yum-utils
# package-cleanup --oldkernels2. Upgrade Kernel on Ubuntu
2.1 Environment
On an Ubuntu 16.04 VM, check the current kernel version with uname -r. The current version is 4.15.0-45-generic; the target version is 4.20.2.
2.2 Prepare Required Packages
Download the desired kernel version from kernel.ubuntu.com . Choose the appropriate amd64 .deb files and download them:
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.5/linux-headers-4.20.5-042005_4.20.5-042005.201901260434_all.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.5/linux-headers-4.20.5-042005-generic_4.20.5-042005.201901260434_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.5/linux-image-unsigned-4.20.5-042005-generic_4.20.5-042005.201901260434_amd64.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v4.20.5/linux-modules-4.20.5-042005-generic_4.20.5-042005.201901260434_amd64.deb2.3 Install
Install the downloaded .deb packages with dpkg: sudo dpkg -i *.deb Reboot the system and verify the new kernel:
# reboot
# uname -r
Linux hadoop-master02 4.20.5-042005-genericKernel upgrade successful.
2.4 Issues and Solutions
During the Ubuntu 16.04 kernel upgrade, a missing libssl1.1 dependency may occur.
Solution: install the libssl1.1 package from the official Ubuntu repositories or download the .deb manually and install it.
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.debSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
