NameDateSize

..29-Aug-201712 KiB

Android.mk29-Aug-20171,017

android_popt.cc29-Aug-20173.5 KiB

attributes.cc29-Aug-20177.4 KiB

attributes.h29-Aug-20171.2 KiB

basicmbr.cc29-Aug-201757.8 KiB

basicmbr.h29-Aug-20175 KiB

bsd.cc29-Aug-201711.4 KiB

bsd.h29-Aug-20173.7 KiB

cgdisk.829-Aug-201715.7 KiB

cgdisk.cc29-Aug-20172.5 KiB

COPYING29-Aug-201717.6 KiB

crc32.cc29-Aug-20171.6 KiB

crc32.h29-Aug-2017610

current.spec29-Aug-20172.5 KiB

diskio-unix.cc29-Aug-201714.6 KiB

diskio-windows.cc29-Aug-201710.4 KiB

diskio.cc29-Aug-20172.1 KiB

diskio.h29-Aug-20171.9 KiB

fixparts.829-Aug-201710.6 KiB

fixparts.cc29-Aug-20173.6 KiB

gdisk.829-Aug-201727.6 KiB

gdisk.cc29-Aug-20172 KiB

gdisk_test.sh29-Aug-20177.7 KiB

gpt.cc29-Aug-201794.4 KiB

gpt.h29-Aug-20177.6 KiB

gptcl.cc29-Aug-201723 KiB

gptcl.h29-Aug-20171.8 KiB

gptcurses.cc29-Aug-201726.3 KiB

gptcurses.h29-Aug-20174.3 KiB

gptpart.cc29-Aug-201713.8 KiB

gptpart.h29-Aug-20173.7 KiB

gpttext.cc29-Aug-201734.5 KiB

gpttext.h29-Aug-20172.5 KiB

guid.cc29-Aug-20177.3 KiB

guid.h29-Aug-20171.6 KiB

Makefile29-Aug-20171.3 KiB

Makefile.freebsd29-Aug-20171.5 KiB

Makefile.mac29-Aug-20171.5 KiB

Makefile.mingw29-Aug-20171.3 KiB

Makefile.mingw6429-Aug-20171.3 KiB

mbr.cc29-Aug-20176.1 KiB

mbr.h29-Aug-20171.2 KiB

mbrpart.cc29-Aug-201711.3 KiB

mbrpart.h29-Aug-20173.8 KiB

MODULE_LICENSE_GPL29-Aug-20170

NEWS29-Aug-201747.7 KiB

NOTICE29-Aug-201717.6 KiB

parttypes.cc29-Aug-201719.1 KiB

parttypes.h29-Aug-20171.9 KiB

popt.h29-Aug-20171.8 KiB

README29-Aug-201713 KiB

README.Windows29-Aug-20176.9 KiB

sgdisk.829-Aug-201726.1 KiB

sgdisk.cc29-Aug-20172.7 KiB

support.cc29-Aug-201711.6 KiB

support.h29-Aug-20172.4 KiB

README

