blob: 11d691094f80f8adb8aec0aad1123e62ea6a4c75 [file] [log] [blame]
srs5694f502e522011-09-10 21:23:51 -04001GPT fdisk (aka gdisk, cgdisk, and sgdisk) and FixParts
srs5694e7b4ff92009-08-18 13:16:10 -04002by Roderick W. Smith, rodsmith@rodsbooks.com
3
4Introduction
5------------
6
srs5694f502e522011-09-10 21:23:51 -04007This package includes the source code for four related disk partitioning
srs5694699941e2011-03-21 21:33:57 -04008programs:
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
srs5694f502e522011-09-10 21:23:51 -040017- cgdisk -- This program is modeled after Linux cfdisk, but it operates on
18 GPT disks rather than the MBR disks that cfdisk modifies. As such, cgdisk
19 is a curses-based text-mode tool for manipulating partitions, which is to
20 say that it uses an interface that relies on arrow keys and a dynamic
21 display rather than the command letters and a scrolling display like
22 gdisk uses.
23
srs5694bf8950c2011-03-12 01:23:12 -050024- sgdisk -- This program is conceptually similar to the Linux sfdisk and
25 FreeBSD gpt programs, but its operational details differ. It enables
26 manipulation of GPT disks using command-line options, so it's suitable
27 for use in scripts or by experts to perform specific tasks that might
28 take several commands in gdisk to accomplish.
29
srs5694f502e522011-09-10 21:23:51 -040030- fixparts -- This program, unlike the preceding three, operates on MBR
srs5694bf8950c2011-03-12 01:23:12 -050031 disks. It's intended to fix certain problems that can be created by
32 various utilities. Specifically, it can fix mis-sized extended partitions
33 and primary partitions located in the middle of extended partitions. It
34 also enables changing primary vs. logical partition status (within limits
35 of what's legal in the MBR scheme) and making a few other minor changes.
36 It does NOT support creating new partitions; for that, you should use
37 fdisk, parted, or some other tool.
38
39More details about the abilities of these tools follows.
40
srs5694f502e522011-09-10 21:23:51 -040041All four programs rely on the same set of underlying code base; they differ
42only in their control interfaces (defined in gdisk.cc, cgdisk.cc,
43sgdisk.cc, and fixparts.cc, respectively) and in which support code they
44use.
srs5694bf8950c2011-03-12 01:23:12 -050045
srs5694f502e522011-09-10 21:23:51 -040046GPT fdisk (gdisk, cgdisk, and sgdisk) Details
47---------------------------------------------
srs5694bf8950c2011-03-12 01:23:12 -050048
49The gdisk program is intended as a (somewhat) fdisk-workalike program for
srs5694f502e522011-09-10 21:23:51 -040050GPT-partitioned disks, cgdisk is similarly a workalike for fdisk, and
51sgdisk provides most of gdisk's functionality in a more script-friendly
52program. Although libparted and programs that use it (GNU Parted, gparted,
53etc.) provide the ability to handle GPT disks, they have certain
54limitations that gdisk overcomes. Specific advantages of gdisk, cgdisk, and
55sgdisk include:
srs5694e7b4ff92009-08-18 13:16:10 -040056
57* The ability to convert MBR-partitioned disks in-place to GPT format,
58 without losing data
59
srs5694221e0872009-08-29 15:00:31 -040060* The ability to convert BSD disklabels in-place to create GPT
61 partitions, without losing data
62
srs5694bf8950c2011-03-12 01:23:12 -050063* The ability to convert from GPT format to MBR format without data loss
srs5694f502e522011-09-10 21:23:51 -040064 (gdisk and sgdisk only)
srs5694e7b4ff92009-08-18 13:16:10 -040065
66* More flexible specification of filesystem type code GUIDs, which
srs5694bf8950c2011-03-12 01:23:12 -050067 GNU Parted tends to corrupt
srs5694e7b4ff92009-08-18 13:16:10 -040068
69* Clear identification of the number of unallocated sectors on a
70 disk
71
72* A user interface that's familiar to long-time users of Linux
srs5694f502e522011-09-10 21:23:51 -040073 fdisk and cfdisk (gdisk and cgdisk only)
srs5694e7b4ff92009-08-18 13:16:10 -040074
srs5694699941e2011-03-21 21:33:57 -040075* The MBR boot loader code is left alone
srs5694e7b4ff92009-08-18 13:16:10 -040076
srs5694f502e522011-09-10 21:23:51 -040077* The ability to create a hybrid MBR, which permits GPT-unaware OSes to
78 access up to three GPT partitions on the disk (gdisk and sgdisk only)
srs5694221e0872009-08-29 15:00:31 -040079
srs56943c0af382010-01-15 19:19:18 -050080Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
srs56940741fa22013-01-09 12:55:40 -050081the filesystem awareness and filesystem-related features of GParted. You
srs5694e7b4ff92009-08-18 13:16:10 -040082can't resize a partition's filesystem or create a partition with a
83filesystem already in place with gdisk, for instance. There's no GUI
84version of gdisk.
85
srs5694f502e522011-09-10 21:23:51 -040086The GPT fdisk package provides three program files: the interactive
87text-mode gdisk, the curses-based interactive cgdisk, and the
88command-line-driven sgdisk. The first two are intended for use in manually
89partitioning disks or changing partitioning details; sgdisk is intended for
90use in scripts to help automate tasks such as disk cloning or preparing
91multiple disks for Linux installation.
srs56943c0af382010-01-15 19:19:18 -050092
srs5694bf8950c2011-03-12 01:23:12 -050093FixParts Details
94----------------
95
96This program's creation was motivated by cries for help I've seen in online
97forums from users who have found their partition tables to be corrupted by
98various buggy partitioning tools. Although most OSes can handle the
99afflicted disks fine, libparted-based tools (GParted, parted, most Linux
100installers, etc.) tend to flake out when presented with these disks.
101Typically, the symptom is a disk that appears to hold no partitions;
102however, sometimes the libparted tool presents partitions other than those
103that the OS sees.
104
105I've observed four causes of these symptoms, three of which FixParts can
106correct:
107
srs5694699941e2011-03-21 21:33:57 -0400108* Old GPT data -- If a disk is used as a GPT disk and then re-used as an
srs5694bf8950c2011-03-12 01:23:12 -0500109 MBR disk, the GPT data may be incompletely erased. This happens if the
110 disk is repartitioned with fdisk or the Microsoft Windows installer, for
111 instance. (Tools based on libparted correctly remove the old GPT data
112 when converting from GPT to MBR format.) FixParts checks for this problem
113 when it starts and offers to correct it. If you opt to erase the GPT
114 data, this erasure occurs immediately, unlike other changes the program
115 makes.
116
srs5694699941e2011-03-21 21:33:57 -0400117* Mis-sized extended partitions -- Some tools create an extended partition
srs5694bf8950c2011-03-12 01:23:12 -0500118 that's too large, typically ending after the last sector of the disk.
119 FixParts automatically corrects this problem (if you use the 'w' option
120 to save the partition table).
121
srs5694699941e2011-03-21 21:33:57 -0400122* Primary partitions inside an extended partition -- Some utilities create
srs5694bf8950c2011-03-12 01:23:12 -0500123 or move primary partitions to within the range covered by the extended
124 partition. FixParts can usually correct this problem by turning the
125 primary partition into a logical partition or by changing one or more
126 other logical partitions into primaries. Such corrections aren't always
127 possible, though, at least not without deleting or resizing other
128 partitions.
129
srs5694699941e2011-03-21 21:33:57 -0400130* Leftover RAID data -- If a disk is used in a RAID array and then re-used
srs5694bf8950c2011-03-12 01:23:12 -0500131 as a non-RAID disk, some utilities can become confused and fail to see
132 the disk. FixParts can NOT correct this problem. You must destroy the old
133 RAID data, or possibly remove the dmraid package from the system, to fix
134 this problem.
135
136When run, FixParts presents an fdisk-like interface, enabling you to adjust
137partition types (primary, logical, or omitted), change type codes, change
138the bootable flag, and so on. Although you can delete a partition (by
139omitting it), you can't create new partitions with the program. If you're
140used to partitioning disks, particularly with Linux fdisk, two unusual
141features of FixParts require elaboration:
142
srs5694699941e2011-03-21 21:33:57 -0400143* No extended partitions -- Internally, FixParts reads the partition table
srs5694bf8950c2011-03-12 01:23:12 -0500144 and discards data on any extended partition(s) it finds. When you save
145 the partition table, the program generates a new extended partition. This
146 design means that the program automatically corrects many problems
147 related to the extended partition. It also means that you'll see no
148 evidence of extended partitions in the FixParts user interface, although
149 it keeps track of the requirements and prevents you from creating illegal
150 layouts, such as a primary between two logicals.
151
srs5694699941e2011-03-21 21:33:57 -0400152* Partition numbering -- In most Linux tools, partitions 1-4 are primaries
srs5694bf8950c2011-03-12 01:23:12 -0500153 and partitions 5 and up are logicals. Although a legal partition table
154 loaded into FixParts will initially conform to this convention, some
155 types of damaged table might not, and various changes you make can also
156 cause deviations. When FixParts writes the partition table, its numbering
157 will be altered to conform to the standard MBR conventions, but you
158 should use the explicit labeling of partitions as primary or logical
159 rather than the partition numbers to determine a partition's status.
160
srs5694e7b4ff92009-08-18 13:16:10 -0400161Installing
162----------
163
srs56943c0af382010-01-15 19:19:18 -0500164To compile GPT fdisk, you must have appropriate development tools
165installed, most notably the GNU Compiler Collection (GCC) and its g++
srs5694bf8950c2011-03-12 01:23:12 -0500166compiler for C++. (Under Windows, Microsoft Visual C++ 2008 can also be
167used.) In addition, note these requirements:
srs56946699b012010-02-04 00:55:30 -0500168
srs56940741fa22013-01-09 12:55:40 -0500169* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is
170 the standard for Linux and OS X, although you may need to install a
171 package called uuid-dev or something similar to get the headers. On
172 FreeBSD, the e2fsprogs-libuuid port must be installed.
srs56946699b012010-02-04 00:55:30 -0500173
srs569400b6d7a2011-06-26 22:40:06 -0400174* The ICU library (http://site.icu-project.org), which provides support for
175 Unicode partition names, is recommended on all
176 platforms except Windows. This library is normally installed in Linux and
177 OS X, but you may need to install the development headers (libicu-dev or
178 something similar in Linux; or the libicu36-dev Fink package in OS X). To
179 compile without ICU support, you must modify the Makefile: Remove the
180 "-D USE_UTF16" part from the CXXFLAGS line and remove references to
181 -licuio, -licuuc, -licudata, and -licucore (details vary between
182 platforms) from the compilation options. Suitable lines are present, but
srs56940741fa22013-01-09 12:55:40 -0500183 commented out, in the Makefile, Makefile.solaris, Makefile.freebsd files.
184 Because of problems with ICU under OS X, the Makefile.mac file doesn't
185 build against ICU by default.
srs56945a608532011-03-17 13:53:01 -0400186
srs5694f502e522011-09-10 21:23:51 -0400187* The cgdisk program requires the ncurses library and its development files
188 (headers). Most Linux distributions install ncurses by default, but you
189 may need to install a package called libncurses5-dev, ncurses-devel, or
190 something similar to obtain the header files. These files were installed
191 already on my Mac OS X development system; however, they may have been
192 installed as dependencies of other programs I've installed. If you're
193 having problems installing ncurses, you can compile gdisk and/or sgdisk
194 without cgdisk by specifying only the targets you want to compile to
195 make.
196
197* The sgdisk program requires the popt library and its development files
198 (headers). Most Linux distributions install popt by default, but you may
199 need to install a package called popt-dev, popt-devel, or something
200 similar to obtain the header files. Mac OS users can find a version of
201 popt for Mac OS from Darwin Ports (http://popt.darwinports.com) or Fink
202 (http://www.finkproject.org); however, you'll first need to install
203 DarwinPorts or Fink (instructions exist on the relevant projects' pages).
204 Alternatively, you can compile gdisk and/or cgdisk alone, without sgdisk;
205 gdisk doesn't require popt.
srs5694ba00fed2010-01-12 18:18:36 -0500206
207When all the necessary development tools and libraries are installed, you
208can uncompress the package and type "make" at the command prompt in the
srs56946699b012010-02-04 00:55:30 -0500209resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
srs56940741fa22013-01-09 12:55:40 -0500210X, "make -f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on
211Solaris, or "make -f Makefile.mingw" to compile using MinGW for Windows.)
212You may also need to add header (include) directories or library
213directories by setting the CXXFLAGS environment variable or by editing the
214Makefile. The result should be program files called gdisk, cgdisk, sgdisk,
215and fixparts. Typing "make gdisk", "make cgdisk", "make sgdisk", or "make
216fixparts" will compile only the requested programs. You can use these
217programs in place or copy the files to a suitable directory, such as
218/usr/local/sbin. You can copy the man pages (gdisk.8, cgdisk.8, sgdisk.8,
219and fixparts.8) to /usr/local/man/man8 to make them available.
srs5694e7b4ff92009-08-18 13:16:10 -0400220
221Caveats
222-------
223
srs56945d58fe02010-01-03 20:57:08 -0500224THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
225CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
srs569400b6d7a2011-06-26 22:40:06 -0400226drives, physical hard disks, and virtual disks in the QEMU and VirtualBox
227environments. Many others have now used the software on their computers, as
228well. I believe all data-corruption bugs to be squashed, but I know full well
229that the odds of my missing something are high. This is particularly true for
230large (over-2TiB) drives; my only direct testing with such disks is with
231virtual QEMU and VirtualBox disks. I've received user reports of success with
232RAID arrays over 2TiB in size, though.
srs5694e7b4ff92009-08-18 13:16:10 -0400233
234My main development platform is a system running the 64-bit version of
srs56940741fa22013-01-09 12:55:40 -0500235Gentoo Linux. I've also tested on several other 32- and 64-bit Linux
236distributions, Intel-based Mac OS X 10.5 and 10.6, 64-bit FreeBSD 7.1, and
237Windows 7.
srs5694e7b4ff92009-08-18 13:16:10 -0400238
239Redistribution
240--------------
241
242This program is licensed under terms of the GNU GPL (see the file COPYING).
243
244Acknowledgements
245----------------
246
247This code is mostly my own; however, I've used three functions from two
248other GPLed programs:
249
250- The code used to generate CRCs is taken from the efone program by
251 Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
252 crc32.cc source code files.)
253
srs56949ba54212010-05-18 23:24:02 -0400254- A function to find the disk size is taken from Linux fdisk by A. V. Le
255 Blanc. This code has subsequently been heavily modified.
srs5694e7b4ff92009-08-18 13:16:10 -0400256
257Additional code contributors include:
258
259- Yves Blusseau (1otnwmz02@sneakemail.com)
260
srs56947f244ba2009-08-18 14:22:12 -0400261- David Hubbard (david.c.hubbard@gmail.com)
srs5694bf8950c2011-03-12 01:23:12 -0500262
263- Justin Maggard (justin.maggard@netgear.com)
264
265- Dwight Schauer (dschauer@ti.com)
266
267- Florian Zumbiehl (florz@florz.de)
srs5694f502e522011-09-10 21:23:51 -0400268
269- Guillaume Delacour (contributed the gdisk_test.sh script)