GPT: Difference between revisions
[unchecked revision] | [unchecked revision] |
(Added Partition Table Header structure) |
mNo edit summary |
||
Line 46: | Line 46: | ||
|- |
|- |
||
|0x58||4||CRC32 of the Partition Entry array. |
|0x58||4||CRC32 of the Partition Entry array. |
||
|- |
|- |
||
|0x5C||'''blocksize'''-0x5C||Reserved (should be zeroed) |
|0x5C||'''blocksize'''-0x5C||Reserved (should be zeroed) |
||
|} |
|} |
||
Note: it is somewhat vague what the Number of Partition Entries field contain. For many applications that is the number of '''actually used''' entries, while many partitioning tools (most notably fdisk and gdisk) handles that as the number of '''maximum available''' entries, using full zero Partition Type to mark empty entries. Unfortunately both interpretation is suggested by the EFI spec, so this is unclear. One thing is certain, there should be no more entries (empty or not) than this field. |
|||
== Partition Entry == |
|||
{| {{wikitable}} |
|||
|'''Offset'''||'''Length (bytes)'''||'''Description''' |
|||
|- |
|||
|0x0||16||Partition Type GUID (zero means unused entry) |
|||
|- |
|||
|0x10||16||Unique Partition GUID |
|||
|- |
|||
|0x20||8||StartingLBA |
|||
|- |
|||
|0x28||8||EndingLBA |
|||
|- |
|||
|0x30||8||Attributes |
|||
|- |
|||
|0x38||72||Partition Name |
|||
|} |
|||
Partition type has no central registry, but with 16 bytes is is unlikely that there'll ever be a collusion. You can find types for OSes on their corresponding corporation's website (for MacOSX see Apple; for Windows see Microsoft etc.) |
|||
Attributes is a bit set. Bit 0 means that the partition is required by the firmware and should not be touched. [[EFI System Partition]] would be a good example, however that's always explicitly assumed to have this bit set. Bit 1 means that the partition contains necessary files to boot an operating system (defined as EFI_PART_USED_BY_OS). |
|||
Name is UNICODE16-LE encoded, meaning it can only store the UNICODE Bilingual Plane (code points 32 to 65535), and each character consumes 2 bytes. However the EFI spec defines name length as 72 bytes, you should never hard-code this into your application. Always use (Partition Entry Size in header - 0x3B) instead. |
|||
== Utilities == |
== Utilities == |
||
Line 57: | Line 80: | ||
* [http://technet.microsoft.com/en-us/library/bb490893.aspx diskpart] on Windows (Vista and upwards) |
* [http://technet.microsoft.com/en-us/library/bb490893.aspx diskpart] on Windows (Vista and upwards) |
||
* [http://www.freebsd.org/cgi/man.cgi?query=gpt&manpath=FreeBSD+7.1-RELEASE gpt] on MacOSX and BSDs. |
* [http://www.freebsd.org/cgi/man.cgi?query=gpt&manpath=FreeBSD+7.1-RELEASE gpt] on MacOSX and BSDs. |
||
* [https://gitlab.com/bztsrc/bootboot/tree/master/mkbootimg mkbootimg] an easy to use disk image creator available on Windows, MacOSX and Linux. |
|||
== Boot loaders == |
== Boot loaders == |
||
[[UEFI|EFI]] firmware is capable of booting from a specific GPT partition, [[EFI System Partition]] which is basically a FAT32 partition. It should contain a slightly modified [[EFI#Binary_Format|PE-executable]], like [http://elilo.sourceforge.net ELILO]. On old machines with legacy BIOS only you can use [[GRUB]], or you can write a custom [[Rolling_Your_Own_Bootloader|boot code]]. |
[[UEFI|EFI]] firmware is capable of booting from a specific GPT partition, [[EFI System Partition]] which is basically a FAT32 partition. It should contain a slightly modified [[EFI#Binary_Format|PE-executable]], like [http://elilo.sourceforge.net ELILO]. On old machines with legacy BIOS only you can use [[GRUB]], or you can write a custom [[Rolling_Your_Own_Bootloader|boot code]]. |
||
[[BOOTBOOT]] by default boots your kernel from [[EFI System Partition]]. On UEFI machines it does that natively, and on legacy BIOS systems and other platforms (ARM for example) it interprets GPT and ESP on its own. |
|||
== See Also == |
== See Also == |
Revision as of 17:39, 19 June 2020
GPT stands for GUID Partition Table. It is made to replace MBR partitioning.
Layout
LBA 0 | Protective Master Boot Record (PMBR). Holds a partition pointing to GPT to avoid accidental overwrite by old programs. |
LBA 1 | partition header, can be identified by 8 bytes magic "EFI PART" (45h 46h 49h 20h 50h 41h 52h 54h) |
LBA 2..33 | partition table entires |
...data on disk... | |
LBA -33..-2 | mirror of partition table |
LBA -1 | mirror of partition header on last addressable sector |
Partition Table Header
Offset | Length (bytes) | Description |
0x0 | 8 | Signature, can be identified by 8 bytes magic "EFI PART" (45h 46h 49h 20h 50h 41h 52h 54h) |
0x8 | 4 | GPT Revision |
0xC | 4 | Header size |
0x10 | 4 | CRC32 checksum of the GPT header |
0x14 | 4 | Reserved |
0x18 | 8 | The LBA containing this header |
0x20 | 8 | The LBA of the alternate GPT header |
0x28 | 8 | The first usable block that can be contained in a GPT entry |
0x30 | 8 | The last usable block that can be contained in a GPT entry |
0x38 | 16 | GUID of the disk |
0x48 | 8 | Starting LBA of the GUID Parition Entry array |
0x50 | 4 | Number of Parition Entries |
0x54 | 4 | Size (in bytes) of each entry in the Parition Entry array - must be a multiple of 8 |
0x58 | 4 | CRC32 of the Partition Entry array. |
0x5C | blocksize-0x5C | Reserved (should be zeroed) |
Note: it is somewhat vague what the Number of Partition Entries field contain. For many applications that is the number of actually used entries, while many partitioning tools (most notably fdisk and gdisk) handles that as the number of maximum available entries, using full zero Partition Type to mark empty entries. Unfortunately both interpretation is suggested by the EFI spec, so this is unclear. One thing is certain, there should be no more entries (empty or not) than this field.
Partition Entry
Offset | Length (bytes) | Description |
0x0 | 16 | Partition Type GUID (zero means unused entry) |
0x10 | 16 | Unique Partition GUID |
0x20 | 8 | StartingLBA |
0x28 | 8 | EndingLBA |
0x30 | 8 | Attributes |
0x38 | 72 | Partition Name |
Partition type has no central registry, but with 16 bytes is is unlikely that there'll ever be a collusion. You can find types for OSes on their corresponding corporation's website (for MacOSX see Apple; for Windows see Microsoft etc.)
Attributes is a bit set. Bit 0 means that the partition is required by the firmware and should not be touched. EFI System Partition would be a good example, however that's always explicitly assumed to have this bit set. Bit 1 means that the partition contains necessary files to boot an operating system (defined as EFI_PART_USED_BY_OS).
Name is UNICODE16-LE encoded, meaning it can only store the UNICODE Bilingual Plane (code points 32 to 65535), and each character consumes 2 bytes. However the EFI spec defines name length as 72 bytes, you should never hard-code this into your application. Always use (Partition Entry Size in header - 0x3B) instead.
Utilities
The following utilities can handle GPT:
- parted, gparted, gdisk on Linux
- diskutil on MacOSX
- diskpart on Windows (Vista and upwards)
- gpt on MacOSX and BSDs.
- mkbootimg an easy to use disk image creator available on Windows, MacOSX and Linux.
Boot loaders
EFI firmware is capable of booting from a specific GPT partition, EFI System Partition which is basically a FAT32 partition. It should contain a slightly modified PE-executable, like ELILO. On old machines with legacy BIOS only you can use GRUB, or you can write a custom boot code.
BOOTBOOT by default boots your kernel from EFI System Partition. On UEFI machines it does that natively, and on legacy BIOS systems and other platforms (ARM for example) it interprets GPT and ESP on its own.