ubuntu 切换linux内核
运行命令查看已安装内核:
dpkg --get-selections |grep linux-image
显示如下:
linux-image-5.4.0-81-generic install linux-image-5.4.0-99-generic install linux-image-generic install
将后面一个数字替换为要切换的小版本 如:58
安装image
apt-get install linux-image-5.4.0-58-generic
将image替换为headers,安装headers
apt-get install linux-headers-5.4.0-58-generic
查看要切换版本的位置序号:
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-77f3eb41-a50b-4464-a277-45119135e95f' { submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-99-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-99-generic-advanced-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-99-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-99-generic-recovery-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-81-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-81-generic-advanced-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-81-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-81-generic-recovery-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-58-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-58-generic-advanced-77f3eb41-a50b-4464-a277-45119135e95f' { menuentry 'Ubuntu, with Linux 5.4.0-58-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-58-generic-recovery-77f3eb41-a50b-4464-a277-45119135e95f' {
可以看到Ubuntu, with Linux 5.4.0-58-generic 在 menuentry 'Ubuntu 的第5行,0开始的序号为4
发现有个更简单方式,查看要切换版本的序号。
直接运行一次:
update-grub
看列表要切换的版本排在哪个位置。 比上面清晰些。
编辑/etc/default/grub
将GRUB_DEFAULT="0"
更改为:GRUB_DEFAULT="1> 4"
注意4前面带个空格。
更新grub
update-grub
重启
reboot now
重启后用uname -r查看内核版本