系统内核升级回滚

查看当前版本

[root@test-app-45-92 ~]# uname -r
3.10.0-1160.15.2.el7.x86_64  #环境的不同,可能查下的内核会有所不同

操作步骤
本案例主要以4.4.234-1.el7.elrepo.x86_64为例,如果升级其它版本,请下载对应的操作系统内核包

操作系统内核包需要通过xftp等工具上传到部署机。

3545af80a5dcfd9029ad051e35a31f08  kernel-lt-4.4.234-1.el7.elrepo.x86_64.rpm
c758965229d03c367148c8932486ed29  kernel-lt-devel-4.4.234-1.el7.elrepo.x86_64.rpm
安装新内核
[root@test-app-45-92 tmp]# rpm -ivh kernel-lt-4.4.234-1.el7.elrepo.x86_64.rpm kernel-lt-devel-4.4.234-1.el7.elrepo.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:kernel-lt-devel-4.4.234-1.el7.elr################################# [ 50%]
   2:kernel-lt-4.4.234-1.el7.elrepo   ################################# [100%]
6.3、查看系统已经安装的内核版本
[root@test-app-45-92 tmp]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (4.4.234-1.el7.elrepo.x86_64) 7 (Core)                                #有此信息表示新内核安装成功
1 : CentOS Linux (3.10.0-1160.15.2.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-d09ed4d648cf48d59efdaaf47927193d) 7 (Core)

设置新的内核为grub2的默认版本
服务器上存在4 个内核,我们要使用 4.4.234 这个版本,编辑 /etc/default/grub 文件来设置

设置 GRUB_DEFAULT=0,通过上面查询显示的编号为 0 的内核作为默认内核:

root@test-app-45-92 tmp]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
#GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

生成 grub 配置文件并重启

[root@test-app-45-92 tmp]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.234-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.4.234-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.15.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.15.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1062.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d09ed4d648cf48d59efdaaf47927193d
Found initrd image: /boot/initramfs-0-rescue-d09ed4d648cf48d59efdaaf47927193d.img
done

重启操作系统

reboot

查看操作系统内核版本

[root@test-app-45-92 tmp]# uname -r
4.4.234-1.el7.elrepo.x86_64                            #内核升级成功

回滚

卸载内核版本
[root@test-app-45-92 tmp]# yum remove kernel-lt-4.4.234-1.el7.elrepo.x86_64 kernel-lt-devel-4.4.234-1.el7.elrepo.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package kernel-lt.x86_64 0:4.4.234-1.el7.elrepo will be erased
---> Package kernel-lt-devel.x86_64 0:4.4.234-1.el7.elrepo will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================
 Package                                         Arch                                   Version                                               Repository                                 Size
==============================================================================================================================================================================================
Removing:
 kernel-lt                                       x86_64                                 4.4.234-1.el7.elrepo                                  installed                                 182 M
 kernel-lt-devel                                 x86_64                                 4.4.234-1.el7.elrepo                                  installed                                  38 M
Transaction Summary
==============================================================================================================================================================================================
Remove  2 Packages
Installed size: 220 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Erasing    : kernel-lt-4.4.234-1.el7.elrepo.x86_64                                                                                                                                      1/2 
  Erasing    : kernel-lt-devel-4.4.234-1.el7.elrepo.x86_64                                                                                                                                2/2 
  Verifying  : kernel-lt-devel-4.4.234-1.el7.elrepo.x86_64                                                                                                                                1/2 
  Verifying  : kernel-lt-4.4.234-1.el7.elrepo.x86_64                                                                                                                                      2/2 
Removed:
  kernel-lt.x86_64 0:4.4.234-1.el7.elrepo                                                    kernel-lt-devel.x86_64 0:4.4.234-1.el7.elrepo                                                   
Complete!

查看系统已经安装的内核版本

[root@test-app-45-92 tmp]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (3.10.0-1160.15.2.el7.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-d09ed4d648cf48d59efdaaf47927193d) 7 (Core)

回滚内核为grub2的默认版本
设置 GRUB_DEFAULT=0,通过上面查询显示的编号为 0 的内核作为默认内核:

[root@test-app-45-92 tmp]# vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=0
#GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

生成 grub 配置文件并重启

[root@test-app-45-92 tmp]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.234-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.4.234-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.15.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.15.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-55d8d02ba82f4ef99c81d0fa54e90604
Found initrd image: /boot/initramfs-0-rescue-55d8d02ba82f4ef99c81d0fa54e90604.img
done

重启操作系统

reboot

查看操作系统内核版本

[root@test-app-45-92 tmp]# uname -r
3.10.0-1160.15.2.el7.x86_64                            #内核回滚成功
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值