linux · 2021年7月21日 0

Centos7升级5.4内核


众所周知,Centos7所有组件都旧的雅痞,内核版本到Centos7.8为止还是3.10,很多新功能都要用到新内核的特性,而Centos7无法实现。

[root@localhost ~]# uname -r 
3.10.0-1127.18.2.el7.x86_64

不过在Centos7.8中,有个禁用kernel的yum源

[root@localhost ~]# yum repolist all | grep kernel
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
centos-kernel/7/x86_64              CentOS LTS Kernels for x86_6 disabled
centos-kernel-experimental/7/x86_64 CentOS Experimental Kernels  disabled

一个是LTS版,一个是experimental
启用LTS的yum源

[root@localhost ~]# yum-config-manager --enable centos-kernel
Loaded plugins: fastestmirror
==================================================================== repo: centos-kernel ====================================================================
[centos-kernel]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = 
cache = 0
cachedir = /var/cache/yum/x86_64/7/centos-kernel
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = 1
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/centos-kernel/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/centos-kernel/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
hdrdir = /var/cache/yum/x86_64/7/centos-kernel/headers
http_caching = all
includepkgs = 
ip_resolve = 
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid = 
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink = 
minrate = 0
mirrorlist = http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=kernel&infra=stock
mirrorlist_expire = 86400
name = CentOS LTS Kernels for x86_64
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/7/centos-kernel
pkgdir = /var/cache/yum/x86_64/7/centos-kernel/packages
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
ui_id = centos-kernel/7/x86_64
ui_repoid_vars = releasever,
   basearch
username = 

安装新内核

[root@localhost ~]# yum install kernel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * centos-kernel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
centos-kernel                                                                                                                         | 2.9 kB  00:00:00     
centos-kernel/7/x86_64/primary_db                                                                                                     | 3.6 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:5.4.65-200.el7 will be installed
--> Processing Dependency: kernel-modules-uname-r = 5.4.65-200.el7.x86_64 for package: kernel-5.4.65-200.el7.x86_64
--> Processing Dependency: kernel-core-uname-r = 5.4.65-200.el7.x86_64 for package: kernel-5.4.65-200.el7.x86_64
--> Running transaction check
---> Package kernel-core.x86_64 0:5.4.65-200.el7 will be installed
---> Package kernel-modules.x86_64 0:5.4.65-200.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                Arch                           Version                                   Repository                             Size
=============================================================================================================================================================
Installing:
 kernel                                 x86_64                         5.4.65-200.el7                            centos-kernel                         3.9 k
Installing for dependencies:
 kernel-core                            x86_64                         5.4.65-200.el7                            centos-kernel                          32 M
 kernel-modules                         x86_64                         5.4.65-200.el7                            centos-kernel                          28 M

Transaction Summary
=============================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 60 M
Installed size: 96 M
Is this ok [y/d/N]:

可以看到这内核版本是5.4的,直接升级!

Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): kernel-5.4.65-200.el7.x86_64.rpm                                                                                               | 3.9 kB  00:00:00     
(2/3): kernel-modules-5.4.65-200.el7.x86_64.rpm                                                                                       |  28 MB  00:00:04     
(3/3): kernel-core-5.4.65-200.el7.x86_64.rpm                                                                                          |  32 MB  00:00:25     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        2.4 MB/s |  60 MB  00:00:25     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-core-5.4.65-200.el7.x86_64                                                                                                         1/3 
  Installing : kernel-modules-5.4.65-200.el7.x86_64                                                                                                      2/3 
  Installing : kernel-5.4.65-200.el7.x86_64                                                                                                              3/3 
  Verifying  : kernel-modules-5.4.65-200.el7.x86_64                                                                                                      1/3 
  Verifying  : kernel-core-5.4.65-200.el7.x86_64                                                                                                         2/3 
  Verifying  : kernel-5.4.65-200.el7.x86_64                                                                                                              3/3 

Installed:
  kernel.x86_64 0:5.4.65-200.el7                                                                                                                             

Dependency Installed:
  kernel-core.x86_64 0:5.4.65-200.el7                                         kernel-modules.x86_64 0:5.4.65-200.el7

重启,使新内核生效,开机后检查内核版本

[root@localhost ~]# uname -r
5.4.65-200.el7.x86_64

成功升级到5.4内核,顺便卸载旧内核

[root@localhost ~]# yum remove $(rpm -qa | grep kernel | grep  "3\.10")
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-1127.el7 will be erased
---> Package kernel.x86_64 0:3.10.0-1127.18.2.el7 will be erased
---> Package kernel-tools.x86_64 0:3.10.0-1127.18.2.el7 will be erased
---> Package kernel-tools-libs.x86_64 0:3.10.0-1127.18.2.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                  Arch                          Version                                       Repository                        Size
=============================================================================================================================================================
Removing:
 kernel                                   x86_64                        3.10.0-1127.el7                               @anaconda                         64 M
 kernel                                   x86_64                        3.10.0-1127.18.2.el7                          @updates                          64 M
 kernel-tools                             x86_64                        3.10.0-1127.18.2.el7                          @updates                         292 k
 kernel-tools-libs                        x86_64                        3.10.0-1127.18.2.el7                          @updates                          18 k

Transaction Summary
=============================================================================================================================================================
Remove  4 Packages

Installed size: 129 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : kernel-tools-3.10.0-1127.18.2.el7.x86_64                                                                                                  1/4 
  Erasing    : kernel.x86_64                                                                                                                             2/4 
  Erasing    : kernel.x86_64                                                                                                                             3/4 
  Erasing    : kernel-tools-libs-3.10.0-1127.18.2.el7.x86_64                                                                                             4/4 
  Verifying  : kernel-tools-libs-3.10.0-1127.18.2.el7.x86_64                                                                                             1/4 
  Verifying  : kernel-tools-3.10.0-1127.18.2.el7.x86_64                                                                                                  2/4 
  Verifying  : kernel-3.10.0-1127.el7.x86_64                                                                                                             3/4 
  Verifying  : kernel-3.10.0-1127.18.2.el7.x86_64                                                                                                        4/4 

Removed:
  kernel.x86_64 0:3.10.0-1127.el7                          kernel.x86_64 0:3.10.0-1127.18.2.el7          kernel-tools.x86_64 0:3.10.0-1127.18.2.el7         
  kernel-tools-libs.x86_64 0:3.10.0-1127.18.2.el7         

Complete!