blob: e818c2cac0794e8f3f7e41bf96e2b4cf24a1c725 [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
srs5694699941e2011-03-21 21:33:57 -04007This package includes the source code for three related disk partitioning
8programs:
srs5694bf8950c2011-03-12 01:23:12 -05009
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
srs5694699941e2011-03-21 21:33:57 -040065* The MBR boot loader code is left alone
srs5694e7b4ff92009-08-18 13:16:10 -040066
srs5694221e0872009-08-29 15:00:31 -040067* The ability to create a hybrid MBR, which permits GPT-unaware
68 OSes to access up to three GPT partitions on the disk
69
srs56943c0af382010-01-15 19:19:18 -050070Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
71the filesystem awareness and filesystem-related features of GNU Parted. You
srs5694e7b4ff92009-08-18 13:16:10 -040072can't resize a partition's filesystem or create a partition with a
73filesystem already in place with gdisk, for instance. There's no GUI
74version of gdisk.
75
srs56943c0af382010-01-15 19:19:18 -050076The GPT fdisk package provides two program files: the interactive text-mode
77gdisk and the command-line-driven sgdisk. The former is intended for use in
78manually partitioning disks or changing partitioning details; the latter is
79intended for use in scripts to help automate tasks such as disk cloning or
80preparing multiple disks for Linux installation.
81
srs5694bf8950c2011-03-12 01:23:12 -050082FixParts Details
83----------------
84
85This program's creation was motivated by cries for help I've seen in online
86forums from users who have found their partition tables to be corrupted by
87various buggy partitioning tools. Although most OSes can handle the
88afflicted disks fine, libparted-based tools (GParted, parted, most Linux
89installers, etc.) tend to flake out when presented with these disks.
90Typically, the symptom is a disk that appears to hold no partitions;
91however, sometimes the libparted tool presents partitions other than those
92that the OS sees.
93
94I've observed four causes of these symptoms, three of which FixParts can
95correct:
96
srs5694699941e2011-03-21 21:33:57 -040097* Old GPT data -- If a disk is used as a GPT disk and then re-used as an
srs5694bf8950c2011-03-12 01:23:12 -050098 MBR disk, the GPT data may be incompletely erased. This happens if the
99 disk is repartitioned with fdisk or the Microsoft Windows installer, for
100 instance. (Tools based on libparted correctly remove the old GPT data
101 when converting from GPT to MBR format.) FixParts checks for this problem
102 when it starts and offers to correct it. If you opt to erase the GPT
103 data, this erasure occurs immediately, unlike other changes the program
104 makes.
105
srs5694699941e2011-03-21 21:33:57 -0400106* Mis-sized extended partitions -- Some tools create an extended partition
srs5694bf8950c2011-03-12 01:23:12 -0500107 that's too large, typically ending after the last sector of the disk.
108 FixParts automatically corrects this problem (if you use the 'w' option
109 to save the partition table).
110
srs5694699941e2011-03-21 21:33:57 -0400111* Primary partitions inside an extended partition -- Some utilities create
srs5694bf8950c2011-03-12 01:23:12 -0500112 or move primary partitions to within the range covered by the extended
113 partition. FixParts can usually correct this problem by turning the
114 primary partition into a logical partition or by changing one or more
115 other logical partitions into primaries. Such corrections aren't always
116 possible, though, at least not without deleting or resizing other
117 partitions.
118
srs5694699941e2011-03-21 21:33:57 -0400119* Leftover RAID data -- If a disk is used in a RAID array and then re-used
srs5694bf8950c2011-03-12 01:23:12 -0500120 as a non-RAID disk, some utilities can become confused and fail to see
121 the disk. FixParts can NOT correct this problem. You must destroy the old
122 RAID data, or possibly remove the dmraid package from the system, to fix
123 this problem.
124
125When run, FixParts presents an fdisk-like interface, enabling you to adjust
126partition types (primary, logical, or omitted), change type codes, change
127the bootable flag, and so on. Although you can delete a partition (by
128omitting it), you can't create new partitions with the program. If you're
129used to partitioning disks, particularly with Linux fdisk, two unusual
130features of FixParts require elaboration:
131
srs5694699941e2011-03-21 21:33:57 -0400132* No extended partitions -- Internally, FixParts reads the partition table
srs5694bf8950c2011-03-12 01:23:12 -0500133 and discards data on any extended partition(s) it finds. When you save
134 the partition table, the program generates a new extended partition. This
135 design means that the program automatically corrects many problems
136 related to the extended partition. It also means that you'll see no
137 evidence of extended partitions in the FixParts user interface, although
138 it keeps track of the requirements and prevents you from creating illegal
139 layouts, such as a primary between two logicals.
140
srs5694699941e2011-03-21 21:33:57 -0400141* Partition numbering -- In most Linux tools, partitions 1-4 are primaries
srs5694bf8950c2011-03-12 01:23:12 -0500142 and partitions 5 and up are logicals. Although a legal partition table
143 loaded into FixParts will initially conform to this convention, some
144 types of damaged table might not, and various changes you make can also
145 cause deviations. When FixParts writes the partition table, its numbering
146 will be altered to conform to the standard MBR conventions, but you
147 should use the explicit labeling of partitions as primary or logical
148 rather than the partition numbers to determine a partition's status.
149
srs5694e7b4ff92009-08-18 13:16:10 -0400150Installing
151----------
152
srs56943c0af382010-01-15 19:19:18 -0500153To compile GPT fdisk, you must have appropriate development tools
154installed, most notably the GNU Compiler Collection (GCC) and its g++
srs5694bf8950c2011-03-12 01:23:12 -0500155compiler for C++. (Under Windows, Microsoft Visual C++ 2008 can also be
156used.) In addition, note these requirements:
srs56946699b012010-02-04 00:55:30 -0500157
158* On Linux, FreeBSD, and OS X, libuuid must be installed. This is the
159 standard for Linux and OS X, although you may need to install a package
160 called uuid-dev or something similar to get the headers. On FreeBSD, the
161 e2fsprogs-libuuid port must be installed.
162
srs569400b6d7a2011-06-26 22:40:06 -0400163* The ICU library (http://site.icu-project.org), which provides support for
164 Unicode partition names, is recommended on all
165 platforms except Windows. This library is normally installed in Linux and
166 OS X, but you may need to install the development headers (libicu-dev or
167 something similar in Linux; or the libicu36-dev Fink package in OS X). To
168 compile without ICU support, you must modify the Makefile: Remove the
169 "-D USE_UTF16" part from the CXXFLAGS line and remove references to
170 -licuio, -licuuc, -licudata, and -licucore (details vary between
171 platforms) from the compilation options. Suitable lines are present, but
172 commented out, in the Makefile, Makefile.mac, and Makefile.bsd files.
srs56945a608532011-03-17 13:53:01 -0400173
srs56946699b012010-02-04 00:55:30 -0500174* The sgdisk program also requires the popt library and its development
175 files (headers). Most Linux distributions install popt by default, but
176 you may need to install a package called popt-dev, popt-devel, or
177 something similar to obtain the header files. Mac OS users can find a
srs569400b6d7a2011-06-26 22:40:06 -0400178 version of popt for Mac OS from Drawin Ports (http://popt.darwinports.com)
179 or Fink (http://www.finkproject.org); however, you'll first need to
180 install DarwinPorts or Fink (instructions exist on the relevant projects'
181 pages). Alternatively, you can compile gdisk alone, without sgdisk; gdisk
182 doesn't require popt.
srs5694ba00fed2010-01-12 18:18:36 -0500183
184When all the necessary development tools and libraries are installed, you
185can uncompress the package and type "make" at the command prompt in the
srs56946699b012010-02-04 00:55:30 -0500186resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
srs56949ba54212010-05-18 23:24:02 -0400187X, "make -f Makefile.freebsd" on FreeBSD, or "make -f Makefile.mingw" to
188compile using MinGW for Windows.) You may also need to add header (include)
189directories or library directories by setting the CXXFLAGS environment
190variable or by editing the Makefile. The result should be program files
srs5694bf8950c2011-03-12 01:23:12 -0500191called gdisk, sgdisk, and fixparts. Typing "make gdisk", "make sgdisk", or
192"make fixparts" will compile only the requested programs. You can use these
193programs in place or copy the files to a suitable directory, such as
194/usr/local/sbin. You can copy the man pages (gdisk.8, sgdisk.8, and
195fixparts.8) to /usr/local/man/man8 to make them available.
srs5694e7b4ff92009-08-18 13:16:10 -0400196
197Caveats
198-------
199
srs56945d58fe02010-01-03 20:57:08 -0500200THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
201CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
srs569400b6d7a2011-06-26 22:40:06 -0400202drives, physical hard disks, and virtual disks in the QEMU and VirtualBox
203environments. Many others have now used the software on their computers, as
204well. I believe all data-corruption bugs to be squashed, but I know full well
205that the odds of my missing something are high. This is particularly true for
206large (over-2TiB) drives; my only direct testing with such disks is with
207virtual QEMU and VirtualBox disks. I've received user reports of success with
208RAID arrays over 2TiB in size, though.
srs5694e7b4ff92009-08-18 13:16:10 -0400209
210My main development platform is a system running the 64-bit version of
srs5694bf8950c2011-03-12 01:23:12 -0500211Gentoo Linux (previously Ubuntu 8.04). I've also tested on several other
srs569400b6d7a2011-06-26 22:40:06 -040021232- and 64-bit Linux distributions, Intel-based Mac OS X 10.5 and 10.6,
srs5694bf8950c2011-03-12 01:23:12 -050021364-bit FreeBSD 7.1, and Windows 7.
srs5694e7b4ff92009-08-18 13:16:10 -0400214
215Redistribution
216--------------
217
218This program is licensed under terms of the GNU GPL (see the file COPYING).
219
220Acknowledgements
221----------------
222
223This code is mostly my own; however, I've used three functions from two
224other GPLed programs:
225
226- The code used to generate CRCs is taken from the efone program by
227 Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
228 crc32.cc source code files.)
229
srs56949ba54212010-05-18 23:24:02 -0400230- A function to find the disk size is taken from Linux fdisk by A. V. Le
231 Blanc. This code has subsequently been heavily modified.
srs5694e7b4ff92009-08-18 13:16:10 -0400232
233Additional code contributors include:
234
235- Yves Blusseau (1otnwmz02@sneakemail.com)
236
srs56947f244ba2009-08-18 14:22:12 -0400237- David Hubbard (david.c.hubbard@gmail.com)
srs5694bf8950c2011-03-12 01:23:12 -0500238
239- Justin Maggard (justin.maggard@netgear.com)
240
241- Dwight Schauer (dschauer@ti.com)
242
243- Florian Zumbiehl (florz@florz.de)