Section: GPT fdisk Manual (8)
sgdisk [ options ] device
GPT fdisk is a text-mode menu-driven package for creation and manipulation of partition tables. It consists of two programs: the text-mode interactive gdisk and the command-line sgdisk. Either program will automatically convert an old-style Master Boot Record (MBR) partition table or BSD disklabel stored without an MBR carrier partition to the newer Globally Unique Identifier (GUID) Partition Table (GPT) format, or will load a GUID partition table. This man page documents the command-line sgdisk program.
Some advanced data manipulation and recovery options require you to understand the distinctions between the main and backup data, as well as between the GPT headers and the partition tables. For information on MBR vs. GPT, as well as GPT terminology and structure, see the extended gdisk documentation at http://www.rodsbooks.com/gdisk/ or consult Wikipedia.
The sgdisk program employs a user interface that's based entirely on the command line, making it suitable for use in scripts or by experts who want to make one or two quick changes to a disk. (The program may query the user when certain errors are encountered, though.) The program's name is based on sfdisk, but the user options of the two programs are entirely different from one another.
Ordinarily, sgdisk operates on disk device files, such as /dev/sda or /dev/hda under Linux, /dev/disk0 under Mac OS X, or /dev/ad0 or /dev/da0 under FreeBSD. The program can also operate on disk image files, which can be either copies of whole disks (made with dd, for instance) or raw disk images used by emulators such as QEMU or VMWare. Note that only raw disk images are supported; sgdisk cannot work on compressed or other advanced disk image formats.
The MBR partitioning system uses a combination of cylinder/head/sector (CHS) addressing and logical block addressing (LBA). The former is klunky and limiting. GPT drops CHS addressing and uses 64-bit LBA mode exclusively. Thus, GPT data structures, and therefore sgdisk, do not need to deal with CHS geometries and all the problems they create.
For best results, you should use an OS-specific partition table program whenever possible. For example, you should make Mac OS X partitions with the Mac OS X Disk Utility program and Linux partitions with the Linux gdisk, sgdisk, or GNU Parted programs.
Upon start, sgdisk attempts to identify the partition type in use on the disk. If it finds valid GPT data, sgdisk will use it. If sgdisk finds a valid MBR or BSD disklabel but no GPT data, it will attempt to convert the MBR or disklabel into GPT form. (BSD disklabels are likely to have unusable first and/or final partitions because they overlap with the GPT data structures, though.) GPT fdisk can identify, but not use data in, Apple Partition Map (APM) disks, which are used on 680x0- and PowerPC-based Macintoshes. If you specify any option that results in changes to an MBR or BSD disklabel, sgdisk ignores those changes unless the -g (--mbrtogpt), -z (--zap), or -Z (--zap-all) option is used. If you use the -g option, sgdisk replaces the MBR or disklabel with a GPT. This action is potentially dangerous! Your system may become unbootable, and partition type codes may become corrupted if the disk uses unrecognized type codes. Boot problems are particularly likely if you're multi-booting with any GPT-unaware OS.
The MBR-to-GPT conversion will leave at least one gap in the partition numbering if the original MBR used logical partitions. These gaps are harmless, but you can eliminate them by using the -s (--sort) option, if you like. (Doing this may require you to update your /etc/fstab file.)
When creating a fresh partition table, certain considerations may be in order:
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 -n 2: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 -d 2 sorts the partition table entries and then deletes partition 2 from the newly-sorted list; but sgdisk -d 2 -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:
sgdisk returns various values depending on its success or failure:
As of March 2014 (version 0.8.10), sgdisk should be considered beta software. Known bugs and limitations include:
Primary author: Roderick W. Smith (firstname.lastname@example.org)
cfdisk (8), cgdisk (8), fdisk (8), gdisk (8), mkfs (8), parted (8), sfdisk (8) fixparts (8)
The sgdisk command is part of the GPT fdisk package and is available from Rod Smith.
Tutoriais de Tecnologia Web