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"

注意>号左右都有空格

相关推荐
BUG_MeDe3 分钟前
LINUX MTU/MSS(1500 1460等)的一些理解
linux·运维·服务器
风流倜傥唐伯虎3 分钟前
Windows 版 Docker 的 Linux 环境(docker-desktop)与 builder-jammy-base:latest 镜像核心区别
linux·docker·容器
曹牧4 分钟前
Nginx:正向代理与反向代理
运维·nginx
Ha_To5 分钟前
2026.1.30 搭建docker仓库
运维·docker·容器
lpfasd1237 分钟前
Docker Desktop 在国内使用的囧境:镜像拉取失败、加速器失效与破局之道
运维·docker·容器
江湖有缘12 分钟前
Docker部署SurveyKing调查问卷系统和考试系统
运维·docker·容器
A懿轩A24 分钟前
【Maven 构建工具】Maven 依赖管理详解:坐标、传递、作用域与依赖冲突解决(一篇搞懂)
java·linux·maven
小小管写大大码10 小时前
如何让vscode变得更智能?vscode接入claude实现自动编程
运维·ide·vscode·自动化·编辑器·ai编程·腾讯云ai代码助手
嵩山小老虎10 小时前
Windows 10/11 安装 WSL2 并配置 VSCode 开发环境(C 语言 / Linux API 适用)
linux·windows·vscode
Fleshy数模10 小时前
CentOS7 安装配置 MySQL5.7 完整教程(本地虚拟机学习版)
linux·mysql·centos