Attempt to fix bad bootsectors

Some (recent) ISO images have started having a zero byte as the first
byte of the MBR boot code embedded in the hard disk image.

When the original Lenovo ISO is booted, nobody has reported any issues,
however when a patched IMG file is created from that, it just hangs
- which does match with having bad bootcode data.

I was unable to reproduce the issue when running the images in qemu,
which is even more confusing.

Since every working image has the same first byte (a "CLI" instruction)
we attempt to repair things by simply changing it back to that byte.
pull/116/head
Hamish Coleman 5 years ago
parent 460ff2c249
commit d417ce260a

@ -213,6 +213,21 @@ sub fixup_part {
return 1;
}
# Some boot records downloaded from Lenovo appear to have been corrupted
# (perhaps this is an attempt to force people to use a UEFI boot?)
#
sub fixup_boot {
my $buf = shift;
if (ord(substr($buf,0,1)) == 0) {
# No normal x86 boot instruction starts with a zero.
warn("Found corrupted bootcode in ISO from Lenovo - attempting fix\n");
substr($buf,0,1) = chr(0xfa);
}
return $buf;
}
sub main() {
if (!defined($ARGV[0])) {
die("Need image filename");
@ -227,6 +242,7 @@ sub main() {
}
$buf = mbr_pack($mbr);
$buf = fixup_boot($buf);
if (defined($ARGV[1]) && $ARGV[1] eq 'debug') {
print(Dumper($mbr));

Loading…
Cancel
Save