sgdisk
Edit GUID Partition Tables
TLDR
Display basic GPT partition summary data for a device
Wipe both GPT and MBR data structures from a device (destroys all partition information)
Convert a GPT disk to MBR format using up to four partitions
Delete a partition entry by number (data in sectors remains untouched)
Save the current in-memory GPT data (protective MBR, headers, and table) to a binary backup file
Load GPT data from a backup file (restoring from a non-original disk is not recommended)
Verify GPT structures for CRC errors, mismatches, or inconsistencies
Display a summary of available partition type codes (no device required)
SYNOPSIS
sgdisk [options] device
PARAMETERS
-A, --attributes=partnum:bitnum:[0|1]
Set or clear a specific partition attribute bit. Useful for setting flags like 'legacy BIOS bootable' or 'read-only'.
-c, --change-name=partnum:name
Change the human-readable name of a specified partition.
-d, --delete=partnum
Delete a partition by its number. Warning: This is destructive.
-g, --new-gpt
Create a new, empty GPT on the specified device. This will destroy all existing data on the disk.
-h, --hybrid=partnum:partnum...[:MBR_part_type:disk_id]
Create a hybrid MBR that mirrors up to three specified GPT partitions. Useful for booting legacy OSes from a GPT disk.
-n, --new=partnum:start:end
Create a new partition. start and end can be sector numbers, '+' followed by size, or '0' for default values.
-o, --mbrtogpt
Convert an MBR partition table to a GPT, preserving as much data as possible. Creates GUIDs randomly.
-p, --print
Print the current partition table for the specified device. This is a read-only operation.
-s, --sort
Sort the partitions by their starting sector number. This can improve disk performance and cleanup partition numbering.
-t, --change-type=partnum:hexcode
Change the type code (GUID) of a partition. Use -T to list available type codes.
-v, --verify
Verify the GPT data structures and report any inconsistencies, offering to fix them if possible.
-z, --zap-all
Zap (destroy) all GPT and MBR data structures on the disk. This is highly destructive and should be used with extreme care.
DESCRIPTION
sgdisk is a powerful command-line utility designed for manipulating GUID Partition Tables (GPTs) on disk devices. Unlike its interactive counterpart, gdisk, sgdisk is primarily intended for non-interactive use, making it ideal for scripting and automated system deployment tasks. It provides comprehensive functionality to create, delete, resize, move, copy, and change attributes of partitions on GPT-formatted disks.
Key capabilities include converting MBR disks to GPT, creating hybrid MBRs for legacy compatibility, and managing partition type codes and GUIDs. It fully supports the advanced features of GPT, such as handling disks larger than 2TB, accommodating more than four primary partitions, and providing robust data integrity through redundant partition tables and checksums. Users should exercise caution as many operations can be data destructive.
CAVEATS
Data Loss Risk: Many sgdisk operations, especially those creating or deleting partitions (e.g., -g, -z, -n, -d), are inherently destructive. Always back up critical data before using sgdisk.
Device Selection: Ensure you specify the correct device (e.g., /dev/sda) and not a partition (e.g., /dev/sda1). Operating on the wrong device can lead to irreversible data loss.
Root Privileges: sgdisk requires root privileges to operate on disk devices.
Hybrid MBRs: While supported, hybrid MBRs (created with -h) are generally discouraged. They are a workaround for legacy systems and can complicate disk management.
Non-Interactive Use: While capable of interactive prompts for some errors, sgdisk is designed for scripting. For interactive partitioning, gdisk is generally preferred.
GPT ADVANTAGES
Compared to the older Master Boot Record (MBR) scheme, GPT offers significant advantages:
Disk Size: Supports disks much larger than 2TB, up to 9.4 ZB.
Number of Partitions: By default, allows for up to 128 primary partitions without the need for extended or logical partitions.
Data Integrity: Stores a CRC32 checksum for the GPT header and partition table, and maintains a backup GPT header and partition table at the end of the disk, enabling recovery from corruption.
GUIDs: Uses Globally Unique Identifiers (GUIDs) for both the disk and individual partitions, minimizing name collisions and providing robust identification.
HISTORY
sgdisk is part of the gdisk partitioning suite, developed by Roderick W. Smith. It emerged as a crucial tool to address the limitations of traditional MBR partitioning (e.g., 2TB disk size limit, 4 primary partition limit) by fully embracing the GUID Partition Table (GPT) standard. While gdisk provides a user-friendly, interactive interface for GPT manipulation, sgdisk was specifically engineered to facilitate scripting and automation. This non-interactive design allows system administrators and deployment scripts to programmatically manage GPT partitions, making it invaluable for automated system provisioning and disk setup tasks where user interaction is not feasible or desired.


