Skip to content

Instantly share code, notes, and snippets.

@vi7
Created August 3, 2022 13:15
Show Gist options
  • Save vi7/26ad2220a7a6600eb1e49c84cac0f229 to your computer and use it in GitHub Desktop.
Save vi7/26ad2220a7a6600eb1e49c84cac0f229 to your computer and use it in GitHub Desktop.
Kernel v5 on CentOS 7
#!/usr/bin/env bash
# Based on the info from
# - http://elrepo.org/tiki/HomePage
# - https://www.golinuxcloud.com/set-default-boot-kernel-version-old-previous-rhel-linux/
# - https://www.casesup.com/category/knowledgebase/howtos/how-to-change-the-default-kernel-in-grub-for--rhel-and-centos
## !!!!!!!!!!!!!!!!!!!! ##
## ##
## !!! IMPORTANT: do not run this as-is, read all in-line comments ##
## ##
## !!!!!!!!!!!!!!!!!!!! ##
# Install ElRepo and long-term support kernel
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
yum -y --enablerepo=elrepo-kernel install kernel-lt
# List available menuentries in the Grub conf
awk -F\' /^menuentry/{print\$2} /etc/grub2.cfg
# sample output:
# CentOS Linux (5.4.208-1.el7.elrepo.x86_64) 7 (Core) <<==== Entry 0
# CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core) <<==== Entry 1
# CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core) <<==== Entry 2
# CentOS Linux (0-rescue-3cda867cd185457f8d6d093c9d10e8f0) 7 (Core)
## !! WARNING !! ##
# grub2-set-default command only works for GRUB configuration files created with GRUB_DEFAULT=saved in /etc/default/grub
## !! WARNING !! ##
# set kernel in the menuentry 0 as a default
grub2-set-default 0
# and check
grep saved /boot/grub2/grubenv
# rebuild grub2 config
grub2-mkconfig -o /boot/grub2/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment