GRUB2显示错误的Windows版本

这是我最近解决的一个问题,所以我在下面发布了答案。
在安装Windows 10之后,每次我得到一个内核更新或者运行update-grub2命令时,它总是显示Windows 7或者Windows恢复环境,而不是Windows 10。我该如何永久修复这个问题?

这些更改已经存在于(我的Mint 19.2)/usr/lib/os-probes/mounted/20microsoft中,但它仍然返回“Windows Vista”。请注意,当双启动系统是Windows 7时,它返回了正确的值,因此看起来是信息源缺失的问题。 - cdg
@cdg 这个问题应该在Linux&Unix上提问,因为这个网站只适用于官方的Ubuntu版本。此外,如果你已经尝试了所有这些方法但仍然无法解决问题,你应该向Mint开发团队提交一个错误报告,因为他们可能没有正确地检测到这个问题。 - Terrance
1个回答

更新日期:2022-10-23:看起来grub团队还没有针对Windows 11进行更新,可能会显示为Windows Vista,所以我已经在下面的答案中添加了如何进行更改。


它仍然显示 Windows 7Windows Recovery Environment 而不是 Windows 10 的原因是文件 /usr/lib/os-probes/mounted/20microsoft 中没有包含 Windows 10 的标签,所以在操作系统的 os-prober 检测过程中会回退到 Windows 7Windows Recovery Environment

要更正这个问题,您需要对以下文件进行以下更改(我将使用 gedit 作为编辑器,但您可以使用其他编辑器):

sudo gedit /usr/lib/os-probes/mounted/20microsoft

注意:在修改文件之前,您应该始终备份文件!
现在为Windows 11添加了,因为它可能被识别为Windows Vista。
if item_in_dir -q bootmgr "$2"; then
        # there might be different boot directories in different case as:
        # boot Boot BOOT
        for boot in $(item_in_dir boot "$2"); do
                bcd=$(item_in_dir bcd "$2/$boot")
                if [ -n "$bcd" ]; then
                        if grep -qs "W.i.n.d.o.w.s. .1.1" "$2/$boot/$bcd"; then
                                long="Windows 11"
                        elif grep -qs "W.i.n.d.o.w.s. .1.0" "$2/$boot/$bcd"; then
                                long="Windows 10"
                        elif grep -qs "W.i.n.d.o.w.s. .8" "$2/$boot/$bcd"; then
                                long="Windows 8 (loader)"
                        elif grep -qs "W.i.n.d.o.w.s. .7" "$2/$boot/$bcd"; then
                                long="Windows 7 (loader)"

上面的部分大约在文件的第34行。你只需要将该行开头的if语句改为elif,然后添加适用于Windows 11的部分,该部分应该位于适用于Windows 10的那一行之前的if语句之上。
保存后,运行os-prober的结果如下:
terrance@terrance-ubuntu:~$ sudo os-prober
/dev/sdc1:Windows 11:Windows:chain

然后运行update-grub2,它将使您的/boot/grub/grub.cfg更新永久化,每当您获得内核更新时,它将显示正确的Windows版本(如下所示):
terrance@terrance-ubuntu:~$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Sourcing file `/etc/default/grub.d/lubuntu-grub-theme.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-52-generic
Found initrd image: /boot/initrd.img-5.15.0-52-generic
Found linux image: /boot/vmlinuz-5.15.0-50-generic
Found initrd image: /boot/initrd.img-5.15.0-50-generic
Found linux image: /boot/vmlinuz-5.13.0-52-generic
Found initrd image: /boot/initrd.img-5.13.0-52-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Found Windows 11 on /dev/sdc1
done

希望这能有所帮助!

4这个问题/修复是否已经向Grub2维护者提交了上游报告? - david6
@david6 我不知道是否已经被解决。昨晚我刚刚发现了这个问题,当时我正在尝试了解更多关于GRUB2以及它如何确定找到的操作系统的信息。 - Terrance
'20microsoft'的脚本看起来很凌乱,可能需要其他改进。 - david6