"sgdisk - Command-line GUID partition table (GPT) manipulator for Linux and Unix" - man sgdisk

See also

  • gdisk is an interactive prompt interface.
  • cgdisk is a curses interface to gdisk, similar to fdisk in MS Windows of yore.


Delete all GPT and MBR entries and create a new GPT

sgdisk -Z /dev/sdz

Create a new partition

  • Partition numbers start at 1
  • The syntax here is --new <partition_number>[:<start>[:<end>]]
  • See the man page for a variety of ways to refrence start and end.
sgdisk --new 1:2048:732566636 /dev/sdz

Randomize GUIDs to ensure uniqueness after cloning

sgdisk --randomize-guids /dev/sdz
sgdisk -p /dev/sdz

Destroy GPT partition table

sgdisk -z /dev/sdz
sgdisk -E /dev/sdz
sgdisk -i 1 /dev/sdz

Backup a GUID partition table

sgdisk -b ~/sdz_partition_backup /dev/sdz

Restore a GUID partition table

sgdisk -l ~/sdz_partition_backup /dev/sdz

Create a new partition

This creates a 4th partition that is 50G using the default starting point (0 is default)

sgdisk /dev/sdz --new=4:0:+50G

Delete the 4th partition

sgdisk /dev/sdz -d 4

Create a new partition number 4 that fills the biggest available section of the disk

sgdisk /dev/sdz -N 4

Grab the name of a partition

# sloppy, doesn't handle spaces or single quotes
sgdisk /dev/sdk -i 1 | grep '^Partition name' | awk '{print $NF}' | sed "s/'//g"