Difference between revisions of "GUID Partition Table"

From ArchWiki
Jump to: navigation, search
(BIOS systems: fix link)
m (Undo revision 433120 by Danboid (talk) The limitation for MBR values is 32-bit sectors.)
 
(71 intermediate revisions by 26 users not shown)
Line 1: Line 1:
 
[[Category:File systems]]
 
[[Category:File systems]]
 +
[[el:GUID Partition Table]]
 
[[es:GUID Partition Table]]
 
[[es:GUID Partition Table]]
[[tr:Guid_Bölümledirme_Tablosu]]
+
[[hu:GUID Partition Table]]
 +
[[ja:GUID Partition Table]]
 +
[[tr:Guid Bölümledirme Tablosu]]
 
[[zh-CN:GUID Partition Table]]
 
[[zh-CN:GUID Partition Table]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|An overview of the GUID Partition Table.}}
+
{{Related|Arch boot process}}
{{Article summary heading|Overview}}
+
{{Related|Master Boot Record}}
{{Article summary text|{{Boot process overview}}}}
+
{{Related|Unified Extensible Firmware Interface}}
{{Article summary heading|Related}}
+
{{Related|Partitioning}}
{{Article summary wiki|Unified Extensible Firmware Interface}}
+
{{Related articles end}}
{{Article summary wiki|Master Boot Record}}
+
{{Article summary wiki|Arch Boot Process}}
+
{{Article summary end}}
+
  
