#1103709 grub-pc: Failure to boot missing Windows disk may corrupt MBR

Package:
grub-pc
Source:
grub-pc
Description:
GRand Unified Bootloader, version 2 (PC/BIOS version)
Submitter:
Richard Allen
Date:
2025-04-21 08:03:02 UTC
Severity:
normal
#1103709#5
Date:
2025-04-20 21:03:13 UTC
From:
To:
Dear Maintainer,

I'm writing this report before I try upgrading to the backported grub. I wanted
to write all this down in case I wasn't able to boot afterwards again.

What led up to the situation? I've setup two operating system disks. Windows 10
is on the primary boot disk with its own bootloader(HD0 below).
Debian12+Grub2.06 is on another disk which I select from the BIOS(HD1 below).
Once a baremetal OS is booted, I boot the other disk under VirtualBox.

What exactly did you do (or not do) that was effective (or ineffective)? I
attempted to boot my Grub2.06+Debian/12 disk inside of VirtualBox on Windows
10. However, I looked away and grub timed out and chose Windows10(whose disk is
not visible in the VM)

What was the outcome of this action? Grub reported:
    error: no such device: ${Win10_DISK_ID}
    setting partition type to 0x83
    error:disk `hd0,msdos1’ not found
    error:disk `hd0,msdos1’ not found

After this, I was unable to boot Grub+Debian within VirtualBox or on bare-
metal. I have attached the MBRs of both disks, before and after this point.

What outcome did you expect instead? I expected that grub, upon failing to
locate the target boot drive, would not attempt to update the partition table.

To repair, I booted the machine with Debian-Live, rebuilt the partition table
with testdisk, then reinstalled grub and was able to boot both in VirtualBox
and natively.

#1103709#10
Date:
2025-04-20 21:28:30 UTC
From:
To:
Also impacts GRUB 2.12-1-~bpo12+1.
#1103709#15
Date:
2025-04-21 08:01:05 UTC
From:
To:
UUID search fails as expected, $root remains hd0,msdos1 (Debian partition).

parttool ($root) hidden- sets the partition type to 0x83 (Linux
filesystem, same as previously, so no change).
It is the only command which writes to the MBR. I acknowledge that GRUB
should be smart and not rewrite the MBR if there is no change.

GRUB does not see the partition any more.

It appears that the contents of hd1_debian.after was shifted by one
byte, which makes it totally unrecogizable by the BIOS, fdisk or any
other tool. This is really surprising. I could not reproduce it in a
QEMU+SeaBIOS virtual machine. Could it be a bug with VirtualBox ?

A possible workaround is to remove the parttool command in
/etc/grub.d/30_os-prober and rebuild grub.cfg with update-grub. This
command is not needed here, use cases which require it are very rare
nowadays.
(...)