LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

sgdisk

Scriptable GPT partition table manager

TLDR

Show partition table
$ sgdisk -p [/dev/sda]
copy
Create new GPT
$ sgdisk -o [/dev/sda]
copy
Create partition
$ sgdisk -n [1:0:+500M] [/dev/sda]
copy
Set partition type
$ sgdisk -t [1:8300] [/dev/sda]
copy
Delete partition
$ sgdisk -d [1] [/dev/sda]
copy
Change partition name
$ sgdisk -c [1:boot] [/dev/sda]
copy
Backup partition table
$ sgdisk -b [backup.gpt] [/dev/sda]
copy
Restore partition table
$ sgdisk -l [backup.gpt] [/dev/sda]
copy

SYNOPSIS

sgdisk [-n part:start:end] [-t part:type] [options] device

DESCRIPTION

sgdisk is the command-line, scriptable counterpart to the interactive gdisk partitioning tool, designed for manipulating GUID Partition Table (GPT) disk layouts. It performs all operations through flags and arguments rather than an interactive menu, making it ideal for use in scripts, automated provisioning, and disk imaging workflows.Partition creation uses flexible notation where sizes can be specified with + prefixes for relative sizing and 0 to fill remaining space. Type codes such as 8300 (Linux filesystem), EF00 (EFI System Partition), and 8200 (Linux swap) identify the purpose of each partition. Multiple operations can be chained in a single command to build complete partition layouts atomically.The tool also supports backing up and restoring entire partition tables, converting MBR disks to GPT, and verifying table integrity. All changes are written in a single operation when the command completes successfully.

PARAMETERS

-p, --print

Print partition table.
-o, --clear
Create new GPT.
-n, --new PART:START:END
Create partition.
-d, --delete PART
Delete partition.
-t, --typecode PART:TYPE
Set type code.
-c, --change-name PART:NAME
Set name.
-b, --backup FILE
Backup table.
-l, --load-backup FILE
Restore table.
-L, --list-types
List known partition type codes.
-i, --info PART
Show detailed information about a partition.
-v, --verify
Verify disk's GPT data structures.
-Z, --zap-all
Destroy both GPT and MBR data structures.
-g, --mbrtogpt
Convert MBR to GPT.

CAVEATS

Destructive operations are immediate and cannot be undone. Specifying the wrong device will destroy data. Only works with GPT partition tables (use fdisk for MBR). Use `-b` to back up the partition table before making changes.

HISTORY

sgdisk is part of the GPT fdisk suite by Rod Smith, first released around 2010. It was created as the scriptable counterpart to the interactive gdisk tool, filling the need for automated GPT partition management in scripts and deployment workflows.

SEE ALSO

gdisk(1), fdisk(1), parted(1)

Copied to clipboard
Kai