这是我最近解决的一个问题,所以我在下面发布了答案。
在安装Windows 10之后,每次我得到一个内核更新或者运行update-grub2命令时,它总是显示Windows 7或者Windows恢复环境,而不是Windows 10。我该如何永久修复这个问题?
在安装Windows 10之后,每次我得到一个内核更新或者运行update-grub2命令时,它总是显示Windows 7或者Windows恢复环境,而不是Windows 10。我该如何永久修复这个问题?
更新日期:2022-10-23:看起来grub团队还没有针对Windows 11进行更新,可能会显示为Windows Vista,所以我已经在下面的答案中添加了如何进行更改。
它仍然显示 Windows 7
或 Windows Recovery Environment
而不是 Windows 10
的原因是文件 /usr/lib/os-probes/mounted/20microsoft
中没有包含 Windows 10
的标签,所以在操作系统的 os-prober
检测过程中会回退到 Windows 7
或 Windows Recovery Environment
。
要更正这个问题,您需要对以下文件进行以下更改(我将使用 gedit 作为编辑器,但您可以使用其他编辑器):
sudo gedit /usr/lib/os-probes/mounted/20microsoft
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)"
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