Some options take no arguments, others take one argument (typically a partition number), and others take
compound arguments with colon delimitation. For instance, -n (--new) takes a partition number, a starting
sector number, and an ending sector number, as in sgdisk-n2:2000:50000/dev/sdc, which creates a new
partition, numbered 2, starting at sector 2000 an ending at sector 50,000, on /dev/sdc.
Unrelated options may be combined; however, some such combinations will be nonsense (such as deleting a
partition and then changing its GUID type code). sgdisk interprets options in the order in which they're
entered, so effects can vary depending on order. For instance, sgdisk-s-d2 sorts the partition table
entries and then deletes partition 2 from the newly-sorted list; but sgdisk-d2-s deletes the original
partition 2 and then sorts the modified partition table.
Error checking and opportunities to correct mistakes in sgdisk are minimal. Although the program
endeavors to keep the GPT data structures legal, it does not prompt for verification before performing
its actions. Unless you require a command-line-driven program, you should use the interactive gdisk
instead of sgdisk, since gdisk allows you to quit without saving your changes, should you make a mistake.
Although sgdisk is based on the same partition-manipulation code as gdisk, sgdisk implements fewer
features than its interactive sibling. Options available in sgdisk are:
-a,--set-alignment=value
Set the sector alignment multiple. GPT fdisk aligns the start of partitions to sectors that are
multiples of this value, which defaults to 1 MiB (2048 on disks with 512-byte sectors) on freshly
formatted disks. This alignment value is necessary to obtain optimum performance with Western
Digital Advanced Format and similar drives with larger physical than logical sector sizes, with
some types of RAID arrays, and with SSD devices. When the -I option is used, this same alignment
value is used to determine partition end points; but partitions end at one less than a multiple of
this value, to keep the partition length a multiple of this value.
-A,--attributes=list|[partnum:show|or|nand|xor|=|set|clear|toggle|get[:bitnum|hexbitmask]]
View or set partition attributes. Use list to see defined (known) attribute values. Omit the
partition number (and even the device filename) when using this option. The others require a
partition number. The show and get options show the current attribute settings (all attributes or
for a particular bit, respectively). The or, nand, xor, =, set, clear, and toggle options enable
you to change the attribute bit value. The set, clear, toggle, and get options work on a bit
number; the others work on a hexadecimal bit mask. For example, type sgdisk-A4:set:2/dev/sdc to
set the bit 2 attribute (legacy BIOS bootable) on partition 4 on /dev/sdc.
-b,--backup=file
Save partition data to a backup file. You can back up your current in-memory partition table to a
disk file using this option. The resulting file is a binary file consisting of the protective MBR,
the main GPT header, the backup GPT header, and one copy of the partition table, in that order.
Note that the backup is of the current in-memory data structures, so if you launch the program,
make changes, and then use this option, the backup will reflect your changes. If the GPT data
structures are damaged, the backup may not accurately reflect the damaged state; instead, they
will reflect GPT fdisk's first-pass interpretation of the GPT.
-B,--byte-swap-name=partnum
Swap the byte order for the name of the specified partition. Some partitioning tools, including
GPT fdisk 1.0.7 and earlier, can write the partition name in the wrong byte order on big-endian
computers, such as the IBM s390 mainframes and PowerPC-based Macs. This feature corrects this
problem.
-c,--change-name=partnum:name
Change the GPT name of a partition. This name is encoded as a UTF-16 string, but proper entry and
display of anything beyond basic ASCII values requires suitable locale and font support. For the
most part, Linux ignores the partition name, but it may be important in some OSes. If you want to
set a name that includes a space, enclose it in quotation marks, as in sgdisk-c1:"SampleName"/dev/sdb. Note that the GPT name of a partition is distinct from the filesystem name, which is
encoded in the filesystem's data structures.
-C,--recompute-chs
Recompute CHS values in protective or hybrid MBR. This option can sometimes help if a disk
utility, OS, or BIOS doesn't like the CHS values used by the partitions in the protective or
hybrid MBR. In particular, the GPT specification requires a CHS value of 0xFFFFFF for over-8GiB
partitions, but this value is technically illegal by the usual standards. Some BIOSes hang if they
encounter this value. This option will recompute a more normal CHS value -- 0xFEFFFF for over-8GiB
partitions, enabling these BIOSes to boot.
-d,--delete=partnum
Delete a partition. This action deletes the entry from the partition table but does not disturb
the data within the sectors originally allocated to the partition on the disk. If a corresponding
hybrid MBR partition exists, gdisk deletes it, as well, and expands any adjacent 0xEE (EFI GPT)
MBR protective partition to fill the new free space.
-D,--display-alignment
Display current sector alignment value. Partitions will be created on multiples of the sector
value reported by this option. You can change the alignment value with the -a option.
-e,--move-second-header
Move backup GPT data structures to the end of the disk. Use this option if you've added disks to a
RAID array, thus creating a virtual disk with space that follows the backup GPT data structures.
This command moves the backup GPT data structures to the end of the disk, where they belong.
-E,--end-of-largest
Displays the sector number of the end of the largest available block of sectors on the disk. A
script may store this value and pass it back as part of -n's option to create a partition. If no
unallocated sectors are available, this function returns the value 0.
-f,--first-in-largest
Displays the sector number of the start of the largest available block of sectors on the disk. A
script may store this value and pass it back as part of -n's option to create a partition. If no
unallocated sectors are available, this function returns the value 0. Note that this parameter is
blind to partition alignment; when you actually create a partition, its start point might be
changed from this value.
-F,--first-aligned-in-largest
Similar to -f (--first-in-largest), except returns the sector number with the current alignment
correction applied. Use this function if you need to compute the actual partition start point
rather than a theoretical start point or the actual start point if you set the alignment value to
1.
-g,--mbrtogpt
Convert an MBR or BSD disklabel disk to a GPT disk. As a safety measure, use of this option is
required on MBR or BSD disklabel disks if you intend to save your changes, in order to prevent
accidentally damaging such disks.
-G,--randomize-guids
Randomize the disk's GUID and all partitions' unique GUIDs (but not their partition type code
GUIDs). This function may be used after cloning a disk in order to render all GUIDs once again
unique.
-h,--hybrid
Create a hybrid MBR. This option takes from one to three partition numbers, separated by colons,
as arguments. You may optionally specify a final partition "EE" to indicate that the EFI GPT (type
0xEE) should be placed last in the table, otherwise it will be placed first, followed by the
partition(s) you specify. Their type codes are based on the GPT fdisk type codes divided by
0x0100, which is usually correct for Windows partitions. If the active/bootable flag should be
set, you must do so in another program, such as fdisk. The gdisk program offers additional hybrid
MBR creation options.
-i,--info=partnum
Show detailed partition information. The summary information produced by the -p command
necessarily omits many details, such as the partition's unique GUID and the translation of
sgdisk's internal partition type code to a plain type name. The -i option displays this
information for a single partition.
-I,--align-end
When possible, align the end points of partitions to one less than a multiple of the alignment
value. When both start and end points are aligned, partitions should be multiples of the alignment
value in size, which is necessary for some partition encryption tools to function correctly. This
option applies to all partitions created after this option on the command line. Note that this
alignment is not always possible; for instance, if the free space at the end of a disk is less
than the alignment value, with the current final partition being aligned, and if sgdisk is asked
to create a partition in that space, then it will not be end-aligned.
-j,--move-main-table=sector
Sets the start sector of the main partition table. This value is normally 2, but it may need to be
increased in some cases, such as when a system-on-chip (SoC) is hard-coded to read boot code from
sector 2. I recommend against adjusting this value unless doing so is absolutely necessary.
-k,--move-backup-table=sector
Sets the start sector of the second/backup partition table. The backup table is usually placed
just before the last sector, which holds the backup header. The default value is thus the size of
the disk, minus one, minus the total size of the partition table (in sectors, usually 32). There
are probably very few reasons to ever change this, and while the EFI standard does not mandate it,
most tooling assumes the backup table to be at the very end of the disk.
-l,--load-backup=file
Load partition data from a backup file. This option is the reverse of the -b option. Note that
restoring partition data from anything but the original disk is not recommended. This option will
work even if the disk's original partition table is bad; however, most other options on the same
command line will be ignored.
-L,--list-types
Display a summary of partition types. GPT uses a GUID to identify partition types for particular
OSes and purposes. For ease of data entry, sgdisk compresses these into two-byte (four-digit
hexadecimal) values that are related to their equivalent MBR codes. Specifically, the MBR code is
multiplied by hexadecimal 0x0100. For instance, the code for Linux swap space in MBR is 0x82, and
it's 0x8200 in gdisk. A one-to-one correspondence is impossible, though. Most notably, the codes
for all varieties of FAT and NTFS partition correspond to a single GPT code (entered as 0x0700 in
sgdisk). Some OSes use a single MBR code but employ many more codes in GPT. For these, sgdisk adds
code numbers sequentially, such as 0xa500 for a FreeBSD disklabel, 0xa501 for FreeBSD boot, 0xa502
for FreeBSD swap, and so on. Note that these two-byte codes are unique to gdisk and sgdisk. This
option does not require you to specify a valid disk device filename.
-m,--gpttombr
Convert disk from GPT to MBR form. This option takes from one to four partition numbers, separated
by colons, as arguments. Their type codes are based on the GPT fdisk type codes divided by 0x0100.
If the active/bootable flag should be set, you must do so in another program, such as fdisk. The
gdisk program offers additional MBR conversion options. It is not possible to convert more than
four partitions from GPT to MBR form or to convert partitions that start above the 2TiB mark or
that are larger than 2TiB.
-n,--new=partnum:start:end
Create a new partition. You enter a partition number, starting sector, and an ending sector. Both
start and end sectors can be specified in absolute terms as sector numbers or as positions
measured in kibibytes (K), mebibytes (M), gibibytes (G), tebibytes (T), or pebibytes (P); for
instance, 40M specifies a position 40MiB from the start of the disk. You can specify locations
relative to the start or end of the specified default range by preceding the number by a '+' or
'-' symbol, as in +2G to specify a point 2GiB after the default start sector, or -200M to specify
a point 200MiB before the last available sector. A start or end value of 0 specifies the default
value, which is the start of the largest available block for the start sector and the end of the
same block for the end sector. A partnum value of 0 causes the program to use the first available
partition number. Subsequent uses of the -A (--attributes), -c (--change-name), -t (--typecode),
and -u (--partition-guid) options may also use 0 to refer to the same partition.
-N,--largest-new=num
Create a new partition that fills the largest available block of space on the disk. You can use
the -a (--set-alignment) option to adjust the alignment, if desired. A num value of 0 causes the
program to use the first available partition number. Subsequent uses of the -A (--attributes), -c
(--change-name), -t (--typecode), and -u (--partition-guid) options may also use 0 to refer to the
same partition.
-o,--clear
Clear out all partition data. This includes GPT header data, all partition definitions, and the
protective MBR. Note that this operation will, like most other operations, fail on a damaged disk.
If you want to prepare a disk you know to be damaged for GPT use, you should first wipe it with -Z
and then partition it normally. This option will work even if the disk's original partition table
is bad; however, most other options on the same command line will be ignored.
-O,--print-mbr
Display basic MBR partition summary data. This includes partition numbers, starting and ending
sector numbers, partition sizes, MBR partition types codes, and partition names. This option is
useful mainly for diagnosing partition table problems, particularly on disks with hybrid MBRs.
-p,--print
Display basic GPT partition summary data. This includes partition numbers, starting and ending
sector numbers, partition sizes, sgdisk's partition types codes, and partition names. For
additional information, use the -i (--info) option.
-P,--pretend
Pretend to make specified changes. In-memory GPT data structures are altered according to other
parameters, but changes are not written to disk.
-r,--transpose
Swap two partitions' entries in the partition table. One or both partitions may be empty, although
swapping two empty partitions is pointless. For instance, if partitions 1-4 are defined,
transposing 1 and 5 results in a table with partitions numbered from 2-5. Transposing partitions
in this way has no effect on their disk space allocation; it only alters their order in the
partition table.
-R,--replicate=second_device_filename
Replicate the main device's partition table on the specified second device. Note that the
replicated partition table is an exact copy, including all GUIDs; if the device should have its
own unique GUIDs, you should use the -G option on the new disk.
-s,--sort
Sort partition entries. GPT partition numbers need not match the order of partitions on the disk.
If you want them to match, you can use this option. Note that some partitioning utilities sort
partitions whenever they make changes. Such changes will be reflected in your device filenames, so
you may need to edit /etc/fstab if you use this option.
-t,--typecode=partnum:{hexcode|GUID}
Change a single partition's type code. You enter the type code using either a two-byte hexadecimal
number, as described earlier, or a fully-specified GUID value, such as
EBD0A0A2-B9E5-4433-87C0-68B6B72699C7.
-T,--transform-bsd=partnum
Transform BSD partitions into GPT partitions. This option works on BSD disklabels held within GPT
(or converted MBR) partitions. Converted partitions' type codes are likely to need manual
adjustment. sgdisk will attempt to convert BSD disklabels stored on the main disk when launched,
but this conversion is likely to produce first and/or last partitions that are unusable. The many
BSD variants means that the probability of sgdisk being unable to convert a BSD disklabel is high
compared to the likelihood of problems with an MBR conversion.
-u,--partition-guid=partnum:guid
Set the partition unique GUID for an individual partition. The GUID may be a complete GUID or 'R'
to set a random GUID.
-U,--disk-guid=guid
Set the GUID for the disk. The GUID may be a complete GUID or 'R' to set a random GUID.
--usage
Print a brief summary of available options.
-v,--verify
Verify disk. This option checks for a variety of problems, such as incorrect CRCs and mismatched
main and backup data. This option does not automatically correct most problems, though; for that,
you must use options on the recovery & transformation menu. If no problems are found, this command
displays a summary of unallocated disk space. This option will work even if the disk's original
partition table is bad; however, most other options on the same command line will be ignored.
-V,--version
Display program version information. This option may be used without specifying a device filename.
-z,--zap
Zap (destroy) the GPT data structures and then exit. Use this option if you want to repartition a
GPT disk using fdisk or some other GPT-unaware program. This option destroys only the GPT data
structures; it leaves the MBR intact. This makes it useful for wiping out GPT data structures
after a disk has been repartitioned for MBR using a GPT-unaware utility; however, there's a risk
that it will damage boot loaders or even the start of the first or end of the last MBR partition.
If you use it on a valid GPT disk, the MBR will be left with an inappropriate EFI GPT (0xEE)
partition definition, which you can delete using another utility.
-Z,--zap-all
Zap (destroy) the GPT and MBR data structures and then exit. This option works much like -z, but
as it wipes the MBR as well as the GPT, it's more suitable if you want to repartition a disk after
using this option, and completely unsuitable if you've already repartitioned the disk.
-?,--help
Print a summary of options.