Blame README

Packit 062bc7
GPT fdisk (aka gdisk, cgdisk, and sgdisk) and FixParts
Packit 062bc7
by Roderick W. Smith, rodsmith@rodsbooks.com
Packit 062bc7
Packit 062bc7
Introduction
Packit 062bc7
------------
Packit 062bc7
Packit 062bc7
This package includes the source code for four related disk partitioning
Packit 062bc7
programs:
Packit 062bc7
Packit 062bc7
- gdisk -- This program is modeled after Linux fdisk, but it operates on
Packit 062bc7
  GUID Partition Table (GPT) disks rather than the Master Boot Record (MBR)
Packit 062bc7
  disks that fdisk modifies. As such, gdisk is an interactive text-mode
Packit 062bc7
  tool for manipulating partitions, but it does nothing to the contents of
Packit 062bc7
  those partitions (usually filesystems, but sometimes swap space or other
Packit 062bc7
  data).
Packit 062bc7
Packit 062bc7
- cgdisk -- This program is modeled after Linux cfdisk, but it operates on
Packit 062bc7
  GPT disks rather than the MBR disks that cfdisk modifies. As such, cgdisk
Packit 062bc7
  is a curses-based text-mode tool for manipulating partitions, which is to
Packit 062bc7
  say that it uses an interface that relies on arrow keys and a dynamic
Packit 062bc7
  display rather than the command letters and a scrolling display like
Packit 062bc7
  gdisk uses.
Packit 062bc7
Packit 062bc7
- sgdisk -- This program is conceptually similar to the Linux sfdisk and
Packit 062bc7
  FreeBSD gpt programs, but its operational details differ. It enables
Packit 062bc7
  manipulation of GPT disks using command-line options, so it's suitable
Packit 062bc7
  for use in scripts or by experts to perform specific tasks that might
Packit 062bc7
  take several commands in gdisk to accomplish.
Packit 062bc7
Packit 062bc7
- fixparts -- This program, unlike the preceding three, operates on MBR
Packit 062bc7
  disks. It's intended to fix certain problems that can be created by
Packit 062bc7
  various utilities. Specifically, it can fix mis-sized extended partitions
Packit 062bc7
  and primary partitions located in the middle of extended partitions. It
