CentOS 7.9升级内核并设置默认启动

Posted 王万林 Ben

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7.9升级内核并设置默认启动相关的知识,希望对你有一定的参考价值。

当前系统

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.59.1.el7.x86_64 #1 SMP Wed Feb 23 16:47:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

将系统更新到最新

[root@localhost ~]# yum -y update

添加ELRepo仓库

[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@localhost ~]# rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

查看可以安装的内核版本

[root@localhost ~]# yum list available --disablerepo='*' --enablerepo=elrepo-kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: elrepo.org
elrepo-kernel                                                                                             | 3.0 kB  00:00:00
elrepo-kernel/primary_db                                                                                  | 2.0 MB  00:00:02
Available Packages
elrepo-release.noarch                                           7.0-5.el7.elrepo                                    elrepo-kernel
kernel-lt.x86_64                                                5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-devel.x86_64                                          5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-doc.noarch                                            5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-headers.x86_64                                        5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-tools.x86_64                                          5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-tools-libs.x86_64                                     5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                               5.4.182-1.el7.elrepo                                elrepo-kernel
kernel-ml.x86_64                                                5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-devel.x86_64                                          5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-doc.noarch                                            5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-headers.x86_64                                        5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools.x86_64                                          5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs.x86_64                                     5.16.12-1.el7.elrepo                                elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                               5.16.12-1.el7.elrepo                                elrepo-kernel
perf.x86_64                                                     5.16.12-1.el7.elrepo                                elrepo-kernel
python-perf.x86_64                                              5.16.12-1.el7.elrepo                                elrepo-kernel

可以选择带lt或mt的进行安装,其中lt表示long-term,ml表示latest mainline,这里装lt

[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-lt
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * elrepo: mirror.rackspace.com
 * elrepo-kernel: mirror.rackspace.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package kernel-lt.x86_64 0:5.4.182-1.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================
 Package                    Arch                    Version                                 Repository                      Size
=================================================================================================================================
Installing:
 kernel-lt                  x86_64                  5.4.182-1.el7.elrepo                    elrepo-kernel                   50 M

Transaction Summary
=================================================================================================================================
Install  1 Package

Total download size: 50 M
Installed size: 228 M
Is this ok [y/d/N]: y
Downloading packages:
kernel-lt-5.4.182-1.el7.elrepo.x86_64.rpm                                                                 |  50 MB  00:01:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-lt-5.4.182-1.el7.elrepo.x86_64                                                                         1/1
  Verifying  : kernel-lt-5.4.182-1.el7.elrepo.x86_64                                                                         1/1

Installed:
  kernel-lt.x86_64 0:5.4.182-1.el7.elrepo

Complete!

设置默认启动

[root@localhost ~]# cat /boot/grub2/grub.cfg |grep "menuentry " | awk -F\\' 'print $2'
CentOS Linux (5.4.182-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-1160.59.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-7b02b47c80952b47b8f12e9ea264eb57) 7 (Core)
[root@localhost ~]# grub2-set-default 'CentOS Linux (5.4.182-1.el7.elrepo.x86_64) 7 (Core)'
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (5.4.182-1.el7.elrepo.x86_64) 7 (Core)

完毕。

参考文章:

How to Upgrade the Linux Kernel on CentOS 7 | PhoenixNAP KBhttps://phoenixnap.com/kb/how-to-upgrade-kernel-centos

以上是关于CentOS 7.9升级内核并设置默认启动的主要内容,如果未能解决你的问题,请参考以下文章

[网络/Linux]CentOS7:OpenSSH升级到7.9p1

Centos 8升级内核版本

centos7设置默认的内核启动

Redhat/Centos 设置默认启动内核

关于CentOS开机启动项的管理与设置

Centos7及ali ecs 升级内核