Linux CentOS7内核升级

1、导入key,提前下载

[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

2、安装yum源,使用elrepo源,提前下载

[root@localhost ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
获取http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
准备中... ################################# [100%]
正在升级/安装...
1:elrepo-release-7.0-3.el7.elrepo ################################# [100%]

3、查看有多少内核版本:

[root@node01 ~]# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
可安装的软件包
elrepo-release.noarch                                                              7.0-4.el7.elrepo                                                       elrepo-kernel
kernel-lt.x86_64                                                                   4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-devel.x86_64                                                             4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-doc.noarch                                                               4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-headers.x86_64                                                           4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-tools.x86_64                                                             4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-tools-libs.x86_64                                                        4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                                                  4.4.214-1.el7.elrepo                                                   elrepo-kernel
kernel-ml-doc.noarch                                                               5.5.4-1.el7.elrepo                                                     elrepo-kernel
kernel-ml-headers.x86_64                                                           5.5.4-1.el7.elrepo                                                     elrepo-kernel
kernel-ml-tools.x86_64                                                             5.5.4-1.el7.elrepo                                                     elrepo-kernel
kernel-ml-tools-libs.x86_64                                                        5.5.4-1.el7.elrepo                                                     elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                                                  5.5.4-1.el7.elrepo                                                     elrepo-kernel
perf.x86_64                                                                        5.5.4-1.el7.elrepo                                                     elrepo-kernel
python-perf.x86_64                                                                 5.5.4-1.el7.elrepo                                                     elrepo-kernel

4、安装内核

[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
yum install -y kernel-lt-5.4.95-1.el7.elrepo --enablerepo=elrepo-kernel #安装指定版本内核。

5、查看系统上可用内核

[root@node01 ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (5.5.4-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-b2a3b7035ddf4f6cb0ebf2369b27135b) 7 (Core)

6、设置新的内核为grub2的默认版本

方法1

[root@localhost ~]# grub2-set-default 0

方法2、编辑 /etc/default/grub 文件

设置 GRUB_DEFAULT=0,通过上面查询显示的编号为 0 的内核作为默认内核:
[root@node01 ~]# vi /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"

生成 grub 配置文件并重启

[root@node01 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.5.4-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.5.4-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-b2a3b7035ddf4f6cb0ebf2369b27135b
Found initrd image: /boot/initramfs-0-rescue-b2a3b7035ddf4f6cb0ebf2369b27135b.img
done
[root@node01 ~]# reboot

7、重启 reboot

[root@node01 ~]# uname -r
5.5.4-1.el7.elrepo.x86_64

8、删除旧内核(可选)

查看系统中全部的内核:
[root@node01 ~]# rpm -qa | grep kernel
kernel-tools-3.10.0-957.el7.x86_64
kernel-ml-5.5.4-1.el7.elrepo.x86_64
kernel-headers-3.10.0-1062.12.1.el7.x86_64
kernel-3.10.0-957.el7.x86_64
kernel-debug-devel-3.10.0-1062.12.1.el7.x86_64
kernel-tools-libs-3.10.0-957.el7.x86_64
kernel-ml-devel-5.5.4-1.el7.elrepo.x86_64

方法1、yum remove 删除旧内核的 RPM 包

[root@node01 ~]# yum remove kernel-tools-3.10.0-957.el7.x86_64 kernel-headers-3.10.0-1062.12.1.el7.x86_64 kernel-3.10.0-957.el7.x86_64 kernel-debug-devel-3.10.0-1062.12.1.el7.x86_64 kernel-tools-libs-3.10.0-957.el7.x86_64

方法2、yum-utils 工具

如果安装的内核不多于 3 个,yum-utils 工具不会删除任何一个。只有在安装的内核大于 3 个时,才会自动删除旧内核。

安装yum-utils

yum install yum-utils

删除旧版本  

package-cleanup --oldkernels

 

posted @ 2020-01-07 11:03  星火撩原  阅读(428)  评论(0编辑  收藏  举报