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"

注意>号左右都有空格

相关推荐
皮小白1 小时前
ubuntu开机检查磁盘失败进入应急模式如何修复
linux·运维·ubuntu
邂逅星河浪漫1 小时前
【CentOS】虚拟机网卡IP地址修改步骤
linux·运维·centos
hhwyqwqhhwy1 小时前
linux 驱动开发相关
linux·驱动开发
IT逆夜2 小时前
实现Yum本地仓库自动同步的完整方案(CentOS 7)
linux·运维·windows
a***59262 小时前
用nginx正向代理https网站
运维·nginx·https
S***26752 小时前
linux上redis升级
linux·运维·redis
赖small强2 小时前
【Linux 网络基础】Linux 平台 DHCP 运作原理与握手过程详解
linux·网络·dhcp
ifanatic3 小时前
[每周一更]-(第161期):分析服务器中内存即将爆满过程
运维·服务器
热爱学习的小怪兽3 小时前
docker的一些常用指令
运维·docker·容器
s***4534 小时前
Linux 下安装 Golang环境
linux·运维·golang