Ubuntu更改内核

需求背景:

由于软件需要在较低版本或者指定版本才可以运行

版本:

配置文件: vi /etc/default/grub

启动界面:

可运行版本:

解决方案:

方案1、更改启动顺序 sudo vi /etc/default/grub

方案2、调整启动顺序 sudo vi /boot/grub/grub.cfg

方案3、更改默认系统

完成效果:

错误BUG:

1\

Warning: os-prober will not be executed to detect other bootable partitions.

Systems on them will not be added to the GRUB boot configuration.

2\

/usr/sbin/grub-mkconfig: 34: /etc/default/grub: Syntax error: Unterminated quoted string

实施步骤:

调整配置: sudo vi /etc/default/grub

更新配置: sudo update-grub

重启:

1.查看当前内核

uname -r

sudo apt update

sudo apt install linux-image-your-version

sudo apt install linux-image-5.15.0-25-generic

-s14:~$ sudo update-grub

Sourcing file `/etc/default/grub'

Sourcing file `/etc/default/grub.d/init-select.cfg'

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-5.15.0-130-generic

Found initrd image: /boot/initrd.img-5.15.0-130-generic

Found linux image: /boot/vmlinuz-5.15.0-127-generic

Found initrd image: /boot/initrd.img-5.15.0-127-generic

Found linux image: /boot/vmlinuz-5.15.0-25-generic

Found initrd image: /boot/initrd.img-5.15.0-25-generic

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.

done

此命令会扫描系统中的所有内核,并更新Grub配置文件(通常位于/boot/grub/grub.cfg),以包含新的内核选项。

4. 配置Grub以选择默认启动的内核(可选)

如果你希望设置某个内核为默认启动项,可以编辑Grub配置文件中的GRUB_DEFAULT变量。这个变量通常位于/etc/default/grub文件中。

例如,要设置默认启动的内核为刚刚安装的内核(假设它在Grub菜单中的索引为0),你可以编辑/etc/default/grub文件,并将GRUB_DEFAULT设置为0

bashCopy Code

sudo nano /etc/default/grub

找到GRUB_DEFAULT行,并将其值更改为新内核的索引(从0开始计数)。保存并关闭文件后,再次运行sudo update-grub命令以应用更改。

注意 ‌:Grub菜单中的内核索引可能会随着新内核的安装和旧内核的卸载而发生变化。因此,在更改GRUB_DEFAULT之前,最好先查看Grub菜单以确认新内核的索引。

5. 重启系统并验证内核切换是否成功

最后,重启系统以应用内核更改:

五、 设置指定内核启动

  1. 查看内核启动顺序,如下所示,找到"Ubuntu 的高级选项",在下面以menuentry开头的就是内核,目前我这上面有三个内核版本和三个内核包,从第一个以0开始计数,切换到5.15.91内核版本,就是第2个。

root@l:e:/home/lr# vi /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-850791fb-48f1-47e5-ae82-0769b2f20b72' {

submenu 'Ubuntu 的高级选项' $menuentry_id_option 'gnulinux-advanced-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu,Linux 5.15.0-119-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-119-generic-advanced-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu, with Linux 5.15.0-119-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-119-generic-recovery-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu,Linux 5.15.0-91-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-91-generic-advanced-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu, with Linux 5.15.0-91-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-91-generic-recovery-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu,Linux 5.15.0-67-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-67-generic-advanced-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Ubuntu, with Linux 5.15.0-67-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.0-67-generic-recovery-850791fb-48f1-47e5-ae82-0769b2f20b72' {

menuentry 'Memory test (memtest86+)' {

menuentry 'Memory test (memtest86+, serial console 115200)'

  1. 修改grub文件

将GRUB_DEFAULT=0 修改为 GRUB_DEFAULT="1>2"

vi /etc/default/grub

  1. 更新grub配置

sudo update-grub

  1. 重启系统

查看内核版本

root@lr-virtual-machine:/home/lr# uname -r

5.15.0-91-generic

那么内核就更新并设置完成了。

Ⅰ. 打开开机引导文件

sudo gedit /etc/default/grub

Ⅱ. 修改默认启动项

GRUB_DEFAULT=2

属性名:开机默认启动系统

值说明:从0开始(按照开机选择界面的顺序对应)

Ⅲ. 修改等待时间

GRUB_TIMEOUT=5

属性名:进入默认启动项的等候时间

值说明:单位:秒,默认10秒

Ⅳ. 调整 GRUB 启动菜单字号

📌屏幕是4K屏时,启动菜单字体较小可以进行设置。

GRUB_GFXMODE=1280x1024x32,1280x1024x24,1024x768x32,1024x768x24,"auto"

Ⅴ. 修改生效

sudo update-grub

1.查看当前内核

uname -r

2.在sources.list添加以下源

sudo vi /etc/apt/sources.list

复制代码
deb http://security.ubuntu.com/ubuntu trusty-security main
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

3.更新

sudo apt update

4.查看可下载的内核版本

apt-cache search linux-image |grep -v generic - debug

5.下载对应内核

sudo apt-get install linux-image-4.15.0-20-generic

6.更新

sudo update-grub

//根据打印出来的内核顺序记住所需的内核版本序号(从零开始,我所需的内核版本序号为4)

7.更改默认的内核版本

sudo vi /etc/default/grub

在GRUB_DEFAULT=0 改为 GRUB_DEFAULT="1 > 4"

注意>号左右都有空格

8.更新

sudo update-grub

9.重启

reboot

8.更新

sudo update-grub

7.更改默认的内核版本

sudo vi /etc/default/grub

在GRUB_DEFAULT=0 改为 GRUB_DEFAULT="1 > 4"

注意>号左右都有空格

相关推荐
Johny_Zhao3 小时前
Docker + CentOS 部署 Zookeeper 集群 + Kubernetes Operator 自动化运维方案
linux·网络安全·docker·信息安全·zookeeper·kubernetes·云计算·系统运维
小毛驴8504 小时前
Linux 后台启动java jar 程序 nohup java -jar
java·linux·jar
一心0925 小时前
ubuntu 20.04.6 sudo 源码包在线升级到1.9.17p1
运维·ubuntu·sudo·漏洞升级
好好学习啊天天向上5 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
你想考研啊5 小时前
三、jenkins使用tomcat部署项目
运维·tomcat·jenkins
tan180°6 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
代码老y6 小时前
Docker:容器化技术的基石与实践指南
运维·docker·容器
典学长编程6 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
wuk9987 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
你想考研啊9 小时前
四、jenkins自动构建和设置邮箱
运维·jenkins