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

相关推荐
小狮子安度因19 分钟前
边缘智能-大模型架构初探
linux·网络
晨春计23 分钟前
【git】
android·linux·git
Flying_Fish_roe35 分钟前
linux-软件包管理-包管理工具(RedHat/CentOS 系)
linux·运维·centos
Splashtop高性能远程控制软件37 分钟前
centos远程桌面连接windows
linux·windows·centos·远程控制·远程桌面
tang&1 小时前
【Linux】进程概念
linux
苏少朋1 小时前
Docker安装 ▎Docker详细讲解 ▎数据卷挂载 ▎Nginx安装理解
linux·nginx·docker·容器
Jerry 二河小鱼1 小时前
在Linux中安装FFmpeg
linux·运维·服务器·ffmpeg
Roc-xb2 小时前
如何在 CentOS 上安装和使用 Neofetch(图文教程)
linux·运维·centos
程序员大阳2 小时前
Linux(6)--CentOS目录
linux·centos·目录
小技与小术2 小时前
lvs命令介绍
linux·运维·服务器·lvs