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 https://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:
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:
Contributors:
* Yves Blusseau (1otnwmz02@sneakemail.com)
* David Hubbard (david.c.hubbard@gmail.com)
* Justin Maggard (justin.maggard@netgear.com)
* Dwight Schauer (das@teegra.net)
* Florian Zumbiehl (florz@florz.de)
https://en.wikipedia.org/wiki/GUID_Partition_Table
https://developer.apple.com/technotes/tn2006/tn2166.html
https://www.rodsbooks.com/gdisk/