栏目头部广告

Linux 升级内核方法

一、升级内核简述

在生产环境中我们时常会遇到升级内核的场景,主要用于解决低版本内核的BUG或者为了支持业务新特性等。

1.1 查看Linux内核版本方法

[root@10-27-0-224 ~]# cat /proc/version
Linux version 3.10.0-862.9.1.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Mon Jul 16 16:29:36 UTC 2018

[root@10-27-0-224 ~]# uname -a
Linux 10-27-0-224 3.10.0-862.9.1.el7.x86_64 #1 SMP Mon Jul 16 16:29:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
(显示系统名、节点名称、操作系统的发行版号、操作系统版本、运行系统的机器 ID 号) 

[root@10-27-0-224 ~]# uname -r
3.10.0-862.9.1.el7.x86_64
(当前操作系统内核版本信息)

1.2 查看Linux系统版本

#当前操作系统内核版本信息
[root@10-27-0-224 ~]# uname -r
3.10.0-862.9.1.el7.x86_64

# 适合Redhat系的Linux
[root@10-27-0-224 ~]# cat /etc/redhat-release  
CentOS Linux release 7.0.1406 (Core) 


[root@10-27-0-224 ~]# cat /etc/issue
CentOS Linux release 7.0.1406 (Core) 
Kernel \r on an \m

二、升级方法

2.1 YUM安装

(1)查看当前可用内核

[root@10-27-0-224 ~]# yum list kernel

Linux 升级内核方法(图1)

(2)安装kernel yum源

[root@10-27-0-224 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org # 导入key
[root@10-27-0-224 ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm  #安装yum源

(3)查看可用内核

[root@10-27-0-224 ~]#  rpm -qa | grep kernel   #方法一
kernel-debug-devel-3.10.0-1160.25.1.el7.x86_64
kernel-tools-libs-3.10.0-1160.25.1.el7.x86_64
kernel-devel-3.10.0-1160.25.1.el7.x86_64
kernel-abi-whitelists-3.10.0-1160.25.1.el7.noarch
kernel-tools-libs-devel-3.10.0-1160.25.1.el7.x86_64
kernel-lt-5.4.128-1.el7.elrepo.x86_64
kernel-3.10.0-862.9.1.el7.x86_64
kernel-3.10.0-1160.25.1.el7.x86_64
kernel-doc-3.10.0-1160.25.1.el7.noarch
kernel-debug-3.10.0-1160.25.1.el7.x86_64
kernel-headers-3.10.0-1160.25.1.el7.x86_64
kernel-tools-3.10.0-1160.25.1.el7.x86_64

[root@10-27-0-224 ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available  #方法二
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: iad.mirror.rackspace.com
Available Packages
elrepo-release.noarch                           7.0-5.el7.elrepo                    elrepo-kernel
kernel-lt-devel.x86_64                          5.4.128-1.el7.elrepo                elrepo-kernel
kernel-lt-doc.noarch                            5.4.128-1.el7.elrepo                elrepo-kernel
kernel-lt-headers.x86_64                        5.4.128-1.el7.elrepo                elrepo-kernel
kernel-lt-tools.x86_64                          5.4.128-1.el7.elrepo                elrepo-kernel
kernel-lt-tools-libs.x86_64                     5.4.128-1.el7.elrepo                elrepo-kernel
kernel-lt-tools-libs-devel.x86_64               5.4.128-1.el7.elrepo                elrepo-kernel
kernel-ml.x86_64                                5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-devel.x86_64                          5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-doc.noarch                            5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-headers.x86_64                        5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-tools.x86_64                          5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-tools-libs.x86_64                     5.12.13-1.el7.elrepo                elrepo-kernel
kernel-ml-tools-libs-devel.x86_64               5.12.13-1.el7.elrepo                elrepo-kernel
perf.x86_64                                     5.12.13-1.el7.elrepo                elrepo-kernel
python-perf.x86_64                              5.12.13-1.el7.elrepo                elrepo-kernel

(4)升级内核操作

[root@10-27-0-224 ~]# yum install kernel-*  #方法一
[root@10-27-0-224 ~]# yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml  #方法二

(5)查看内核个数

[root@10-27-0-224 ~]# grep "menuentry " /boot/grub2/grub.cfg
menuentry 'CentOS Linux (3.10.0-1160.25.1.el7.x86_64.debug) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-5f46dcbf-57ca-44c0-9843-c2cbd30da1dc' {
menuentry 'CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-5f46dcbf-57ca-44c0-9843-c2cbd30da1dc' {
menuentry 'CentOS Linux (3.10.0-862.9.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-5f46dcbf-57ca-44c0-9843-c2cbd30da1dc' {
menuentry 'CentOS Linux 7 Rescue 8d1fcbed219ea3264af0402615579c5a (3.10.0-862.9.1.el7.x86_64)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-123.el7.x86_64-advanced-5f46dcbf-57ca-44c0-9843-c2cbd30da1dc' {

(6)查看当前优先启动内核

[root@10-27-0-224 ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)

(7)通过设置默认启动来回退内核版本

[root@10-27-0-224 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64.debug) 7 (Core)
1 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-862.9.1.el7.x86_64) 7 (Core)
3 : CentOS Linux 7 Rescue 8d1fcbed219ea3264af0402615579c5a (3.10.0-862.9.1.el7.x86_64)

[root@10-27-0-224 ~]# grub2-set-default 2  #设置默认优先启动的内核
[root@10-27-0-224 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg  #更新配置文件

2.2 RPM安装

(1)CentOS内核下载网址

http://vault.centos.org/

http://vault.centos.org/7.4.1708/os/x86_64/Packages/kernel-3.10.0-693.el7.x86_64.rpm

http://vault.centos.org/7.4.1708/os/x86_64/Packages/kernel-devel-3.10.0-693.el7.x86_64.rpm

(2)第三方内核下载地址

https://elrepo.org/linux/kernel/el7/x86_64/RPMS/

(3)下载并安装内核

[root@10-27-0-224 ~]# wget https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.128-1.el7.elrepo.x86_64.rpm 
[root@10-27-0-224 ~]# rpm -ivh kernel-lt-5.4.128-1.el7.elrepo.x86_64.rpm

Linux 升级内核方法(图2)

(4)查看当前内核列表

[root@10-27-0-224 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.4.128-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64.debug) 7 (Core)
2 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-862.9.1.el7.x86_64) 7 (Core)
4 : CentOS Linux 7 Rescue 8d1fcbed219ea3264af0402615579c5a (3.10.0-862.9.1.el7.x86_64)

(5)指定默认从新内核启动

[root@10-27-0-224 ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)

[root@10-27-0-224 ~]# grub2-set-default 0
[root@10-27-0-224 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

# 卸载老内核
yum remove kernel-3.10.0-1160.25.1.el7.x86_64 -y

2.3 UCloud快杰云主机4.19内核版本降低至3.10

# 降到3.10内核操作:
yum install linux-firmware
yum install kernel
wget https://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/Packages/kernel-3.10.0-1160.el7.x86_64.rpm

wget https://vault.centos.org/7.9.2009/os/x86_64/Packages/kernel-3.10.0-1160.el7.x86_64.rpm
rpm -ivh kernel-3.10.0-1160.el7.x86_64.rpm --force
reboot

作者:UStarGao

链接:https://www.starcto.com/application_of_operational/172.html
来源:STARCTO
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

UCloud云平台推荐


UCloud新用户专属注册连接

UCloud CDN超值特惠专场

UCloud全球云主机(UHost/VPS)大促页面

UCloud快杰云主机大促页面

标签: Linux升级内核
文章页广告

随便看看

栏目底部广告
`