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 天前
Active Directory服务账户是什么?
运维·服务器·网络
HIT_Weston1 天前
84、【Ubuntu】【Hugo】搭建私人博客:文章目录(三)
linux·运维·ubuntu
moxiaoran57531 天前
使用docker安装myql 8.0
运维·docker·容器
qq_5470261791 天前
Linux 常用快捷键及文本编辑器
linux·运维·服务器
埃伊蟹黄面1 天前
磁盘级文件系统核心原理解析
linux·文件
醇氧1 天前
【Linux】 安装 Azul Zulu JDK
java·linux·运维
小康小小涵1 天前
睿抗机器人大赛魔力元宝
python·ubuntu·gitee·github
一直跑1 天前
查看显卡驱动版本,查看哪个用户使用显卡(GPU)进程
linux·服务器
滴水之功1 天前
Windows远程桌面(非图形化界面)连接Ubuntu22.04
linux
借你耳朵说爱你1 天前
在Linux上挂载磁盘
linux