centos7.7-升级内核后进入grub-rescue 模式

1. 背景

        工作需要适配centos7.7.1908 (Core)-3.10.0-1160.11.1.el7.x86_64

        环境默认的内核版本是:

 [root@localhost ~]# cat /proc/version 
Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)


系统的grub菜单相关内容是:

[root@localhost ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (3.10.0-1160.15.2.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-e290797803974b52bed754cf98033673) 7 (Core)

2.操作步骤

        在网上下载kernel-3.10.0-1160.11.1.el7.x86_64.rpm和kernel-devel-3.10.0-1160.11.1.el7.x86_64.rpm

2.1 下载地址

        kernel-3.10.0-1160.11.1.el7.x86_64.rpm

   https://centos.pkgs.org/7/centos-updates-x86_64/kernel-3.10.0-1160.11.1.el7.x86_64.rpm.html

        kernel-devel-3.10.0-1160.11.1.el7.x86_64.rpm

   http://mirror.centos.org/centos/7/updates/x86_64/Packages/kernel-devel-3.10.0-1160.11.1.el7.x86_64.rpm     

2.2 安装过程       

 rpm -ivh kernel-3.10.0-1160.11.1.el7.x86_64.rpm

 rpm -ivh kernel-devel-3.10.0-1160.11.1.el7.x86_64.rpm

   此时查看grub2关于内核版本选择的相关信息

[root@localhost 3.10.0-1160.11.1.el7]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-e290797803974b52bed754cf98033673) 7 (Core)

       

    更改启动顺序 ,修改 GRUB_DEFAULT的值变成0(指向最新安装的内核,默认的值是saved,是按照上一次进入系统的时候选择的内容来默认选择)

 vim /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"

接着运行grub2-mkconfig命令来重新创建内核配置

[root@localhost 3.10.0-1160.11.1.el7]# grub2-mkconfig
Generating grub configuration file ...
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
set pager=1

if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

terminal_output console
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###

### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
  source ${prefix}/user.cfg
  if [ -n "${GRUB2_PASSWORD}" ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
fi
### END /etc/grub.d/01_users ###

### BEGIN /etc/grub.d/10_linux ###
Found linux image: /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.11.1.el7.x86_64.img
menuentry 'CentOS Linux (3.10.0-1160.11.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1160.11.1.el7.x86_64-advanced-4c4e29b9-c28f-4fdb-aae6-923e92be5afa' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  df379286-1330-4a86-9c96-5ffa71b4ec93
	else
	  search --no-floppy --fs-uuid --set=root df379286-1330-4a86-9c96-5ffa71b4ec93
	fi
	linux16 /vmlinuz-3.10.0-1160.11.1.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet 
	initrd16 /initramfs-3.10.0-1160.11.1.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
menuentry 'CentOS Linux (3.10.0-1062.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1062.el7.x86_64-advanced-4c4e29b9-c28f-4fdb-aae6-923e92be5afa' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  df379286-1330-4a86-9c96-5ffa71b4ec93
	else
	  search --no-floppy --fs-uuid --set=root df379286-1330-4a86-9c96-5ffa71b4ec93
	fi
	linux16 /vmlinuz-3.10.0-1062.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet 
	initrd16 /initramfs-3.10.0-1062.el7.x86_64.img
}
Found linux image: /boot/vmlinuz-0-rescue-e290797803974b52bed754cf98033673
Found initrd image: /boot/initramfs-0-rescue-e290797803974b52bed754cf98033673.img
menuentry 'CentOS Linux (0-rescue-e290797803974b52bed754cf98033673) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-e290797803974b52bed754cf98033673-advanced-4c4e29b9-c28f-4fdb-aae6-923e92be5afa' {
	load_video
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  df379286-1330-4a86-9c96-5ffa71b4ec93
	else
	  search --no-floppy --fs-uuid --set=root df379286-1330-4a86-9c96-5ffa71b4ec93
	fi
	linux16 /vmlinuz-0-rescue-e290797803974b52bed754cf98033673 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet 
	initrd16 /initramfs-0-rescue-e290797803974b52bed754cf98033673.img
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
done

重启操作系统       

reboot -f

3.问题现象

3.1 在低版本内核升级,没有操作grub2-mkconfig

系统启动的时候没有选择内核的界面,直接进入了grub的rescue模式

3.2 在高版本内核(15.2)直接安装11.1升级包

此时会提示更高版本的内核已经安装,需要--force参数强制安装。

4.问题解决

        按照升级后,重新生成grub相关配置文件的流程,升级成功。

5.总结

        正常升级内核的顺序,应该是安装好升级包和头文件,要重新生成grub的配置。

以前都省略掉了grub重新生成配置的操作,并没出现问题,这次就出现了此问题,那么这次升级是搞坏了grub吗?

        

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值