1GPT fdisk (aka gdisk, cgdisk, and sgdisk) and FixParts
2by Roderick W. Smith, rodsmith@rodsbooks.com
3
4Introduction
5------------
6
7This package includes the source code for four related disk partitioning
8programs:
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- 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
24- 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
30- fixparts -- This program, unlike the preceding three, operates on MBR
31  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
41All 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.
45
46GPT fdisk (gdisk, cgdisk, and sgdisk) Details
47---------------------------------------------
48
49The gdisk program is intended as a (somewhat) fdisk-workalike program for
50GPT-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:
56
57* The ability to convert MBR-partitioned disks in-place to GPT format,
58  without losing data
59
60* The ability to convert BSD disklabels in-place to create GPT
61  partitions, without losing data
62
63* The ability to convert from GPT format to MBR format without data loss
64  (gdisk and sgdisk only)
65
66* More flexible specification of filesystem type code GUIDs, which
67  GNU Parted tends to corrupt
68
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
73  fdisk and cfdisk (gdisk and cgdisk only)
74
75* The MBR boot loader code is left alone
76
77* 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)
79
80Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
81the filesystem awareness and filesystem-related features of GParted. You
82can'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
86The 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.
92
93FixParts 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
108* Old GPT data -- If a disk is used as a GPT disk and then re-used as an
109  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
117* Mis-sized extended partitions -- Some tools create an extended partition
118  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
122* Primary partitions inside an extended partition -- Some utilities create
123  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
130* Leftover RAID data -- If a disk is used in a RAID array and then re-used
131  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
143* No extended partitions -- Internally, FixParts reads the partition table
144  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
152* Partition numbering -- In most Linux tools, partitions 1-4 are primaries
153  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
161Installing
162----------
163
164To compile GPT fdisk, you must have appropriate development tools
165installed, most notably the GNU Compiler Collection (GCC) and its g++
166compiler for C++. I've also tested compilation with Clang, which seems to
167work; however, I've not done extensive testing of the resulting binaries,
168beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can
169be used instead. In addition, note these requirements:
170
171* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is
172  the standard for Linux and OS X, although you may need to install a
173  package called uuid-dev or something similar to get the headers. On
174  FreeBSD, the e2fsprogs-libuuid port must be installed.
175
176* The ICU library (http://site.icu-project.org), which provides support for
177  Unicode partition names, is optional on all platforms except Windows, on
178  which it's not supported. Using this library was required to get proper
179  UTF-16 partition name support in GPT fdisk versions prior to 0.8.9, but
180  as of that version it should not longer be required. Nonetheless, you can
181  use it if you're having problems with the new UTF-16 support. This
182  library is normally installed in Linux and OS X, but you may need to
183  install the development headers (libicu-dev or something similar in
184  Linux; or the libicu36-dev Fink package in OS X). To compile with ICU
185  support, you must modify the Makefile: Look for commented-out lines that
186  refer to USE_UTF16, -licuuc, -licudata, or -licucore. Uncomment them and
187  comment out the equivalents that lack these lines.
188
189* The cgdisk program requires the ncurses library and its development files
190  (headers). Most Linux distributions install ncurses by default, but you
191  may need to install a package called libncurses5-dev, ncurses-devel, or
192  something similar to obtain the header files. These files were installed
193  already on my Mac OS X development system; however, they may have been
194  installed as dependencies of other programs I've installed. If you're
195  having problems installing ncurses, you can compile gdisk and/or sgdisk
196  without cgdisk by specifying only the targets you want to compile to
197  make.
198
199* The sgdisk program requires the popt library and its development files
200  (headers). Most Linux distributions install popt by default, but you may
201  need to install a package called popt-dev, popt-devel, or something
202  similar to obtain the header files. Mac OS users can find a version of
203  popt for Mac OS from Darwin Ports (http://popt.darwinports.com) or Fink
204  (http://www.finkproject.org); however, you'll first need to install
205  DarwinPorts or Fink (instructions exist on the relevant projects' pages).
206  Alternatively, you can compile gdisk and/or cgdisk alone, without sgdisk;
207  gdisk doesn't require popt.
208
209When all the necessary development tools and libraries are installed, you
210can uncompress the package and type "make" at the command prompt in the
211resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
212X, "make -f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on
213Solaris, or "make -f Makefile.mingw" to compile using MinGW for Windows.)
214You may also need to add header (include) directories or library
215directories by setting the CXXFLAGS environment variable or by editing the
216Makefile. The result should be program files called gdisk, cgdisk, sgdisk,
217and fixparts. Typing "make gdisk", "make cgdisk", "make sgdisk", or "make
218fixparts" will compile only the requested programs. You can use these
219programs in place or copy the files to a suitable directory, such as
220/usr/local/sbin. You can copy the man pages (gdisk.8, cgdisk.8, sgdisk.8,
221and fixparts.8) to /usr/local/man/man8 to make them available.
222
223Caveats
224-------
225
226THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
227CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
228drives, physical hard disks, and virtual disks in the QEMU and VirtualBox
229environments. Many others have now used the software on their computers, as
230well. I believe all data-corruption bugs to be squashed, but I know full well
231that the odds of my missing something are high. This is particularly true for
232large (over-2TiB) drives; my only direct testing with such disks is with
233virtual QEMU and VirtualBox disks. I've received user reports of success with
234RAID arrays over 2TiB in size, though.
235
236My main development platform is a system running the 64-bit version of
237Gentoo Linux. I've also tested on several other 32- and 64-bit Linux
238distributions, Intel-based Mac OS X 10.5 and 10.6, 64-bit FreeBSD 7.1, and
239Windows 7.
240
241Redistribution
242--------------
243
244This program is licensed under terms of the GNU GPL (see the file COPYING).
245
246Acknowledgements
247----------------
248
249This code is mostly my own; however, I've used three functions from two
250other GPLed programs:
251
252- The code used to generate CRCs is taken from the efone program by
253  Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
254  crc32.cc source code files.)
255
256- A function to find the disk size is taken from Linux fdisk by A. V. Le
257  Blanc. This code has subsequently been heavily modified.
258
259Additional code contributors include:
260
261- Yves Blusseau (1otnwmz02@sneakemail.com)
262
263- David Hubbard (david.c.hubbard@gmail.com)
264
265- Justin Maggard (justin.maggard@netgear.com)
266
267- Dwight Schauer (dschauer@ti.com)
268
269- Florian Zumbiehl (florz@florz.de)
270
271- Guillaume Delacour (contributed the gdisk_test.sh script)
272

README.Windows

1GPT fdisk (aka gdisk) and FixParts
2
3by Roderick W. Smith, rodsmith@rodsbooks.com
4
5******************************** IMPORTANT ********************************
6Most versions of Windows cannot boot from a GPT disk on BIOS-based
7computers, and most varieties prior to Vista cannot read GPT disks. GPT
8fdisk is a partition editor for GPT disks, and it will *AUTOMATICALLY
9CONVERT* MBR disks to GPT form. Therefore, you should **NOT** use GPT fdisk
10on a Windows system unless you fully understand what you're doing or are
11certain that your computer boots in EFI/UEFI mode! If you accidentally use
12GPT fdisk on a BIOS-mode boot disk, or perhaps even on a data disk, you may
13find recovery to be very difficult! Pre-installed Windows 8 and later
14systems almost always use GPT disks and boot in EFI/UEFI mode, but
15self-installed Windows 8 systems sometimes use BIOS mode. This caveat does
16not apply to FixParts, though; that tool works only on MBR disks.
17***************************************************************************
18
19Read the main README file for general information on the program, and read
20the gdisk.html or fixparts.html documents (the Linux man pages converted to
21HTML format) for detailed use information. My GPT fdisk Web page,
22http://www.rodsbooks.com/gdisk/, provides a more tutorial introduction to
23the software. I originally wrote GPT fdisk on Linux, and some Linux- and
24Unix-centric language remains in the documentation.
25
26Windows Use Notes
27-----------------
28
29The Windows version of GPT fdisk was added with version 0.6.2 of the
30package. The Windows binary package includes the gdisk.exe interactive
31text-mode program file but no equivalent to the sgdisk program that's
32available with Linux, FreeBSD, and OS X builds. In theory, an sgdisk.exe
33for Windows could be built if the popt library were installed. I've not
34attempted to do this myself, though. If you care to try, check
35http://gnuwin32.sourceforge.net/packages/popt.htm for information on popt
36for Windows.
37
38Beginning with version 0.8.10, I'm distributing both 32-bit and 64-bit
39binaries, which include the strings "32" or "64" in their names. The 32-bit
40binaries work fine on most versions of Windows, but some 64-bit
41installations of Windows 8 lack 32-bit support libraries and so may need
42the 64-bit binaries.
43
44The FixParts program (fixparts32.exe and fixparts64.exe) is new with GPT
45fdisk 0.7.0. As described in the main README file, this program fixes
46certain partition table problems that can be created by buggy partitioning
47software. Windows seems to be unfazed by most such problems, but I've not
48done an extensive survey of Windows partitioning tools on this score.
49
50To install the programs, copy the gdisk32.exe and fixparts32.exe (or
51gdisk64.exe and fixparts64.exe) program files to any directory on your
52path, such as C:\Windows. Alternatively, you can change to the program's
53directory or type its complete path whenever you use it.
54
55To use the programs, first launch a Command Prompt as the Administrator. To
56do this, locate the Command Prompt program icon, right-click it, and select
57"Run as Administrator." If you use a non-Administrator Command Prompt, you
58won't be able to edit hard disk partition tables, although you will be able
59to edit raw disk image files.
60
61The program requires a hard disk identifier as an option. You can specify
62this in either of two forms. The first way is as a number followed by a
63colon, as in:
64
65gdisk 0:
66
67Disks are numbered starting from 0, so the preceding command launches gdisk
68on the first disk. The second way to specify a disk device is via a
69harder-to-remember name:
70
71gdisk32 \\.\physicaldrive0
72
73This command is equivalent to the earlier one -- it edits the partition
74table on the first physical disk. Change the number at the end of the
75device name to change the disk edited.
76
77If you pass the "-l" option to gdisk.exe in addition to the disk
78identifier, the program displays the current partition table information
79and then exits. This use entails no risk to MBR disks, since the program
80never writes data back to the disk when used in this way.
81
82As noted above, editing the first disk with GPT fdisk is usually a Bad
83Idea. An exception would be if your system uses an Extensible Firmware
84Interface (EFI) and already boots from a GPT disk. It's safer to edit
85non-boot disks, which usually have numbers of 1 and above, but only if you
86run a version of Windows with GPT support. For more information on Windows'
87support of GPT, see Microsoft's Web page on the topic:
88
89http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx
90
91The Windows binaries I've compiled do not support Unicode UTF-16LE GPT
92partition names. This feature was added to version 0.7.1 of the software
93for Linux, FreeBSD, and OS X, and with changes to some #ifndef lines in the
94source files, it can be compiled for Windows; however, it seems to do
95little good in Windows because of Command Prompt window and/or ICU library
96limitations. Thus, I've omitted this support in the interests of
97simplifying the binary distribution, since including it would mean
98distributing the ICU libraries.
99
100Source Code and Compilation Issues
101----------------------------------
102
103I have successfully compiled GPT fdisk using three different Windows
104compilers:
105
106- MinGW (http://www.mingw.org), and in particular its Linux-hosted
107  cross-compiler -- Under Ubuntu Linux, the Makefile.mingw and
108  Makefile.mingw64 files enable compilation of the software via MinGW.
109  (Type "make -f Makefile.mingw" to compile 32-bit binaries, and "make -f
110  Makefile.mingw64" to compile 64-bit binaries.) If you try to compile
111  using another compiler or even using MinGW under Windows or another Linux
112  variety, you may need to adjust the Makefile.mingw options.
113
114- Microsoft Visual C++ 2008 Express
115  (http://www.microsoft.com/express/Windows/) -- This compiler requires a
116  third-party stdint.h file (I used the one from
117  http://msinttypes.googlecode.com/svn/trunk/stdint.h), but it otherwise
118  works fine. A project is easily created by adding all the *.h files and
119  all the *.cc files except diskio-unix.cc, sgdisk.cc, and whichever
120  program file you intend to NOT build (gdisk.cc or fixparts.cc).
121
122- Microsoft Visual C++ 2010 Express -- This compiler works much like the
123  2008 version, although I didn't need to add a third-party stdint.h file.
124
125The MinGW compiler produces much larger executables than do the MS
126compilers. The resulting binaries seem to work equally well, but my testing
127has been minimal.
128
129I've also attempted to compile the code with OpenWatcom 1.8, but this
130attempt failed, mostly because the compiler can't yet handle iostream
131output on standard C++ strings. OpenWatcom also seems to have incorrectly
132set the value of UINT32_MAX as if uint32_t values were 64-bit integers.
133This alone won't cause the compile to fail, but it would create bugs.
134
135If you modify GPT fdisk to get it to compile under another compiler, I
136welcome submission of patches.
137