bug-xorriso
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-xorriso] [bug #46716] Protective MBR partition is not marked as


From: Alexander E. Patrakov
Subject: Re: [Bug-xorriso] [bug #46716] Protective MBR partition is not marked as bootable
Date: Sat, 19 Dec 2015 21:40:04 +0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0

19.12.2015 21:28, Alexander E. Patrakov пишет:
19.12.2015 20:23, Thomas Schmitt пишет:

For the investigation i could need:

- An ISO produced by grub-mkrescue as used by Alexander.
   Lean would be nice. Please post download URL.
   Newest xorriso releases can deduce the used options from the
   ISO and replay them.
   Please also tell your exact grub-mkreascue arguments.

- A quick starter for Debian Jessie or Sid how i get to the same
   GRUB2 environment in which Alexander runs grub-mkrescue.
   (This is on my todo list since half a year. I apologize.)

I think that the easiest option would be to describe the way how to
produce the minimal iso that can only boot to GRUB command line, as
that's enough to reproduce the issue.

1. Make yourself a virtual machine, install Debian Jessie i386 there
from the official CD. Install "standard system utilities", ssh server if
you want, and nothing else.

2. Install some additional packages:

apt-get -y install mtools xorriso \
   grub-efi-amd64-bin grub-efi-ia32-bin grub-pc-bin grub2-common

3. Make a minimal iso image:

mkdir minimal
touch minimal/empty-file.txt
grub-mkrescue --modules="part_gpt part_msdos" -o output.iso minimal

The --modules="part_gpt part_msdos" argument is a workaround for the
fact that Debian Jessie doesn't have the fix from grub commit eeea31b2.
It isn't needed with modern grub.

The iso, if you still need it, is available at
http://82.193.153.141/minimal.iso

4. Copy it out of the VM, try to boot it several ways. Here "boots" =
"displays GRUB command prompt", which is exactly the purpose of the test
ISO.

qemu-system-x86_64 -enable-kvm -hda minimal.iso  # boots
qemu-system-x86_64 -enable-kvm -cdrom minimal.iso  # boots
qemu-system-x86_64 -bios OVMF.fd -enable-kvm -hda minimal.iso  # boots,
both for 32-bit and 64-bit OVMF
qemu-system-x86_64 -bios OVMF.fd -enable-kvm -cdrom minimal.iso # boots,
both for 32-bit and 64-bit OVMF

Then, write the iso to the USB flash stick with dd, try to find an old
PC with a braindamaged BIOS that checks for bootable partitions, and
test it there. Result: the USB flash drive is not recognized as bootable.

If you don't have such old PC, you can simulate the BIOS bug by
rebuilding seabios with this patch (just apply the patch and run "make"):

diff --git a/src/boot.c b/src/boot.c
index e0f73a3..4e60143 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -627,6 +627,13 @@ boot_disk(u8 bootdrv, int checksig)
              printf("Boot failed: not a bootable disk\n\n");
              return;
          }
+        if (!GET_FARVAR(bootseg, mbr->partitions[0].status) &&
+            !GET_FARVAR(bootseg, mbr->partitions[1].status) &&
+            !GET_FARVAR(bootseg, mbr->partitions[2].status) &&
+            !GET_FARVAR(bootseg, mbr->partitions[3].status)) {
+                printf("Boot failed: no bootable partition\n\n");
+                return;
+        }
      }

      tpm_add_bcv(bootdrv, MAKE_FLATPTR(bootseg, 0), 512);

Then:

qemu-system-x86_64 -bios seabios/out/bios.bin -enable-kvm -cdrom
minimal.iso  # boots
qemu-system-x86_64 -bios seabios/out/bios.bin -enable-kvm -hda
minimal.iso  # fails

P.S. the BIOS bug is documented in Arch wiki:
https://wiki.archlinux.org/index.php/GUID_Partition_Table#Workarounds


By the way, I have also created an ISO with a hybrid MBR by treating the original minimal.iso with gdisk. The iso is available at http://82.193.153.141/minimal-hybrid.iso

The resulting iso boots in qemu (even with a patched bios). I have not yet tested it on the DG965SS board, will do that tomorrow.

-------

$ /usr/sbin/gdisk minimal.iso
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): r

Recovery/transformation command (? for help): o

Disk size is 32852 sectors (16.0 MiB)
MBR disk identifier: 0x00000000
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
   1                     1        32851   primary     0xEE

Recovery/transformation command (? for help): p
Disk minimal.iso: 32852 sectors, 16.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): C2131A78-F7A0-4E9B-AD7F-E455E9B7E46C
Partition table holds up to 176 entries
First usable sector is 64, last usable sector is 32806
Partitions will be aligned on 16-sector boundaries
Total free space is 3 sectors (1.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              64             335   136.0 KiB   0700  Gap0
   2             336            6095   2.8 MiB     EF00  EFI boot partition
   3            6096           32803   13.0 MiB    0700  Gap1

Recovery/transformation command (? for help): h

WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,
just hit the Enter key at the below prompt and your MBR partition table will
be untouched.

Type from one to three GPT partition numbers, separated by spaces, to be
added to the hybrid MBR, in sequence: 1 2 3
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): y

Creating entry for GPT partition #1 (MBR partition #2)
Enter an MBR hex code (default 07):
Set the bootable flag? (Y/N): y

Creating entry for GPT partition #2 (MBR partition #3)
Enter an MBR hex code (default EF):
Set the bootable flag? (Y/N): n

Creating entry for GPT partition #3 (MBR partition #4)
Enter an MBR hex code (default 07):
Set the bootable flag? (Y/N): n

Recovery/transformation command (? for help): o

Disk size is 32852 sectors (16.0 MiB)
MBR disk identifier: 0x00000000
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
   1                     1           63   primary     0xEE
   2      *             64          335   primary     0x07
   3                   336         6095   primary     0xEF
   4                  6096        32803   primary     0x07

Recovery/transformation command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to minimal.iso.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]