GUID Partition Table (GPT)

GPT 是一個實體硬碟的分割區表的結構布局的標準。它是可延伸韌體介面(UEFI)標準的一部分,被用於替代 BIOS 系統中的一 32bits 來儲存邏輯塊位址和大小資訊的主開機紀錄(Master Boot Record, MBR)分割區表。

在 Embedded System 中,通常會把 UFS(Universal Flash Storage) 切割成好幾個 LUN(Logical Unit Number),每個 LUN 可以視為一個虛擬硬碟,也就是說每個 LUN 都會有自己的 GPT,又每個 GPT 最多只能紀錄 128 Entries,所以每個 LUN 中,最多可以存在 128 個 Partitions,而每個 Partition 都會有自己的 Partition Entry。





GPT 的結構

在 MBR 硬碟中,分割區資訊直接儲存於主開機紀錄(MBR)中(主開機紀錄中還儲存著系統的啟動程式)。但在 GPT 硬碟中,分割區表的位置資訊儲存在 GPT Header 中。只是出於相容性考慮,硬碟的第一個磁區仍然用作 MBR,之後才是 GPT Header。

跟現代的 MBR 一樣,GPT 也使用邏輯區塊位址(Logical Block Addressing, LBA)取代了早期的 CHS 尋址方式。傳統 MBR 資訊儲存於 LBA 0,GPT Header 儲存於LBA 1,接下來才是 Partition Entry。在上圖的例子中,每個 LBA 為 512 bytes,每個 Partition Entry 的記錄為 128 bytes。

而為了減少分割區表損壞的風險,GPT 在硬碟最後儲存了一份分割區表的副本。



GPT 的資料結構

GPT Header 的資料結構
佔 512 bytes

typedef struct {
    unsigned char data[16];
} guid_t;

typedef struct gpt_hdr {
    uint64_t signature;  // "EFI PART", 45 46 49 20 50 41 52 54
    uint32_t revision;  // for GPT version 1.0, the value is 00h 00h 01h 00h)
    uint32_t header_size;  // in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes)
    uint32_t header_crc32;  // CRC32 of header (offset +0 up to header size) in little endian, with this field zeroed during calculation
    uint32_t reserved;  // must be zero
    uint64_t current_lba;  // location of this header copy
    uint64_t backup_lba;  // location of the other header copy
    uint64_t first_usable_lba;  // primary partition table last LBA + 1
    uint64_t last_usable_lba;  // secondary partition table first LBA − 1
    guid_t   disk_guid;  // Disk GUID in mixed endian
    uint64_t partition_entries_start_lba;  // Starting LBA of array of partition entries (always 2 in primary copy)
    uint32_t number_of_partitions;  // Number of partition entries in array
    uint32_t partition_entry_size;  // Size of a single partition entry (usually 80h or 128)
    uint32_t partition_array_crc32;  // CRC32 of partition entries array in little endian
    uint8_t  reserved_padding[420];  // Reserved; must be zeroes for the rest of the block (420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes)
} __attribute__((packed)) gpt_hdr_t;

 

 

 


GPT Partition Entry 的資料結構
佔 128 bytes

typedef struct gpt_partition_entry {
    guid_t   partition_type_guid;  // Partition type GUID (mixed endian)
    guid_t   unique_partition_guid;  // Unique partition GUID (mixed endian)
    uint64_t first_lba;  // First LBA (little endian) 
    uint64_t last_lba;  // Last LBA (inclusive, usually odd) 
    uint64_t attribute_flags;  // Attribute flags (e.g. bit 60 denotes read-only)
    char16_t  partition_name[36];  // Partition name (36 UTF-16LE code units)
} __attribute__((packed)) gpt_partition_entry_t;


其 attribute_flags 佔 64 bits,作用為:

Bit Content
0 Platform required (系統需要此 Partition 才能正常運作)
1 EFI firmware should ignore the content of the partition and not try to read from it
2 Legacy BIOS bootable (equivalent to active flag (typically bit 7 set) at offset +0h in partition entries of the MBR partition table)
3 ~ 47 Reserved for future use
48 ~ 63 供不同的 partition type 各別使用

 

 

 


Reference

GUID磁碟分割表
GUID Partition Table

文字內容 或 影像內容 部份參考、引用自網路,如有侵權,請告知,謝謝。

 

 

 

arrow
arrow
    全站熱搜

    silverwind1982 發表在 痞客邦 留言(0) 人氣()