GUID Partition Table

From ArchWiki
Revision as of 22:03, 12 November 2010 by Mr.Elendig (talk | contribs) (GPT support in Kernel: zcat | gre -> zgrep)
Jump to: navigation, search

GUID Partition Table is a new style of partitioning which is part of the UEFI Specification. It is different from the Master Boot Record (the more commonly used partitioning style) in many aspects and has many advantages.

To understand GPT, it is important to understand what is MBR and what are its disadvantages.

For any partitioning style, the number of partitions that can be defined is based on the total space allotted for the partition table and the space required for storing the information of a single partition.

What is Master Boot Record ?

The MBR partition table stores the partitions info as follows

Location in the HDD Purpose of the Code
First 440 bytes MBR boot code that is launched by the BIOS
441-446 bytes MBR Disk signature
447-510 bytes Actual Partition Table with info about primary/extended partitions but not logical partitions
511-512 bytes MBR Boot signature 0xAA55

The entire information about the primary partitions is limited to the 64 bytes allotted. To extend this, extended partitions were used. A extended partition is simply a primary partition ( in the MBR ) which acts like a container for other partitions called logical partitions. So one is limited to either 4 primary partitions, or 3 primary and 1 extended partitions with many logical partitions inside it.

Problems with MBR

  1. Only 4 primary partitions or 3 primary + 1 extended partitions with many logical partitions inside it. If you have 3 primary + 1 extended partitions, and you have some free space outside the extended partition area, you cannot create a new partition over that space.
  2. Within the extended partition, the logical partitions meta-data is stored in linked-list structure. So if one link is lost, all the logical partitions following that meta-data is lost.
  3. MBR supports only 1 byte partition type codes which leads to many collisions.
  4. MBR stores partition sector information using 32-bit LBA values. This LBA length along with 512 byte sector size (more commonly used) limits the maximum addressable size of the disk to be 2 TB. Any space beyond 2 TB cannot be defined in a partition if MBR partitioning is used.

What is GUID Partition Table ?

GUID Partition Table uses GUIDs ( or UUIDs in linux world ) to define Partitions and its types, hence the name. The GPT consists of a

  1. First 512 bytes of the HDD - Protective MBR - Same as a normal MBR but the 64-byte area contains a single 0xEE type Primary partition entry defined over the entire size of the disk or in case of >2 TB, upto a partition size of 2 TB.
  2. Next 512 bytes - Primary GPT Header - Contains the Unique Disk GUID, Location of the Primary Partition Table, No. of possible entries in the partition table, CRC32 checksums of itself and the Primary Partition Table, Location of the Secondary (or Backup) GPT Header
  3. Next 16 KB (by default) - Primary GPT Table - 128 Partition entries each with each entry of size 128 byte ( hence 16 KB ). This size can be changed to accommodate more table entries ( >128 ) and it can also be reduced ( but UEFI Spec requires space for minimum of 128 table entries which is 16 KB ). Sector numbers are stored as 64-bit LBA and each partition has a Partition type GUID and a Unique Partition GUID.
  4. The very last 512 byte space of the HDD - Secondary GPT Header - Contains the Unique Disk GUID, Location of the Secondary Partition Table, No. of possible entries in the partition table, CRC32 checksums of itself and the Secondary Partition Table, Location of the Primary GPT Header. This header can be used to recover GPT info in case the primary header is corrupted.
  5. 16 KB from the last excluding the very last 512 byte - Secondary GPT table - It is byte-for-byte identical to the Primary table. Used mainly for recovery operations.

Advantages of GUID Partition Table

  1. Uses GUIDs to identify partition types - No collisions
  2. Provides a unique disk GUID and partition GUID for each partition - A good filesystem-independent way of referencing partitions and disks.
  3. Minimum of 128 partition table entries - No need for extended and logical partitions.
  4. Uses 64-bit LBA for storing Sector numbers - maximum addressable disk size is 2 ZiB.
  5. Stores a backup header and partition table at the end of the disk that aids in recovery if the main copy is clobbered.
  6. CRC32 checksums to detect errors and corruption of the partition table.

How to use GPT for booting Archlinux ?

Note: Although GPT is part of UEFI Specification, a UEFI based system is not required to use GPT (both for booting as well as simply storing data).

GPT support in Kernel

First, and most important, is that the kernel's CONFIG_EFI_PARTITION option must be set to 'y' (to compile EFI partition support into the kernel; 'm', for a loadable module, is not sufficient). This is true of the Arch default kernel; if you are running a different kernel, you can use zgrep CONFIG_EFI_PARTITION /proc/config.gz to check for this setting. This option is required even if GPT-formatted disks are used only for storing data and not for booting linux.

Bootloader support

Archlinux provides three bootloaders GRUB-Legacy, GRUB2 and SYSLINUX. The default bootloader of Archlinux installer - GRUB-Legacy, does not support GPT.

GRUB2 provides the ability to boot from GPT in both BIOS based systems and UEFI based systems. All partition defining commands remain the same ( like (hd0,8) ). Just load the part_gpt grub2 module from grub2 shell or include "insmod part_gpt" line before "set root=" line in grub.cfg file. Usually grub-probe will automatically add this module to core.img or grub.efi file if it detects the HDD to be using GPT.

To enable GRUB2 to embed core.img file in GPT disks for BIOS based systems, a BIOS Boot Partition of size of about 1 MB (no filesystem) is required. See below on how to create it.

Tools to edit GPT

gdisk (GPT fdisk)

gdisk is a very good fdisk-like tool for editing GPT disks - Good for non-FS tasks

Available in Arch Linux extra repo (package name: gdisk)

Note: The partitioning tools in util-linux-ng -- cfdisk, fdisk, and sfdisk -- do not support GPT.

Convert from MBR to GPT without data loss

One of the best features of GPT fdisk it its ability to convert MBR and BSD disklabels to GPT without data loss. Upon conversion, all the MBR primary partitions and the logical partitions become GPT partitions with the correct partition type GUIDs and Unique partition GUIDs created for each partition.

Just open the MBR disk using gdisk and exit with "w" option (to write the changes back to the disk - similar to fdisk) to convert the MBR disk to GPT. After conversion, the bootloaders will need to be reinstalled to configure them to boot from GPT.

GNU Parted

Good for FS-resizing operations and other FS-related tasks

GUI wrappers are available for parted.

BIOS Boot Partition

Create a 1 MB (approx) partition using GPT fdisk or GNU Parted with no filesystem. The location of the partition does not matter but it is advisable to put it somewhere in the beginning of the disk before the /boot partition. Set the partition type to "EF02" in GPT fdisk or set "bios_grub" flag on in GNU Parted or GParted.

This partition is currently used by GRUB2 alone and only in BIOS-GPT setups. No such partition type exists in case of MBR partitioning (at least not for GRUB2). This partition is also not required if the system is UEFI based, as no embedding takes place in that case. Neither GRUB-legacy nor SYSLINUX require this partition.

Note: This partition should be created before grub-install or grub-setup (of GRUB2) is run or before the bootloader install step of Archlinux installer (if GRUB2 is selected as bootloader).


  1. Wikipedia's Page on GPT and MBR
  2. Homepage of Rod Smith's GPT fdisk tool and its Project page - gptfdisk
  3. Rod Smith's page on Converting MBR to GPT and Booting OSes from GPT
  4. System Rescue CD's page on GPT
  5. GRUB2 Wiki page on why BIOS Boot Partition is required
  6. Make the most of large drives with GPT and Linux - IBM Developer Works
  7. Microsoft's Windows and GPT FAQ