GPT

最後更新: 2020-11-18

介紹

 

GUID Partition Table (GPT) uses GUIDs (or UUIDs in linux world) to define partitions and its types

目錄

  • 結構
  • GPT support on Linux
  • sgdisk
  • gdisk

 


結構

 

First logical sector (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

Second logical sector (512 bytes)

Primary GPT Header
Unique Disk GUID, Location of the Primary Partition Table,
Number of possible entries in partition table,
Primary Partition Table
CRC32 checksums of itself
Location of the Secondary (or Backup) GPT Header

16 KiB (by default) following the second logical sector

Primary GPT Table - 128 Partition entries (an entry of size 128 bytes)
- Partition Type GUID (64-bit LBA)
- Unique Partition GUID (64-bit LBA)

16 KiB (by default) before the last logical sector of the disk
Secondary GPT table

last logical sector of the disk (512 bytes)
512 bytes     Secondary GPT Header

 

Windows EFI

MBR uses a combination of cylinder/head/sector (CHS) addressing and logical block addressing (LBA)
GPT drops CHS addressing and uses  64-bit  LBA  mode

Boot disks for EFI-based systems require an EFI System Partition  (sgdisk  internal  code  0xEF00)
formatted  as  FAT-32.
The recommended size of this partition is between 100 and 300 MiB.
Boot-related files are stored here.
(Note that GNU Parted identifies such partitions as having the "boot flag" set.)

If Windows is to boot from a GPT disk, a partition of type  Microsoft  Reserved  (sgdisk  internal
code 0x0C01) is recommended. This partition should be about 128 MiB in size. It ordinarily follows
the EFI System Partition and immediately precedes the Windows  data  partitions.  (Note  that  GNU
Parted  creates  all  FAT partitions as this type, which actually makes the partition unusable for
normal file storage in both Windows and Mac OS X.)

 


GPT support on Linux

 

"CONFIG_EFI_PARTITION" option in the kernel config enables GPT support in the kernel

All UEFI Bootloaders support GPT disks

grep CONFIG_EFI_PARTITION /boot/config-`uname -r`

CONFIG_EFI_PARTITION=y

 


sgdisk

 

# Tools

  • gdisk - text-mode interactive
  • sgdisk - command-line

# help

sgdisk --help

# List

-p   # Display basic GPT partition summary data.

sgdisk -p /dev/sda

Disk /dev/sda: 468862128 sectors, 223.6 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 82B2AE61-D8F8-4666-AD16-17D3F8E60231
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 468862094
Partitions will be aligned on 2048-sector boundaries
Total free space is 363439213 sectors (173.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          534527   260.0 MiB   EF00  EFI system partition
   2          534528          567295   16.0 MiB    0C01  Microsoft reserved ...
   3          567296       105424895   50.0 GiB    0700  Basic data partition

# Detail info

-i   # Show detailed partition information.

sgdisk -i 1 /dev/sda

# Randomizes the GUID on the disk

sgdisk -G /dev/sdY

 

Backup/Restore GPT partition table

 

# Backup

sgdisk -b $BACKUPFILE $SOURCEDRIVE

 * -b, --backup=file

# Restore

sgdisk -l $BACKUPFILE $TARGETDRIVE

* -l, --load-backup

* Load partition data from a backup file. This option is the reverse of the -b option.

Note that restoring partition data from anything but the original disk is not recommended.

 


gdisk
 

Install

# C6

yum install gdisk

List the partition table use:

gdisk -l <device>

GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdg: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 33CE76A0-FC42-456B-B572-B85665FA55DB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      1953525134   931.5 GiB   8300  Dsk-1T-A

Interactive Shell

p       print the partition table

Disk /dev/sdh: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 51A59665-1D19-4757-AF79-8A9961157824
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      1953525134   931.5 GiB   8300  Linux filesystem

add / delete partition

n       add a new partition

d       delete a partition

w       write table to disk and exit

c       change a partition's name

v       verify disk

x       extra functionality (experts only)

m       return to main menu

Extra functionality (x)

d       # display the sector alignment value

l        # set the sector alignment value

e       # relocate backup data structures to the end of the disk

o       # print protective MBR data

Disk size is 1953525168 sectors (931.5 GiB)
MBR disk identifier: 0x00000000
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
   1                     1   1953525167   primary     0xEE

Clone GPT by gdisk

u       # replicate partition table on new device

Clone 完 partation 後, Disk 的 UUID 與 Partition 的 UUID 是不同的

 * g(x) / c(x) / c 是必須的, 因為它們會影響系統的 /dev/disk/by-X

blkid /dev/sd[hg]

/dev/sdg: PTUUID="02f05592-a6ca-4eab-a355-bdb4432902ba" PTTYPE="gpt"
/dev/sdh: PTUUID="33ce76a0-fc42-456b-b572-b85665fa55db" PTTYPE="gpt"

blkid /dev/sd[hg]1

/dev/sdg1: PARTLABEL="Dsk-1T-B" PARTUUID="cabe4d0b-58a2-4e96-9894-5461060aadfa"
/dev/sdh1: PARTLABEL="Dsk-1T-A" PARTUUID="cabe4d0b-58a2-4e96-9894-5461060aadfa"

Change UUID

g       change disk GUID

c       change partition GUID

i        show detailed information on a partition

 


Other

 

 

 

 

Creative Commons license icon Creative Commons license icon