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 installed,
165most notably the GNU Compiler Collection (GCC) and its g++ compiler for C++.
166I've also tested compilation with Clang, which seems to work; however, I've
167not done extensive testing of the resulting binaries, beyond checking a few
168basics. See the README.Windows files for additional notes on compiling the
169software for Windows. In addition, note these requirements:
170
171* On Linux, FreeBSD, macOS, and Solaris, libuuid must be installed. This is
172 the standard for Linux and macOS, 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 no 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 macOS, 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 macOS). 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. On my macOS development
193 system, I installed the nurses Homebrew ("brew") package; however, other
194 Unix-style software repositories are available and may work for you (see
195 the next item). If you're having problems installing ncurses, you can
196 compile gdisk and/or sgdisk without cgdisk by specifying only the targets
197 you want to compile to 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. MacOS users can find a version of
203 popt for Mac OS from Darwin Ports (http://popt.darwinports.com), MacPorts
204 (https://trac.macports.org/browser/trunk/dports/devel/popt/Portfile), Fink
205 (http://www.finkproject.org), or brew (http://macappstore.org/popt/);
206 however, you'll first need to install the relevant environment
207 (instructions exist on the relevant projects' pages). When I re-built my
208 Mac build environment in February of 2020, I found that brew was, by far,
209 the easiest of these to install. Some of the others seem to have been
210 abandoned, but I didn't investigate thoroughly. I'm leaving the references
211 in case they might be useful in the future. Instead of installing one of
212 These ports, you can compile gdisk and/or cgdisk alone, without sgdisk;
213 gdisk and cgdisk don't require popt.
214
215When all the necessary development tools and libraries are installed, you
216can uncompress the package and type "make" at the command prompt in the
217resulting directory. (Beginning with version 1.0.9, GPT fdisk provides a
218consolidated Makefile for all supported OSes. Earlier versions used
219OS-specific Makefiles, such as Makefile.mac and Makefile.freebsd, which are
220still provided, but are deprecated.) You must use GNU make (gmake on
221FreeBSD) with this Makefile. You may also need to add header (include)
222directories or library directories by setting the CXXFLAGS environment
223variable or by editing the Makefile. The result should be program files
224called gdisk, cgdisk, sgdisk, and fixparts (or variants with "32.exe" or
225"64.exe" added for Windows binaries). Typing "make gdisk", "make cgdisk",
226"make sgdisk", or "make fixparts" will compile only the requested programs.
227You can use these programs in place or copy the files to a suitable
228directory, such as /usr/local/sbin. You can copy the man pages (gdisk.8,
229cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8 to make them
230available.
231
232Cross-compiling is possible, but is not well-tested, except for compiling
233Windows binaries on Linux. (See README.Windows for details.) To
234cross-compile, specify the TARGET environment variable when launching make,
235as in "TARGET=win64 make" to compile for 64-bit (x86-64, X64, AMD64) Windows
236on a non-Windows platform. Supported TARGET values are linux, freebsd,
237solaris, macos, win32, and win64.
238
239Caveats
240-------
241
242DISK PARTITIONING SOFTWARE IS DANGEROUS! Although the GPT fdisk project has
243existed since 2009, I do not claim it is entirely bug-free; in fact a glance
244at the revision history shows recent bug fixes. I believe all
245data-corruption bugs to be squashed, but I know full well that the odds of
246my missing something are high. This is particularly true for large
247(over-2TiB) drives and use in exotic environments.
248
249My main development platform is a system running the 64-bit version of
250Ubuntu Linux. I've also tested on several other 32- and 64-bit Linux
251distributions, Intel-based macOS 10 and 11, 64-bit FreeBSD 7.1, and Windows
2527 and 10. Other environments qualify as "exotic," and even macOS and Windows
253are borderline exotic in this context, since I use Linux almost exclusively,
254and my impression is that GPT fdisk is far more commonly used on Linux than
255in other OSes.
256
257Redistribution
258--------------
259
260This program is licensed under terms of the GNU GPL (see the file COPYING).
261
262Acknowledgements
263----------------
264
265This code is mostly my own; however, I've used three functions from two
266other GPLed programs:
267
268- The code used to generate CRCs is taken from the efone program by
269 Krzysztof Dabrowski and ElysiuM deeZine. (See the crc32.h and
270 crc32.cc source code files.)
271
272- A function to find the disk size is taken from Linux fdisk by A. V. Le
273 Blanc. This code has subsequently been heavily modified.
274
275Additional code contributors include:
276
277- Yves Blusseau (1otnwmz02@sneakemail.com)
278
279- David Hubbard (david.c.hubbard@gmail.com)
280
281- Justin Maggard (justin.maggard@netgear.com)
282
283- Dwight Schauer (das@teegra.net)
284
285- Florian Zumbiehl (florz@florz.de)
286
287- Guillaume Delacour (contributed the gdisk_test.sh script)
288
README-efi.txt
1README for EFI version of GPT fdisk
2===================================
3
4GPT fdisk for EFI is a binary build of gdisk to run as a pre-boot EFI
5application. It's OS-independent and may be used to check or recover
6partition tables before installing or booting an OS. It may be used to
7overcome boot problems caused by partition table damage or to prepare a
8partition table prior to installing an OS.
9
10Installing GPT fdisk for EFI
11----------------------------
12
13The contents of this archive are:
14
15- COPYING -- The GNU GPL
16- gdisk.html -- The gdisk man page, in HTML form
17- gdisk_x64.efi -- The gdisk binary, built for EFI (x86-64 CPU)
18- NEWS -- The GPT fdisk changelog
19- README-efi.txt -- This file
20- refind.cer -- The rEFInd public key, .cer (DER) form
21- refind.crt -- The rEFInd public key, .crt form
22
23The gdisk_x64.efi binary included here is built using the UEFI GPT fdisk
24library (https://sourceforge.net/p/uefigptfdisk/), which is a beta-level
25partial C++ library for UEFI. To use it, you must copy it to your EFI
26System Partition (ESP) or some other EFI-accessible location. Under Linux,
27the ESP is usually one of the first two or three partitions on /dev/sda.
28Under OS X, it's usually the first partition on /dev/disk0 (that is,
29/dev/disk0s1). Under Windows, you can mount it to S: by typing "mountvol S:
30/S" in an Administrator command prompt. In any of these cases, the
31recommended location for gdisk_x64.efi is the EFI/tools directory on the
32ESP. In that location, my rEFInd boot manager will detect the gdisk binary
33and create a menu option to launch it. If you don't use rEFInd, you can
34launch the program using an EFI shell, register it as a boot program with
35your firmware, or configure your boot manager (GRUB, gummiboot, etc.) to
36launch it. Note that boot LOADERS, such as SYSLINUX and ELILO, can't launch
37gdisk.
38
39Alternatively, you can create a USB flash drive that will launch gdisk when
40you boot from it. To do so, create a FAT filesystem on a partition on a USB
41flash drive and copy gdisk_x64.efi to it as EFI/BOOT/bootx64.efi. (You'll
42need to create the EFI/BOOT directory.) Some systems may require the FAT
43filesystem to be flagged as an ESP (with a type code of EF00 in gdisk). You
44can use your firmware's built-in boot manager to boot from the USB flash
45drive. Some such boot managers present two options for booting USB flash
46drives. If yours does this, select the option that includes the string
47"UEFI" in the description.
48
49The gdisk_x64.efi binary is signed with the rEFInd Secure Boot key. Thus,
50if you're launching a rEFInd that I've compiled and distributed myself,
51gdisk should launch, too. If you're *NOT* running rEFInd but ARE using
52Shim, you'll need to add the refind.cer file to your MOK list by using the
53MokManager utility. If you're using Secure Boot and you've signed rEFInd
54yourself, you'll need to sign gdisk_x64.efi yourself, too. Note that the
55rEFInd PPA distributes unsigned binaries and signs them with a local key
56stored in /etc/refind/keys. To copy and sign the gdisk_x64.efi binary, you
57should type (as root or using sudo):
58
59sbsign --key /etc/refind.d/keys/refind_local.key \
60 --cert /etc/refind.d/keys/refind.crt \
61 --output /boot/efi/EFI/tooks/gdisk_x64.efi ./gdisk_x64.efi
62
63This command assumes you have local rEFInd keys stored in the locations
64created by the rEFInd installation script. Substitute your own keys if
65you've built them in some other way. Some distributions don't provide the
66sbsign binary, so you may need to build it yourself. See the following page
67for details:
68
69https://git.kernel.org/cgit/linux/kernel/git/jejb/sbsigntools.git/
70
71Note that you do *NOT* need to sign gdisk if your computer doesn't use
72Secure Boot or if you've disabled this feature.
73
74Using gdisk for EFI
75-------------------
76
77The EFI version of gdisk is basically the same as using the Linux, OS X, or
78other OS versions. One exception is that you do not specify a disk device
79on the command line; gdisk for EFI instead displays a list of devices when
80you launch and enables you to select one, as in:
81
82List of hard disks found:
83 1: Disk EFI_HANDLE(3EB5DD98): 108423424 sectors, 51.7 GiB
84 Acpi(PNP0A03,0)/Pci(1|1)/Ata(Primary,Master)
85 2: Disk EFI_HANDLE(3EB58289): 105456768 sectors, 50.3 GiB
86 Acpi(PNP0A03,0)/Pci(D|0)?
87
88Disk number (1-2): 2
89
90Once you've selected your disk, it should operate in much the same way as
91any other version of gdisk. (See the next section, though!) Some programs,
92including my rEFInd boot manager, complain about the changed partition
93table, even if you've made no changes. If you run into problems using other
94programs or launching an OS immediately after running gdisk, reboot; that
95should cause the firmware to re-load its partition table.
96
97Caveats
98-------
99
100I've tested gdisk_x64.efi on several systems. It's worked fine for me on 4
101of 6 computers (5 of 7, counting VirtualBox). Two systems gave me problems,
102though:
103
104* gdisk presented a never-ending list of options (as if receiving a
105 never-ending string of "?" or other unrecognized command characters) on a
106 2014 MacBook Air.
107* A computer based on an Intel DG43NB motherboard rebooted as soon as I
108 launched gdisk.
109
110Both computers have relatively old EFIs. (Despite its newness, the Mac has
111a 1.10 EFI, as do all Macs, to the best of my knowledge.) Most of the
112computers that worked had 2.31 EFIs, although one had a 2.10 EFI.
113
114The bottom line is that I can't guarantee that this binary will work on all
115computers. It's conceivable that recompiling gdisk with the latest version
116of the UEFI GPT fdisk library will help. Also, I haven't compiled a 32-bit
117version, so if you have a 32-bit EFI, you'll have to compile it yourself or
118do without.
119
120References
121----------
122
123The following sites have useful additional information:
124
125UEFI GPT fdisk:
126https://sourceforge.net/projects/uefigptfdisk/
127
128sbsigntools git repository:
129https://git.kernel.org/cgit/linux/kernel/git/jejb/sbsigntools.git/
130
131rEFInd:
132http://www.rodsbooks.com/refind/
133
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 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