如何让GRUB检测Windows启动分区?

如何让GRUB检测Windows启动分区?

我使用的是双引导 Windows/Kali linux,自从最新的 grub 更新以来,Windows 条目已被删除。

当我从 BIOS 启动时,Windows 启动分区可以工作,但不知何故我无法让 GRUB 自动将其添加到其配置中。

操作系统已正确检测:

╰─❯ sudo os-prober
/dev/sda2@/EFI/Microsoft/Boot/bootmgfw.efi:Windows Boot Manager:Windows:efi
╰─❯ efibootmgr -v
BootCurrent: 0007
Timeout: 0 seconds
BootOrder: 0007,0006,0001,0000,0002,0003,0004,0005
Boot0000  Windows Boot Manager  HD(2,GPT,e7826255-29ed-4a3f-9293-05f922724cd1,0x800,0x100000)/File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...a................
Boot0001  UEFI: Samsung SSD 860 EVO 1TB, Partition 2    HD(2,GPT,e7826255-29ed-4a3f-9293-05f922724cd1,0x800,0x100000)/File(\EFI\Boot\BootX64.efi)..BO
Boot0002* Diskette Drive    BBS(Floppy,Diskette Drive,0x0)..BO
Boot0003* USB Storage Device    BBS(USB,USB Storage Device,0x0)..BO
Boot0004* CD/DVD/CD-RW Drive    BBS(CDROM,CD/DVD/CD-RW Drive,0x0)..BO
Boot0005* Onboard NIC   BBS(Network,Onboard NIC,0x0)..BO
Boot0006* Grub  PciRoot(0x0)/Pci(0x17,0x0)/Sata(0,65535,0)/HD(2,GPT,e7826255-29ed-4a3f-9293-05f922724cd1,0x800,0x100000)/File(\EFI\Boot\bootx64.efi)
Boot0007* kali  HD(2,GPT,e7826255-29ed-4a3f-9293-05f922724cd1,0x800,0x100000)/File(\EFI\kali\grubx64.efi)

这是我的分区:

╰─❯ sudo parted -l
Model: ATA Samsung SSD 860 (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name     Flags
 2      1049kB  538MB   537MB   fat32                    boot, esp
 3      538MB   239GB   239GB   ext4
 4      239GB   256GB   16.8GB  linux-swap(v1)           swap
 1      256GB   1000GB  744GB   ntfs            Storage  msftdata


Model: BC501 NVMe SK hynix 512GB (nvme)
Disk /dev/nvme0n1: 512GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name                          Flags
 1      1049kB  17.8MB  16.8MB               Microsoft reserved partition  msftres
 2      17.8MB  510GB   510GB   ntfs         Basic data partition          msftdata
 3      510GB   511GB   773MB   ntfs                                       hidden, diag
 4      511GB   512GB   1139MB  ntfs         Basic data partition          diag

尝试手动挂载分区时:

╰─❯ sudo mount /dev/sda2 /boot/efi
mount: /boot/efi: /dev/sda2 already mounted on /boot/efi.
       dmesg(1) may have more information after failed mount system call.

更新 grub 时未添加 Windows 条目(与 相同的输出grub-mkconfig

╰─❯ sudo update-grub
Generating grub configuration file ...
Found theme: /boot/grub/themes/kali/theme.txt
Found background image: /boot/grub/themes/fallout-grub/background.png
Found linux image: /boot/vmlinuz-5.17.0-kali3-amd64
Found initrd image: /boot/initrd.img-5.17.0-kali3-amd64
Found linux image: /boot/vmlinuz-5.16.0-kali7-amd64
Found initrd image: /boot/initrd.img-5.16.0-kali7-amd64
Found linux image: /boot/vmlinuz-5.17.0-kali3-amd64
Found initrd image: /boot/initrd.img-5.17.0-kali3-amd64
Found linux image: /boot/vmlinuz-5.16.0-kali7-amd64
Found initrd image: /boot/initrd.img-5.16.0-kali7-amd64
Adding boot menu entry for EFI firmware configuration
done

答案1

/etc/grub.d/40_custom按照@artem-s-tashkinov的建议,我通过基于grub备份( )编辑文件来手动添加Windows条目/etc/grub.d/backup/boot_grub/grub.cfg,替换UUID并运行update-grub

╰─❯ cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "Windows 10" --class windows --class os $menuentry_id_option 'osprober-efi-' {
    insmod part_gpt
    insmod fat
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root  7A03-CA46
    else
      search --no-floppy --fs-uuid --set=root 7A03-CA46
    fi
    chainloader /efi/Microsoft/Boot/bootmgfw.efi
}

这很好用,谢谢。

相关内容