blob: 0cda7146ec7fab3963ce8035894bab560dded8f1 [file] [log] [blame]
srs5694bf8950c2011-03-12 01:23:12 -05001GPT fdisk (aka gdisk and sgdisk) and FixParts
srs5694e7b4ff92009-08-18 13:16:10 -04002by Roderick W. Smith, rodsmith@rodsbooks.com
3
4Introduction
5------------
6
srs5694bf8950c2011-03-12 01:23:12 -05007This binary archive includes the source code for three related disk
8partitioning programs:
9
10- gdisk -- This program is modeled after Linux fdisk, but it operates on
11 GUID Partition Table (GPT) disks rather than the Master Boot Record (MBR)
12 disks that fdisk modifies. As such, gdisk is an interactive text-mode
13 tool for manipulating partitions, but it does nothing to the contents of
14 those partitions (usually filesystems, but sometimes swap space or other
15 data).
16
17- sgdisk -- This program is conceptually similar to the Linux sfdisk and
18 FreeBSD gpt programs, but its operational details differ. It enables
19 manipulation of GPT disks using command-line options, so it's suitable
20 for use in scripts or by experts to perform specific tasks that might
21 take several commands in gdisk to accomplish.
22
23- fixparts -- This program, unlike the preceding two, operates on MBR
24 disks. It's intended to fix certain problems that can be created by
25 various utilities. Specifically, it can fix mis-sized extended partitions
26 and primary partitions located in the middle of extended partitions. It
27 also enables changing primary vs. logical partition status (within limits
28 of what's legal in the MBR scheme) and making a few other minor changes.
29 It does NOT support creating new partitions; for that, you should use
30 fdisk, parted, or some other tool.
31
32More details about the abilities of these tools follows.
33
34All three programs rely on the same set of underlying code base; they
35differ only in their control interfaces (defined in gdisk.cc, sgdisk.cc,
36and fixparts.cc, respectively) and in which support code they use.
37
38GPT fdisk (gdisk and sgdisk) Details
39------------------------------------
40
41The gdisk program is intended as a (somewhat) fdisk-workalike program for
42GPT-partitioned disks, and sgdisk provides most of gdisk's functionality in
43a more script-friendly program. Although libparted and programs that use it
44(GNU Parted, gparted, etc.) provide the ability to handle GPT disks, they
45have certain limitations that gdisk overcomes. Specific advantages of gdisk
46and sgdisk include:
srs5694e7b4ff92009-08-18 13:16:10 -040047
48* The ability to convert MBR-partitioned disks in-place to GPT format,
49 without losing data
50
srs5694221e0872009-08-29 15:00:31 -040051* The ability to convert BSD disklabels in-place to create GPT
52 partitions, without losing data
53
srs5694bf8950c2011-03-12 01:23:12 -050054* The ability to convert from GPT format to MBR format without data loss
srs5694e7b4ff92009-08-18 13:16:10 -040055
56* More flexible specification of filesystem type code GUIDs, which
srs5694bf8950c2011-03-12 01:23:12 -050057 GNU Parted tends to corrupt
srs5694e7b4ff92009-08-18 13:16:10 -040058
59* Clear identification of the number of unallocated sectors on a
60 disk
61
62* A user interface that's familiar to long-time users of Linux
srs56943c0af382010-01-15 19:19:18 -050063 fdisk (gdisk only)
srs5694e7b4ff92009-08-18 13:16:10 -040064
65* The MBR boot loader code is left alone (GNU Parted tends to
66 wipe it out with every change)
67
srs5694221e0872009-08-29 15:00:31 -040068* The ability to create a hybrid MBR, which permits GPT-unaware
69 OSes to access up to three GPT partitions on the disk
70
srs56943c0af382010-01-15 19:19:18 -050071Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
72the filesystem awareness and filesystem-related features of GNU Parted. You
srs5694e7b4ff92009-08-18 13:16:10 -040073can't resize a partition's filesystem or create a partition with a
74filesystem already in place with gdisk, for instance. There's no GUI
75version of gdisk.
76
srs56943c0af382010-01-15 19:19:18 -050077The GPT fdisk package provides two program files: the interactive text-mode
78gdisk and the command-line-driven sgdisk. The former is intended for use in
79manually partitioning disks or changing partitioning details; the latter is
80intended for use in scripts to help automate tasks such as disk cloning or
81preparing multiple disks for Linux installation.
82
srs5694bf8950c2011-03-12 01:23:12 -050083FixParts Details
84----------------
85
86This program's creation was motivated by cries for help I've seen in online
87forums from users who have found their partition tables to be corrupted by
88various buggy partitioning tools. Although most OSes can handle the
89afflicted disks fine, libparted-based tools (GParted, parted, most Linux
90installers, etc.) tend to flake out when presented with these disks.
91Typically, the symptom is a disk that appears to hold no partitions;
92however, sometimes the libparted tool presents partitions other than those
93that the OS sees.
94
95I've observed four causes of these symptoms, three of which FixParts can
96correct:
97
98- Old GPT data -- If a disk is used as a GPT disk and then re-used as an
99 MBR disk, the GPT data may be incompletely erased. This happens if the
100 disk is repartitioned with fdisk or the Microsoft Windows installer, for
101 instance. (Tools based on libparted correctly remove the old GPT data
102 when converting from GPT to MBR format.) FixParts checks for this problem
103 when it starts and offers to correct it. If you opt to erase the GPT
104 data, this erasure occurs immediately, unlike other changes the program
105 makes.
106
107- Mis-sized extended partitions -- Some tools create an extended partition
108 that's too large, typically ending after the last sector of the disk.
109 FixParts automatically corrects this problem (if you use the 'w' option
110 to save the partition table).
111
112- Primary partitions inside an extended partition -- Some utilities create
113 or move primary partitions to within the range covered by the extended
114 partition. FixParts can usually correct this problem by turning the
115 primary partition into a logical partition or by changing one or more
116 other logical partitions into primaries. Such corrections aren't always
117 possible, though, at least not without deleting or resizing other
118 partitions.
119
120- Leftover RAID data -- If a disk is used in a RAID array and then re-used
121 as a non-RAID disk, some utilities can become confused and fail to see
122 the disk. FixParts can NOT correct this problem. You must destroy the old
123 RAID data, or possibly remove the dmraid package from the system, to fix
124 this problem.
125
126When run, FixParts presents an fdisk-like interface, enabling you to adjust
127partition types (primary, logical, or omitted), change type codes, change
128the bootable flag, and so on. Although you can delete a partition (by
129omitting it), you can't create new partitions with the program. If you're
130used to partitioning disks, particularly with Linux fdisk, two unusual
131features of FixParts require elaboration:
132
133- No extended partitions -- Internally, FixParts reads the partition table
134 and discards data on any extended partition(s) it finds. When you save
135 the partition table, the program generates a new extended partition. This
136 design means that the program automatically corrects many problems
137 related to the extended partition. It also means that you'll see no
138 evidence of extended partitions in the FixParts user interface, although
139 it keeps track of the requirements and prevents you from creating illegal
140 layouts, such as a primary between two logicals.
141
142- Partition numbering -- In most Linux tools, partitions 1-4 are primaries
143 and partitions 5 and up are logicals. Although a legal partition table
144 loaded into FixParts will initially conform to this convention, some
145 types of damaged table might not, and various changes you make can also
146 cause deviations. When FixParts writes the partition table, its numbering
147 will be altered to conform to the standard MBR conventions, but you
148 should use the explicit labeling of partitions as primary or logical
149 rather than the partition numbers to determine a partition's status.
150
srs5694e7b4ff92009-08-18 13:16:10 -0400151Installing
152----------
153
srs56943c0af382010-01-15 19:19:18 -0500154To compile GPT fdisk, you must have appropriate development tools
155installed, most notably the GNU Compiler Collection (GCC) and its g++
srs5694bf8950c2011-03-12 01:23:12 -0500156compiler for C++. (Under Windows, Microsoft Visual C++ 2008 can also be
157used.) In addition, note these requirements:
srs56946699b012010-02-04 00:55:30 -0500158
159* On Linux, FreeBSD, and OS X, libuuid must be installed. This is the
160 standard for Linux and OS X, although you may need to install a package
161 called uuid-dev or something similar to get the headers. On FreeBSD, the
162 e2fsprogs-libuuid port must be installed.
163
164* The sgdisk program also requires the popt library and its development
165 files (headers). Most Linux distributions install popt by default, but
166 you may need to install a package called popt-dev, popt-devel, or
167 something similar to obtain the header files. Mac OS users can find a
168 version of popt for Mac OS from http://popt.darwinports.com; however,
169 you'll first need to install DarwinPorts (instructions exist on the
170 preceding page). Alternatively, you can compile gdisk alone, without
171 sgdisk; gdisk doesn't require popt.
srs5694ba00fed2010-01-12 18:18:36 -0500172
173When all the necessary development tools and libraries are installed, you
174can uncompress the package and type "make" at the command prompt in the
srs56946699b012010-02-04 00:55:30 -0500175resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
srs56949ba54212010-05-18 23:24:02 -0400176X, "make -f Makefile.freebsd" on FreeBSD, or "make -f Makefile.mingw" to
177compile using MinGW for Windows.) You may also need to add header (include)
178directories or library directories by setting the CXXFLAGS environment
179variable or by editing the Makefile. The result should be program files
srs5694bf8950c2011-03-12 01:23:12 -0500180called gdisk, sgdisk, and fixparts. Typing "make gdisk", "make sgdisk", or
181"make fixparts" will compile only the requested programs. You can use these
182programs in place or copy the files to a suitable directory, such as
183/usr/local/sbin. You can copy the man pages (gdisk.8, sgdisk.8, and
184fixparts.8) to /usr/local/man/man8 to make them available.
srs5694e7b4ff92009-08-18 13:16:10 -0400185
186Caveats
187-------
188
srs56945d58fe02010-01-03 20:57:08 -0500189THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
190CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
191drives, a handful of PATA and SATA hard disks, and several virtual disks in
srs5694bf8950c2011-03-12 01:23:12 -0500192the QEMU and VirtualBox environments. Many others have now used the
193software on their computers, as well. I believe all data-corruption bugs to
194be squashed, but I know full well that the odds of my missing something are
195high. This is particularly true for large drives; my only direct testing
196with such disks is with virtual QEMU disks. I've received user reports of
197success with RAID arrays over 2TiB in size, though.
srs5694e7b4ff92009-08-18 13:16:10 -0400198
199My main development platform is a system running the 64-bit version of
srs5694bf8950c2011-03-12 01:23:12 -0500200Gentoo Linux (previously Ubuntu 8.04). I've also tested on several other
20132- and 64-bit Linux distributions Intel-based Mac OS X 10.5 and 10.6,
20264-bit FreeBSD 7.1, and Windows 7.
srs5694e7b4ff92009-08-18 13:16:10 -0400203
204Redistribution
205--------------
206
207This program is licensed under terms of the GNU GPL (see the file COPYING).
208
209Acknowledgements
210----------------
211
212This code is mostly my own; however, I've used three functions from two
213other GPLed programs:
214
215- The code used to generate CRCs is taken from the efone program by
216 Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
217 crc32.cc source code files.)
218
srs56949ba54212010-05-18 23:24:02 -0400219- A function to find the disk size is taken from Linux fdisk by A. V. Le
220 Blanc. This code has subsequently been heavily modified.
srs5694e7b4ff92009-08-18 13:16:10 -0400221
222Additional code contributors include:
223
224- Yves Blusseau (1otnwmz02@sneakemail.com)
225
srs56947f244ba2009-08-18 14:22:12 -0400226- David Hubbard (david.c.hubbard@gmail.com)
srs5694bf8950c2011-03-12 01:23:12 -0500227
228- Justin Maggard (justin.maggard@netgear.com)
229
230- Dwight Schauer (dschauer@ti.com)
231
232- Florian Zumbiehl (florz@florz.de)