gdisk partition table editor

This is a simplified version of the documentation without discussion and with examples.

For the original see RodsBooks

Thanks to Roderick W. Smith and additional contributers.

Text, menu partition editor, includes ability to convert MBR partition table to GPT.

sudo gdisk -l disk # Lists the partition table.

> sudo /usr/local/bin/gdisk -l /dev/disk0
GPT fdisk (gdisk) version 1.0.1

Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
  MBR: hybrid
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with hybrid MBR; using GPT.
Disk /dev/disk0: 625142448 sectors, 298.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A4EA6CAD-DDA9-400E-AA1B-7FF1F2BDF062
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 625142414
Partitions will be aligned on 8-sector boundaries
Total free space is 2178782 sectors (1.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640        98065887   46.6 GiB    AF00  Macintosh HD
   3        98556832        99826367   619.9 MiB   AF00  Recovery HD
   4        99827712       281176527   86.5 GiB    AF00  PHOTOS90
   5       282446072       407457295   59.6 GiB    AF00  HDIMAGES
   6       407719440       496488895   42.3 GiB    AF00  DATA45G
   7       496751040       606991511   52.6 GiB    AF00  HDIMAGES 2
   8       606991512       608261047   619.9 MiB   AB00  Recovery HD
   9       608261048       624880263   7.9 GiB     AF00  recovQ8GB
  10        98125020        98494514   180.4 MiB   AF00  email_cache

No modifications are written until explicitly written, quit to leave partition table unchanged.

pprint partition table see -l
bbackup partition table which includes any changes made.
Enter backup filename to save: /0_160310.gpt              
The operation has completed successfully.

ls -l /0_160310.gpt
rw-r--r--   1 root  wheel  17920 Mar 10 15:00 0_160310.gpt
Invoke recovery & transformation menu to restore
vverify the changed partition table
Caution: Partition 10 doesn't begin on a 8-sector boundary. This may
result in degraded performance on some modern (2009 and later) hard disks.

Consult http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/
for information on disk alignment.

No problems found. 2178782 free sectors (1.0 GiB) available in 8
segments, the largest of which is 1269544 (619.9 MiB) in size.
iinformation; prompted for partition number
command (? for help): i
Partition number (1-10): 1
Partition GUID code: C12A7328-F81F-11D2-BA4B-00A0C93EC93B (EFI System)
Partition unique GUID: 74B80E3E-D90A-4946-9B56-993F85901214
First sector: 40 (at 20.0 KiB)
Last sector: 409639 (at 200.0 MiB)
Partition size: 409600 sectors (200.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'EFI System Partition'

Command (? for help): I
Partition number (1-10):2
Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
Partition unique GUID: 8184AD94-2146-4A57-A1EB-A81B5BE61F44
First sector: 409640 (at 200.0 MiB)
Last sector: 98065887 (at 46.8 GiB)
Partition size: 97656248 sectors (46.6 GiB)
Attribute flags: 0000000000000000
Partition name: 'Macintosh HD'

Command (? for help): i
Partition number (1-10): 3
Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
Partition unique GUID: 7B350544-051D-426D-9281-F921018F2BE0
First sector: 98556832 (at 47.0 GiB)
Last sector: 99826367 (at 47.6 GiB)
Partition size: 1269536 sectors (619.9 MiB)
Attribute flags: 0000000000000000
Partition name: 'Recovery HD' 
nnew
Partition number (11-128, default 11): 
First sector (34-625142414, default = 281176528) or {+-}size{KMGTP}: 
Last sector (281176528-282446071, default = 282446071) or {+-}size{KMGTP}: 
Current type is 'Apple HFS/HFS+'
Hex code or GUID (L to show codes, Enter = AF00): 
Changed type of partition to 'Apple HFS/HFS+'
cchange name of partition (use diskutil rename)
Partition number (1-11): 11
Enter name: cache


need exclusive use of the DISK
rrecovery & transformationi menu
ddelete partition from table only.
qquit, does NOT imply writing the table to disk.
wwrite. use v first

quit, Shutdown and boot a live CD or recovery partition.

Use the partitioning utility that came with your operating system (diskutil for OS X) to view the revised partition table.
Then shutdown and boot the system normally.

oobliterate the Entire partition table!
xxpert menu (get into even more trouble than the main menu allows.)
?display terse help                     rearranged ed
p   print the partition table
i   show detailed information on a partition
b   back up GPT data to a file
n   add a new partition
c   change a partition's name  (use diskutil rename)
d   delete a partition
v   verify disk (partition table)
o   create a new empty GUID partition table (GPT)
r   recovery and transformation options (experts only)
s   sort partitions
t   change a partition's type code
l   list known partition types
w   write table to disk and exit
x   extra functionality (experts only)
q   quit without saving changes
?   print this menu
From Command (main menu) via r
Recovery/transformation command (? for help): ?
l   load partition data from a backup file
c   load backup partition table from disk (rebuilding main)
e   load main partition table from disk (rebuilding backup)

d   use main GPT header (rebuilding backup) be sure you are in Recovery/Transform menu as d is delete in main menu
b   use backup GPT header (rebuilding main)

f   load MBR and build fresh GPT from it
g   convert GPT into MBR and exit
h   make hybrid MBR
t   transform BSD disklabel partition

o   print protective MBR data
 
    Disk size is 625142448 sectors (298.1 GiB)
    MBR disk identifier: 0x00000000
    MBR partitions:

     Number  Boot  Start Sector   End Sector   Status      Code
        1                     1    625142447   primary     0xEE
p   print the partition table (same as from Command 
i   show detailed information on a partition (same as from Command 
v   verify disk (same as from Command
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu
m   return to main menu
q   quit without saving changes
Expert command (? for help): ?
a   set attributes
c   change partition GUID
d   display the sector alignment value
l   set the sector alignment value
e   relocate backup data structures to the end of the disk
g   change disk GUID
h   recompute CHS values in protective/hybrid MBR
n   create a new protective MBR
s   resize partition table
t   transpose two partition table entries
u   replicate partition table on new device
z   zap (destroy) GPT data structures and exit

r   recovery and transformation options (experts only)
i   show detailed information on a partition
w   write table to disk and exit
v   verify disk
m   return to main menu
o   print protective MBR data
p   print the partition table
q   quit without saving changes
?   print this menu
aset attributes
Partition number (1-9): 1
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automount

Attribute value is 0000000000000000. Set fields are:
  No fields set

Toggle which attribute field (0-63, 64 or  to exit): 


nnew
llist partition TYPES
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
3000 ONIE boot             3001 ONIE config           3900 Plan 9              
4100 PowerPC PReP boot     4200 Windows LDM data      4201 Windows LDM metadata
4202 Windows Storage Spac  7501 IBM GPFS              7f00 ChromeOS kernel     
7f01 ChromeOS root         7f02 ChromeOS reserved     8200 Linux swap          
8300 Linux filesystem      8301 Linux reserved        8302 Linux /home         
8303 Linux x86 root (/)    8304 Linux x86-64 root (/  8305 Linux ARM64 root (/)
8306 Linux /srv            8307 Linux ARM32 root (/)  8400 Intel Rapid Start   
8e00 Linux LVM             a500 FreeBSD disklabel     a501 FreeBSD boot        
a502 FreeBSD swap          a503 FreeBSD UFS           a504 FreeBSD ZFS         
a505 FreeBSD Vinum/RAID    a580 Midnight BSD data     a581 Midnight BSD boot   
a582 Midnight BSD swap     a583 Midnight BSD UFS      a584 Midnight BSD ZFS    
a585 Midnight BSD Vinum    a600 OpenBSD disklabel     a800 Apple UFS           
a901 NetBSD swap           a902 NetBSD FFS            a903 NetBSD LFS          
a904 NetBSD concatenated   a905 NetBSD encrypted      a906 NetBSD RAID         
ab00 Recovery HD           af00 Apple HFS/HFS+        af01 Apple RAID          
af02 Apple RAID offline    af03 Apple label           af04 AppleTV recovery    
af05 Apple Core Storage    bc00 Acronis Secure Zone   be00 Solaris boot        
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition 
f800 Ceph OSD              f801 Ceph dm-crypt OSD     f802 Ceph journal        
f803 Ceph dm-crypt journa  f804 Ceph disk in creatio  f805 Ceph dm-crypt disk i
fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
fd00 Linux RAID            

See

gpt, diskutil