Ubuntu安装/切换内核

查看当前已安装的内核

$ sudo dpkg --get-selections |grep linux-image
linux-image-5.15.0-71-generic                   install
linux-image-5.15.0-72-generic                   install
linux-image-5.4.0-149-generic                   install
linux-image-generic-hwe-20.04                   install

安装指定版本内核

Install kernel-generic:通用内核,一般 PC 及 Server

sudo apt list linux-headers-5.15.*-*-generic linux-image-5.15.*-*-generic
sudo apt install linux-headers-5.15.*-*-generic linux-image-5.15.*-*-generic

Install low-latency kernel:低延迟内核,适用于工业嵌入式系统(Industrial embedded systems)

sudo apt list linux-headers-5.15.*-*-lowlatency linux-image-5.15.*-*-lowlatency
sudo apt install linux-headers-5.15.*-*-lowlatency linux-image-5.15.*-*-lowlatency

更新initramfs

sudo update-initramfs -u -k all

修改引导菜单

/etc/default/grub

GRUB_DEFAULT=0
# GRUB_TIMEOUT_STYLE=hidden    >>>>>>>>>>>注释该行 显示grub菜单
GRUB_TIMEOUT=20                >>>>>>>>>>>设置菜单超时时长
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

sudo update-grub

reboot
通过grub菜单进入使用新内核的系统
sudo apt autoremove
卸载掉旧内核

检查内核启动顺序

grep menuentry /boot/grub/grub.cfg

编辑默认启动内核

vim /etc/default/grub

GRUB_DEFAULT=0 
# 改为
修改GRUB_DEFAULT的值为"1>2" 
# 或者
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-42-generic"

sudo update-grub

reboot

uname -r # 检查
posted @ 2023-05-24 16:46  ishmaelwanglin  阅读(3287)  评论(0编辑  收藏  举报