1SGDISK(8) GPT fdisk Manual SGDISK(8)
2
3
4
6 sgdisk - Command-line GUID partition table (GPT) manipulator for Linux
7 and Unix
8
10 sgdisk [ options ] device
11
12
14 GPT fdisk is a text-mode menu-driven package for creation and manipula‐
15 tion of partition tables. It consists of two programs: the text-mode
16 interactive gdisk and the command-line sgdisk. Either program will
17 automatically convert an old-style Master Boot Record (MBR) partition
18 table or BSD disklabel stored without an MBR carrier partition to the
19 newer Globally Unique Identifier (GUID) Partition Table (GPT) format,
20 or will load a GUID partition table. This man page documents the com‐
21 mand-line sgdisk program.
22
23 Some advanced data manipulation and recovery options require you to
24 understand the distinctions between the main and backup data, as well
25 as between the GPT headers and the partition tables. For information on
26 MBR vs. GPT, as well as GPT terminology and structure, see the extended
27 gdisk documentation at http://www.rodsbooks.com/gdisk/ or consult
28 Wikipedia.
29
30 The sgdisk program employs a user interface that's based entirely on
31 the command line, making it suitable for use in scripts or by experts
32 who want to make one or two quick changes to a disk. (The program may
33 query the user when certain errors are encountered, though.) The pro‐
34 gram's name is based on sfdisk, but the user options of the two pro‐
35 grams are entirely different from one another.
36
37 Ordinarily, sgdisk operates on disk device files, such as /dev/sda or
38 /dev/hda under Linux, /dev/disk0 under Mac OS X, or /dev/ad0 or
39 /dev/da0 under FreeBSD. The program can also operate on disk image
40 files, which can be either copies of whole disks (made with dd, for
41 instance) or raw disk images used by emulators such as QEMU or VMWare.
42 Note that only raw disk images are supported; sgdisk cannot work on
43 compressed or other advanced disk image formats.
44
45 The MBR partitioning system uses a combination of cylinder/head/sector
46 (CHS) addressing and logical block addressing (LBA). The former is
47 klunky and limiting. GPT drops CHS addressing and uses 64-bit LBA mode
48 exclusively. Thus, GPT data structures, and therefore sgdisk, do not
49 need to deal with CHS geometries and all the problems they create.
50
51 For best results, you should use an OS-specific partition table program
52 whenever possible. For example, you should make Mac OS X partitions
53 with the Mac OS X Disk Utility program and Linux partitions with the
54 Linux gdisk, sgdisk, or GNU Parted programs.
55
56 Upon start, sgdisk attempts to identify the partition type in use on
57 the disk. If it finds valid GPT data, sgdisk will use it. If sgdisk
58 finds a valid MBR or BSD disklabel but no GPT data, it will attempt to
59 convert the MBR or disklabel into GPT form. (BSD disklabels are likely
60 to have unusable first and/or final partitions because they overlap
61 with the GPT data structures, though.) GPT fdisk can identify, but not
62 use data in, Apple Partition Map (APM) disks, which are used on 680x0-
63 and PowerPC-based Macintoshes. If you specify any option that results
64 in changes to an MBR or BSD disklabel, sgdisk ignores those changes
65 unless the -g (--mbrtogpt), -z (--zap), or -Z (--zap-all) option is
66 used. If you use the -g option, sgdisk replaces the MBR or disklabel
67 with a GPT. This action is potentially dangerous! Your system may
68 become unbootable, and partition type codes may become corrupted if the
69 disk uses unrecognized type codes. Boot problems are particularly
70 likely if you're multi-booting with any GPT-unaware OS.
71
72 The MBR-to-GPT conversion will leave at least one gap in the partition
73 numbering if the original MBR used logical partitions. These gaps are
74 harmless, but you can eliminate them by using the -s (--sort) option,
75 if you like. (Doing this may require you to update your /etc/fstab
76 file.)
77
78 When creating a fresh partition table, certain considerations may be in
79 order:
80
81
82 * For data (non-boot) disks, and for boot disks used on BIOS-based
83 computers with GRUB as the boot loader, partitions may be cre‐
84 ated in whatever order and in whatever sizes are desired.
85
86
87 * Boot disks for EFI-based systems require an EFI System Partition
88 (sgdisk internal code 0xEF00) formatted as FAT-32. The recom‐
89 mended size of this partition is between 100 and 300 MiB.
90 Boot-related files are stored here. (Note that GNU Parted iden‐
91 tifies such partitions as having the "boot flag" set.)
92
93
94 * Some boot loaders for BIOS-based systems make use of a BIOS Boot
95 Partition (sgdisk internal code 0xEF02), in which the secondary
96 boot loader is stored, possibly without the benefit of a
97 filesystem. This partition can typically be quite small (roughly
98 32 to 200 KiB), but you should consult your boot loader documen‐
99 tation for details.
100
101
102 * If Windows is to boot from a GPT disk, a partition of type Mi‐
103 crosoft Reserved (sgdisk internal code 0x0C01) is recommended.
104 This partition should be about 128 MiB in size. It ordinarily
105 follows the EFI System Partition and immediately precedes the
106 Windows data partitions. (Note that GNU Parted creates all FAT
107 partitions as this type, which actually makes the partition
108 unusable for normal file storage in both Windows and Mac OS X.)
109
110
111 * Some OSes' GPT utilities create some blank space (typically 128
112 MiB) after each partition. The intent is to enable future disk
113 utilities to use this space. Such free space is not required of
114 GPT disks, but creating it may help in future disk maintenance.
115
116
118 Some options take no arguments, others take one argument (typically a
119 partition number), and others take compound arguments with colon delim‐
120 itation. For instance, -n (--new) takes a partition number, a starting
121 sector number, and an ending sector number, as in sgdisk -n
122 2:2000:50000 /dev/sdc, which creates a new partition, numbered 2,
123 starting at sector 2000 an ending at sector 50,000, on /dev/sdc.
124
125 Unrelated options may be combined; however, some such combinations will
126 be nonsense (such as deleting a partition and then changing its GUID
127 type code). sgdisk interprets options in the order in which they're
128 entered, so effects can vary depending on order. For instance, sgdisk
129 -s -d 2 sorts the partition table entries and then deletes partition 2
130 from the newly-sorted list; but sgdisk -d 2 -s deletes the original
131 partition 2 and then sorts the modified partition table.
132
133 Error checking and opportunities to correct mistakes in sgdisk are min‐
134 imal. Although the program endeavors to keep the GPT data structures
135 legal, it does not prompt for verification before performing its
136 actions. Unless you require a command-line-driven program, you should
137 use the interactive gdisk instead of sgdisk, since gdisk allows you to
138 quit without saving your changes, should you make a mistake.
139
140 Although sgdisk is based on the same partition-manipulation code as
141 gdisk, sgdisk implements fewer features than its interactive sibling.
142 Options available in sgdisk are:
143
144
145 -a, --set-alignment=value
146 Set the sector alignment multiple. GPT fdisk aligns the start of
147 partitions to sectors that are multiples of this value, which
148 defaults to 2048 on freshly formatted disks. This alignment
149 value is necessary to obtain optimum performance with Western
150 Digital Advanced Format and similar drives with larger physical
151 than logical sector sizes, with some types of RAID arrays, and
152 with SSD devices.
153
154
155 -A, --attributes=list|[partnum:show|or|nand|xor|=|set|clear|tog‐
156 gle|get[:bitnum|hexbitmask]]
157 View or set partition attributes. Use list to see defined
158 (known) attribute values. Omit the partition number (and even
159 the device filename) when using this option. The others require
160 a partition number. The show and get options show the current
161 attribute settings (all attributes or for a particular bit,
162 respectively). The or, nand, xor, =, set, clear, and toggle
163 options enable you to change the attribute bit value. The set,
164 clear, toggle, and get options work on a bit number; the others
165 work on a hexadecimal bit mask. For example, type sgdisk -A
166 4:set:2 /dev/sdc to set the bit 2 attribute (legacy BIOS
167 bootable) on partition 4 on /dev/sdc.
168
169
170 -b, --backup=file
171 Save partition data to a backup file. You can back up your cur‐
172 rent in-memory partition table to a disk file using this option.
173 The resulting file is a binary file consisting of the protective
174 MBR, the main GPT header, the backup GPT header, and one copy of
175 the partition table, in that order. Note that the backup is of
176 the current in-memory data structures, so if you launch the pro‐
177 gram, make changes, and then use this option, the backup will
178 reflect your changes. If the GPT data structures are damaged,
179 the backup may not accurately reflect the damaged state;
180 instead, they will reflect GPT fdisk's first-pass interpretation
181 of the GPT.
182
183
184 -c, --change-name=partnum:name
185 Change the GPT name of a partition. This name is encoded as a
186 UTF-16 string, but proper entry and display of anything beyond
187 basic ASCII values requires suitable locale and font support.
188 For the most part, Linux ignores the partition name, but it may
189 be important in some OSes. GPT fdisk sets a default name based
190 on the partition type code. If you want to set a name that
191 includes a space, enclose it in quotation marks, as in sgdisk -c
192 1:"Sample Name" /dev/sdb. Note that the GPT name of a partition
193 is distinct from the filesystem name, which is encoded in the
194 filesystem's data structures.
195
196
197 -C, --recompute-chs
198 Recompute CHS values in protective or hybrid MBR. This option
199 can sometimes help if a disk utility, OS, or BIOS doesn't like
200 the CHS values used by the partitions in the protective or
201 hybrid MBR. In particular, the GPT specification requires a CHS
202 value of 0xFFFFFF for over-8GiB partitions, but this value is
203 technically illegal by the usual standards. Some BIOSes hang if
204 they encounter this value. This option will recompute a more
205 normal CHS value -- 0xFEFFFF for over-8GiB partitions, enabling
206 these BIOSes to boot.
207
208
209 -d, --delete=partnum
210 Delete a partition. This action deletes the entry from the par‐
211 tition table but does not disturb the data within the sectors
212 originally allocated to the partition on the disk. If a corre‐
213 sponding hybrid MBR partition exists, gdisk deletes it, as well,
214 and expands any adjacent 0xEE (EFI GPT) MBR protective partition
215 to fill the new free space.
216
217
218 -D, --display-alignment
219 Display current sector alignment value. Partitions will be cre‐
220 ated on multiples of the sector value reported by this option.
221 You can change the alignment value with the -a option.
222
223
224 e, --move-second-header
225 Move backup GPT data structures to the end of the disk. Use this
226 option if you've added disks to a RAID array, thus creating a
227 virtual disk with space that follows the backup GPT data struc‐
228 tures. This command moves the backup GPT data structures to the
229 end of the disk, where they belong.
230
231
232 -E, --end-of-largest
233 Displays the sector number of the end of the largest available
234 block of sectors on the disk. A script may store this value and
235 pass it back as part of -n's option to create a partition. If no
236 unallocated sectors are available, this function returns the
237 value 0.
238
239
240 -f, --first-in-largest
241 Displays the sector number of the start of the largest available
242 block of sectors on the disk. A script may store this value and
243 pass it back as part of -n's option to create a partition. If no
244 unallocated sectors are available, this function returns the
245 value 0. Note that this parameter is blind to partition align‐
246 ment; when you actually create a partition, its start point
247 might be changed from this value.
248
249
250 -F, --first-aligned-in-largest
251 Similar to -f (--first-in-largest), except returns the sector
252 number with the current alignment correction applied. Use this
253 function if you need to compute the actual partition start point
254 rather than a theoretical start point or the actual start point
255 if you set the alignment value to 1.
256
257
258 -g, --mbrtogpt
259 Convert an MBR or BSD disklabel disk to a GPT disk. As a safety
260 measure, use of this option is required on MBR or BSD disklabel
261 disks if you intend to save your changes, in order to prevent
262 accidentally damaging such disks.
263
264
265 -G, --randomize-guids
266 Randomize the disk's GUID and all partitions' unique GUIDs (but
267 not their partition type code GUIDs). This function may be used
268 after cloning a disk in order to render all GUIDs once again
269 unique.
270
271
272 -h, --hybrid
273 Create a hybrid MBR. This option takes from one to three parti‐
274 tion numbers, separated by colons, as arguments. The created
275 hybrid MBR places an EFI GPT (type 0xEE) partition first in the
276 table, followed by the partition(s) you specify. Their type
277 codes are based on the GPT fdisk type codes divided by 0x0100,
278 which is usually correct for Windows partitions. If the
279 active/bootable flag should be set, you must do so in another
280 program, such as fdisk. The gdisk program offers additional
281 hybrid MBR creation options.
282
283
284 -i, --info=partnum
285 Show detailed partition information. The summary information
286 produced by the -p command necessarily omits many details, such
287 as the partition's unique GUID and the translation of sgdisk's
288 internal partition type code to a plain type name. The -i option
289 displays this information for a single partition.
290
291
292 -l, --load-backup=file
293 Load partition data from a backup file. This option is the
294 reverse of the -b option. Note that restoring partition data
295 from anything but the original disk is not recommended. This
296 option will work even if the disk's original partition table is
297 bad; however, most other options on the same command line will
298 be ignored.
299
300
301 -L, --list-types
302 Display a summary of partition types. GPT uses a GUID to iden‐
303 tify partition types for particular OSes and purposes. For ease
304 of data entry, sgdisk compresses these into two-byte (four-digit
305 hexadecimal) values that are related to their equivalent MBR
306 codes. Specifically, the MBR code is multiplied by hexadecimal
307 0x0100. For instance, the code for Linux swap space in MBR is
308 0x82, and it's 0x8200 in gdisk. A one-to-one correspondence is
309 impossible, though. Most notably, the codes for all varieties of
310 FAT and NTFS partition correspond to a single GPT code (entered
311 as 0x0700 in sgdisk). Some OSes use a single MBR code but employ
312 many more codes in GPT. For these, sgdisk adds code numbers
313 sequentially, such as 0xa500 for a FreeBSD disklabel, 0xa501 for
314 FreeBSD boot, 0xa502 for FreeBSD swap, and so on. Note that
315 these two-byte codes are unique to gdisk and sgdisk. This option
316 does not require you to specify a valid disk device filename.
317
318
319 -m, --gpttombr
320 Convert disk from GPT to MBR form. This option takes from one to
321 four partition numbers, separated by colons, as arguments. Their
322 type codes are based on the GPT fdisk type codes divided by
323 0x0100. If the active/bootable flag should be set, you must do
324 so in another program, such as fdisk. The gdisk program offers
325 additional MBR conversion options. It is not possible to convert
326 more than four partitions from GPT to MBR form or to convert
327 partitions that start above the 2TiB mark or that are larger
328 than 2TiB.
329
330
331 -n, --new=partnum:start:end
332 Create a new partition. You enter a partition number, starting
333 sector, and an ending sector. Both start and end sectors can be
334 specified in absolute terms as sector numbers or as positions
335 measured in kibibytes (K), mebibytes (M), gibibytes (G),
336 tebibytes (T), or pebibytes (P); for instance, 40M specifies a
337 position 40MiB from the start of the disk. You can specify loca‐
338 tions relative to the start or end of the specified default
339 range by preceding the number by a '+' or '-' symbol, as in +2G
340 to specify a point 2GiB after the default start sector, or -200M
341 to specify a point 200MiB before the last available sector. A
342 start or end value of 0 specifies the default value, which is
343 the start of the largest available block for the start sector
344 and the end of the same block for the end sector. A partnum
345 value of 0 causes the program to use the first available parti‐
346 tion number.
347
348
349 -N, --largest-new=num
350 Create a new partition that fills the largest available block of
351 space on the disk. Note that if used on a completely blank disk,
352 this is likely to result in a sector-moved warning, since the
353 first available sector (normally 34) doesn't fall on a 2048-sec‐
354 tor boundary (the default for alignment). You can use the -a
355 (--set-alignment) option to adjust the alignment, if desired. A
356 num value of 0 causes the program to use the first available
357 partition number.
358
359
360 -o, --clear
361 Clear out all partition data. This includes GPT header data, all
362 partition definitions, and the protective MBR. Note that this
363 operation will, like most other operations, fail on a damaged
364 disk. If you want to prepare a disk you know to be damaged for
365 GPT use, you should first wipe it with -Z and then partition it
366 normally. This option will work even if the disk's original par‐
367 tition table is bad; however, most other options on the same
368 command line will be ignored.
369
370
371 -p, --print
372 Display basic partition summary data. This includes partition
373 numbers, starting and ending sector numbers, partition sizes,
374 sgdisk's partition types codes, and partition names. For addi‐
375 tional information, use the -i (--info) option.
376
377
378 -P, --pretend
379 Pretend to make specified changes. In-memory GPT data structures
380 are altered according to other parameters, but changes are not
381 written to disk.
382
383
384 -r, --transpose
385 Swap two partitions' entries in the partition table. One or both
386 partitions may be empty, although swapping two empty partitions
387 is pointless. For instance, if partitions 1-4 are defined,
388 transposing 1 and 5 results in a table with partitions numbered
389 from 2-5. Transposing partitions in this way has no effect on
390 their disk space allocation; it only alters their order in the
391 partition table.
392
393
394 -R, --replicate=second_device_filename
395 Replicate the main device's partition table on the specified
396 second device. Note that the replicated partition table is an
397 exact copy, including all GUIDs; if the device should have its
398 own unique GUIDs, you should use the -G option on the new disk.
399
400
401 -s, --sort
402 Sort partition entries. GPT partition numbers need not match the
403 order of partitions on the disk. If you want them to match, you
404 can use this option. Note that some partitioning utilities sort
405 partitions whenever they make changes. Such changes will be
406 reflected in your device filenames, so you may need to edit
407 /etc/fstab if you use this option.
408
409
410 -t, --typecode=partnum:{hexcode|GUID}
411 Change a single partition's type code. You enter the type code
412 using either a two-byte hexadecimal number, as described ear‐
413 lier, or a fully-specified GUID value, such as
414 EBD0A0A2-B9E5-4433-87C0-68B6B72699C7.
415
416
417 -T, --transform-bsd=partnum
418 Transform BSD partitions into GPT partitions. This option works
419 on BSD disklabels held within GPT (or converted MBR) partitions.
420 Converted partitions' type codes are likely to need manual
421 adjustment. sgdisk will attempt to convert BSD disklabels stored
422 on the main disk when launched, but this conversion is likely to
423 produce first and/or last partitions that are unusable. The many
424 BSD variants means that the probability of sgdisk being unable
425 to convert a BSD disklabel is high compared to the likelihood of
426 problems with an MBR conversion.
427
428
429 -u, --partition-guid=partnum:guid
430 Set the partition unique GUID for an individual partition. The
431 GUID may be a complete GUID or 'R' to set a random GUID.
432
433
434 -U, --disk-guid=guid
435 Set the GUID for the disk. The GUID may be a complete GUID or
436 'R' to set a random GUID.
437
438
439 --usage
440 Print a brief summary of available options.
441
442
443 -v, --verify
444 Verify disk. This option checks for a variety of problems, such
445 as incorrect CRCs and mismatched main and backup data. This
446 option does not automatically correct most problems, though; for
447 that, you must use options on the recovery & transformation
448 menu. If no problems are found, this command displays a summary
449 of unallocated disk space. This option will work even if the
450 disk's original partition table is bad; however, most other
451 options on the same command line will be ignored.
452
453
454 -V, --version
455 Display program version information. This option may be used
456 without specifying a device filename.
457
458
459 -z, --zap
460 Zap (destroy) the GPT data structures and then exit. Use this
461 option if you want to repartition a GPT disk using fdisk or some
462 other GPT-unaware program. This option destroys only the GPT
463 data structures; it leaves the MBR intact. This makes it useful
464 for wiping out GPT data structures after a disk has been repar‐
465 titioned for MBR using a GPT-unaware utility; however, there's a
466 risk that it will damage boot loaders or even the start of the
467 first or end of the last MBR partition. If you use it on a valid
468 GPT disk, the MBR will be left with an inappropriate EFI GPT
469 (0xEE) partition definition, which you can delete using another
470 utility.
471
472
473 -Z, --zap-all
474 Zap (destroy) the GPT and MBR data structures and then exit.
475 This option works much like -z, but as it wipes the MBR as well
476 as the GPT, it's more suitable if you want to repartition a disk
477 after using this option, and completely unsuitable if you've
478 already repartitioned the disk.
479
480
481 -?, --help
482 Print a summary of options.
483
484
486 sgdisk returns various values depending on its success or failure:
487
488
489 0 Normal program execution
490
491
492 1 Too few arguments
493
494
495 2 An error occurred while reading the partition table
496
497
498 3 Non-GPT disk detected and no -g option
499
500
501 4 An error prevented saving changes
502
503
504 8 Disk replication operation (-R) failed
505
506
508 As of October 2011 (version 0.8.1), sgdisk should be considered beta
509 software. Known bugs and limitations include:
510
511
512 * The program compiles correctly only on Linux, FreeBSD, and Mac
513 OS X. Linux versions for x86-64 (64-bit), x86 (32-bit), and Pow‐
514 erPC (32-bit) have been tested, with the x86-64 version having
515 seen the most testing.
516
517
518 * The FreeBSD version of the program can't write changes to the
519 partition table to a disk when existing partitions on that disk
520 are mounted. (The same problem exists with many other FreeBSD
521 utilities, such as gpt, fdisk, and dd.) This limitation can be
522 overcome by typing sysctl kern.geom.debugflags=16 at a shell
523 prompt.
524
525
526 * The fields used to display the start and end sector numbers for
527 partitions in the -p option are 14 characters wide. This trans‐
528 lates to a limitation of about 45 PiB. On larger disks, the dis‐
529 played columns will go out of alignment.
530
531
532 * The program can load only up to 128 partitions (4 primary parti‐
533 tions and 124 logical partitions) when converting from MBR for‐
534 mat. This limit can be raised by changing the #define
535 MAX_MBR_PARTS line in the basicmbr.h source code file and recom‐
536 piling; however, such a change will require using a
537 larger-than-normal partition table. (The limit of 128 partitions
538 was chosen because that number equals the 128 partitions sup‐
539 ported by the most common partition table size.)
540
541
542 * Converting from MBR format sometimes fails because of insuffi‐
543 cient space at the start or (more commonly) the end of the disk.
544 Resizing the partition table (using the 's' option in the
545 experts' menu) can sometimes overcome this problem; however, in
546 extreme cases it may be necessary to resize a partition using
547 GNU Parted or a similar tool prior to conversion with gdisk.
548
549
550 * MBR conversions work only if the disk has correct LBA partition
551 descriptors. These descriptors should be present on any disk
552 over 8 GiB in size or on smaller disks partitioned with any but
553 very ancient software.
554
555
556 * BSD disklabel support can create first and/or last partitions
557 that overlap with the GPT data structures. This can sometimes be
558 compensated by adjusting the partition table size, but in
559 extreme cases the affected partition(s) may need to be deleted.
560
561
562 * Because of the highly variable nature of BSD disklabel struc‐
563 tures, conversions from this form may be unreliable -- parti‐
564 tions may be dropped, converted in a way that creates overlaps
565 with other partitions, or converted with incorrect start or end
566 values. Use this feature with caution!
567
568
569 * Booting after converting an MBR or BSD disklabel disk is likely
570 to be disrupted. Sometimes re-installing a boot loader will fix
571 the problem, but other times you may need to switch boot load‐
572 ers. Except on EFI-based platforms, Windows through at least
573 Windows 7 RC doesn't support booting from GPT disks. Creating a
574 hybrid MBR (using the 'h' option on the recovery & transforma‐
575 tion menu) or abandoning GPT in favor of MBR may be your only
576 options in this case.
577
578
580 Primary author: Roderick W. Smith (rodsmith@rodsbooks.com)
581
582 Contributors:
583
584 * Yves Blusseau (1otnwmz02@sneakemail.com)
585
586 * David Hubbard (david.c.hubbard@gmail.com)
587
588 * Justin Maggard (justin.maggard@netgear.com)
589
590 * Dwight Schauer (dschauer@ti.com)
591
592 * Florian Zumbiehl (florz@florz.de)
593
594
595
597 cfdisk (8), cgdisk (8), fdisk (8), gdisk (8), mkfs (8), parted (8),
598 sfdisk (8) fixparts (8)
599
600 http://en.wikipedia.org/wiki/GUID_Partition_Table
601
602 http://developer.apple.com/technotes/tn2006/tn2166.html
603
604 http://www.rodsbooks.com/gdisk/
605
606
608 The sgdisk command is part of the GPT fdisk package and is available
609 from Rod Smith.
610
611
612
613Roderick W. Smith 0.8.1 SGDISK(8)