help-grub
[Top][All Lists]
Advanced

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

Re: grub-install into hybrid MBR on GPT disk on legacy BIOS


From: Pascal Hambourg
Subject: Re: grub-install into hybrid MBR on GPT disk on legacy BIOS
Date: Mon, 8 Jan 2018 00:47:43 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

Le 07/01/2018 à 21:52, jzb a écrit :

I have an old laptop that is legacy-BIOS only.  It has one SATA hard-drive.  I
want to use GPT partitioning scheme for my disk for runtime (4.14.5 kernel
with UEFI/GPT support), but it still needs to be bootable from a legacy-only
BIOS that only knows MBR scheme.  No other way to boot from that one disk.

All my research shows that this should be supported, but I have to use hybrid
MBR.

Really ? I have several setups with GPT+BIOS boot and no need for a hybrid MBR. On some machines, it worked at once. On some others, I had to mark the GPT partition in the protective MBR as bootable so that the broken BIOS accepts to boot from that disk. The only time I had to use a hybrid MBR was when I wanted to add multiboot with Windows (as test).

AFAIK gdisk cannot set the boot flag in the MBR. Parted and fdisk can.
Big fat warning : the last time I used parted on a GPT disk with a hybrid MBR, it erased it and rebuilt a standard protective MBR.

Number  Start (sector)    End (sector)  Size       Code  Name
    1            2048         2050047   1000.0 MiB  EF02

~1 GB for a BIOS boot partition is just a waste of space. It requires less than 100 kB (yes, kilobytes).

    2         2097152        10485759   4.0 GiB     8300
    3        10485760        52428799   20.0 GiB    8300  Linux filesystem
    4        52428800       312581774   124.0 GiB   8300  Linux filesystem
(...)
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
    1                     1         2047   primary     0xEE
    2      *           2048      2050047   primary     0xEF
    3               2097152     10485759   primary     0x83
    4              10485760     52428799   primary     0x83

I have the EE partition first, and there's the EF02 for grub to install into.

Note that code EF (EFI) in DOS/MBR does not match code EF02 (BIOS boot) in GPT.

(grub-install -v --target=i386-pc /dev/sda
  /dev/sda1 is mounted as /boot [ext2 filesystem])
                                 ^^^^^^^^^^^^^^^ <- is this okay for hybrid???

No it's not ok, either for hybrid or protective MBR.
It seems that you set the "BIOS boot" type on partition 1 but it actually contains an ext2 filesystem mounted as /boot. If you are using it as /boot, not as a BIOS boot partition, you should not set the BIOS boot type, or grub-install may overwrite it. A real BIOS boot partition has no filesystem and is not mounted nor used in any way by Linux. It must be reserved to GRUB.

Note that Linux and GRUB ignore the partition table in the hybrid MBR.

grub-install: info: setting the root device to `hostdisk//dev/sda,gpt1'.
grub-install: info: saving <2048,0,512>.
grub-install: info: saving <2049,0,512>.
grub-install: info: saving <2050,0,512>.
...
grub-install: info: saving <2145,0,512>.
grub-install: info: saving <2146,0,512>.
grub-install: info: saving <2147,0,512>.
Installation finished. No error reported.

I'm not sure what exactly happened. It looks like grub-install wrote the core image into the first 98 sectors of sda1 (as it would with a regular BIOS boot partitions). If it really did that, then it overwrote the beginning of the boot filesystem (and maybe the system overwrote again some sectors when writing into /boot, such as updating the ext2 superblock when unmounting the filesystem).

This is all as it should, as far as I can tell, assuming that sector 2048 is
where grub should embed itself (not so sure come to think of it).  But then I
go to reboot, and all I get is the

GRUB

printout, and nothing further.  Other than that one word, the screen is blank.
  Seems the boot-sector code ran, but that's as far as it gets (assuming that's
where 'GRUB' output comes from).

Not surprising. IIUC, you corrupted both the core image and /boot.

Check the filesystem in sda1 and repair/rebuild it if needed.
Change its type into "Linux filesystem" with gdisk or other tool.
Create a new partition with type "BIOS boot". There is enough free space between partitions 1 and 2.
Re-run grub-install -v.

BTW, I want the kernel to use the GPT
scheme as that's the only way to get a PARTUUID for the partitions

Not exactly. Since kernel 3.8 or so, the DOS/MBR scheme also has PARTUUIDs. They are not real UUIDs but are built by the kernel by combining the disk identifier (32-bit field in the MBR) and the partition number.



reply via email to

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