做龙的传人
爱国的中国人

Debian 9 修改GRUB默认启动内核

这里记录下修改步骤,方便自己和其他鸡友操作。

1. 查看当前内核的启动顺序

运行:$ cat /boot/grub/grub.cfg ,查看当前内核的启动顺序:

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default=0
fi

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
	set gfxpayload="${1}"
}
set linux_gfx_mode=
export linux_gfx_mode
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  d689cedc-8dc2-4ebb-919f-fe47b628db44
	else
	  search --no-floppy --fs-uuid --set=root d689cedc-8dc2-4ebb-919f-fe47b628db44
	fi
	echo	'Loading Linux 4.19.0-1-amd64 ...'
	linux	/boot/vmlinuz-4.19.0-1-amd64 root=UUID=d689cedc-8dc2-4ebb-919f-fe47b628db44 ro  quiet
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-4.19.0-1-amd64
}
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
	menuentry 'Debian GNU/Linux, with Linux 4.19.0-1-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.0-1-amd64-advanced-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  d689cedc-8dc2-4ebb-919f-fe47b628db44
		else
		  search --no-floppy --fs-uuid --set=root d689cedc-8dc2-4ebb-919f-fe47b628db44
		fi
		echo	'Loading Linux 4.19.0-1-amd64 ...'
		linux	/boot/vmlinuz-4.19.0-1-amd64 root=UUID=d689cedc-8dc2-4ebb-919f-fe47b628db44 ro  quiet
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.19.0-1-amd64
	}
	menuentry 'Debian GNU/Linux, with Linux 4.19.0-1-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.0-1-amd64-recovery-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  d689cedc-8dc2-4ebb-919f-fe47b628db44
		else
		  search --no-floppy --fs-uuid --set=root d689cedc-8dc2-4ebb-919f-fe47b628db44
		fi
		echo	'Loading Linux 4.19.0-1-amd64 ...'
		linux	/boot/vmlinuz-4.19.0-1-amd64 root=UUID=d689cedc-8dc2-4ebb-919f-fe47b628db44 ro single 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.19.0-1-amd64
	}
	menuentry 'Debian GNU/Linux, with Linux 4.18.0-3-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-3-amd64-advanced-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  d689cedc-8dc2-4ebb-919f-fe47b628db44
		else
		  search --no-floppy --fs-uuid --set=root d689cedc-8dc2-4ebb-919f-fe47b628db44
		fi
		echo	'Loading Linux 4.18.0-3-amd64 ...'
		linux	/boot/vmlinuz-4.18.0-3-amd64 root=UUID=d689cedc-8dc2-4ebb-919f-fe47b628db44 ro  quiet
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.18.0-3-amd64
	}
	menuentry 'Debian GNU/Linux, with Linux 4.18.0-3-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.18.0-3-amd64-recovery-d689cedc-8dc2-4ebb-919f-fe47b628db44' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  d689cedc-8dc2-4ebb-919f-fe47b628db44
		else
		  search --no-floppy --fs-uuid --set=root d689cedc-8dc2-4ebb-919f-fe47b628db44
		fi
		echo	'Loading Linux 4.18.0-3-amd64 ...'
		linux	/boot/vmlinuz-4.18.0-3-amd64 root=UUID=d689cedc-8dc2-4ebb-919f-fe47b628db44 ro single 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.18.0-3-amd64
	}
}

2. 修改grub文件

假设要修改为4.18.0-3内核启动, 修改文件/etc/default/grub,运行:sudo vim /etc/default/grub

GRUB_DEFAULT=0 修改为
GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 4.18.0-3-amd64"

其中Advanced options for Debian GNU/Linux是一级菜单,Debian GNU/Linux, with Linux 4.18.0-3-amd64是二级菜单, 中间用>连接。

3. 更新修改后的grub

sudo update-grub

这时候重新cat /boot/grub/grub.cfg 可以看到已经更新了,然后reboot重启后, 用uname -r就可以看到当前使用的内核已经成功更换。

 

赞(0) 打赏
欢迎转载,标明出处:CNBoy 四海部落 » Debian 9 修改GRUB默认启动内核
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

不论走到哪里,我们都是自豪的中国人!

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