Partitioning – What Is the Purpose of MBR Active Partition?

bootloadermbrpartitioning

The concept of booting the bootloaders on UEFI is straight and simple as putting the .efi bootloaders on the EFI system partition. The .efi file then load the corresponding operating systems. However, I still can't get why MBR needs an active partition to boot the OS.

From my study so far, the MBR bootstrap code resides on the first 446 bytes of the disk, which will be automatically executed by the BIOS after POST (as a de-factor standard). It can load the OS directly, but most of the time, the code is so small that its main job is to load the actual bootloader lying somewhere on another partition.

Why do we need to set a partition as active to boot from it? Theoretically, the MBR bootstrap code can run whatever, from wherever it feels like.

Best Answer

Why do we need to set a partition as active to boot from it? Theoretically, the MBR bootstrap code can run whatever, from wherever it feels like.

Yes, and in practice, the MBR bootstrap code often does exactly that.

But the bootstrap code needs some method to find where the next stage of the bootloader is stored. (The whole bootloader is never just 446 bytes; the MBR is just its stage 1.)

Having a bootsector which parses the MBR partition table and looks for the 'active' flag just happens to be a very versatile solution to this problem – it allows for a completely static bootsector (no special tool needed to generate it), and any bootsector doing so works equally well with any OS.

For example, the syslinux MBR bootsector appears to be fully interchangeable with the Windows MBR bootsector. If you dual-boot Linux and Windows, it doesn't matter which bootsector you have, they both do the same thing so you can always just swap the 'active' bit to swap OSes. (And installing the bootsector is just copying mbr.bin to raw disk.)

But different bootloaders certainly have different approaches: for example, the popular Linux GRUB2 stores its second stage in the "post-MBR gap" and dynamically generates the bootstrap code according to its location; i.e. the MBR bootsector knows which LBA the second stage starts at (completely ignoring the partition table and the 'active' flag), and this might vary between disks, so the bootsector must be written by the grub-install program individually for each disk.

(GRUB2 does not normally use partition VBRs either; while it can "chainload" those, its typical configuration actually directly accesses the real filesystem and loades the OS kernel files.)

Related Question