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"

注意>号左右都有空格

相关推荐
哲霖软件5 分钟前
ERP 赋能非标自动化行业:破解物料与库存管理难题
运维·自动化
qq_542515411 小时前
Ubuntu 22.04.4 LTS安装ToDesk最新版打不开,无响应?旧版本4.7.2_277版本分享
linux·ubuntu·todesk
火车叼位1 小时前
替代 Tiny Win10 的 Linux 方案:Debian XFCE 精简桌面搭建
linux·运维
小麦嵌入式1 小时前
FPGA入门(四):时序逻辑计数器原理与 LED 闪烁实现
linux·驱动开发·stm32·嵌入式硬件·fpga开发·硬件工程·dsp开发
皮卡蛋炒饭.2 小时前
传输层协议UDP
linux·网络协议·udp
大明者省3 小时前
宝塔开了端口,Ubuntu 还得开相应端口才能打通
服务器·数据库·ubuntu
syagain_zsx3 小时前
Linux指令初识(实用篇)
linux·运维·服务器
OYangxf3 小时前
Git Commit Message
运维·git
Alter12303 小时前
从“力大砖飞”到“拟态共生”,新华三定义AI基础设施的系统级进化
大数据·运维·人工智能
王木风3 小时前
终端里的编程副驾:DeepSeek-TUI-项目深度拆解,实测与原理分析
linux·运维·人工智能·rust·node.js