在实验环境下,已安装了最新的CentOS 7.6操作系统,现在需要升级内核版本。
实验环境
CentOS-7-x86_64-Minimal-1810.iso
CentOS Linux release 7.6.1810 (Core)
Kernel 3.10.0-957.10.1.el7.x86_64
载入elrepo源,搜索内核更新资源,并进行更新操作。
具体实验步骤:
# 载入公钥
Python
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
1
[root@localhost~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装ELRepo
Python
[root@localhost ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
1
[root@localhost~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# 载入elrepo-kernel元数据
Python
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
1
[root@localhost~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
# 查看可用的rpm包
Python
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
1
[root@localhost~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*
# 安装最新版本的kernel
Python
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml.x86_64
1
[root@localhost~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml.x86_64
重启,选择新版本内核进入系统。
此时,操作系统使用的内核已升级为【5.0.9-1.el7.elrepo.x86_64】
最后一步,需要将内核工具包一并升级
# 删除旧版本工具包
Python
[root@localhost ~]# yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64
1
[root@localhost~]# yum remove kernel-tools-libs.x86_64 kernel-tools.x86_64
# 安装新版本工具包
Python
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml-tools.x86_64
1
[root@localhost~]# yum --disablerepo=\* --enablerepo=elrepo-kernel install -y kernel-ml-tools.x86_64
至此,已完成升级。
1,首先查看当前系统有几个内核。比如:
Python
[root@localhost ~]# cat /boot/grub2/grub.cfg |grep menuentry
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
menuentry 'CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
menuentry 'CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
menuentry 'CentOS Linux (3.10.0-862.14.4.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
menuentry 'CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
menuentry 'CentOS Linux (0-rescue-b5adcba47ef3440c8ddb98ba96e19379) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-b5adcba47ef3440c8ddb98ba96e19379-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd' {
1
2
3
4
5
6
7
8
9
10
11
[root@localhost~]# cat /boot/grub2/grub.cfg |grep menuentry
if[x"${feature_menuentry_id}"=xy];then
menuentry_id_option="--id"
menuentry_id_option=""
exportmenuentry_id_option
menuentry'CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
menuentry'CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
menuentry'CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
menuentry'CentOS Linux (3.10.0-862.14.4.el7.x86_64) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
menuentry'CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-3.10.0-862.el7.x86_64-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
menuentry'CentOS Linux (0-rescue-b5adcba47ef3440c8ddb98ba96e19379) 7 (Core)'--classcentos--classgnu-linux--classgnu--classos--unrestricted$menuentry_id_option'gnulinux-0-rescue-b5adcba47ef3440c8ddb98ba96e19379-advanced-45ec2f3d-c5dc-4ab2-bb07-133b56e5b9dd'{
温馨提示:如果发现没有上面的那一项,请先执行下边命令生成grub配置文件
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
1
[root@localhost~]# grub2-mkconfig -o /boot/grub2/grub.cfg
2,设置默认的启动内核。比如我们选择上边中的 CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)这个内核为默认启动。
Python
[root@localhost ~]# grub2-set-default "CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)"
1
[root@localhost~]# grub2-set-default "CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)"
[root@localhost ~]# grub2-set-default “CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)”
验证是否修改成功:
Python
[root@localhost ~]# grub2-editenv list
saved_entry=CentOS Linux (5.0.9-1.el7.elrepo.x86_64) 7 (Core)
1
2
[root@localhost~]# grub2-editenv list
saved_entry=CentOSLinux(5.0.9-1.el7.elrepo.x86_64)7(Core)