Ubuntu 如何指定内核版本启动

计算弹性计算技术服务知识库
问题现象

Ubuntu 系统安装了多版本的内核,因为默认使用了最新版本的内核启动,导致客户网卡驱动出现问题,如何回退到之前正常的内核版本?

排查步骤
  1. 查看当前使用的内核版本
root@iv-ycnthj7v28cva4f20b0a:~# uname -r
5.15.0-82-generic
  1. 查看已经安装的内核版本列表,确认需要回退的 kernel 版本(本示例是 5.15.0-67 版本)
root@iv-ycnthj7v28cva4f20b0a:~# dpkg --list | grep linux-image
ii  linux-image-5.15.0-67-generic          5.15.0-67.86~20.04.2              amd64        Signed kernel image generic
ii  linux-image-5.15.0-82-generic          5.15.0-82.91~20.04.1              amd64        Signed kernel image generic

解决方案

1.修改 grub 配置文件是高危操作,如果修改错误会导致系统无法正常启动,所以在操作前,建议对 ECS 实例本身进行快照。 2.本实例操作环境为 20.14, 其他版本类似

1.通过 VNC 选择低版本的内核进入系统

1.1 控制台重启 ECS 实例, 远程连接进入 VNC 界面 快速 快速按 Esc,进入 Grub 界面,如下: 图片 1.2 选择Advanced options for ubuntu 选项,进入选择内核界面如下: 图片 1.3 选择对应的内核版本例如 Ubuntu, with Linux 5.15.0-67-generic ,并进入系统

图片 1.4 登陆系统验证内核版本

图片

2.设置设置默认启动内核

2.1 找到内核对应的 menuentry 名称

root@iv-ycnthj7v28cva4f20b0a:~# cat /boot/grub/grub.cfg | grep "5.15.0-67-generic"|grep "menuentry" | awk -F"'" '{print $2}'
Ubuntu, with Linux 5.15.0-67-generic

2.2 修改 /etc/default/grub 文件,将 GRUB_DEFAULT 参数值修改为 2.1 步骤获取到的内核 名称

root@iv-ycnthj7v28cva4f20b0a:~# cat /etc/default/grub | grep '^GRUB_DEFAULT'
GRUB_DEFAULT="Ubuntu, with Linux 5.15.0-67-generic"

2.3 更新grub配置,重新生成grub配置文件

root@iv-ycnthj7v28cva4f20b0a:~# update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Found linux image: /boot/vmlinuz-5.15.0-79-generic
Found initrd image: /boot/initrd.img-5.15.0-79-generic
Warning: Please don't use old title `Ubuntu, with Linux 5.15.0-79-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-79-generic' (for versions before 2.00) or `gnulinux-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47>gnulinux-5.15.0-79-generic-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47' (for 2.00 or later)
Found linux image: /boot/vmlinuz-5.15.0-78-generic
Found initrd image: /boot/initrd.img-5.15.0-78-generic
…………
…………

2.4 查看有关于 grub 版本的 warining 报错

Warning: Please don't use old title `Ubuntu, with Linux 5.15.0-79-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-79-generic' (for versions before 2.00) or `gnulinux-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47>gnulinux-5.15.0-79-generic-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47' (for 2.00 or later)

2.5 重新编辑 /etc/default/grub 文件, 并更新为 2.00 or later 版本之后的数值

root@iv-ycnthj7v28cva4f20b0a:~# cat /etc/default/grub | grep '^GRUB_DEFAULT'
GRUB_DEFAULT="gnulinux-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47>gnulinux-5.15.0-79-generic-advanced-f3279c1c-386c-4763-98be-f0d93cb0fd47"

2.6 更新grub配置,重新生成grub配置文件

root@iv-ycnthj7v28cva4f20b0a:~# update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Found linux image: /boot/vmlinuz-5.15.0-79-generic
Found initrd image: /boot/initrd.img-5.15.0-79-generic
Found linux image: /boot/vmlinuz-5.15.0-78-generic
Found initrd image: /boot/initrd.img-5.15.0-78-generic
Found linux image: /boot/vmlinuz-5.15.0-76-generic
Found initrd image: /boot/initrd.img-5.15.0-76-generic
Found linux image: /boot/vmlinuz-5.15.0-75-generic
Found initrd image: /boot/initrd.img-5.15.0-75-generic
Found linux image: /boot/vmlinuz-5.15.0-74-generic
Found initrd image: /boot/initrd.img-5.15.0-74-generic
Found linux image: /boot/vmlinuz-5.15.0-73-generic
Found initrd image: /boot/initrd.img-5.15.0-73-generic
Found linux image: /boot/vmlinuz-5.15.0-72-generic
Found initrd image: /boot/initrd.img-5.15.0-72-generic
Found linux image: /boot/vmlinuz-5.15.0-71-generic
Found initrd image: /boot/initrd.img-5.15.0-71-generic
Found linux image: /boot/vmlinuz-5.15.0-70-generic
Found initrd image: /boot/initrd.img-5.15.0-70-generic
Found linux image: /boot/vmlinuz-5.15.0-69-generic
Found initrd image: /boot/initrd.img-5.15.0-69-generic
Found linux image: /boot/vmlinuz-5.15.0-67-generic
Found initrd image: /boot/initrd.img-5.15.0-67-generic
…………
…………
Adding boot menu entry for UEFI Firmware Settings
done

2.7 控制台重启操作系统 图片 2.8 验证重启后的默认内核版本

root@iv-ycnthj7v28cva4f20b0a:~# uname -r
5.15.0-79-generic
522
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论