起因

最近因为系统内核自动升级,导致显卡驱动检测不到,炼丹环境被破坏。无奈只能重装驱动,于是跟着手册操作发现驱动要求的是内核版本是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
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默认关闭对其他操作系统的识别,系统会出现以下警告:
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
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

版权属于:染念
作品采用:本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
更新于: 2024年09月07日 21:25
0


183 文章数
695 评论量
4 分类数
186 页面数
已在风雨中度过 7年249天21小时40分
目录
来自 《Ubuntu22.04回退系统内核》
© 2024 染念的笔记
浙ICP备19020194号-1
暗黑模式
暗黑模式
评论
返回顶部
© 2024 染念的笔记
浙ICP备19020194号-1
暗黑模式
暗黑模式
评论
返回顶部