• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 as well as the sgdisk program that's available
32with Linux, FreeBSD, and OS X builds.
33
34Beginning with version 0.8.10, I'm distributing both 32-bit and 64-bit
35binaries, which include the strings "32" or "64" in their names. The 32-bit
36binaries work fine on most versions of Windows, but some 64-bit
37installations of Windows 8 lack 32-bit support libraries and so may need
38the 64-bit binaries.
39
40The FixParts program (fixparts32.exe and fixparts64.exe) is new with GPT
41fdisk 0.7.0. As described in the main README file, this program fixes
42certain partition table problems that can be created by buggy partitioning
43software. Windows seems to be unfazed by most such problems, but I've not
44done an extensive survey of Windows partitioning tools on this score.
45
46To install the programs, copy the gdisk32.exe, cgdisk32.exe, sgdisk32.exe
47and fixparts32.exe (or gdisk64.exe, cgdisk64.exe, sgdisk64.exe and
48fixparts64.exe) program files to any directory on your path, such as
49C:\Windows. Alternatively, you can change to the program's directory or type
50its complete path whenever you use it.
51
52To use the programs, first launch a Command Prompt as the Administrator. To
53do this, locate the Command Prompt program icon, right-click it, and select
54"Run as Administrator." If you use a non-Administrator Command Prompt, you
55won't be able to edit hard disk partition tables, although you will be able
56to edit raw disk image files.
57
58The program requires a hard disk identifier as an option. You can specify
59this in either of two forms. The first way is as a number followed by a
60colon, as in:
61
62gdisk 0:
63
64Disks are numbered starting from 0, so the preceding command launches gdisk
65on the first disk. The second way to specify a disk device is via a
66harder-to-remember name:
67
68gdisk32 \\.\physicaldrive0
69
70This command is equivalent to the earlier one -- it edits the partition
71table on the first physical disk. Change the number at the end of the
72device name to change the disk edited.
73
74If you pass the "-l" option to gdisk64.exe in addition to the disk
75identifier, the program displays the current partition table information and
76then exits. (Alternatively, you can pass "-p" to sgdisk64.exe.) This use
77entails no risk to MBR disks, since the program never writes data back to
78the disk when used in this way.
79
80As noted above, editing the first disk with GPT fdisk is a Bad Idea on older
81BIOS-based computers. Newer computers typically use an Extensible Firmware
82Interface (EFI) and boot from GPT disks. It's safer to edit non-boot disks,
83which usually have numbers of 1 and above, but only if you run a version of
84Windows with GPT support. For more information on Windows' support of GPT,
85see Microsoft's Web page on the topic:
86
87http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx
88
89The Windows binaries I've compiled do not support Unicode UTF-16LE GPT
90partition names. This feature was added to version 0.7.1 of the software
91for Linux, FreeBSD, and OS X, and with changes to some #ifndef lines in the
92source files, it can be compiled for Windows; however, it seems to do
93little good in Windows because of Command Prompt window and/or ICU library
94limitations. Thus, I've omitted this support in the interests of
95simplifying the binary distribution, since including it would mean
96distributing the ICU libraries.
97
98Source Code and Compilation Issues
99----------------------------------
100
101I have successfully compiled GPT fdisk using three different Windows
102compilers:
103
104- MinGW (https://www.mingw-w64.org/), using either a Linux-hosted
105  cross-compiler or under Windows using the original MinGW or MSYS2
106  (https://www.msys2.org). This is my only GPT fdisk development environment
107  for Windows in 2022.
108
109- Microsoft Visual C++ 2008 Express
110  (http://www.microsoft.com/express/Windows/) -- This compiler requires a
111  third-party stdint.h file (I used the one from
112  http://web.archive.org/web/20130317001712/http://msinttypes.googlecode.com/svn/trunk/stdint.h),
113  but it otherwise worked fine the last time I tried it. A project is easily
114  created by adding all the *.h files and all the *.cc files except
115  diskio-unix.cc, sgdisk.cc, and whichever program file you intend to NOT
116  build (gdisk.cc or fixparts.cc).
117
118- Microsoft Visual C++ 2010 Express -- This compiler works much like the
119  2008 version, although I didn't need to add a third-party stdint.h file.
120
121Although I used Microsoft Visual C++ in the past, I haven't tried using
122these compilers recently and so I can't promise they would work today (in
1232022).
124
125If you modify GPT fdisk to get it to compile under another compiler, I
126welcome submission of patches.
127
128The following instructions focus on use of MinGW to compile GPT fdisk for
129Windows.
130
131My primary development environment is Ubuntu Linux, using the MinGW
132cross-compiler. This system can compile the gdisk and fixparts binaries with
133no need for additional libraries; after installing MinGW (via the
134g++-mingw-w64 package in Ubuntu, or the equivalent in another distribution),
135you can type "TARGET=win32 make" to compile 32-bit binaries, and
136"TARGET=win64 make" to compile 64-bit binaries. This will attempt to build
137gdisk, sgdisk, and fixparts; but the sgdisk build will fail until you
138install the popt libraries, as described shortly. You can build the other
139binaries by specifying them, as in "TARGET=win64 make gdisk" to build the
14064-bit gdisk binary alone.
141
142If you use Windows, your best bet is likely to be to install the MSYS2
143package (https://www.msys2.org). This package provides MinGW and a package
144management system based on pacman (used by Arch Linux) for installing
145additional libraries. To install the libraries needed to compile sgdisk and
146cgdisk, type "pacman -S mingw-w64-x86_64-popt mingw-w64-x86_64-gettext
147mingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change
148'x86_64' to 'i686' for 32-bit packages. This command will install the popt
149library needed by sgdisk and the ncurses library needed by cgdisk, along
150with gettext, which is needed by popt. With these libraries installed, you
151should be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk,
152and fixparts. Typing "make" alone in the MSYS2 shell should build all four
153programs for the host architecture (x86-64 or i686); to compile for the
154other architecture, you must specify it with a "TARGET=" specification, as
155under Linux. (The Makefile does not currently support ARM64 targets for
156Windows.)
157
158If you want to compile sgdisk for Windows under Linux, you can do so;
159however, you must copy the relevant header and library files from a Windows
160installation to Linux. Specifically, you must copy:
161
162    Windows File                   Linux Directory
163    ------------                   ---------------
164    /mingw64/include/popt.h        /usr/x86_64-w64-mingw32/include/
165    /mingw64/lib/libpopt.a         /usr/x86_64-w64-mingw32/lib/
166    /mingw64/lib/libintl.a         /usr/x86_64-w64-mingw32/lib/
167    /mingw64/lib/libiconv.a        /usr/x86_64-w64-mingw32/lib/
168
169For 32-bit binaries, change /mingw64 to /mingw32 on the Windows source and
170x86_64-w64-mingw32 to i686-w64-mingw32 on the Linux destination.
171
172In theory, you should be able to do something similar to compile cgdisk. The
173relevant files are:
174
175    Windows File                            Linux Directory
176    ------------                            ---------------
177    /mingw64/include/ncursesw/curses.h      /usr/x86_64-w64-mingw32/include/ncursesw/
178    /mingw64/include/ncursesw/ncurses.h     /usr/x86_64-w64-mingw32/include/ncursesw/
179    /mingw64/include/ncursesw/ncurses_dll.h /usr/x86_64-w64-mingw32/include/ncursesw/
180    /mingw64/include/ncursesw/unctrl.h      /usr/x86_64-w64-mingw32/include/ncursesw/
181    /mingw64/lib/libncurses.a               /usr/x86_64-w64-mingw32/lib/
182
183In practice, this has not worked for me; the compilation fails with a
184complaint about an undefined reference to 'nanosleep'. My guess is that the
185ncurses version installed in Windows is too new to work with the MinGW
186libraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with
187another distribution, though.
188
189The Makefile is configured to create statically-linked binaries so as to
190simplify installation of the binaries. If you want smaller binaries, you can
191remove the various static options from the Makefile. You can also strip the
192binaries ("make strip") to remove unused code.
193