Ubuntu22.04回退系统内核

文章目录

起因

最近因为系统内核自动升级,导致显卡驱动检测不到,炼丹环境被破坏。无奈只能重装驱动,于是跟着手册操作发现驱动要求的是内核版本是5.15.0-25-generic,而我通过uname -r发现这时候的内核版本是6.8.0-40-generic,看来只能回退了。

我搜索了网上很多的文章,没有一篇文章能够完全解决这个问题,所以在我多次尝试之下,我将我的折腾经验分享给未来有需要的人。

回退操作

  1. 查看自己的grub版本:

    grub-install --version

  • 记住这个版本是2.00以后还是2.00以前,但如果是Ubuntu22.04,肯定是大于2.00版本的
  • 比如我就是grub-install (GRUB) 2.06-2ubuntu7.2
  • 查询这个版本的原因是,后续我们要通过修改/etc/default/grub文件,而不同版本的语法是不同的
  1. 接下来查看自己现有的内核版本grep 'menuentry' /boot/grub/grub.cfg
bash 复制代码
if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
  menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
	menuentry 'Ubuntu, with Linux 6.8.0-40-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.8.0-40-generic-advanced-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
	menuentry 'Ubuntu, with Linux 6.8.0-40-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.8.0-40-generic-recovery-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
	menuentry 'Ubuntu, with Linux 6.5.0-18-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.5.0-18-generic-advanced-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
	menuentry 'Ubuntu, with Linux 6.5.0-18-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.5.0-18-generic-recovery-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0' {
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
  1. 如果没有自己想要的版本,那么就要安装,如果有的话,直接掉下一步。
  • sudo apt install linux-image-5.15.0-25-generic,你可以修改你的需要的版本
  1. sudo vim /etc/default/grub
  • 将第一个GRUB_DEFAULT=0改成GRUB_DEFAULT="..."
  1. 省略号的内容看第2步的查询结果,对于grub是2版本之前的版本,复制上面menuentry之后的单引号内的字符串,写Advanced options for Ubuntu>Ubuntu,Linux 6.5.0-18-generic,不要填 (recovery mode) ,对于2之后的版本,写$menuentry_id_option之后的内容,例如gnulinux-advanced-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0>gnulinux-5.15.0-25-generic-advanced-9732298b-8d7e-4ef9-9b9f-a0335b12c0d0,注意看,有些地方重复了2次
  2. ubuntu22.04系统中grub默认关闭对其他操作系统的识别,系统会出现以下警告:
bash 复制代码
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
  1. 因此还需要在/etc/default/grub,添加GRUB_DISABLE_OS_PROBER=false
  2. 最后执行sudo update-grub
bash 复制代码
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
done
  1. 得到上述信息之后重启电脑sudo reboot

  2. 重启之后,再使用uname -r看看是不是自己想要的版本,然后打开/etc/default/grub,将第一个改回GRUB_DEFAULT=0,最后执行sudo update-grub

卸载内核

使用dpkg --get-selections | grep linux-image查看现有内核,对于不需要的,我们通过以下步骤进行卸载:

  • sudo apt purge linux-image-6.5.0-18-generic
  • sudo apt autoremove
  • cd /lib/modulesls删除一些配置文件

卸载之后也不要忘了sudo update-grub与重启

禁止内核升级

造成上面最烦的原因是因为内核升级了,而有时候我们就算设置系统不更新,内核还是会悄悄升级,所以我们可以使用下面的方向固化内核:

sudo apt-mark hold linux-image-5.15.0-25-generic

相关推荐
夜月yeyue2 小时前
Linux内高端内存
linux·运维·单片机·嵌入式硬件·ci/cd·硬件架构
猫豆~3 小时前
nginx实战-PHP——day2
linux·centos·云计算
杨云龙UP3 小时前
MySQL 自动备份与覆盖恢复实战:一套脚本搞定全库/按库备份恢复
linux·运维·数据库·sql·mysql
三小尛3 小时前
Linux的常见指令
linux
starvapour3 小时前
Ubuntu下sudo的免密操作
linux·ubuntu
sjg200104143 小时前
Deepin 20.9 误装gcc-8-base_8.4.0-1ubuntu1~16.04.1_amd64 后卸载
linux·运维·服务器
一帘忧梦3 小时前
linux 系统rcs脚本启动
linux·运维·lua
jerryinwuhan4 小时前
1210_1 Linux
linux·运维·服务器
福尔摩斯张5 小时前
Linux信号捕捉特性详解:从基础到高级实践(超详细)
linux·运维·服务器·c语言·前端·驱动开发·microsoft
looking_for__5 小时前
【Linux】进程控制
linux