Bootstrap

ubuntu Linux多个内核选择

一、问题

ununtu经常自动升级,或者是我们在update时,系统自动升级内核。此时会导致较高版本的内核与系统相互矛盾,而导致卡机等问题。此时需要对多余内核进行设置为默认内核或者将不正确内核删除。


两种方法:设置默认内核 ;删除内核。

二、设置默认内核

1、查看已经安装内核

dpkg --get-selections |grep linux-image

输出为:

linux-image-5.4.0-100-generic			deinstall
linux-image-5.4.0-107-generic			install
linux-image-5.4.0-109-generic			install
linux-image-5.4.0-42-generic			deinstall
linux-image-5.4.0-70-generic			deinstall
linux-image-generic-hwe-18.04			install

其中install是已经安装的,但是deinstall是已经卸载的

2、查看内核启动顺序

grep menuentry /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-93a5fee9-0321-409e-bac2-50327a6c34ee' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-109-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-109-generic-advanced-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-109-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-109-generic-recovery-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-107-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-107-generic-advanced-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-107-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-107-generic-recovery-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-91-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-91-generic-advanced-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-91-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-91-generic-recovery-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-89-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-89-generic-advanced-93a5fee9-0321-409e-bac2-50327a6c34ee' {
	menuentry 'Ubuntu, with Linux 5.4.0-89-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-89-generic-recovery-93a5fee9-0321-409e-bac2-50327a6c34ee' {
menuentry 'Windows Boot Manager (on /dev/nvme0n1p1)' --class windows --class os $menuentry_id_option 'osprober-efi-CA62-4E14' {
menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {

可以看出我们系统默认启动Ubuntu, with Linux 5.4.0-109-generic内核,但是我们正常可用的是Ubuntu, with Linux 5.4.0-91-generic内核

3、修改内核启动顺序

sudo gedit /etc/default/grub

打开/etc/default/grub文件
将GRUB_DEFAULT=0注释,新增
GRUB_DEFAULT=“Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-91-generic”
注意:这里面的版本号选择自己电脑对应版本

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

#GRUB_DEFAULT=0
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-91-generic"
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i8042.dumbkbd"
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"

4、重启

三、删除内核

1、查看已经安装内核

dpkg --get-selections |grep linux

输出为:

binutils-x86-64-linux-gnu			install
console-setup-linux				install
libselinux1:amd64				install
linux-base					install
linux-firmware					install
linux-generic-hwe-18.04				install
linux-headers-5.4.0-107-generic			install
linux-headers-5.4.0-109-generic			install
linux-headers-generic-hwe-18.04			install
linux-hwe-5.4-headers-5.4.0-100			install
linux-hwe-5.4-headers-5.4.0-107			install
linux-hwe-5.4-headers-5.4.0-109			install
linux-hwe-5.4-headers-5.4.0-42			install
linux-hwe-5.4-headers-5.4.0-70			install
linux-image-5.4.0-100-generic			deinstall
linux-image-5.4.0-107-generic			install
linux-image-5.4.0-109-generic			install
linux-image-5.4.0-42-generic			deinstall
linux-image-5.4.0-70-generic			deinstall
linux-image-generic-hwe-18.04			install
linux-libc-dev:amd64				install
linux-modules-5.4.0-100-generic			deinstall
linux-modules-5.4.0-107-generic			install
linux-modules-5.4.0-109-generic			install
linux-modules-5.4.0-42-generic			deinstall
linux-modules-5.4.0-70-generic			deinstall
linux-modules-extra-5.4.0-100-generic		deinstall
linux-modules-extra-5.4.0-107-generic		install
linux-modules-extra-5.4.0-109-generic		install
linux-modules-extra-5.4.0-42-generic		deinstall
linux-modules-extra-5.4.0-70-generic		deinstall
linux-signed-generic-hwe-18.04			install
linux-sound-base				install
pptp-linux					install
syslinux					install
syslinux-common					install
syslinux-legacy					install
util-linux					install

2、删除内核

sudo apt-get remove \
linux-headers-5.4.0-100 \
linux-headers-5.4.0-100-generic \
linux-image-5.4.0-107-generic \
linux-modules-5.4.0-107-generic \
linux-modules-extra-5.4.0-107-generic

卸载后,再重新检查一下现有的内核,deinstall就是卸载完成的

dpkg --get-selections | grep linux

3、更新GRUB

sudo update-grub

这种方式我没有成功,但是第一种我成功了。

;