Ubuntu 20.04 LTS修改内核版本
参考:https://cloud.tencent.com/developer/article/2121264
11. 修改内核版本
11.1 查看自己的grub版本
# grub-install --version
grub-install (GRUB) 2.04-1ubuntu26.16
11.2 查看现有的内核版本(完全版)
# grep 'menuentry' /boot/grub/grub.cfg
[ 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-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
menuentry 'Ubuntu, with Linux 5.4.0-144-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-144-generic-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
menuentry 'Ubuntu, with Linux 5.4.0-144-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-144-generic-recovery-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
menuentry 'Ubuntu, with Linux 5.4.0-125-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-125-generic-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
menuentry 'Ubuntu, with Linux 5.4.0-125-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-125-generic-recovery-2c4a365d-d766-4ed8-bc34-e66c06859e45' {}
11.3 修改grub
# vim /etc/default/grub
将GRUB_DEFAULT=0修改为:
GRUB_DEFAULT="Ubuntu, with Linux 5.4.0-125-generic"
# update-grub
...
...
Warning: Please don't use old title `Ubuntu, with Linux 5.4.0-125-generic' for GRUB_DEFAULT, use 'Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-125-generic' (for versions before 2.00) or 'gnulinux-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45>gnulinux-5.4.0-125-generic-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45' (for 2.00 or later)
...
...
再将GRUB_DEFAULT修改为:
GRUB_DEFAULT="gnulinux-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45>gnulinux-5.4.0-125-generic-advanced-2c4a365d-d766-4ed8-bc34-e66c06859e45"
再次执行update-grub不应再看到任何警告提示,重启后验证内核版本。
11.4 删除原来的内核
查看当前的所有已安装的内核:
# dpkg --get-selections | grep linux-image
linux-image-5.4.0-125-generic install
linux-image-5.4.0-144-generic install
linux-image-generic install
删除内核:
# apt remove linux-image-5.4.0-144-generic
# apt autoremove
# dpkg -P linux-image-5.4.0-144-generic
11.5 最后别忘记修改/etc/default/grub的GRUB_DEFAULT为0,以及update-grub。