1. View the current kernel version
[[email protected] ~]#cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core) [[email protected] ~]#uname -r 3.10.0-1062.el7.x86_64
2. Upgrade the kernel version
(1) Domestic yum mirroring configuration
Backup system default configuration source
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
Download aliyun Mirror yum
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Update System Upgrade Package
#yum update -y
Enable ELRepo warehouse
ELRepo warehouse is based on Linux for enterprise-class storage, delivery and other community support for RedHat Enterprise (RHEL) RHEL based Linux distributions (CentOS, Scientific, Fedora, etc.).
ELRepo focused on packages and associated hardware, including file system drivers, video drivers, network drivers, sound drivers and the camera driver and the like.
Import public key ELRepo warehouse
#rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
Yum install ELRepo warehouse source
[[email protected] ~] #rpm -ivhU http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
3. The mounting system kernel package
[[email protected] ~]#yum --disablerepo="*" --enablerepo="elrepo-kernel" list available Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn elrepo-kernel | 2.9 kB 00:00:00 elrepo-kernel/primary_db | 1.8 MB 00:00:00 Available Packages elrepo-release.noarch 7.0-4.el7.elrepo elrepo-kernel kernel-lt.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-devel.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-doc.noarch 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-headers.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-tools.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs-devel.x86_64 4.4.199-1.el7.elrepo elrepo-kernel kernel-ml.x86_64 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-devel.x86_64 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-doc.noarch 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-headers.x86_64 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-tools.x86_64 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs.x86_64 5.3.9-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs-devel.x86_64 5.3.9-1.el7.elrepo elrepo-kernel perf.x86_64 5.3.9-1.el7.elrepo elrepo-kernel python-perf.x86_64 5.3.9-1.el7.elrepo elrepo-kerne
5.3.9 can be seen that there are differences, both kernel-lt 4.4.199 and kernel-ml kernel lt ml and above:
kernel-ml packages are provided by the stabilized source branch main Linux Kernel Archives constructed. Kernel configuration based on the default RHEL-7 configuration, and if necessary to enable the function to add. These packages deliberately named kernel-ml, so as not to conflict with the RHEL-7 kernel happen, so they can be installed and updated with regular kernel.
kernel-lt packet from the source code provided Linux Kernel Archives constructed, the same package as kernel-ml. Except that the kernel-lt-based long-term support branch, the main kernel-ml based on stable branch.
There are two cores in ELRepo option is a kernel-lt (long-term support version), is a kernel-ml (mainline latest version), the use of long-term support version (kernel-lt), more stable number.
#yum --enablerepo=elrepo-kernel install kernel-lt -y
--enablerepo option is turned on CentOS designated warehouse system.
View all available cores on the system:
#awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (4.4.199-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1062.4.1.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-a19b5bd4e2cf4a9aa74027ab3c4150a3) 7 (Core)
Set the new kernel as the default version of grub2
There are four cores on the server, we want to use this version 4.4.199, can be set by grub2-set-default 0 command or edit / etc / default / grub file
The method by grub2-set-default 0 Command Set
Where 0 is check out the available cores above
#grub2-set-default 0
Method 2 editing / etc / default / grub file
Provided GRUB_DEFAULT = 0, the number displayed by the above query as the core 0 is the default kernel:
#vim /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=0 GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet" GRUB_DISABLE_RECOVERY="true"
Generate grub file and restart
Grub2 # -o-mkconfig /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.4.199-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.4.199-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1062.4.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1062.4.1.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-a19b5bd4e2cf4a9aa74027ab3c4150a3 Found initrd image: /boot/initramfs-0-rescue-a19b5bd4e2cf4a9aa74027ab3c4150a3.img done #reboot
Start Viewing the kernel:
verification:
#uname -r 4.4.199-1.el7.elrepo.x86_64
4. Delete the old kernel (optional)
View all system kernel:
#rpm -qa | egrep kernel kernel-3.10.0-1062.el7.x86_64 kernel-tools-3.10.0-1062.4.1.el7.x86_64 kernel-3.10.0-1062.4.1.el7.x86_64 kernel-tools-libs-3.10.0-1062.4.1.el7.x86_64 kernel-headers-3.10.0-1062.4.1.el7.x86_64 kernel-lt-4.4.199-1.el7.elrepo.x86_64
Method 1 yum the Remove to delete the old kernel rpm package
yum remove kernel-3.10.0-1062.el7.x86_64 \ kernel-tools-3.10.0-1062.4.1.el7.x86_64 \ kernel-3.10.0-1062.4.1.el7.x86_64 \ kernel-tools-libs-3.10.0-1062.4.1.el7.x86_64 \ kernel-headers-3.10.0-1062.4.1.el7.x86_64 -y
Method 2 yum-utils tool
If you install a kernel no more than three, yum-utils will not remove any of them. Only when you install kernel is greater than three, it will automatically delete old kernel.
Install yum-utils
#yum install yum-utils -y
Remove the old version:
#package-cleanup --oldkernels
Check the kernel boot
Reference links:
https://www.cnblogs.com/xzkzzz/p/9627658.html