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

相关推荐
Yyyy4824 小时前
Ubuntu安装Jenkis
linux·运维·ubuntu
zhuzewennamoamtf5 小时前
Linux SPI设备驱动
android·linux·运维
春日见5 小时前
在虚拟机上面无法正启动机械臂的控制launch文件
linux·运维·服务器·人工智能·驱动开发·ubuntu
松涛和鸣6 小时前
Linux Makefile : From Basic Syntax to Multi-File Project Compilation
linux·运维·服务器·前端·windows·哈希算法
Predestination王瀞潞6 小时前
JDK安装及环境变量配置
java·linux·开发语言
再睡一夏就好7 小时前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
小小药7 小时前
09-vmware配置虚机连接互联网-nat模式
linux·运维·centos
Bright Xu7 小时前
Qemu 安装 LoongArch架构 Fedora Remix F42 Linux系统
linux·loongarch·国产cpu
莫白媛7 小时前
Linux创作笔记综合汇总篇
linux·运维·笔记
studytosky8 小时前
Linux系统编程:深度解析 Linux 进程,从底层架构到内存模型
linux·运维·服务器·开发语言·架构·vim