Packit 062bc7
  also enables changing primary vs. logical partition status (within limits
Packit 062bc7
  of what's legal in the MBR scheme) and making a few other minor changes.
Packit 062bc7
  It does NOT support creating new partitions; for that, you should use
Packit 062bc7
  fdisk, parted, or some other tool.
Packit 062bc7
Packit 062bc7
More details about the abilities of these tools follows.
Packit 062bc7
Packit 062bc7
All four programs rely on the same set of underlying code base; they differ
Packit 062bc7
only in their control interfaces (defined in gdisk.cc, cgdisk.cc,
Packit 062bc7
sgdisk.cc, and fixparts.cc, respectively) and in which support code they
Packit 062bc7
use.
Packit 062bc7
Packit 062bc7
GPT fdisk (gdisk, cgdisk, and sgdisk) Details
Packit 062bc7
---------------------------------------------
Packit 062bc7
Packit 062bc7
The gdisk program is intended as a (somewhat) fdisk-workalike program for
Packit 062bc7
GPT-partitioned disks, cgdisk is similarly a workalike for fdisk, and
Packit 062bc7
sgdisk provides most of gdisk's functionality in a more script-friendly
Packit 062bc7
program. Although libparted and programs that use it (GNU Parted, gparted,
Packit 062bc7
etc.) provide the ability to handle GPT disks, they have certain
Packit 062bc7
limitations that gdisk overcomes. Specific advantages of gdisk, cgdisk, and
Packit 062bc7
sgdisk include:
Packit 062bc7
Packit 062bc7
* The ability to convert MBR-partitioned disks in-place to GPT format,
Packit 062bc7
  without losing data
Packit 062bc7
Packit 062bc7
* The ability to convert BSD disklabels in-place to create GPT
Packit 062bc7
  partitions, without losing data
Packit 062bc7
Packit 062bc7
* The ability to convert from GPT format to MBR format without data loss
Packit 062bc7
  (gdisk and sgdisk only)
Packit 062bc7
Packit 062bc7
* More flexible specification of filesystem type code GUIDs, which
Packit 062bc7
  GNU Parted tends to corrupt
Packit 062bc7
Packit 062bc7
* Clear identification of the number of unallocated sectors on a
Packit 062bc7
  disk
Packit 062bc7
Packit 062bc7
* A user interface that's familiar to long-time users of Linux
Packit 062bc7
  fdisk and cfdisk (gdisk and cgdisk only)
Packit 062bc7
Packit 062bc7
* The MBR boot loader code is left alone
Packit 062bc7
Packit 062bc7
* The ability to create a hybrid MBR, which permits GPT-unaware OSes to
Packit 062bc7
  access up to three GPT partitions on the disk (gdisk and sgdisk only)
Packit 062bc7
Packit 062bc7
Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
Packit 062bc7
the filesystem awareness and filesystem-related features of GParted. You
Packit 062bc7
can't resize a partition's filesystem or create a partition with a
Packit 062bc7
filesystem already in place with gdisk, for instance. There's no GUI
Packit 062bc7
version of gdisk.
Packit 062bc7
Packit 062bc7
The GPT fdisk package provides three program files: the interactive
Packit 062bc7
text-mode gdisk, the curses-based interactive cgdisk, and the
Packit 062bc7
command-line-driven sgdisk. The first two are intended for use in manually
Packit 062bc7
partitioning disks or changing partitioning details; sgdisk is intended for
Packit 062bc7
use in scripts to help automate tasks such as disk cloning or preparing
Packit 062bc7
multiple disks for Linux installation.
Packit 062bc7
Packit 062bc7
FixParts Details
Packit 062bc7
----------------
Packit 062bc7
Packit 062bc7
This program's creation was motivated by cries for help I've seen in online
Packit 062bc7
forums from users who have found their partition tables to be corrupted by
Packit 062bc7
various buggy partitioning tools. Although most OSes can handle the
Packit 062bc7
afflicted disks fine, libparted-based tools (GParted, parted, most Linux
Packit 062bc7
installers, etc.) tend to flake out when presented with these disks.
Packit 062bc7
Typically, the symptom is a disk that appears to hold no partitions;
Packit 062bc7
however, sometimes the libparted tool presents partitions other than those
Packit 062bc7
that the OS sees.
Packit 062bc7
Packit 062bc7
I've observed four causes of these symptoms, three of which FixParts can
Packit 062bc7
correct:
Packit 062bc7
Packit 062bc7
* Old GPT data -- If a disk is used as a GPT disk and then re-used as an
Packit 062bc7
  MBR disk, the GPT data may be incompletely erased. This happens if the
Packit 062bc7
  disk is repartitioned with fdisk or the Microsoft Windows installer, for
Packit 062bc7
  instance. (Tools based on libparted correctly remove the old GPT data
Packit 062bc7
  when converting from GPT to MBR format.) FixParts checks for this problem
Packit 062bc7
  when it starts and offers to correct it. If you opt to erase the GPT
Packit 062bc7
  data, this erasure occurs immediately, unlike other changes the program
Packit 062bc7
  makes.
Packit 062bc7
Packit 062bc7
* Mis-sized extended partitions -- Some tools create an extended partition
Packit 062bc7
  that's too large, typically ending after the last sector of the disk.
Packit 062bc7
  FixParts automatically corrects this problem (if you use the 'w' option
Packit 062bc7
  to save the partition table).
Packit 062bc7
Packit 062bc7
* Primary partitions inside an extended partition -- Some utilities create
Packit 062bc7
  or move primary partitions to within the range covered by the extended
Packit 062bc7
  partition. FixParts can usually correct this problem by turning the
Packit 062bc7
  primary partition into a logical partition or by changing one or more
Packit 062bc7
  other logical partitions into primaries. Such corrections aren't always
Packit 062bc7
  possible, though, at least not without deleting or resizing other
Packit 062bc7
  partitions.
Packit 062bc7
Packit 062bc7
* Leftover RAID data -- If a disk is used in a RAID array and then re-used
Packit 062bc7
  as a non-RAID disk, some utilities can become confused and fail to see
Packit 062bc7
  the disk. FixParts can NOT correct this problem. You must destroy the old
Packit 062bc7
  RAID data, or possibly remove the dmraid package from the system, to fix
Packit 062bc7
  this problem.
Packit 062bc7
Packit 062bc7
When run, FixParts presents an fdisk-like interface, enabling you to adjust
Packit 062bc7
partition types (primary, logical, or omitted), change type codes, change
Packit 062bc7
the bootable flag, and so on. Although you can delete a partition (by
Packit 062bc7
omitting it), you can't create new partitions with the program. If you're
Packit 062bc7
used to partitioning disks, particularly with Linux fdisk, two unusual
Packit 062bc7
features of FixParts require elaboration:
Packit 062bc7
Packit 062bc7
* No extended partitions -- Internally, FixParts reads the partition table
Packit 062bc7
  and discards data on any extended partition(s) it finds. When you save
Packit 062bc7
  the partition table, the program generates a new extended partition. This
Packit 062bc7
  design means that the program automatically corrects many problems
Packit 062bc7
  related to the extended partition. It also means that you'll see no
Packit 062bc7
  evidence of extended partitions in the FixParts user interface, although
Packit 062bc7
  it keeps track of the requirements and prevents you from creating illegal
Packit 062bc7
  layouts, such as a primary between two logicals.
Packit 062bc7
Packit 062bc7
* Partition numbering -- In most Linux tools, partitions 1-4 are primaries
Packit 062bc7
  and partitions 5 and up are logicals. Although a legal partition table
Packit 062bc7
  loaded into FixParts will initially conform to this convention, some
Packit 062bc7
  types of damaged table might not, and various changes you make can also
Packit 062bc7
  cause deviations. When FixParts writes the partition table, its numbering
Packit 062bc7
  will be altered to conform to the standard MBR conventions, but you
Packit 062bc7
  should use the explicit labeling of partitions as primary or logical
Packit 062bc7
  rather than the partition numbers to determine a partition's status.
Packit 062bc7
Packit 062bc7
Installing
Packit 062bc7
----------
Packit 062bc7
Packit 062bc7
To compile GPT fdisk, you must have appropriate development tools
Packit 062bc7
installed, most notably the GNU Compiler Collection (GCC) and its g++
Packit 062bc7
compiler for C++. I've also tested compilation with Clang, which seems to
Packit 062bc7
work; however, I've not done extensive testing of the resulting binaries,
Packit 062bc7
beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can
Packit 062bc7
be used instead. In addition, note these requirements:
Packit 062bc7
Packit 062bc7
* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is
Packit 062bc7
  the standard for Linux and OS X, although you may need to install a
Packit 062bc7
  package called uuid-dev or something similar to get the headers. On
Packit 062bc7
  FreeBSD, the e2fsprogs-libuuid port must be installed.
Packit 062bc7
Packit 062bc7
* The ICU library (http://site.icu-project.org), which provides support for
Packit 062bc7
  Unicode partition names, is optional on all platforms except Windows, on
Packit 062bc7
  which it's not supported. Using this library was required to get proper
Packit 062bc7
  UTF-16 partition name support in GPT fdisk versions prior to 0.8.9, but
Packit 062bc7
  as of that version it should not longer be required. Nonetheless, you can
Packit 062bc7
  use it if you're having problems with the new UTF-16 support. This
Packit 062bc7
  library is normally installed in Linux and OS X, but you may need to
Packit 062bc7
  install the development headers (libicu-dev or something similar in
Packit 062bc7
  Linux; or the libicu36-dev Fink package in OS X). To compile with ICU
Packit 062bc7
  support, you must modify the Makefile: Look for commented-out lines that
Packit 062bc7
  refer to USE_UTF16, -licuuc, -licudata, or -licucore. Uncomment them and
Packit 062bc7
  comment out the equivalents that lack these lines.
Packit 062bc7
Packit 062bc7
* The cgdisk program requires the ncurses library and its development files
Packit 062bc7
  (headers). Most Linux distributions install ncurses by default, but you
Packit 062bc7
  may need to install a package called libncurses5-dev, ncurses-devel, or
Packit 062bc7
  something similar to obtain the header files. These files were installed
Packit 062bc7
  already on my Mac OS X development system; however, they may have been
Packit 062bc7
  installed as dependencies of other programs I've installed. If you're
Packit 062bc7
  having problems installing ncurses, you can compile gdisk and/or sgdisk
Packit 062bc7
  without cgdisk by specifying only the targets you want to compile to
Packit 062bc7
  make.
Packit 062bc7
Packit 062bc7
* The sgdisk program requires the popt library and its development files
Packit 062bc7
  (headers). Most Linux distributions install popt by default, but you may
Packit 062bc7
  need to install a package called popt-dev, popt-devel, or something
Packit 062bc7
  similar to obtain the header files. Mac OS users can find a version of
Packit 062bc7
  popt for Mac OS from Darwin Ports (http://popt.darwinports.com), MacPorts
Packit 062bc7
  (https://trac.macports.org/browser/trunk/dports/devel/popt/Portfile), or
Packit 062bc7
  Fink (http://www.finkproject.org);  however, you'll first need to install
Packit 062bc7
  DarwinPorts, MacPorts, or Fink (instructions exist on the relevant
Packit 062bc7
  projects' pages). Alternatively, you can compile gdisk and/or cgdisk
Packit 062bc7
  alone, without sgdisk; gdisk doesn't require popt.
Packit 062bc7
Packit 062bc7
When all the necessary development tools and libraries are installed, you
Packit 062bc7
can uncompress the package and type "make" at the command prompt in the
Packit 062bc7
resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS
Packit 062bc7
X, "make -f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on
Packit 062bc7
Solaris, or "make -f Makefile.mingw" to compile using MinGW for Windows.)
Packit 062bc7
You may also need to add header (include) directories or library
Packit 062bc7
directories by setting the CXXFLAGS environment variable or by editing the
Packit 062bc7
Makefile. The result should be program files called gdisk, cgdisk, sgdisk,
Packit 062bc7
and fixparts. Typing "make gdisk", "make cgdisk", "make sgdisk", or "make
Packit 062bc7
fixparts" will compile only the requested programs. You can use these
Packit 062bc7
programs in place or copy the files to a suitable directory, such as
Packit 062bc7
/usr/local/sbin. You can copy the man pages (gdisk.8, cgdisk.8, sgdisk.8,
Packit 062bc7
and fixparts.8) to /usr/local/man/man8 to make them available.
Packit 062bc7
Packit 062bc7
Caveats
Packit 062bc7
-------
Packit 062bc7
Packit 062bc7
THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR
Packit 062bc7
CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash
Packit 062bc7
drives, physical hard disks, and virtual disks in the QEMU and VirtualBox
Packit 062bc7
environments. Many others have now used the software on their computers, as
Packit 062bc7
well. I believe all data-corruption bugs to be squashed, but I know full well
Packit 062bc7
that the odds of my missing something are high. This is particularly true for
Packit 062bc7
large (over-2TiB) drives; my only direct testing with such disks is with
Packit 062bc7
virtual QEMU and VirtualBox disks. I've received user reports of success with
Packit 062bc7
RAID arrays over 2TiB in size, though.
Packit 062bc7
Packit 062bc7
My main development platform is a system running the 64-bit version of
Packit 062bc7
Ubuntu Linux. I've also tested on several other 32- and 64-bit Linux
Packit 062bc7
distributions, Intel-based Mac OS X 10.6 and several later versions, 64-bit
Packit 062bc7
FreeBSD 7.1, and Windows 7 and 10.
Packit 062bc7
Packit 062bc7
Redistribution
Packit 062bc7
--------------
Packit 062bc7
Packit 062bc7
This program is licensed under terms of the GNU GPL (see the file COPYING).
Packit 062bc7
Packit 062bc7
Acknowledgements
Packit 062bc7
----------------
Packit 062bc7
Packit 062bc7
This code is mostly my own; however, I've used three functions from two
Packit 062bc7
other GPLed programs:
Packit 062bc7
Packit 062bc7
- The code used to generate CRCs is taken from the efone program by
Packit 062bc7
  Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
Packit 062bc7
  crc32.cc source code files.)
Packit 062bc7
Packit 062bc7
- A function to find the disk size is taken from Linux fdisk by A. V. Le
Packit 062bc7
  Blanc. This code has subsequently been heavily modified.
Packit 062bc7
Packit 062bc7
Additional code contributors include:
Packit 062bc7
Packit 062bc7
- Yves Blusseau (1otnwmz02@sneakemail.com)
Packit 062bc7
Packit 062bc7
- David Hubbard (david.c.hubbard@gmail.com)
Packit 062bc7
Packit 062bc7
- Justin Maggard (justin.maggard@netgear.com)
Packit 062bc7
Packit 062bc7
- Dwight Schauer (dschauer@ti.com)
Packit 062bc7
Packit 062bc7
- Florian Zumbiehl (florz@florz.de)
Packit 062bc7
Packit 062bc7
- Guillaume Delacour (contributed the gdisk_test.sh script)