一、Ubuntu20.04更换系统默认启动内核,【采用apt 更新在线内核】
参考:
https://blog.csdn.net/weixin_46584887/article/details/125973263
二、操作步骤
首先使用如下命令可以查看系统目前正在使用的内核:
uname -r
输出如下:
zqfeng@zqfeng-hp-laptop:~$ uname -r 5.15.0-41-generic
使用如下命令可以查看系统可用的内核:
dpkg --get-selections | grep linux-image
输出如下:
zqfeng@zqfeng-hp-laptop:~$ dpkg --get-selections | grep linux-image linux-image-5.13.0-30-generic deinstall linux-image-5.13.0-52-generic deinstall linux-image-5.15.0-41-generic install linux-image-5.15.0-43-generic install linux-image-generic-hwe-20.04 install
其中显示 install 的就是当前系统可用的内核,接着我们同样修改 /etc/default/grub 文件:
sudo gedit /etc/default/grub
我们不修改 GRUB_DEFAULT 参数的值,而是添加如下两条命令:
GRUB_SAVEDEFAULT=true GRUB_DEFAULT=saved
接着注释掉 GRUB_TIMEOUT_STYLE 这一段代码,设置 GRUB_TIMEOUT 值为 30:
# GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=30
这样做的目的是使得开机前留下30秒的时间进入 grub 选择界面,接着更新 grub 配置:
sudo update-grub
重启系统:
sudo reboot
在开机之前的 grub 界面中,选择 Advantages for ubuntu 选项,接着选择自己想要的内核版本进入便可,系统会默认选择你本次的启动内核为默认内核版本。
三、附
开机后依然使用 uname -r 查看系统内核版本,接着需要注释掉 GRUB_TIMEOUT=30 这一段代码,设置 GRUB_TIMEOUT_STYLE 值为 hidden,不然下次开机还会弹出 grub 界面:
GRUB_TIMEOUT_STYLE=hidden # GRUB_TIMEOUT=30
更新一下配置:
sudo update-grub
问题解决。
二、 Ubuntu切换指定版本的内核,【通过从官网下载镜像进行安装内核】
参考:
https://blog.csdn.net/weixin_40837318/article/details/123798456
从 http://kernel.ubuntu.com/~kernel-ppa/mainline/ 中选择需要的版本:
根据你的系统架构下载 *.deb 文件:
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.180/amd64/linux-headers-5.4.180-0504180_5.4.180-0504180.202202161239_all.deb wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.180/amd64/linux-headers-5.4.180-0504180-generic_5.4.180-0504180.202202161239_amd64.deb wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.180/amd64/linux-image-unsigned-5.4.180-0504180-generic_5.4.180-0504180.202202161239_amd64.deb
安装*.deb:
sudo dpkg -i *.deb
更新grub:
sudo update-grub
2 确定当前使用的内核id:
grep submenu /boot/grub/grub.cfg
如下:
submenu 'Ubuntu 高级选项' $menuentry_id_option 'gnulinux-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' {
将单引号中的id记录下来gnulinux-advanced-3f5e97d5-cd08-4560-94df-613149aac32e。
3 查找想要使用的内核id :
grep gnulinux /boot/grub/grub.cfg
set default="gnulinux-advanced-3f5e97d5-cd08-4560-94df-613149aac32e>gnulinux-4.4.248-0404248-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e" menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-3f5e97d5-cd08-4560-94df-613149aac32e' { submenu 'Ubuntu 高级选项' $menuentry_id_option 'gnulinux-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu,Linux 4.15.1-041501-lowlatency' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-lowlatency-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.15.1-041501-lowlatency (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-lowlatency-init-upstart-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.15.1-041501-lowlatency (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-lowlatency-recovery-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu,Linux 4.15.1-041501-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.15.1-041501-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-generic-init-upstart-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.15.1-041501-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.1-041501-generic-recovery-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu,Linux 4.4.248-0404248-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.248-0404248-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.4.248-0404248-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.248-0404248-generic-init-upstart-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.4.248-0404248-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.248-0404248-generic-recovery-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu,Linux 4.4.0-141-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-141-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.4.0-141-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-141-generic-init-upstart-3f5e97d5-cd08-4560-94df-613149aac32e' { menuentry 'Ubuntu, with Linux 4.4.0-141-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-141-generic-recovery-3f5e97d5-cd08-4560-94df-613149aac32e' {
选择我们想要切换的内核,这里我选择的为:gnulinux-4.4.248-0404248-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e
4 修改grub文件,切换内核:
vim /etc/default/grub
根据第二步和第三步得到的内核:
将
GRUB_DEFAULT=0
改为:
GRUB_DEFAULT="gnulinux-advanced-3f5e97d5-cd08-4560-94df-613149aac32e>gnulinux-4.4.248-0404248-generic-advanced-3f5e97d5-cd08-4560-94df-613149aac32e"
5 更新grub:
sudo update-grub
6 重启
查看系统内核版本:
uname -r
标签:Ubuntu20.04,gnu,--,默认,generic,menuentry,内核,linux,class From: https://www.cnblogs.com/zjxcyr/p/16925851.html