We’ve talked about MBR partition. GPT partition is much simpler than MBR partition meanwhile more powerful. All LBAs use 64 bits so they can address sectors ranging from 0 to 2^64-1, which means the capacity of HDDs it can deal is almost unlimited unlike the 2TB limitation of MBR disk. The number of partitions you can create with GPT is also unlimited because you can specify the entries in the GPT partition table, unlike the MBR partition table which has the fixed 4 entries. There is also a backup GPT to achieve the error redundancy.
The struct of GPT is very simple. The very first sector(sector 0) on the disk is still the MBR but the MBR’s partition table only contains one entry with the partition type set to 0xee. This MBR is called protected MBR and not used for partition management. The protection MBR is only for those old partition tools that cannot recognize GPT partition. If they meet a partition of type 0xee, they should stop handling the partition and the disk to avoid damage of GPT partitions. The second sector on the disk is GPT header. The header has a signature “EFI PART”. The header contains the lba of itself(1), the size of the header(92 bytes) and the CRC of the header. It also contains the lba of the backup GPT header, the lba of the first and the last usable sector, the location(lba 2) of the GPT partition table, the number of entries(128) in the partition table, and the size of each entry(128 bytes), and the CRC of the partition table.
The backup GPT header is typically put at the end of the disk. The GPT partition table also has a backup which is typically put immediately before the backup GPT header. While the backup GPT partition table is exactly the same as the main GPT partition table, the backup GPT header is slightly different from the main GPT header. First, the header lba field of main GPT header(typically 1) is copied to the backup GPT header lba field of the backup GPT header, and the backup GPT header lba field of main GPT header is now the same as the GPT header LBA field of the backup GPT header, i.e., the two GPT headers backup each other. Second, the partition table lba is different in the main GPT header and the backup GPT header because the main partition table and the backup partition table are put at different locations. Third, since the content of the main GPT header and the backup GPT header is different, the header CRC field is also different. The partition table CRC, however, keeps the same for the two GPT headers.
The GPT partition table is an array of partition entries. Usually, the entries are of size 128 bytes and there are 128 entries in the table so the whole partition table occupies 32 sectors. The format of the entry is also very straight-forward, which contains the GUID of the type of the partition, the GUID of the partition itself, the lba of the start/stop sector of the partition and the partition name. The type GUID is different from the partition GUID in that partitions of the same type have the same type GUID but their partition GUIDs differentiate each other. For example, all “basic data partitions” share a single type GUID while “microsoft reserved partition” uses another type GUID.