GUID Partition Table (GPT) is a new style of partitioning which is part of the [[Unified Extensible Firmware Interface]] Specification, using the [[Wikipedia:Globally unique identifier | globally unique identifier]] for devices. It is different from the [[Master Boot Record]] (the more commonly used partitioning style) in many aspects and has many advantages.
+
GUID Partition Table (GPT) is a partitioning scheme that is part of the [[Unified Extensible Firmware Interface]] specification; it uses a [[Wikipedia:Globally unique identifier|globally unique identifier]] for qualifying devices. It is the next generation partitioning scheme designed to succeed the [[Master Boot Record]] partitioning scheme method.  It evolved to deal with [[Master Boot Record#Problems_with_MBR|several shortcomings]] of the MBR partitioning scheme method and offers additional advantages.
  
To understand GPT, it is important to understand what MBR is and what its disadvantages are.
+
== About the GUID Partition Table ==
  
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.
+
GUID Partition Table (GPT) uses GUIDs (or UUIDs in linux world) to define partitions and its types, hence the name. The GPT consists of:
  
== Master Boot Record ==
+
{| class="wikitable"
The MBR partition table stores the partitions info in the first sector of a hard disk as follows
+
! Location in the HDD !! Purpose
 
+
|-
{| border="1"
+
| First logical sector of the disk or First 512 bytes || 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 [[Wikipedia:TiB|TiB]], upto a partition size of 2 TiB.
! Location in the HDD !! Purpose of the Code
+
|-
|-
+
| Second logical sector of the disk or Next 512 bytes || Primary GPT Header - Contains the Unique Disk GUID, Location of the Primary Partition Table, Number of possible entries in partition table, CRC32 checksums of itself and the Primary Partition Table, Location of the Secondary (or Backup) GPT Header
| First 440 bytes || MBR boot code that is launched by the BIOS.
+
|-
|-
+
| 16 KiB (by default) following the second logical sector of the disk
| 441-446 bytes || MBR disk signature.
+
| Primary GPT Table - 128 Partition entries (by default, can be higher), each with an entry of size 128 bytes (hence total of 16 KiB for 128 partition entries). Sector numbers are stored as 64-bit LBA and each partition has a Partition Type GUID and a Unique Partition GUID.
|-
+
|-
| 447-510 bytes || Actual partition table with info about primary and extended partitions. (Note that logical partitions are not listed here)
+
| 16 KiB (by default) before the last logical sector of the disk || Secondary GPT table - It is byte-for-byte identical to the Primary table. Used mainly for recovery in case the primary partition table is damaged.
|-
+
|-
| 511-512 bytes || MBR boot signature 0xAA55.
+
| Last logical sector of the disk or Last 512 bytes || Secondary GPT Header - Contains the Unique Disk GUID, Location of the Secondary Partition Table, Number 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.
 
|}
 
|}
  
The entire information about the primary partitions is limited to the 64 bytes allotted. To extend this, extended partitions were used. An 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.
+
=== Advantages of GPT ===
 
+
=== Problems with MBR ===
+
# Only 4 primary partitions or 3 primary + 1 extended partitions (with arbitrary number of logical partitions within the extended partition) can be defined. 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 free space.
+
# Within the extended partition, the logical partitions' meta-data is stored in a linked-list structure. If one link is lost, all the logical partitions following that metadata is lost.
+
# MBR supports only 1 byte partition type codes which leads to many collisions.
+
# 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 TiB. Any space beyond 2 TiB cannot be defined as a partition if MBR partitioning is used.
+
 
+
== GUID Partition Table ==
+
GUID Partition Table (GPT) uses GUIDs (or UUIDs in linux world) to define partitions and its types, hence the name. The GPT consists of:
+
{| border="1"
+
! Location in the HDD !! Purpose
+
|-
+
| First logical sector of the disk or First 512 bytes || 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 TiB, upto a partition size of 2 TiB.
+
|-
+
| Second logical sector of the disk or Next 512 bytes || Primary GPT Header - Contains the Unique Disk GUID, Location of the Primary Partition Table, Number of possible entries in partition table, CRC32 checksums of itself and the Primary Partition Table, Location of the Secondary (or Backup) GPT Header
+
|-
+
| 16 KiB (by default) following the second logical sector of the disk
+
| Primary GPT Table - 128 Partition entries (by default, can be higher), each with an entry of size 128 bytes (hence total of 16 KiB for 128 partition entries). Sector numbers are stored as 64-bit LBA and each partition has a Partition Type GUID and a Unique Partition GUID.
+
|-
+
| 16 KiB (by default) before the last logical sector of the disk || Secondary GPT table - It is byte-for-byte identical to the Primary table. Used mainly for recovery in case the primary partition table is damaged.
+
|-
+
| Last logical sector of the disk or Last 512 bytes || Secondary GPT Header - Contains the Unique Disk GUID, Location of the Secondary Partition Table, Number 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.
+
|}
+
  
=== Advantages of GPT ===
 
 
# Uses GUIDs (UUIDs) to identify partition types - No collisions.
 
# Uses GUIDs (UUIDs) to identify partition types - No collisions.
 
# Provides a unique disk GUID and unique partition GUID for each partition - A good filesystem-independent way of referencing partitions and disks.
 
# Provides a unique disk GUID and unique partition GUID for each partition - A good filesystem-independent way of referencing partitions and disks.
 
# Arbitrary number of partitions - depends on space allocated for the partition table - No need for extended and logical partitions. By default the GPT table contains space for defining 128 partitions. However if the user wants to define more partitions, he/she can allocate more space to the partition table (currently only gdisk is known to support this feature).
 
# Arbitrary number of partitions - depends on space allocated for the partition table - No need for extended and logical partitions. By default the GPT table contains space for defining 128 partitions. However if the user wants to define more partitions, he/she can allocate more space to the partition table (currently only gdisk is known to support this feature).
# Uses 64-bit LBA for storing Sector numbers - maximum addressable disk size is 2 ZiB.
+
# Uses 64-bit LBA for storing Sector numbers - maximum addressable disk size is 2 [[Wikipedia:ZiB|ZiB]]. MBR is limited to addressing 2 TiB of space per drive.
 
# Stores a backup header and partition table at the end of the disk that aids in recovery in case the primary ones are damaged.
 
# Stores a backup header and partition table at the end of the disk that aids in recovery in case the primary ones are damaged.
 
# CRC32 checksums to detect errors and corruption of the header and partition table.
 
# CRC32 checksums to detect errors and corruption of the header and partition table.
Line 75: Line 51:
 
=== UEFI systems ===
 
=== UEFI systems ===
  
All UEFI Bootloaders support GPT disks since GPT is a part of UEFI Specification and thus mandatory for UEFI boot. See [[UEFI_Bootloaders]] for more info.
+
All UEFI Bootloaders support GPT disks since GPT is a part of UEFI Specification and thus mandatory for UEFI boot. See [[Boot loaders]] for more information.
  
 
=== BIOS systems ===
 
=== BIOS systems ===
  
{{Note|Some BIOS systems may not boot from GPT disks. See http://mjg59.dreamwidth.org/8035.html and http://rodsbooks.com/gdisk/bios.html for more info and possible workarounds.}}
+
While GPT support on BIOS systems is theoretically possible it sometimes isn't practical and other times there are complete incompatibilities. Technically the BIOS is only supposed to execute the code on the MBR, therefore leaving the possibility of differing partitioning schemes... However a BIOS may do additional checks including: checking a MBR's integrity, and possibly even for a MBR partition table (though usually only the first partition).  If this is a case, a number of workarounds exist that may be able to repair the problem (listed below).
  
* [[GRUB]](2) requires a 1007 KiB [[GRUB2#GUID_Partition_Table_.28GPT.29_specific_instructions|BIOS Boot Partition]] (EF02 type code in gdisk and bios_grub flag in GNU Parted) in BIOS systems to embed its {{ic|core.img}} file due to lack of post-MBR embed gap in GPT disks. Runtime GPT support in GRUB(2) is provided by the {{ic|part_gpt}} module.
+
{{Warning|For Windows, there is '''no''' support for booting from a BIOS/GPT partitioning scheme.  If you have already installed Windows with a BIOS/MBR partitioning scheme '''do not''' convert the drive to GPT!  Windows will fail to boot if this is done - irrespective of the bootloader used to chainload Windows.  One can either install Windows in UEFI mode and use an [[UEFI Bootloaders|UEFI bootloader]] (which uses GPT), or possibly restore/install Windows on a BIOS/GPT hybrid MBR (see partitioning examples).}}
  
* [[Syslinux]] requires the partition containing {{ic|/boot/syslinux/ldlinux.sys}} (irrespective whether {{ic|/boot}} is a separate partition or not) to be marked as "Legacy BIOS Bootable" GPT attribute (''legacy_boot'' flag in GNU Parted) to identify the partition containing the Syslinux boot files by its 440-byte MBR boot code {{ic|gptmbr.bin}}. See [[Syslinux#GUID_Partition_Table_aka_GPT]] for more information. It is equivalent to "boot" flag in MBR disks.
+
Bootloaders that support GPT/BIOS partitioning scheme bootloading:
  
* [[GRUB Legacy]], present in the AUR as {{AUR|grub-legacy}}, does not support GPT disks. Fedora's heavily patched GRUB Legacy fork {{AUR|grub-legacy-fedora-git}} contains GPT patches from Intel (tested in Fedora, not tested in Arch).
+
* [[GRUB#GUID_Partition_Table_.28GPT.29_specific_instructions|GRUB]]
 +
* [[Syslinux#GUID_partition_table|Syslinux]]
  
{{Note|Fedora developers have mentioned that after the release of Fedora 17, ''grub-legacy-fedora'' development will stop. Fedora already uses GRUB(2) as its default BIOS bootloader since F16. Users are recommended to switch to GRUB(2) or Syslinux instead.}}
+
Not suported: [[GRUB Legacy]] and [[LILO]].
  
{{Note|Some Intel Desktop Board motherboards will only boot a GPT disk if the protective MBR partition has its Boot flag set. This can be done safely with fdisk/cfdisk without damaging the GPT (but have backups / double-check the integrity of the GPT afterwards anyway).}}
+
==== Workarounds ====
  
* [[LILO]]'s GPT support has not been tested so it is unclear whether it has issues booting in GPT disks.
+
A few workarounds may help boot a BIOS/GPT partitioning scheme; however, before trying these, try booting a BIOS/GPT partitioning scheme with the bootloaders standard procedure.  If it doesn't work, these may help boot them ([http://www.rodsbooks.com/gdisk/bios.html#bios read this] for full reference):
 +
 
 +
* Set the boot flag on the protective MBR partition (type 0xEE) .  This can be done with {{ic|parted /dev/sdX}} and {{ic|disk_toggle pmbr_boot}} or using {{ic|1=sgdisk /dev/sdX --attributes=1:set:2}}.
 +
* Be sure there is no EFI system partition
 +
* Create a hybrid MBR.  This will be needed for a BIOS that looks for a valid MBR partition (see example below).
 +
* Recompute CHS (Cylinder/Head/Sector) values in the protective MBR.  GPT does not use these values but the protective MBR may need to be calibrated to them to work for those BIOS that test them.
 +
* A second disk that has a valid MBR table may signify to the BIOS that it is alright to execute the code on the protective MBR.
 +
* Many computers since 2011 may have support for an EFI booting if wanting from a BIOS option.
  
 
== Partitioning Utilities ==
 
== Partitioning Utilities ==
 +
 +
Several partitioning utilities exists.
 +
 
=== GPT fdisk ===
 
=== GPT fdisk ===
  
 
GPT fdisk is a set of text-mode utilities for editing GPT disks. It consists of gdisk, sgdisk and cgdisk which are equivalent to respective tools from util-linux fdisk (used for MBR disks). It is available in the [extra] repository as {{Pkg|gptfdisk}}.
 
GPT fdisk is a set of text-mode utilities for editing GPT disks. It consists of gdisk, sgdisk and cgdisk which are equivalent to respective tools from util-linux fdisk (used for MBR disks). It is available in the [extra] repository as {{Pkg|gptfdisk}}.
  
{{Note|The fdisk partitioning utilities from util-linux (i.e. fdisk, cfdisk and sfdisk) do not support GPT, and may damage the GPT header and partition table if used on a GPT disk.}}
+
=== GNU Parted ===
 +
 
 +
[[GNU Parted]] is a full-featured command line program for creating and manipulating partition tables. It can be used interactively and is the backend for the popular [[GParted]] GUI partitioning tool.
 +
 
 +
It supports GPT as well as MBR.
 +
 
 +
=== Util-linux fdisk ===
 +
 
 +
{{Out of date|Is GPT support still in beta?}}
 +
 
 +
The [[fdisk]] utility from {{Pkg|util-linux}} (based on util-linux internal libfdisk) partially supports GPT, but it is still in beta stage (as on 07 October 2013). The related utilities cfdisk and sfdisk do not yet support GPT, and may damage the GPT header and partition table if used on a GPT disk.
 +
 
 +
== Partitioning examples ==
 +
 
 +
{{Merge|fdisk|Keep the info in one place.}}
 +
{{Merge|parted|Keep the info in one place.}}
 +
 
 +
Examples of various partitioning setups.
 +
 
 +
=== gdisk basic ===
 +
 
 +
# gdisk /dev/sdX
 +
o  # create new empty GUID partition table
 +
n  # partition 1 [enter], from beginning [enter], to 100GiB [+100GiB], linux fs type [enter]
 +
n  # partition 2 [enter], from beginning [enter], to 108GiB [+8GiB],  linux swap    [8200]
 +
w  # write table to disk and exit
 +
 
 +
=== gdisk basic (with hybrid MBR) ===
 +
 
 +
Tip: use MiB, GiB to align to 2048 sectors:
 +
 
 +
# gdisk /dev/sdX
 +
o  # create new empty GUID partition table
 +
n  # partition 1 [enter], from beginning [enter], to 100GiB [+100GiB], linux fs type [enter]
 +
n  # partition 2 [enter], from beginning [enter], to 108GiB [+8GiB],  linux swap    [8200]
 +
n  # partition 3 [enter], from beginning [enter],          [+1MiB],  linux fs type [enter]
 +
r  # recovery/transformation menu
 +
h  # make hybrid mbr
 +
3  # add partition 3 to hybrid mbr
 +
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): '''N'''
 +
Enter an MBR hex code (default 83): [enter]
 +
Set the bootable flag? (Y/N): Y
 +
Unused partition space(s) found. Use one to protect more partitions? (Y/N): N
 +
w  # write table to disk and exit
 +
 
 +
=== parted basic (via command line options) ===
 +
 
 +
parted --script /dev/sda mklabel gpt
 +
parted --script --align optimal /dev/sda mkpart primary ext4 0% -8GiB mkpart primary linux-swap -8GiB 100%
 +
 
 +
=== sgdisk basic (auto discover) ===
 +
 
 +
Get the values of: '''disk space''' and '''swap space''', then set '''root partition''' space.
 +
 
 +
* '''Disk space''' is rounded '''down''' to nearest mebibyte, and the header GPT metadata space is deducted (1 MiB).
 +
* '''Swap space''' is rounded '''up''' to nearest mebibyte based on memory.
 +
 
 +
diskspace=$(( $(grep sda$ /proc/partitions | awk '{print $3}') * 2 / 2048 - 1 ))
 +
swapspace=$(( $(head -n1 /proc/meminfo | awk '{print $2}') / 1024 + 1 ))
 +
rootspace=$(( $diskspace - $swapspace ))
 +
 
 +
Then run this (this is a '''dry-run''' used for testing, remove '''--pretend''' to alter partition table):
 +
 
 +
sgdisk --clear --new 1:0:+${rootspace}MiB --new 2:0:+${swapspace}MiB --typecode 2:8200 --pretend --print /dev/sda
  
==== Convert from MBR to GPT ====
+
=== Convert from MBR to GPT ===
  
 
One of the best features of gdisk (and sgdisk and cgdisk too) is 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.  
 
One of the best features of gdisk (and sgdisk and cgdisk too) is 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.  
Line 106: Line 156:
 
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. '''Watch out for any error and fix them before writing any change to disk''' because you may risk losing data. See http://www.rodsbooks.com/gdisk/mbr2gpt.html for more info. After conversion, the bootloaders will need to be reinstalled to configure them to boot from GPT.
 
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. '''Watch out for any error and fix them before writing any change to disk''' because you may risk losing data. See http://www.rodsbooks.com/gdisk/mbr2gpt.html for more info. After conversion, the bootloaders will need to be reinstalled to configure them to boot from GPT.
  
{{Note|Remember that GPT stores a secondary table at the end of disk. You must make sure that the last 1 MiB of the disk is not used by any partition.}}
+
{{Note|
 +
* Remember that GPT stores a secondary table at the end of disk. This data structure consumes 33 512-byte sectors by default. MBR doesn't have a similar data structure at its end, which means that the last partition on an MBR disk sometimes extends to the very end of the disk and prevents complete conversion. If this happens to you, you must abandon the conversion, resize the final partition, or convert everything but the final partition.
 +
* Keep in mind that if your Boot-Manager is GRUB, it needs a [[GRUB#GUID Partition Table (GPT) specific instructions|BIOS Boot Partition]]. If your MBR Partitioning Layout isn't too old, there is a good chance that the first partition starts at sector 2048 for alignment reasons. That means at the beginning will be 1007 [[Wikipedia:KiB|KiB]] of empty space where this bios-boot partition can be created. To do this, first do the mbr->gpt conversion with gdisk as described above. Afterwards, create a new partition with gdisk and manually specify its position to be sectors 34 - 2047, and set the {{ic|EF02}} partition type.
 +
* There are known corruption issues with the backup GPT table on laptops that are Intel chipset based, and run in RAID mode. The solution is to use AHCI instead of RAID, if possible. }}
  
{{Note|Keep in mind that if your Boot-Manager is Grub, it needs a [[GRUB2#GPT_specific_instructions|BIOS Boot Partition]]. If your MBR Partitioning Layout isn't too old, there is a good chance that the first partition starts at sector 2048 for alignment reasons. That means at the beginning will be 1007KiB of empty space where this bios-boot partition can be created. To do this, first do the mbr->gpt conversion with gdisk as described above. Afterwards, create a new partition with gdisk and manually specify its position to be sectors 34 - 2047, and set the {{ic|EF02}} partition type.}}
+
See also [[fdisk#Convert between MBR and GPT]].
  
=== GNU Parted ===
+
=== Resize a partition ===
 +
 
 +
This is generally applicable to reduce partition, so a new one can be created in that space. But it can be applied to growing a partition also. This example is for reducing a partition size.
 +
 
 +
{{Warning|Backup your data before attempting this. Resizing a partition can possibly compromise the filesystem on it. Try this on a [[:Category:Virtualization|virtual machine environment]], before trying this on a live system.}}
 +
 
 +
# parted /dev/sdX
 +
p # take note of where the target partition ends
 +
resizepart <PART NUMBER> <NEW END SIZE>
 +
quit
 +
 
 +
After this, the filesystem on the reduced partition might need to be recreated. A new partition can be created in the new space at the end of the resized partition. The partition numbering will not be sequential. [[#Sort_the_partitions|Sorting]] can be used.
 +
 
 +
=== Sort the partitions ===
 +
 
 +
This applies for when a new partition is created in the space between two partitions, after one of them is [[#Resize_a_partition|resized]].
 +
 
 +
# gdisk /dev/sdX
 +
s # this will sort the partitions
 +
w
 +
 
 +
After sorting the partitions, it might be required to adjust the {{ic|/etc/fstab}} and/or the {{ic|/etc/crypttab}} configuration files, the latter only in case of [[Dm-crypt/System configuration#crypttab|encrypted]] partitions.
  
In GNU Parted >=3.0, the {{ic|parted}} command-line utility does not support any filesystem related operation, and most of the FS related code has been removed from the libparted, leaving only minimal code required by external applications like gparted. The upstream recommends using the filesystem specific tools or one of the parted's GUI wrappers like gparted (which calls these external tools) for filesystem related operations.
+
== See also ==
  
==See also==
+
* Wikipedia's  Page on [[wikipedia:GUID_Partition_Table|GPT]] and [[wikipedia:Master_boot_record|MBR]]
# Wikipedia's  Page on [http://en.wikipedia.org/wiki/GUID_Partition_Table GPT] and [http://en.wikipedia.org/wiki/Master_boot_record MBR]
+
* [http://rodsbooks.com/gdisk/ Homepage of Rod Smith's GPT fdisk tool] and its [http://sourceforge.net/projects/gptfdisk/ Sourceforge.net Project page - gptfdisk]
# [http://rodsbooks.com/gdisk/ Homepage of Rod Smith's GPT fdisk tool] and its [http://sourceforge.net/projects/gptfdisk/ Sourceforge.net Project page - gptfdisk]
+
* Rod Smith's page on [http://www.rodsbooks.com/gdisk/whatsgpt.html What's a GPT?] [http://rodsbooks.com/gdisk/mbr2gpt.html Converting MBR to GPT] and [http://rodsbooks.com/gdisk/booting.html Booting OSes from GPT]
# Rod Smith's page on [http://rodsbooks.com/gdisk/mbr2gpt.html Converting MBR to GPT] and [http://rodsbooks.com/gdisk/booting.html Booting OSes from GPT]
+
* Rod Smith's page on the [http://www.rodsbooks.com/linux-fs-code/index.html New Partition Type GUID] for Linux data partitions
# Rod Smith's page on the [http://www.rodsbooks.com/linux-fs-code/index.html New Partition Type GUID] for Linux data partitions
+
* [http://sysresccd.org/Sysresccd-Partitioning-The-new-GPT-disk-layout System Rescue CD's page on GPT]
# [http://sysresccd.org/Sysresccd-Partitioning-The-new-GPT-disk-layout System Rescue CD's page on GPT]
+
* Wikipedia page on [[wikipedia:BIOS_Boot_partition|BIOS Boot Partition]]
# Wikipedia page on [http://en.wikipedia.org/wiki/BIOS_Boot_partition BIOS Boot Partition]
+
* [http://www.ibm.com/developerworks/linux/library/l-gpt/index.html?ca=dgr-lnxw07GPT-Storagedth-lx&S_TACT=105AGY83&S_CMP=grlnxw07 Make the most of large drives with GPT and Linux - IBM Developer Works]
# [http://www.ibm.com/developerworks/linux/library/l-gpt/index.html?ca=dgr-lnxw07GPT-Storagedth-lx&S_TACT=105AGY83&S_CMP=grlnxw07 Make the most of large drives with GPT and Linux - IBM Developer Works]
+
* [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ]
# [http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx Microsoft's Windows and GPT FAQ]
+
* Fedora developer discussion on [http://mjg59.dreamwidth.org/8035.html BIOS/GPT configuration]

Latest revision as of 13:22, 7 May 2016

GUID Partition Table (GPT) is a partitioning scheme that is part of the Unified Extensible Firmware Interface specification; it uses a globally unique identifier for qualifying devices. It is the next generation partitioning scheme designed to succeed the Master Boot Record partitioning scheme method. It evolved to deal with several shortcomings of the MBR partitioning scheme method and offers additional advantages.

About the GUID Partition Table

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

Location in the HDD Purpose
First logical sector of the disk or First 512 bytes 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 TiB, upto a partition size of 2 TiB.
Second logical sector of the disk or Next 512 bytes Primary GPT Header - Contains the Unique Disk GUID, Location of the Primary Partition Table, Number of possible entries in partition table, CRC32 checksums of itself and the Primary Partition Table, Location of the Secondary (or Backup) GPT Header
16 KiB (by default) following the second logical sector of the disk Primary GPT Table - 128 Partition entries (by default, can be higher), each with an entry of size 128 bytes (hence total of 16 KiB for 128 partition entries). Sector numbers are stored as 64-bit LBA and each partition has a Partition Type GUID and a Unique Partition GUID.
16 KiB (by default) before the last logical sector of the disk Secondary GPT table - It is byte-for-byte identical to the Primary table. Used mainly for recovery in case the primary partition table is damaged.
Last logical sector of the disk or Last 512 bytes Secondary GPT Header - Contains the Unique Disk GUID, Location of the Secondary Partition Table, Number 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.

Advantages of GPT

  1. Uses GUIDs (UUIDs) to identify partition types - No collisions.
  2. Provides a unique disk GUID and unique partition GUID for each partition - A good filesystem-independent way of referencing partitions and disks.
  3. Arbitrary number of partitions - depends on space allocated for the partition table - No need for extended and logical partitions. By default the GPT table contains space for defining 128 partitions. However if the user wants to define more partitions, he/she can allocate more space to the partition table (currently only gdisk is known to support this feature).
  4. Uses 64-bit LBA for storing Sector numbers - maximum addressable disk size is 2 ZiB. MBR is limited to addressing 2 TiB of space per drive.
  5. Stores a backup header and partition table at the end of the disk that aids in recovery in case the primary ones are damaged.
  6. CRC32 checksums to detect errors and corruption of the header and partition table.

Kernel Support

CONFIG_EFI_PARTITION option in the kernel config enables GPT support in the kernel (despite the name EFI PARTITION). This options must be built-in the kernel and not compiled as a loadable module. This option is required even if GPT disks are used only for data storage and not for booting. This option is enabled by default in Arch's linux and linux-lts kernels in [core] repo. In case of a custom kernel enable this option by doing CONFIG_EFI_PARTITION=y.

Bootloader Support

UEFI systems

All UEFI Bootloaders support GPT disks since GPT is a part of UEFI Specification and thus mandatory for UEFI boot. See Boot loaders for more information.

BIOS systems

While GPT support on BIOS systems is theoretically possible it sometimes isn't practical and other times there are complete incompatibilities. Technically the BIOS is only supposed to execute the code on the MBR, therefore leaving the possibility of differing partitioning schemes... However a BIOS may do additional checks including: checking a MBR's integrity, and possibly even for a MBR partition table (though usually only the first partition). If this is a case, a number of workarounds exist that may be able to repair the problem (listed below).

Warning: For Windows, there is no support for booting from a BIOS/GPT partitioning scheme. If you have already installed Windows with a BIOS/MBR partitioning scheme do not convert the drive to GPT! Windows will fail to boot if this is done - irrespective of the bootloader used to chainload Windows. One can either install Windows in UEFI mode and use an UEFI bootloader (which uses GPT), or possibly restore/install Windows on a BIOS/GPT hybrid MBR (see partitioning examples).

Bootloaders that support GPT/BIOS partitioning scheme bootloading:

Not suported: GRUB Legacy and LILO.

Workarounds

A few workarounds may help boot a BIOS/GPT partitioning scheme; however, before trying these, try booting a BIOS/GPT partitioning scheme with the bootloaders standard procedure. If it doesn't work, these may help boot them (read this for full reference):

  • Set the boot flag on the protective MBR partition (type 0xEE) . This can be done with parted /dev/sdX and disk_toggle pmbr_boot or using sgdisk /dev/sdX --attributes=1:set:2.
  • Be sure there is no EFI system partition
  • Create a hybrid MBR. This will be needed for a BIOS that looks for a valid MBR partition (see example below).
  • Recompute CHS (Cylinder/Head/Sector) values in the protective MBR. GPT does not use these values but the protective MBR may need to be calibrated to them to work for those BIOS that test them.
  • A second disk that has a valid MBR table may signify to the BIOS that it is alright to execute the code on the protective MBR.
  • Many computers since 2011 may have support for an EFI booting if wanting from a BIOS option.

Partitioning Utilities

Several partitioning utilities exists.

GPT fdisk

GPT fdisk is a set of text-mode utilities for editing GPT disks. It consists of gdisk, sgdisk and cgdisk which are equivalent to respective tools from util-linux fdisk (used for MBR disks). It is available in the [extra] repository as gptfdisk.

GNU Parted

GNU Parted is a full-featured command line program for creating and manipulating partition tables. It can be used interactively and is the backend for the popular GParted GUI partitioning tool.

It supports GPT as well as MBR.

Util-linux fdisk

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Is GPT support still in beta? (Discuss in Talk:GUID Partition Table#)

The fdisk utility from util-linux (based on util-linux internal libfdisk) partially supports GPT, but it is still in beta stage (as on 07 October 2013). The related utilities cfdisk and sfdisk do not yet support GPT, and may damage the GPT header and partition table if used on a GPT disk.

Partitioning examples

Merge-arrows-2.pngThis article or section is a candidate for merging with fdisk.Merge-arrows-2.png

Notes: Keep the info in one place. (Discuss in Talk:GUID Partition Table#)

Merge-arrows-2.pngThis article or section is a candidate for merging with parted.Merge-arrows-2.png

Notes: Keep the info in one place. (Discuss in Talk:GUID Partition Table#)

Examples of various partitioning setups.

gdisk basic

# gdisk /dev/sdX
o  # create new empty GUID partition table
n  # partition 1 [enter], from beginning [enter], to 100GiB [+100GiB], linux fs type [enter]
n  # partition 2 [enter], from beginning [enter], to 108GiB [+8GiB],   linux swap    [8200]
w  # write table to disk and exit

gdisk basic (with hybrid MBR)

Tip: use MiB, GiB to align to 2048 sectors:

# gdisk /dev/sdX
o  # create new empty GUID partition table
n  # partition 1 [enter], from beginning [enter], to 100GiB [+100GiB], linux fs type [enter]
n  # partition 2 [enter], from beginning [enter], to 108GiB [+8GiB],   linux swap    [8200]
n  # partition 3 [enter], from beginning [enter],           [+1MiB],   linux fs type [enter]
r  # recovery/transformation menu
h  # make hybrid mbr
3  # add partition 3 to hybrid mbr
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): N
Enter an MBR hex code (default 83): [enter]
Set the bootable flag? (Y/N): Y
Unused partition space(s) found. Use one to protect more partitions? (Y/N): N
w  # write table to disk and exit

parted basic (via command line options)

parted --script /dev/sda mklabel gpt
parted --script --align optimal /dev/sda mkpart primary ext4 0% -8GiB mkpart primary linux-swap -8GiB 100%

sgdisk basic (auto discover)

Get the values of: disk space and swap space, then set root partition space.

  • Disk space is rounded down to nearest mebibyte, and the header GPT metadata space is deducted (1 MiB).
  • Swap space is rounded up to nearest mebibyte based on memory.
diskspace=$(( $(grep sda$ /proc/partitions | awk '{print $3}') * 2 / 2048 - 1 ))
swapspace=$(( $(head -n1 /proc/meminfo | awk '{print $2}') / 1024 + 1 ))
rootspace=$(( $diskspace - $swapspace ))

Then run this (this is a dry-run used for testing, remove --pretend to alter partition table):

sgdisk --clear --new 1:0:+${rootspace}MiB --new 2:0:+${swapspace}MiB --typecode 2:8200 --pretend --print /dev/sda

Convert from MBR to GPT

One of the best features of gdisk (and sgdisk and cgdisk too) is 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. Watch out for any error and fix them before writing any change to disk because you may risk losing data. See http://www.rodsbooks.com/gdisk/mbr2gpt.html for more info. After conversion, the bootloaders will need to be reinstalled to configure them to boot from GPT.

Note:
  • Remember that GPT stores a secondary table at the end of disk. This data structure consumes 33 512-byte sectors by default. MBR doesn't have a similar data structure at its end, which means that the last partition on an MBR disk sometimes extends to the very end of the disk and prevents complete conversion. If this happens to you, you must abandon the conversion, resize the final partition, or convert everything but the final partition.
  • Keep in mind that if your Boot-Manager is GRUB, it needs a BIOS Boot Partition. If your MBR Partitioning Layout isn't too old, there is a good chance that the first partition starts at sector 2048 for alignment reasons. That means at the beginning will be 1007 KiB of empty space where this bios-boot partition can be created. To do this, first do the mbr->gpt conversion with gdisk as described above. Afterwards, create a new partition with gdisk and manually specify its position to be sectors 34 - 2047, and set the EF02 partition type.
  • There are known corruption issues with the backup GPT table on laptops that are Intel chipset based, and run in RAID mode. The solution is to use AHCI instead of RAID, if possible.

See also fdisk#Convert between MBR and GPT.

Resize a partition

This is generally applicable to reduce partition, so a new one can be created in that space. But it can be applied to growing a partition also. This example is for reducing a partition size.

Warning: Backup your data before attempting this. Resizing a partition can possibly compromise the filesystem on it. Try this on a virtual machine environment, before trying this on a live system.
# parted /dev/sdX
p # take note of where the target partition ends
resizepart <PART NUMBER> <NEW END SIZE>
quit

After this, the filesystem on the reduced partition might need to be recreated. A new partition can be created in the new space at the end of the resized partition. The partition numbering will not be sequential. Sorting can be used.

Sort the partitions

This applies for when a new partition is created in the space between two partitions, after one of them is resized.

# gdisk /dev/sdX
s # this will sort the partitions
w

After sorting the partitions, it might be required to adjust the /etc/fstab and/or the /etc/crypttab configuration files, the latter only in case of encrypted partitions.

See also