Sgdisk - GPT Partition Manipulator
Sgdisk is a powerful command-line utility for Linux and Unix systems designed to manipulate GUID Partition Table (GPT) disk labels. It provides essential functionalities for managing disk partitions, including converting between MBR and GPT formats, cloning partition layouts, and ensuring data integrity.
Convert MBR to GPT
Easily convert your Master Boot Record (MBR) partitioned disk to a
GUID Partition Table (GPT) using the -g option. This is
a crucial step for disks larger than 2TB or when adopting modern
partitioning schemes.
# Convert an MBR partition table to GPT
sgdisk -g /dev/sda
Convert GPT to MBR
While less common, you can convert a GPT disk back to MBR using the
-m option. Note that this conversion has limitations,
especially with disks containing more than four primary partitions.
# Convert GPT to MBR (limited to four partitions)
sgdisk -m /dev/sda
Sort GPT Partitions
Maintain partition order and integrity after creating or deleting
partitions. The -s option sorts the GPT partitions
according to their starting sectors, ensuring a clean layout.
# Sort GPT partitions on the disk
sgdisk -s /dev/sda
Backup and Restore GPT/MBR
Safeguard your partition table by creating binary backups. The
-b option creates a backup file containing the
protective MBR, GPT header, backup GPT header, and partition table
entries. Use -l to restore from a backup.
# Create a binary backup of the partition table
sgdisk -b=sgdisk-sda.bak /dev/sda
# Restore GPT/MBR from a backup file
sgdisk -l=sgdisk-sda.bak /dev/sda
Clone Partition Layout
Duplicate the partition layout from one disk to another with the
-R option. This is incredibly useful for migrating data
or setting up identical disk configurations.
# Clone partition layout from /dev/sda to /dev/sdc
sgdisk -R=/dev/sdc /dev/sda
Randomize GUIDs
After cloning a partition layout, it's essential to randomize the
GUIDs to avoid conflicts. Use the -G option on the
destination disk to assign new, unique GUIDs to all partitions.
# Randomize GUIDs on the cloned disk
sgdisk -G /dev/sdc