双系统电脑,设置 Windows 优先启动加载

Windows 2022-01-16 阅读 285 评论 0

电脑有2块硬盘,都安装了 Windows 10,后来在其中的一块固态硬盘上又安装 Ubuntu 20.04,安装完成后,默认是Ubuntu优先启动,如下图。

Ubuntu优先启动

我用 Windows 10 比较频繁,想改变默认启动选项,将 Windows 10 优先启动。

1. 修改 GRUB_DEFAULT

运行 grep menuentry /boot/grub/grub.cfg,将列出所有的启动入口。

$ 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-7d2460fe-c19c-4e8e-b33a-6a0623bdccc0' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-7d2460fe-c19c-4e8e-b33a-6a0623bdccc0' {
	menuentry 'Ubuntu, with Linux 5.11.0-27-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.11.0-27-generic-advanced-7d2460fe-c19c-4e8e-b33a-6a0623bdccc0' {
	menuentry 'Ubuntu, with Linux 5.11.0-27-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.11.0-27-generic-recovery-7d2460fe-c19c-4e8e-b33a-6a0623bdccc0' {
menuentry 'Windows Boot Manager (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-efi-D94C-1CC4' {
menuentry 'Windows Boot Manager (on /dev/sdb1)' --class windows --class os $menuentry_id_option 'osprober-efi-2710-810B' {

我想启动的 Windows 10 在 Windows Boot Manager (on /dev/sda1),复制这一块的信息,修改 /etc/default/grub 文件。

sudo nano /etc/default/grub

GRUB_DEFAULT=0

改为

GRUB_DEFAULT="Windows Boot Manager (on /dev/sda1)"

GRUB_DEFAULT 默认为 0,从启动页中,可以看出,Windows 10 在第3行,GRUB_DEFAULT 如果为数字,从0开始计数,这里也可以改为2。

GRUB_DEFAULT=2

2. 运行 update-grub

运行 sudo update-grub,使第一步的修改生效。

$ 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.11.0-27-generic
Found initrd image: /boot/initrd.img-5.11.0-27-generic
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Found Windows Boot Manager on /dev/sdb1@/efi/Microsoft/Boot/bootmgfw.efi
done

重启电脑,默认启动项将是 Windows 10。

重启电脑,默认启动项是 Windows 10

最后更新 2022-01-16