xref: /aosp_15_r20/external/gptfdisk/README.Windows (revision 57696d54d05c64fd1b1787f8371dbcf104911cfb)
1*57696d54SAkhilesh SanikopGPT fdisk (aka gdisk) and FixParts
2*57696d54SAkhilesh Sanikop
3*57696d54SAkhilesh Sanikopby Roderick W. Smith, [email protected]
4*57696d54SAkhilesh Sanikop
5*57696d54SAkhilesh Sanikop******************************** IMPORTANT ********************************
6*57696d54SAkhilesh SanikopMost versions of Windows cannot boot from a GPT disk on BIOS-based
7*57696d54SAkhilesh Sanikopcomputers, and most varieties prior to Vista cannot read GPT disks. GPT
8*57696d54SAkhilesh Sanikopfdisk is a partition editor for GPT disks, and it will *AUTOMATICALLY
9*57696d54SAkhilesh SanikopCONVERT* MBR disks to GPT form. Therefore, you should **NOT** use GPT fdisk
10*57696d54SAkhilesh Sanikopon a Windows system unless you fully understand what you're doing or are
11*57696d54SAkhilesh Sanikopcertain that your computer boots in EFI/UEFI mode! If you accidentally use
12*57696d54SAkhilesh SanikopGPT fdisk on a BIOS-mode boot disk, or perhaps even on a data disk, you may
13*57696d54SAkhilesh Sanikopfind recovery to be very difficult! Pre-installed Windows 8 and later
14*57696d54SAkhilesh Sanikopsystems almost always use GPT disks and boot in EFI/UEFI mode, but
15*57696d54SAkhilesh Sanikopself-installed Windows 8 systems sometimes use BIOS mode. This caveat does
16*57696d54SAkhilesh Sanikopnot apply to FixParts, though; that tool works only on MBR disks.
17*57696d54SAkhilesh Sanikop***************************************************************************
18*57696d54SAkhilesh Sanikop
19*57696d54SAkhilesh SanikopRead the main README file for general information on the program, and read
20*57696d54SAkhilesh Sanikopthe gdisk.html or fixparts.html documents (the Linux man pages converted to
21*57696d54SAkhilesh SanikopHTML format) for detailed use information. My GPT fdisk Web page,
22*57696d54SAkhilesh Sanikophttp://www.rodsbooks.com/gdisk/, provides a more tutorial introduction to
23*57696d54SAkhilesh Sanikopthe software. I originally wrote GPT fdisk on Linux, and some Linux- and
24*57696d54SAkhilesh SanikopUnix-centric language remains in the documentation.
25*57696d54SAkhilesh Sanikop
26*57696d54SAkhilesh SanikopWindows Use Notes
27*57696d54SAkhilesh Sanikop-----------------
28*57696d54SAkhilesh Sanikop
29*57696d54SAkhilesh SanikopThe Windows version of GPT fdisk was added with version 0.6.2 of the
30*57696d54SAkhilesh Sanikoppackage. The Windows binary package includes the gdisk.exe interactive
31*57696d54SAkhilesh Sanikoptext-mode program file as well as the sgdisk program that's available
32*57696d54SAkhilesh Sanikopwith Linux, FreeBSD, and OS X builds.
33*57696d54SAkhilesh Sanikop
34*57696d54SAkhilesh SanikopBeginning with version 0.8.10, I'm distributing both 32-bit and 64-bit
35*57696d54SAkhilesh Sanikopbinaries, which include the strings "32" or "64" in their names. The 32-bit
36*57696d54SAkhilesh Sanikopbinaries work fine on most versions of Windows, but some 64-bit
37*57696d54SAkhilesh Sanikopinstallations of Windows 8 lack 32-bit support libraries and so may need
38*57696d54SAkhilesh Sanikopthe 64-bit binaries.
39*57696d54SAkhilesh Sanikop
40*57696d54SAkhilesh SanikopThe FixParts program (fixparts32.exe and fixparts64.exe) is new with GPT
41*57696d54SAkhilesh Sanikopfdisk 0.7.0. As described in the main README file, this program fixes
42*57696d54SAkhilesh Sanikopcertain partition table problems that can be created by buggy partitioning
43*57696d54SAkhilesh Sanikopsoftware. Windows seems to be unfazed by most such problems, but I've not
44*57696d54SAkhilesh Sanikopdone an extensive survey of Windows partitioning tools on this score.
45*57696d54SAkhilesh Sanikop
46*57696d54SAkhilesh SanikopTo install the programs, copy the gdisk32.exe, cgdisk32.exe, sgdisk32.exe
47*57696d54SAkhilesh Sanikopand fixparts32.exe (or gdisk64.exe, cgdisk64.exe, sgdisk64.exe and
48*57696d54SAkhilesh Sanikopfixparts64.exe) program files to any directory on your path, such as
49*57696d54SAkhilesh SanikopC:\Windows. Alternatively, you can change to the program's directory or type
50*57696d54SAkhilesh Sanikopits complete path whenever you use it.
51*57696d54SAkhilesh Sanikop
52*57696d54SAkhilesh SanikopTo use the programs, first launch a Command Prompt as the Administrator. To
53*57696d54SAkhilesh Sanikopdo this, locate the Command Prompt program icon, right-click it, and select
54*57696d54SAkhilesh Sanikop"Run as Administrator." If you use a non-Administrator Command Prompt, you
55*57696d54SAkhilesh Sanikopwon't be able to edit hard disk partition tables, although you will be able
56*57696d54SAkhilesh Sanikopto edit raw disk image files.
57*57696d54SAkhilesh Sanikop
58*57696d54SAkhilesh SanikopThe program requires a hard disk identifier as an option. You can specify
59*57696d54SAkhilesh Sanikopthis in either of two forms. The first way is as a number followed by a
60*57696d54SAkhilesh Sanikopcolon, as in:
61*57696d54SAkhilesh Sanikop
62*57696d54SAkhilesh Sanikopgdisk 0:
63*57696d54SAkhilesh Sanikop
64*57696d54SAkhilesh SanikopDisks are numbered starting from 0, so the preceding command launches gdisk
65*57696d54SAkhilesh Sanikopon the first disk. The second way to specify a disk device is via a
66*57696d54SAkhilesh Sanikopharder-to-remember name:
67*57696d54SAkhilesh Sanikop
68*57696d54SAkhilesh Sanikopgdisk32 \\.\physicaldrive0
69*57696d54SAkhilesh Sanikop
70*57696d54SAkhilesh SanikopThis command is equivalent to the earlier one -- it edits the partition
71*57696d54SAkhilesh Sanikoptable on the first physical disk. Change the number at the end of the
72*57696d54SAkhilesh Sanikopdevice name to change the disk edited.
73*57696d54SAkhilesh Sanikop
74*57696d54SAkhilesh SanikopIf you pass the "-l" option to gdisk64.exe in addition to the disk
75*57696d54SAkhilesh Sanikopidentifier, the program displays the current partition table information and
76*57696d54SAkhilesh Sanikopthen exits. (Alternatively, you can pass "-p" to sgdisk64.exe.) This use
77*57696d54SAkhilesh Sanikopentails no risk to MBR disks, since the program never writes data back to
78*57696d54SAkhilesh Sanikopthe disk when used in this way.
79*57696d54SAkhilesh Sanikop
80*57696d54SAkhilesh SanikopAs noted above, editing the first disk with GPT fdisk is a Bad Idea on older
81*57696d54SAkhilesh SanikopBIOS-based computers. Newer computers typically use an Extensible Firmware
82*57696d54SAkhilesh SanikopInterface (EFI) and boot from GPT disks. It's safer to edit non-boot disks,
83*57696d54SAkhilesh Sanikopwhich usually have numbers of 1 and above, but only if you run a version of
84*57696d54SAkhilesh SanikopWindows with GPT support. For more information on Windows' support of GPT,
85*57696d54SAkhilesh Sanikopsee Microsoft's Web page on the topic:
86*57696d54SAkhilesh Sanikop
87*57696d54SAkhilesh Sanikophttp://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx
88*57696d54SAkhilesh Sanikop
89*57696d54SAkhilesh SanikopThe Windows binaries I've compiled do not support Unicode UTF-16LE GPT
90*57696d54SAkhilesh Sanikoppartition names. This feature was added to version 0.7.1 of the software
91*57696d54SAkhilesh Sanikopfor Linux, FreeBSD, and OS X, and with changes to some #ifndef lines in the
92*57696d54SAkhilesh Sanikopsource files, it can be compiled for Windows; however, it seems to do
93*57696d54SAkhilesh Sanikoplittle good in Windows because of Command Prompt window and/or ICU library
94*57696d54SAkhilesh Sanikoplimitations. Thus, I've omitted this support in the interests of
95*57696d54SAkhilesh Sanikopsimplifying the binary distribution, since including it would mean
96*57696d54SAkhilesh Sanikopdistributing the ICU libraries.
97*57696d54SAkhilesh Sanikop
98*57696d54SAkhilesh SanikopSource Code and Compilation Issues
99*57696d54SAkhilesh Sanikop----------------------------------
100*57696d54SAkhilesh Sanikop
101*57696d54SAkhilesh SanikopI have successfully compiled GPT fdisk using three different Windows
102*57696d54SAkhilesh Sanikopcompilers:
103*57696d54SAkhilesh Sanikop
104*57696d54SAkhilesh Sanikop- MinGW (https://www.mingw-w64.org/), using either a Linux-hosted
105*57696d54SAkhilesh Sanikop  cross-compiler or under Windows using the original MinGW or MSYS2
106*57696d54SAkhilesh Sanikop  (https://www.msys2.org). This is my only GPT fdisk development environment
107*57696d54SAkhilesh Sanikop  for Windows in 2022.
108*57696d54SAkhilesh Sanikop
109*57696d54SAkhilesh Sanikop- Microsoft Visual C++ 2008 Express
110*57696d54SAkhilesh Sanikop  (http://www.microsoft.com/express/Windows/) -- This compiler requires a
111*57696d54SAkhilesh Sanikop  third-party stdint.h file (I used the one from
112*57696d54SAkhilesh Sanikop  http://web.archive.org/web/20130317001712/http://msinttypes.googlecode.com/svn/trunk/stdint.h),
113*57696d54SAkhilesh Sanikop  but it otherwise worked fine the last time I tried it. A project is easily
114*57696d54SAkhilesh Sanikop  created by adding all the *.h files and all the *.cc files except
115*57696d54SAkhilesh Sanikop  diskio-unix.cc, sgdisk.cc, and whichever program file you intend to NOT
116*57696d54SAkhilesh Sanikop  build (gdisk.cc or fixparts.cc).
117*57696d54SAkhilesh Sanikop
118*57696d54SAkhilesh Sanikop- Microsoft Visual C++ 2010 Express -- This compiler works much like the
119*57696d54SAkhilesh Sanikop  2008 version, although I didn't need to add a third-party stdint.h file.
120*57696d54SAkhilesh Sanikop
121*57696d54SAkhilesh SanikopAlthough I used Microsoft Visual C++ in the past, I haven't tried using
122*57696d54SAkhilesh Sanikopthese compilers recently and so I can't promise they would work today (in
123*57696d54SAkhilesh Sanikop2022).
124*57696d54SAkhilesh Sanikop
125*57696d54SAkhilesh SanikopIf you modify GPT fdisk to get it to compile under another compiler, I
126*57696d54SAkhilesh Sanikopwelcome submission of patches.
127*57696d54SAkhilesh Sanikop
128*57696d54SAkhilesh SanikopThe following instructions focus on use of MinGW to compile GPT fdisk for
129*57696d54SAkhilesh SanikopWindows.
130*57696d54SAkhilesh Sanikop
131*57696d54SAkhilesh SanikopMy primary development environment is Ubuntu Linux, using the MinGW
132*57696d54SAkhilesh Sanikopcross-compiler. This system can compile the gdisk and fixparts binaries with
133*57696d54SAkhilesh Sanikopno need for additional libraries; after installing MinGW (via the
134*57696d54SAkhilesh Sanikopg++-mingw-w64 package in Ubuntu, or the equivalent in another distribution),
135*57696d54SAkhilesh Sanikopyou can type "TARGET=win32 make" to compile 32-bit binaries, and
136*57696d54SAkhilesh Sanikop"TARGET=win64 make" to compile 64-bit binaries. This will attempt to build
137*57696d54SAkhilesh Sanikopgdisk, sgdisk, and fixparts; but the sgdisk build will fail until you
138*57696d54SAkhilesh Sanikopinstall the popt libraries, as described shortly. You can build the other
139*57696d54SAkhilesh Sanikopbinaries by specifying them, as in "TARGET=win64 make gdisk" to build the
140*57696d54SAkhilesh Sanikop64-bit gdisk binary alone.
141*57696d54SAkhilesh Sanikop
142*57696d54SAkhilesh SanikopIf you use Windows, your best bet is likely to be to install the MSYS2
143*57696d54SAkhilesh Sanikoppackage (https://www.msys2.org). This package provides MinGW and a package
144*57696d54SAkhilesh Sanikopmanagement system based on pacman (used by Arch Linux) for installing
145*57696d54SAkhilesh Sanikopadditional libraries. To install the libraries needed to compile sgdisk and
146*57696d54SAkhilesh Sanikopcgdisk, type "pacman -S mingw-w64-x86_64-popt mingw-w64-x86_64-gettext
147*57696d54SAkhilesh Sanikopmingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change
148*57696d54SAkhilesh Sanikop'x86_64' to 'i686' for 32-bit packages. This command will install the popt
149*57696d54SAkhilesh Sanikoplibrary needed by sgdisk and the ncurses library needed by cgdisk, along
150*57696d54SAkhilesh Sanikopwith gettext, which is needed by popt. With these libraries installed, you
151*57696d54SAkhilesh Sanikopshould be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk,
152*57696d54SAkhilesh Sanikopand fixparts. Typing "make" alone in the MSYS2 shell should build all four
153*57696d54SAkhilesh Sanikopprograms for the host architecture (x86-64 or i686); to compile for the
154*57696d54SAkhilesh Sanikopother architecture, you must specify it with a "TARGET=" specification, as
155*57696d54SAkhilesh Sanikopunder Linux. (The Makefile does not currently support ARM64 targets for
156*57696d54SAkhilesh SanikopWindows.)
157*57696d54SAkhilesh Sanikop
158*57696d54SAkhilesh SanikopIf you want to compile sgdisk for Windows under Linux, you can do so;
159*57696d54SAkhilesh Sanikophowever, you must copy the relevant header and library files from a Windows
160*57696d54SAkhilesh Sanikopinstallation to Linux. Specifically, you must copy:
161*57696d54SAkhilesh Sanikop
162*57696d54SAkhilesh Sanikop    Windows File                   Linux Directory
163*57696d54SAkhilesh Sanikop    ------------                   ---------------
164*57696d54SAkhilesh Sanikop    /mingw64/include/popt.h        /usr/x86_64-w64-mingw32/include/
165*57696d54SAkhilesh Sanikop    /mingw64/lib/libpopt.a         /usr/x86_64-w64-mingw32/lib/
166*57696d54SAkhilesh Sanikop    /mingw64/lib/libintl.a         /usr/x86_64-w64-mingw32/lib/
167*57696d54SAkhilesh Sanikop    /mingw64/lib/libiconv.a        /usr/x86_64-w64-mingw32/lib/
168*57696d54SAkhilesh Sanikop
169*57696d54SAkhilesh SanikopFor 32-bit binaries, change /mingw64 to /mingw32 on the Windows source and
170*57696d54SAkhilesh Sanikopx86_64-w64-mingw32 to i686-w64-mingw32 on the Linux destination.
171*57696d54SAkhilesh Sanikop
172*57696d54SAkhilesh SanikopIn theory, you should be able to do something similar to compile cgdisk. The
173*57696d54SAkhilesh Sanikoprelevant files are:
174*57696d54SAkhilesh Sanikop
175*57696d54SAkhilesh Sanikop    Windows File                            Linux Directory
176*57696d54SAkhilesh Sanikop    ------------                            ---------------
177*57696d54SAkhilesh Sanikop    /mingw64/include/ncursesw/curses.h      /usr/x86_64-w64-mingw32/include/ncursesw/
178*57696d54SAkhilesh Sanikop    /mingw64/include/ncursesw/ncurses.h     /usr/x86_64-w64-mingw32/include/ncursesw/
179*57696d54SAkhilesh Sanikop    /mingw64/include/ncursesw/ncurses_dll.h /usr/x86_64-w64-mingw32/include/ncursesw/
180*57696d54SAkhilesh Sanikop    /mingw64/include/ncursesw/unctrl.h      /usr/x86_64-w64-mingw32/include/ncursesw/
181*57696d54SAkhilesh Sanikop    /mingw64/lib/libncurses.a               /usr/x86_64-w64-mingw32/lib/
182*57696d54SAkhilesh Sanikop
183*57696d54SAkhilesh SanikopIn practice, this has not worked for me; the compilation fails with a
184*57696d54SAkhilesh Sanikopcomplaint about an undefined reference to 'nanosleep'. My guess is that the
185*57696d54SAkhilesh Sanikopncurses version installed in Windows is too new to work with the MinGW
186*57696d54SAkhilesh Sanikoplibraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with
187*57696d54SAkhilesh Sanikopanother distribution, though.
188*57696d54SAkhilesh Sanikop
189*57696d54SAkhilesh SanikopThe Makefile is configured to create statically-linked binaries so as to
190*57696d54SAkhilesh Sanikopsimplify installation of the binaries. If you want smaller binaries, you can
191*57696d54SAkhilesh Sanikopremove the various static options from the Makefile. You can also strip the
192*57696d54SAkhilesh Sanikopbinaries ("make strip") to remove unused code.
193