0

I wanted to know how the grub2 works on a MBR partitioned disk and GPT partitioned disk in a detailed way, means what all partitions are required, what files are created etc. in each of the cases and how these partitions are accessed/modified in each of the two cases while booting any OS. It will be helpful if any one can guide me in this regard.

1

There are actually four common (or at least semi-common) cases:

  • BIOS-mode GRUB on MBR -- This is the traditional PC configuration. In it, GRUB is split into multiple stages. The first stage resides in the first 440 bytes of the Master Boot Record (MBR). This first stage then loads and executes a second stage of GRUB, which typically resides in the sectors immediately following the MBR. This space is officially unallocated on most MBR disks, so putting GRUB code there is a bit risky; but it usually works OK. Additional code resides in files, typically in the /boot/grub directory of the OS used to install GRUB. There are numerous variants on this configuration possible. For instance, putting the GRUB first stage in a Partition Boot Record (PBR; the first sector of a partition) was once popular, but is pretty uncommon today, and in fact I'm not 100% sure that modern GRUB 2 still supports this option.
  • BIOS-mode GRUB on GPT -- In this variant, the first stage of GRUB still resides in the MBR (which for GPT is known as a protective MBR, which primarily exists to stop GPT-unaware tools from messing with the disk). The sectors following the MBR on a GPT disk, though, are GPT data structures and so cannot be used by GRUB. Instead, GRUB 2 relies on a partition known as the BIOS Boot Partition, which has a GPT type code of 21686148-6449-6E6F-744E-656564454649 ("bios_grub flag" set in libparted-based tools, or type EF02 in GPT fdisk). Additional files reside in the /boot/grub directory, as with BIOS/MBR GRUB installations.
  • EFI-mode GRUB on MBR -- In this configuration, the first GRUB code resides in a GRUB EFI binary stored on the EFI System Partition (ESP; type code 0xEF on an MBR disk). This file could be named anything, but it's typically called grubx64.efi in a subdirectory of EFI named after the distribution (such as EFI/ubuntu/grubx64.efi), or sometimes EFI/BOOT/bootx64.efi (the "fallback filename," most commonly used on bootable external media like USB drives). As with BIOS-mode GRUB, additional configuration and driver files reside elsewhere, typically in /boot/grub on the installation OS; however, some distributions put these file on the ESP alongside the main GRUB binary. Note that this is the least common of the four configurations, since few EFI-based computers boot from MBR disks.
  • EFI-mode GRUB on GPT -- This configuration is just like EFI-mode on MBR, except that the ESP has a type code of C12A7328-F81F-11D2-BA4B-00A0C93EC93B ("boot flag" set on libparted-based tools, or type EF00 in GPT fdisk). This configuration is rapidly becoming the most common one, as the transition from BIOS to EFI is proceeding quickly.

In addition to these cases, there are less common ones involving more exotic firmware and partition tables.

As you can see, there's considerable variability in the details, and some details vary depending on your Linux distribution -- or how you set up the details yourself, if you're installing GRUB manually from source code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.