1cf200d32Sopenharmony_ciGPT fdisk (aka gdisk) and FixParts
2cf200d32Sopenharmony_ci
3cf200d32Sopenharmony_ciby Roderick W. Smith, rodsmith@rodsbooks.com
4cf200d32Sopenharmony_ci
5cf200d32Sopenharmony_ci******************************** IMPORTANT ********************************
6cf200d32Sopenharmony_ciMost versions of Windows cannot boot from a GPT disk on BIOS-based
7cf200d32Sopenharmony_cicomputers, and most varieties prior to Vista cannot read GPT disks. GPT
8cf200d32Sopenharmony_cifdisk is a partition editor for GPT disks, and it will *AUTOMATICALLY
9cf200d32Sopenharmony_ciCONVERT* MBR disks to GPT form. Therefore, you should **NOT** use GPT fdisk
10cf200d32Sopenharmony_cion a Windows system unless you fully understand what you're doing or are
11cf200d32Sopenharmony_cicertain that your computer boots in EFI/UEFI mode! If you accidentally use
12cf200d32Sopenharmony_ciGPT fdisk on a BIOS-mode boot disk, or perhaps even on a data disk, you may
13cf200d32Sopenharmony_cifind recovery to be very difficult! Pre-installed Windows 8 and later
14cf200d32Sopenharmony_cisystems almost always use GPT disks and boot in EFI/UEFI mode, but
15cf200d32Sopenharmony_ciself-installed Windows 8 systems sometimes use BIOS mode. This caveat does
16cf200d32Sopenharmony_cinot apply to FixParts, though; that tool works only on MBR disks.
17cf200d32Sopenharmony_ci***************************************************************************
18cf200d32Sopenharmony_ci
19cf200d32Sopenharmony_ciRead the main README file for general information on the program, and read
20cf200d32Sopenharmony_cithe gdisk.html or fixparts.html documents (the Linux man pages converted to
21cf200d32Sopenharmony_ciHTML format) for detailed use information. My GPT fdisk Web page,
22cf200d32Sopenharmony_cihttp://www.rodsbooks.com/gdisk/, provides a more tutorial introduction to
23cf200d32Sopenharmony_cithe software. I originally wrote GPT fdisk on Linux, and some Linux- and
24cf200d32Sopenharmony_ciUnix-centric language remains in the documentation.
25cf200d32Sopenharmony_ci
26cf200d32Sopenharmony_ciWindows Use Notes
27cf200d32Sopenharmony_ci-----------------
28cf200d32Sopenharmony_ci
29cf200d32Sopenharmony_ciThe Windows version of GPT fdisk was added with version 0.6.2 of the
30cf200d32Sopenharmony_cipackage. The Windows binary package includes the gdisk.exe interactive
31cf200d32Sopenharmony_citext-mode program file as well as the sgdisk program that's available
32cf200d32Sopenharmony_ciwith Linux, FreeBSD, and OS X builds.
33cf200d32Sopenharmony_ci
34cf200d32Sopenharmony_ciBeginning with version 0.8.10, I'm distributing both 32-bit and 64-bit
35cf200d32Sopenharmony_cibinaries, which include the strings "32" or "64" in their names. The 32-bit
36cf200d32Sopenharmony_cibinaries work fine on most versions of Windows, but some 64-bit
37cf200d32Sopenharmony_ciinstallations of Windows 8 lack 32-bit support libraries and so may need
38cf200d32Sopenharmony_cithe 64-bit binaries.
39cf200d32Sopenharmony_ci
40cf200d32Sopenharmony_ciThe FixParts program (fixparts32.exe and fixparts64.exe) is new with GPT
41cf200d32Sopenharmony_cifdisk 0.7.0. As described in the main README file, this program fixes
42cf200d32Sopenharmony_cicertain partition table problems that can be created by buggy partitioning
43cf200d32Sopenharmony_cisoftware. Windows seems to be unfazed by most such problems, but I've not
44cf200d32Sopenharmony_cidone an extensive survey of Windows partitioning tools on this score.
45cf200d32Sopenharmony_ci
46cf200d32Sopenharmony_ciTo install the programs, copy the gdisk32.exe, cgdisk32.exe, sgdisk32.exe
47cf200d32Sopenharmony_ciand fixparts32.exe (or gdisk64.exe, cgdisk64.exe, sgdisk64.exe and
48cf200d32Sopenharmony_cifixparts64.exe) program files to any directory on your path, such as
49cf200d32Sopenharmony_ciC:\Windows. Alternatively, you can change to the program's directory or type
50cf200d32Sopenharmony_ciits complete path whenever you use it.
51cf200d32Sopenharmony_ci
52cf200d32Sopenharmony_ciTo use the programs, first launch a Command Prompt as the Administrator. To
53cf200d32Sopenharmony_cido this, locate the Command Prompt program icon, right-click it, and select
54cf200d32Sopenharmony_ci"Run as Administrator." If you use a non-Administrator Command Prompt, you
55cf200d32Sopenharmony_ciwon't be able to edit hard disk partition tables, although you will be able
56cf200d32Sopenharmony_cito edit raw disk image files.
57cf200d32Sopenharmony_ci
58cf200d32Sopenharmony_ciThe program requires a hard disk identifier as an option. You can specify
59cf200d32Sopenharmony_cithis in either of two forms. The first way is as a number followed by a
60cf200d32Sopenharmony_cicolon, as in:
61cf200d32Sopenharmony_ci
62cf200d32Sopenharmony_cigdisk 0:
63cf200d32Sopenharmony_ci
64cf200d32Sopenharmony_ciDisks are numbered starting from 0, so the preceding command launches gdisk
65cf200d32Sopenharmony_cion the first disk. The second way to specify a disk device is via a
66cf200d32Sopenharmony_ciharder-to-remember name:
67cf200d32Sopenharmony_ci
68cf200d32Sopenharmony_cigdisk32 \\.\physicaldrive0
69cf200d32Sopenharmony_ci
70cf200d32Sopenharmony_ciThis command is equivalent to the earlier one -- it edits the partition
71cf200d32Sopenharmony_citable on the first physical disk. Change the number at the end of the
72cf200d32Sopenharmony_cidevice name to change the disk edited.
73cf200d32Sopenharmony_ci
74cf200d32Sopenharmony_ciIf you pass the "-l" option to gdisk64.exe in addition to the disk
75cf200d32Sopenharmony_ciidentifier, the program displays the current partition table information and
76cf200d32Sopenharmony_cithen exits. (Alternatively, you can pass "-p" to sgdisk64.exe.) This use
77cf200d32Sopenharmony_cientails no risk to MBR disks, since the program never writes data back to
78cf200d32Sopenharmony_cithe disk when used in this way.
79cf200d32Sopenharmony_ci
80cf200d32Sopenharmony_ciAs noted above, editing the first disk with GPT fdisk is a Bad Idea on older
81cf200d32Sopenharmony_ciBIOS-based computers. Newer computers typically use an Extensible Firmware
82cf200d32Sopenharmony_ciInterface (EFI) and boot from GPT disks. It's safer to edit non-boot disks,
83cf200d32Sopenharmony_ciwhich usually have numbers of 1 and above, but only if you run a version of
84cf200d32Sopenharmony_ciWindows with GPT support. For more information on Windows' support of GPT,
85cf200d32Sopenharmony_cisee Microsoft's Web page on the topic:
86cf200d32Sopenharmony_ci
87cf200d32Sopenharmony_cihttp://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx
88cf200d32Sopenharmony_ci
89cf200d32Sopenharmony_ciThe Windows binaries I've compiled do not support Unicode UTF-16LE GPT
90cf200d32Sopenharmony_cipartition names. This feature was added to version 0.7.1 of the software
91cf200d32Sopenharmony_cifor Linux, FreeBSD, and OS X, and with changes to some #ifndef lines in the
92cf200d32Sopenharmony_cisource files, it can be compiled for Windows; however, it seems to do
93cf200d32Sopenharmony_cilittle good in Windows because of Command Prompt window and/or ICU library
94cf200d32Sopenharmony_cilimitations. Thus, I've omitted this support in the interests of
95cf200d32Sopenharmony_cisimplifying the binary distribution, since including it would mean
96cf200d32Sopenharmony_cidistributing the ICU libraries.
97cf200d32Sopenharmony_ci
98cf200d32Sopenharmony_ciSource Code and Compilation Issues
99cf200d32Sopenharmony_ci----------------------------------
100cf200d32Sopenharmony_ci
101cf200d32Sopenharmony_ciI have successfully compiled GPT fdisk using three different Windows
102cf200d32Sopenharmony_cicompilers:
103cf200d32Sopenharmony_ci
104cf200d32Sopenharmony_ci- MinGW (https://www.mingw-w64.org/), using either a Linux-hosted
105cf200d32Sopenharmony_ci  cross-compiler or under Windows using the original MinGW or MSYS2
106cf200d32Sopenharmony_ci  (https://www.msys2.org). This is my only GPT fdisk development environment
107cf200d32Sopenharmony_ci  for Windows in 2022.
108cf200d32Sopenharmony_ci
109cf200d32Sopenharmony_ci- Microsoft Visual C++ 2008 Express
110cf200d32Sopenharmony_ci  (http://www.microsoft.com/express/Windows/) -- This compiler requires a
111cf200d32Sopenharmony_ci  third-party stdint.h file (I used the one from
112cf200d32Sopenharmony_ci  http://web.archive.org/web/20130317001712/http://msinttypes.googlecode.com/svn/trunk/stdint.h),
113cf200d32Sopenharmony_ci  but it otherwise worked fine the last time I tried it. A project is easily
114cf200d32Sopenharmony_ci  created by adding all the *.h files and all the *.cc files except
115cf200d32Sopenharmony_ci  diskio-unix.cc, sgdisk.cc, and whichever program file you intend to NOT
116cf200d32Sopenharmony_ci  build (gdisk.cc or fixparts.cc).
117cf200d32Sopenharmony_ci
118cf200d32Sopenharmony_ci- Microsoft Visual C++ 2010 Express -- This compiler works much like the
119cf200d32Sopenharmony_ci  2008 version, although I didn't need to add a third-party stdint.h file.
120cf200d32Sopenharmony_ci
121cf200d32Sopenharmony_ciAlthough I used Microsoft Visual C++ in the past, I haven't tried using
122cf200d32Sopenharmony_cithese compilers recently and so I can't promise they would work today (in
123cf200d32Sopenharmony_ci2022).
124cf200d32Sopenharmony_ci
125cf200d32Sopenharmony_ciIf you modify GPT fdisk to get it to compile under another compiler, I
126cf200d32Sopenharmony_ciwelcome submission of patches.
127cf200d32Sopenharmony_ci
128cf200d32Sopenharmony_ciThe following instructions focus on use of MinGW to compile GPT fdisk for
129cf200d32Sopenharmony_ciWindows.
130cf200d32Sopenharmony_ci
131cf200d32Sopenharmony_ciMy primary development environment is Ubuntu Linux, using the MinGW
132cf200d32Sopenharmony_cicross-compiler. This system can compile the gdisk and fixparts binaries with
133cf200d32Sopenharmony_cino need for additional libraries; after installing MinGW (via the
134cf200d32Sopenharmony_cig++-mingw-w64 package in Ubuntu, or the equivalent in another distribution),
135cf200d32Sopenharmony_ciyou can type "TARGET=win32 make" to compile 32-bit binaries, and
136cf200d32Sopenharmony_ci"TARGET=win64 make" to compile 64-bit binaries. This will attempt to build
137cf200d32Sopenharmony_cigdisk, sgdisk, and fixparts; but the sgdisk build will fail until you
138cf200d32Sopenharmony_ciinstall the popt libraries, as described shortly. You can build the other
139cf200d32Sopenharmony_cibinaries by specifying them, as in "TARGET=win64 make gdisk" to build the
140cf200d32Sopenharmony_ci64-bit gdisk binary alone.
141cf200d32Sopenharmony_ci
142cf200d32Sopenharmony_ciIf you use Windows, your best bet is likely to be to install the MSYS2
143cf200d32Sopenharmony_cipackage (https://www.msys2.org). This package provides MinGW and a package
144cf200d32Sopenharmony_cimanagement system based on pacman (used by Arch Linux) for installing
145cf200d32Sopenharmony_ciadditional libraries. To install the libraries needed to compile sgdisk and
146cf200d32Sopenharmony_cicgdisk, type "pacman -S mingw-w64-x86_64-popt mingw-w64-x86_64-gettext
147cf200d32Sopenharmony_cimingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change
148cf200d32Sopenharmony_ci'x86_64' to 'i686' for 32-bit packages. This command will install the popt
149cf200d32Sopenharmony_cilibrary needed by sgdisk and the ncurses library needed by cgdisk, along
150cf200d32Sopenharmony_ciwith gettext, which is needed by popt. With these libraries installed, you
151cf200d32Sopenharmony_cishould be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk,
152cf200d32Sopenharmony_ciand fixparts. Typing "make" alone in the MSYS2 shell should build all four
153cf200d32Sopenharmony_ciprograms for the host architecture (x86-64 or i686); to compile for the
154cf200d32Sopenharmony_ciother architecture, you must specify it with a "TARGET=" specification, as
155cf200d32Sopenharmony_ciunder Linux. (The Makefile does not currently support ARM64 targets for
156cf200d32Sopenharmony_ciWindows.)
157cf200d32Sopenharmony_ci
158cf200d32Sopenharmony_ciIf you want to compile sgdisk for Windows under Linux, you can do so;
159cf200d32Sopenharmony_cihowever, you must copy the relevant header and library files from a Windows
160cf200d32Sopenharmony_ciinstallation to Linux. Specifically, you must copy:
161cf200d32Sopenharmony_ci
162cf200d32Sopenharmony_ci    Windows File                   Linux Directory
163cf200d32Sopenharmony_ci    ------------                   ---------------
164cf200d32Sopenharmony_ci    /mingw64/include/popt.h        /usr/x86_64-w64-mingw32/include/
165cf200d32Sopenharmony_ci    /mingw64/lib/libpopt.a         /usr/x86_64-w64-mingw32/lib/
166cf200d32Sopenharmony_ci    /mingw64/lib/libintl.a         /usr/x86_64-w64-mingw32/lib/
167cf200d32Sopenharmony_ci    /mingw64/lib/libiconv.a        /usr/x86_64-w64-mingw32/lib/
168cf200d32Sopenharmony_ci
169cf200d32Sopenharmony_ciFor 32-bit binaries, change /mingw64 to /mingw32 on the Windows source and
170cf200d32Sopenharmony_cix86_64-w64-mingw32 to i686-w64-mingw32 on the Linux destination.
171cf200d32Sopenharmony_ci
172cf200d32Sopenharmony_ciIn theory, you should be able to do something similar to compile cgdisk. The
173cf200d32Sopenharmony_cirelevant files are:
174cf200d32Sopenharmony_ci
175cf200d32Sopenharmony_ci    Windows File                            Linux Directory
176cf200d32Sopenharmony_ci    ------------                            ---------------
177cf200d32Sopenharmony_ci    /mingw64/include/ncursesw/curses.h      /usr/x86_64-w64-mingw32/include/ncursesw/
178cf200d32Sopenharmony_ci    /mingw64/include/ncursesw/ncurses.h     /usr/x86_64-w64-mingw32/include/ncursesw/
179cf200d32Sopenharmony_ci    /mingw64/include/ncursesw/ncurses_dll.h /usr/x86_64-w64-mingw32/include/ncursesw/
180cf200d32Sopenharmony_ci    /mingw64/include/ncursesw/unctrl.h      /usr/x86_64-w64-mingw32/include/ncursesw/
181cf200d32Sopenharmony_ci    /mingw64/lib/libncurses.a               /usr/x86_64-w64-mingw32/lib/
182cf200d32Sopenharmony_ci
183cf200d32Sopenharmony_ciIn practice, this has not worked for me; the compilation fails with a
184cf200d32Sopenharmony_cicomplaint about an undefined reference to 'nanosleep'. My guess is that the
185cf200d32Sopenharmony_cincurses version installed in Windows is too new to work with the MinGW
186cf200d32Sopenharmony_cilibraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with
187cf200d32Sopenharmony_cianother distribution, though.
188cf200d32Sopenharmony_ci
189cf200d32Sopenharmony_ciThe Makefile is configured to create statically-linked binaries so as to
190cf200d32Sopenharmony_cisimplify installation of the binaries. If you want smaller binaries, you can
191cf200d32Sopenharmony_ciremove the various static options from the Makefile. You can also strip the
192cf200d32Sopenharmony_cibinaries ("make strip") to remove unused code.
193