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
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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

染念

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值