blob: 29debf28b7d9bd5e68b686259cb31652e7f745df [file] [log] [blame]
srs569473ba4792010-01-12 18:18:17 -05001.\" Copyright 2009 Roderick W. Smith (rodsmith@rodsbooks.com)
2.\" May be distributed under the GNU General Public License
3.TH "SGDISK" "8" "0.6.0" "Roderick W. Smith" "GPT fdisk Manual"
4.SH "NAME"
5sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix
6.SH "SYNOPSIS"
7.BI "sgdisk "
8[ options ]
9.I device
10
11.SH "DESCRIPTION"
12GPT fdisk is a text\-mode menu\-driven package for creation and manipulation of
13partition tables. It consists of two programs: the text\-mode interactive
14\fBgdisk\fR and the command\-line \fBsgdisk\fR. Either program will
15automatically convert an old\-style Master Boot Record (MBR) partition table
16or BSD disklabel stored without an MBR carrier partition to the newer Globally
17Unique Identifier (GUID) Partition Table (GPT) format, or will load a GUID
18partition table. This man page documents the command\-line \fBsgdisk\fR
19program.
20
21Some advanced data manipulation and
22recovery options require you to understand the distinctions between the
23main and backup data, as well as between the GPT headers and the partition
24tables. For information on MBR vs. GPT, as well as GPT terminology and
25structure, see the extended \fBgdisk\fR documentation at
26\fIhttp://www.rodsbooks.com/gdisk/\fR or consult Wikipedia.
27
28The \fBsgdisk\fR program employs a user interface that's based entirely on
29the command line, making it suitable for use in scripts or by experts who
30want to make one or two quick changes to a disk. (The program may query the
31user when certain errors are encountered, though.) The program's name is
32based on \fBsfdisk\fR, but the user options of the two programs are
33entirely different from one another.
34
35Ordinarily, \fBsgdisk\fR operates on disk device files, such as
36\fI/dev/sda\fR or \fI/dev/hda\fR under Linux, \fI/dev/disk0\fR under
37Mac OS X, or \fI/dev/ad0\fR or \fI/dev/da0\fR under FreeBSD. The program
38can also operate on disk image files, which can be either copies of whole
39disks (made with \fBdd\fR, for instance) or raw disk images used by
40emulators such as QEMU or VMWare. Note that only \fIraw\fR disk images
41are supported; \fBsgdisk\fR cannot work on compressed or other advanced
42disk image formats.
43
44The MBR partitioning system uses a combination of cylinder/head/sector
45(CHS) addressing and logical block addressing (LBA). The former is klunky
46and limiting. GPT drops CHS addressing and uses 64\-bit LBA mode
47exclusively. Thus, GPT data structures, and therefore
48\fBsgdisk\fR, do not need to deal with CHS geometries and all the problems
49they create.
50
51For best results, you should use an OS\-specific partition table
52program whenever possible. For example, you should make Mac OS X
53partitions with the Mac OS X Disk Utility program and Linux partitions
54with the Linux \fBgdisk\fR, \fBsgdisk\fR, or GNU Parted programs.
55
56Upon start, \fBsgdisk\fR attempts to identify the partition type in use on
57the disk. If it finds valid GPT data, \fBsgdisk\fR will use it. If
58\fBsgdisk\fR finds a valid MBR or BSD disklabel but no GPT data, it will
59attempt to convert the MBR or disklabel into GPT form. (BSD disklabels are
60likely to have unusable first and/or final partitions because they overlap
61with the GPT data structures, though.) GPT fdisk can identify, but not use
62data in, Apple Partition Map (APM) disks, which are used on 680x0\- and
63PowerPC\-based Macintoshes. If you specify any option that results in changes
64to an MBR or BSD disklabel, \fBsgdisk\fR ignores those changes unless the
65\fI\-g\fR (\fI\-\-mbrtogpt\fR) or \fI\-z\fR (\fI\-\-zap\fR) option is used.
66If you use the \fI\-g\fR option, \fBsgdisk\fR replaces the MBR or disklabel
67with a GPT. \fIThis action is potentially dangerous!\fR Your system may become
68unbootable, and partition type codes may become corrupted if the disk uses
69unrecognized type codes. Boot problems are particularly likely if you're
70multi\-booting with any GPT\-unaware OS.
71
72The MBR\-to\-GPT conversion will leave at least one gap in the partition
73numbering if the original MBR used logical partitions. These gaps are
74harmless, but you can eliminate them by using the \fI\-s\fR (\fI\-\-sort\fR)
75option, if you like. (Doing this may require you to update your
76\fI/etc/fstab\fR file.)
77
78When creating a fresh partition table, certain considerations may be in
79order:
80
81.TP
82.B *
83For data (non\-boot) disks, and for boot disks used on BIOS\-based computers
84with GRUB as the boot loader, partitions may be created in whatever order
85and in whatever sizes are desired.
86
87.TP
88.B *
89Boot disks for EFI\-based systems require an \fIEFI System
90Partition\fR (\fBsgdisk\fR internal code 0xEF00) formatted as FAT\-32.
91The recommended size of this partition is between 100 and 200 MiB.
92Boot\-related files are stored here. (Note that GNU Parted identifies
93such partitions as having the "boot flag" set.)
94
95.TP
96.B *
97Some boot loaders for BIOS\-based systems make use of a \fIBIOS Boot
98Partition\fR (\fBsgdisk\fR internal code 0xEF02), in which the secondary
99boot loader is stored, possibly without the benefit of a filesystem. This
100partition can typically be quite small (roughly 32 to 200 KiB), but you
101should consult your boot loader documentation for details.
102
103.TP
104.B *
105If Windows is to boot from a GPT disk, a partition of type \fIMicrosoft
106Reserved\fR (\fBsgdisk\fR
107internal code 0x0C01) is recommended. This partition should be about 128 MiB
108in size. It ordinarily follows the EFI System Partition and immediately
109precedes the Windows data partitions. (Note that GNU Parted creates all
110FAT partitions as this type, which actually makes the partition unusable
111for normal file storage in both Windows and Mac OS X.)
112
113.TP
114.B *
115Some OSes' GPT utilities create some blank space (typically 128 MiB) after
116each partition. The intent is to enable future disk utilities to use this
117space. Such free space is not required of GPT disks, but creating it may
118help in future disk maintenance.
119
120.SH "OPTIONS"
121Some options take no arguments, others take one argument (typically a partition
122number), and others take compound arguments with colon delimitation. For
123instance, \fI\-n\fR (\fI\-\-new\fR) takes a partition number, a starting
124sector number, and an ending sector number, as in \fBsgdisk \-n 2:2000:50000
125/dev/sdc\fR, which creates a new partition, numbered 2, starting at sector
1262000 an ending at sector 50,000, on \fI/dev/sdc\fR.
127
128Unrelated options may be combined; however, some such combinations will be
129nonsense (such as deleting a partition and then changing its GUID type code).
130\fBsgdisk\fR interprets options in the order in which they're entered, so
131effects can vary depending on order. For instance, \fBsgdisk \-s \-d 2\fR
132sorts the partition table entries and then deletes partition 2 from the
133newly\-sorted list; but \fBsgdisk \-d 2 \-s\fR deletes the original partition
1342 and then sorts the modified partition table.
135
136Error checking and opportunities to correct mistakes in \fBsgdisk\fR are
137minimal. Although the program endeavors to keep the GPT data structures legal,
138it does not prompt for verification before performing its actions. Unless you
139require a command\-line\-driven program, you should use the interactive
140\fBgdisk\fR instead of \fBsgdisk\fR, since \fBgdisk\fR allows you to
141quit without saving your changes, should you make a mistake.
142
143Although \fBsgdisk\fR is based on the same partition\-manipulation code as
144\fBgdisk\fR, \fBsgdisk\fR implements fewer features than its interactive
145sibling. Options available in \fBsgdisk\fR are:
146
147.TP
148.B \-a, \-\-set\-alignment=value
149Set the sector alignment multiple. GPT fdisk aligns the start of partitions
150to sectors that are multiples of this value, which defaults to 8 on disks
151larger than 800GiB with 512\-byte sectors and to 1 on smaller disks or those
152with non\-512\-byte sectors. This alignment value is necessary to obtain
153optimum performance with Western Digital Advanced Format and similar drives
154with larger physical than logical sector sizes.
155
156.TP
157.B \-b, \-\-backup=file
158Save partition data to a backup file. You can back up your current
159in\-memory partition table to a disk file using this option. The resulting
160file is a binary file consisting of the protective MBR, the main GPT
161header, the backup GPT header, and one copy of the partition table, in that
162order. Note that the backup is of the current in\-memory data structures, so
163if you launch the program, make changes, and then use this option, the
164backup will reflect your changes. If the GPT data structures are damaged,
165the backup may not accurately reflect the damaged state; instead, they
166will reflect GPT fdisk's first\-pass interpretation of the GPT.
167
168.TP
169.B \-c, \-\-change=partnum:name
170Change the GPT name of a partition. This name is encoded as a UTF\-16
171string, but \fBsgdisk\fR
172supports only ASCII characters as names. For the most part, Linux ignores
173the partition name, but it may be important in some OSes. GPT fdisk sets
174a default name based on the partition type code. If you want to set a name
175that includes a space, enclose it in quotation marks, as in
176\fIsgdisk \-c 1:"Sample Name" /dev/sdb\fR.
177
178.TP
179.B \-d, \-\-delete=partnum
180Delete a partition. This action deletes the entry from the partition table
181but does not disturb the data within the sectors originally allocated to
182the partition on the disk. If a corresponding hybrid MBR partition exists,
183\fBgdisk\fR deletes it, as well, and expands any adjacent 0xEE (EFI GPT)
184MBR protective partition to fill the new free space.
185
186.TP
187.B e, \-\-move\-second\-header
188Move backup GPT data structures to the end of the disk. Use this option if
189you've added disks to a RAID array, thus creating a virtual disk with space
190that follows the backup GPT data structures. This command moves the backup
191GPT data structures to the end of the disk, where they belong.
192
193.TP
194.B E, \-\-end\-of\-largest
195Displays the sector number of the end of the largest available block of
196sectors on the disk. A script may store this value and pass it back as
197part of \fI\-n\fR's option to create a partition. If no unallocated
198sectors are available, this function returns the value 0.
199
200.TP
201.B \-f, \-\-first\-in\-largest
202Displays the sector number of the start of the largest available block of
203sectors on the disk. A script may store this value and pass it back as
204part of \fI\-n\fR's option to create a partition. If no unallocated
205sectors are available, this function returns the value 0.
206
207.TP
208.B \-g, \-\-mbrtogpt
srs56943c0af382010-01-15 19:19:18 -0500209Convert an MBR or BSD disklabel disk to a GPT disk. As a safety measure, use of
210this option is required on MBR or BSD disklabel disks if you intend to save your
211changes, in order to prevent accidentally damaging such disks.
srs569473ba4792010-01-12 18:18:17 -0500212
213.TP
214.B \-i, \-\-info=partnum
215Show detailed partition information. The summary information produced by
216the \fI\-p\fR command necessarily omits many details, such as the partition's
217unique GUID and the translation of \fBsgdisk\fR's
218internal partition type code to a plain type name. The \fI\-i\fR option
219displays this information for a single partition.
220
221.TP
222.B \-l, \-\-load\-backup=file
223Load partition data from a backup file. This option is the reverse of the
224\fI\-b\fR option. Note that restoring partition data from anything
225but the original disk is not recommended.
226
227.TP
228.B \-L, \-\-list\-types
229Display a summary of partition types. GPT uses a GUID to identify
230partition types for particular OSes and purposes. For ease of data entry,
231\fBsgdisk\fR compresses these into two\-byte (four\-digit hexadecimal)
232values that are related to their equivalent MBR codes. Specifically, the
233MBR code is multiplied by hexadecimal 0x0100. For instance, the code for
234Linux swap space in MBR is 0x82, and it's 0x8200 in \fBgdisk\fR.
235A one\-to\-one correspondence is impossible, though. Most notably, many DOS,
236Windows, and Linux data partition codes correspond to a single GPT code
237(entered as 0x0700 in \fBsgdisk\fR). Some OSes use a single MBR code but
238employ many more codes in GPT. For these, \fBsgdisk\fR
239adds code numbers sequentially, such as 0xa500 for a FreeBSD disklabel,
2400xa501 for FreeBSD boot, 0xa502 for FreeBSD swap, and so on. Note that
241these two\-byte codes are unique to \fBgdisk\fR and \fBsgdisk\fR. This
242option does not require you to specify a valid disk device filename.
243
244.TP
245.B \-n, \-\-new=partnum:start:end
246Create a new partition. You enter a partition
247number, starting sector, and an ending sector. Both start and end sectors
248can be specified in absolute terms as sector numbers or as positions
249measured in kilobytes (K), megabytes (M), gigabytes (G), or terabytes (T);
250for instance, \fI\fB40M\fR\fR specifies a position 40MiB from the start of
251the disk. You can specify locations relative to the start or end of the
252specified default range by preceding the number by a '+' or '\-' symbol, as
253in \fI\fB+2G\fR\fR to specify a point 2GiB after the default start sector,
254or \fI\fB\-200M\fR\fR to specify a point 200MiB before the last available
255sector. Pressing the Enter key with no input specifies the default value,
256which is the start of the largest available block for the start sector and
257the end of the same block for the end sector.
258
259.TP
260.B \-o, \-\-clear
261Clear out all partition data. This includes GPT header data,
262all partition definitions, and the protective MBR.
263
264.TP
265.B \-p, \-\-print
266Display basic partition summary data. This includes partition
267numbers, starting and ending sector numbers, partition sizes,
268\fBsgdisk\fR's partition types codes, and partition names. For
269additional information, use the \fI\-i\fR (\fI\-\-info\fR) option.
270
271.TP
272.B \-P, \-\-pretend
273Pretend to make specified changes. In\-memory GPT data structures are
274altered according to other parameters, but changes are not written
275to disk.
276
277.TP
278.B \-s, \-\-sort
279Sort partition entries. GPT partition numbers need not match the order of
280partitions on the disk. If you want them to match, you can use this option.
281Note that some partitioning utilities sort partitions whenever they make
282changes. Such changes will be reflected in your device filenames, so you
283may need to edit \fI/etc/fstab\fR if you use this option.
284
285.TP
286.B \-t, \-\-typecode=partnum:hexcode
287Change a single partition's type code. You enter the type code using a
288two\-byte hexadecimal number, as described earlier.
289
290.TP
291.B \-T, \-\-transform\-bsd=partnum
292Transform BSD partitions into GPT partitions. This option works on BSD
293disklabels held within GPT (or converted MBR) partitions. Converted
294partitions' type codes are likely to need manual adjustment. \fBsgdisk\fR
295will attempt to convert BSD disklabels stored on the main disk when
296launched, but this conversion is likely to produce first and/or last
297partitions that are unusable. The many BSD variants means that the
298probability of \fBsgdisk\fR being unable to convert a BSD disklabel is
299high compared to the likelihood of problems with an MBR conversion.
300
301.TP
302.B \-\-usage
303Print a brief summary of available options.
304
305.TP
306.B \-v, \-\-verify
307Verify disk. This option checks for a variety of problems, such as
308incorrect CRCs and mismatched main and backup data. This option does not
309automatically correct most problems, though; for that, you must use
310options on the recovery & transformation menu. If no problems are found,
311this command displays a summary of unallocated disk space.
312
313.TP
314.B \-V, \-\-version
315Display program version information. This option may be used without
316specifying a device filename.
317
318.TP
319.B \-z, \-\-zap
320Zap (destroy) the GPT data structures and exit. Use this option if you want to
321repartition a GPT disk using \fBfdisk\fR or some other GPT\-unaware program.
322You'll be given the choice of preserving the existing MBR, in case it's a
323hybrid MBR with salvageable partitions or if you've already created new MBR
324partitions and want to erase the remnants of your GPT partitions. \fIIf you've
325already created new MBR partitions, it's conceivable that this option will
326damage the first and/or last MBR partitions!\fR Such an event is unlikely, but
327could occur if your new MBR partitions overlap the old GPT data structures.
328
329.TP
330.B \-?, \-\-help
331Print a summary of options.
332
333.SH "RETURN VALUES"
334\fBsgdisk\fR returns various values depending on its success or failure:
335
336.TP
337.B 0
338Normal program execution
339
340.TP
341.B 1
342Too few arguments
343
344.TP
srs56943c0af382010-01-15 19:19:18 -0500345.B 2
srs569473ba4792010-01-12 18:18:17 -0500346An error occurred while reading the partition table
347
348.TP
349.B 3
350Non\-GPT disk detected and no \fI\-g\fR option
351
352.TP
353.B 4
354An error prevented saving changes
355.SH "BUGS"
356As of January 2010 (version 0.6.0), \fBsgdisk\fR
357should be considered beta software. Known bugs and limitations include:
358
359.TP
360.B *
361The program compiles correctly only on Linux, FreeBSD, and Mac OS X. Linux
362versions for x86\-64 (64\-bit), x86 (32\-bit), and PowerPC (32\-bit) have been
363tested, with the x86\-64 version having seen the most testing.
364
365.TP
366.B *
367The FreeBSD version of the program can't write changes to the partition
368table to a disk when existing partitions on that disk are mounted. (The
369same problem exists with many other FreeBSD utilities, such as
370\fBgpt\fR, \fBfdisk\fR, and \fBdd\fR.)
371
372.TP
373.B *
374The fields used to display the start and end sector numbers for partitions
375in the \fI\-p\fR option are 14 characters wide. This translates to a limitation
376of about 45 PiB. On larger disks, the displayed columns will go out of
377alignment.
378
379.TP
380.B *
381Only ASCII characters are supported in the partition name field. If an
382existing partition uses non\-ASCII UTF\-16 characters, they're likely to be
383corrupted in the 'i' and 'p' menu options' displays; however, they should be
384preserved when loading and saving partitions.
385
386.TP
387.B *
388The program can load only up to 128 partitions (4 primary partitions and
389124 logical partitions) when converting from MBR format. This limit can
390be raised by changing the \fI#define MAX_MBR_PARTS\fR line in the
391\fImbr.h\fR source code file and recompiling; however, such a change
392will require using a larger\-than\-normal partition table. (The limit
393of 128 partitions was chosen because that number equals the 128 partitions
394supported by the most common partition table size.)
395
396.TP
397.B *
398Converting from MBR format sometimes fails because of insufficient space at
399the start or (more commonly) the end of the disk. Resizing the partition
400table (using the 's' option in the experts' menu) can sometimes overcome
401this problem; however, in extreme cases it may be necessary to resize a
402partition using GNU Parted or a similar tool prior to conversion with
403\fBgdisk\fR.
404
405.TP
406.B *
407MBR conversions work only if the disk has correct LBA partition
408descriptors. These descriptors should be present on any disk over 8 GiB in
409size or on smaller disks partitioned with any but very ancient software.
410
411.TP
412.B *
413BSD disklabel support can create first and/or last partitions that overlap
414with the GPT data structures. This can sometimes be compensated by
415adjusting the partition table size, but in extreme cases the affected
416partition(s) may need to be deleted.
417
418.TP
419.B *
420Because of the highly variable nature of BSD disklabel structures,
421conversions from this form may be unreliable \-\- partitions may be dropped,
422converted in a way that creates overlaps with other partitions, or
423converted with incorrect start or end values. Use this feature with
424caution!
425
426.TP
427.B *
428Booting after converting an MBR or BSD disklabel disk is likely to be
429disrupted. Sometimes re\-installing a boot loader will fix the problem, but
430other times you may need to switch boot loaders. Except on EFI\-based
431platforms, Windows through at least Windows 7 RC doesn't support booting
432from GPT disks. Creating a hybrid MBR (using the 'h' option on the recovery &
433transformation menu) or abandoning GPT in favor of MBR may be your only
434options in this case.
435
436.PP
437
438The support for big\-endian CPUs (PowerPC, for example) is new, as of version
4390.3.5. I advise using caution on that platform, particularly with the more
440obscure features of the program.
441
442.SH "AUTHORS"
443Primary author: Roderick W. Smith (rodsmith@rodsbooks.com)
444
445Contributors:
446
447* Yves Blusseau (1otnwmz02@sneakemail.com)
448
449* David Hubbard (david.c.hubbard@gmail.com)
450
451.SH "SEE ALSO"
452\fBcfdisk (8)\fR,
453\fBfdisk (8)\fR,
454\fBgdisk (8)\fR,
455\fBmkfs (8)\fR,
456\fBparted (8)\fR,
457\fBsfdisk (8)\fR
458
459\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
460
461\fIhttp://developer.apple.com/technotes/tn2006/tn2166.html\fR
462
463\fIhttp://www.rodsbooks.com/gdisk/\fR
464
465.SH "AVAILABILITY"
466The \fBsgdisk\fR command is part of the \fIGPT fdisk\fR package and is
467available from Rod Smith.