LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > hydrurga
User Name
Password

Notices


Rating: 2 votes, 5.00 average.

Partitions - MBR vs. GPT

Posted 07-10-2017 at 08:32 AM by hydrurga
Updated 07-22-2017 at 03:31 AM by hydrurga

The two main partitioning schemes used on Linux and Windows/DOS are MBR and, more recently, GPT. This article doesn't cover the Mac's original Apple Partition Scheme and additional partition schemes used by various other operating systems.

To understand partitions, it is important to remember that storage devices divide up their space into sectors which are traditionally 512 bytes in length. However, since 2010, most large hard disks (called Advanced Format (AF)) now have physical sectors of size 4096 bytes. In order to be compatible with older software, AF disks normally emulate a logical sector size of 512 bytes (512e), but some can also expose their native logical sector size of 4096 bytes (4Kn).

Although hybrid workarounds do exist, you normally shouldn't mix MBR and GPT systems on the same disk. You can however use a mixture of GPT and MBR disks on the same system, except where you plan to chain bootloaders between different disks.

Master Boot Record (MBR)
--------------------------------
The MBR partitioning scheme has been used on PCs since it was developed for MS-DOS on IBM PCs in the early 1980s. Created for hardware much less powerful than is current found, it has only lasted this long due to the clever hacks that have been introduced in order to get around its limitations.
  • Allows 4 primary partitions, which are numbered 1-4 whether they are used or not. One of these can hold a placeholder extended partition containing a linked list of logical partitions, for which the numbering starts at 5. The use of udev in Linux allows for a theoretical unlimited number of logical partitions.
    *
  • The MBR must live in the first sector (512 bytes) of a device. It consists of an initial bootloader (446 bytes), a partition table (64 bytes), and a boot signature (2 bytes).
    *
  • Addressing in the MBR was originally carried out by means of CHS Addressing (Cylinder-Head-Sector). This form of addressing used 24-bit addresses and thus could address up to 2^24 * 512 bytes = 8GiB. In order to resolve this limitation, 32-bit Logical Block Addressing (LBA) was introduced, allowing the MBR to address up to 2^32 * 512 bytes = 2TiB. Thus the maximum partition size, as well as the maximum amount of space usable from the start of a device, in a MBR scheme is normally 2TiB.
    *
  • The above 2TiB limitation can be overcome by using an Advanced Format disk in 4Kn mode, the resultant logical sector size of 4096 bytes increasing the maximum to 16TiB. Linux has supported 4Kn drives since kernel 2.6.31, Windows since Windows 8.
    *
  • Note that it is also possible to use a disk over 2TiB with MBR by creating a partition which starts before the 2TiB point on the disk and extends over it. With the partition size limit of 2TiB, this would mean that a disk of almost 4TiB could be used. However this is not recommended as some MBR-handling tools may not work correctly with such a setup, resulting in potential loss of data (see here).
    *
  • Each disk contains a Disk Identifier, a 4-byte longword number (e.g. 0x000252e8) that is randomly generated and stored in the MBR sector when the MBR is created. Note that Windows >= Vista uses this to locate the boot device, so changing it can prevent Windows from booting.
    *
  • MBR partitions are each marked with 1 byte Partition Type (see fdisk's Id and Type columns), including: 07 - NTFS/exFAT, 0f - Extended Partition (LBA addressing), 82 - Linux swap, 83 - native Linux filesystem.
    *
  • There is no error detection capability in MBR. An error in a single data structure can cause great problems, and an error in one of the linked list logical partitions can block subsequent logical partitions.
    *
  • Windows insists that its operating system is in one of the primary partitions. Linux doesn't have this limitation.

GUID Partition Table (GPT)
--------------------------------
The GPT (GUID stands for "Globally Unique Identifiers") partition scheme was developed by Intel in the late 1990s to overcome the limitations of MBR. It later became part of the UEFI specification.
  • There is no such thing as primary, extended and logical partitions in GPT, just partitions. Theoretically there can be an unlimited number of these, but the default is 128 unless more are supported by the operating system.
    *
  • GPT uses 64-bit LBA addressing, resulting in a maximum partition size and addressable hard disk size of 2^64 * 512 bytes = 8ZiB (8.6 billion TiB), increased to 64ZiB with 4096-byte sectors. These values are greater than the restrictions normally imposed by particular filesystems.
    *
  • Better data integrity is provided by GPT than MBR. Its data structures are duplicated at the start and the end of the disk, while CRC values are computed for important data structures (the GPT Header & the Partition Array). Because of this, don't use a hex editor to directly change values in the GPT structures.
    *
  • Each disk has a Disk Identifier, a 16-byte GUID randomly generated when the GPT is created.
    *
  • Each partition has a unique 16-byte Partition GUID to identify it. It also has a 16-byte Partition Type GUID which makes partition-type collisions less likely. The partition manager gdisk uses shortened Partition Codes (effectively the MBR Partition Type * 100h plus some additional codes), including: EF02 - BIOS Boot Partition, 8300 - Linux native filesystem.
    *
  • Space is provided for a human-readable partition name (in addition to a filesystem's capability to store a name label).
    *
  • To use GPT, you must ensure that the kernel, the boot loader application, and your low-level disk utilities all support it. Every major Linux distribution supports GPT.
    *
  • The first disk sector on a GPT partitioned disk is reserved for the Protective MBR, containing an MBR table which defines a single partition of type 0xEE (EFI GPT) spanning the entire disk on sub-2TiB disks, 2TiB on larger disks. This protects a GPT disk from damage by GPT-unaware disk utilities which will read the table and see a disk with no free space.
Posted in Uncategorized
Views 5494 Comments 7
« Prev     Main     Next »
Total Comments 7

Comments

  1. Old Comment
    1st blog? Really? With that extra large brain of yours?

    Nice work.
    Posted 07-10-2017 at 11:01 AM by Habitual Habitual is offline
  2. Old Comment
    Ah, you silver-tongued LQer, you. Thanks, Habitual.
    Posted 07-10-2017 at 11:42 AM by hydrurga hydrurga is offline
  3. Old Comment
    Quote:
    Thus the maximum partition size, as well as the maximum amount of space usable from the start of a device, in a MBR scheme is normally 2TiB.
    Not strictly true - if a partition starts before the 2T limit, it can also be 2T in size (512 byte sectors). Thus up to almost 4T can be assigned if careful.
    Posted 07-22-2017 at 12:07 AM by syg00 syg00 is offline
  4. Old Comment
    Much appreciated, svg. "If careful" is the relevant phrase here. I've added a bullet point to the MBR section ("Note that it is also possible...") to address this point. Please let me know if you have any further comments on this or any other portions of the blog. Cheers.
    Posted 07-22-2017 at 03:34 AM by hydrurga hydrurga is offline
  5. Old Comment
    I had previously read this blog entry without commenting. But having read it once more it certainly deserves a big WELL DONE! I think the LQ blog space is much under utilized and am glad to see well written articles posted here! Thanks, and more!
    Posted 07-22-2017 at 10:41 PM by astrogeek astrogeek is offline
  6. Old Comment
    sweet
    Posted 07-23-2017 at 07:13 PM by aus9 aus9 is offline
  7. Old Comment
    I agree with astrogeek that the LQ Blog section is underused.

    We need more top class efforts like this one from hydrurga.
    Posted 08-02-2017 at 03:02 AM by beachboy2 beachboy2 is offline
 

  



All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration