LinuxCommandLibrary

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 type codes.

CAVEATS

Destructive operations are immediate. Wrong device destroys data. No MBR support.

HISTORY

sgdisk is part of GPT fdisk by Rod Smith. It provides scriptable GPT partition management.

SEE ALSO

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

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community