How to change GPT partition type on windows?
Solution 1:
DiskPart can actually do this. Select the appropriate disk and partition, then use the set id
command. For example, this changes the selected partition into an EFI partition:
set id=c12a7328-f81f-11d2-ba4b-00a0c93ec93b
Using a combination of the set id
TechNet article and detail partition
, I discovered these common possible values:
- Recovery:
de94bba4-06d1-4d40-a16a-bfd50179d6ac
- Normal:
ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
- EFI:
c12a7328-f81f-11d2-ba4b-00a0c93ec93b
- Reserved:
e3c9e316-0b5c-4db8-817d-f92df00215ae
It's probably a good idea to consult the partition attributes for a partition of a certain type (look at a healthy computer) so the set flags make sense. As you discovered, gpt attributes
sets flags; detail partition
displays them.
Danger zone: setting the Reserved type
The TechNet documentation says that DiskPart won't let you make a partition into a Microsoft Reserved one. That claim is true, so you might want to use a different tool. If you really want to use DiskPart, you'll have to whack the Windows disk management infrastructure it so that it doesn't know what types are not allowed. Danger! I have not tested the following steps on a bootable disk; they're here for entertainment purposes only. Do them at your own risk, preferably on a throwaway computer or VM.
Break out a hex editor - I like XVI32 - and open a copy of vdsbas.dll
(in System32). That's the module that serves most disk-related operations, and it's the one responsible for policing partition types. The GUID of the Microsoft Reserved type starts at byte 0x21CD8 for the version that comes with Windows 10 x64; you should search for the hex string 16 E3 C9 E3
(0xE3C9E316 in little-endian). Flipping a bit there will make the whacked copy not know you're setting a special type. You'll have to change the security settings on the original copy of vdsbas.dll
before Windows will let you overwrite it. You'll also have to make sure the Virtual Disk service isn't running (stopping it in Services is fine), otherwise the file will be in use.
Note that such Reserved partitions must not be associated with a volume. I do not know whether DiskPart has a way to keep a partition that way.
There's probably a good reason Microsoft doesn't let you set this type, so make a back-up of anything important on the drive if you decide to go this route. If you direly need such a partition back, it's probably better to reinstall/repair Windows from official media.
Solution 2:
There seems to be a bit of confusion, or at least imprecise use of terminology, in this question and its discussion. Thus, it may be useful to review the GPT data structures, which are described in the Wikipedia article on GPT. (The EFI spec is more authoritative, and is freely available, but requires accepting license terms to download. See here to get it.) GPT type codes are actually GUID values -- see the partition type GUIDs table in the Wikipedia article for a listing of well-known values. There are also GPT attributes and partition names; these are three entirely independent data structures (although many partitioning tools set partition names based on the type code). I know of no GPT partition type called "primary." I suspect that the reference to this type is a result of confusion with MBR partitions, which can be primary, extended, or logical; but these concepts are meaningless in GPT. Some tools continue to apply the term "primary" in reference to all GPT partitions, presumably because the tools were originally written for MBR disks, and so require a primary/extended/logical identification for all partitions.
Type codes, in both MBR and GPT, identify the intended use of the partition. Windows, OS X, and some other OSes use type codes as a sort of "filter" -- these OSes ignore partitions that aren't of certain types, so that you can set up (say) a Linux filesystem on a partition with a Linux-specific type code and Windows won't try to format it. There are also several Windows-specific type codes (see the Wikipedia table), and some that are cross-OS (like the code for the EFI System Partition, or ESP).
Attributes are less commonly used (type codes are mandatory), but they may modify the way the OS or firmware treats the partition. A "hidden" attribute, for instance, tells the OS to ignore the partition. This may or may not be honored, depending on the OS. Attributes can vary from one partition type to another.
Partition names exist mainly for human consumption, so that you can identify partitions. I haven't investigated it extensively, but I think that OS X is finicky about the name assigned to its Recovery HD
partition; in my (brief) tests, it flaked out when this partition was renamed. I haven't encountered any other case of OSes or utilities caring about partition names, although they're often assigned to descriptions associated with the type code when partitions are created.
I'm not very familiar with Microsoft's diskpart
tool, but as Ben N specifies in his answer, it it possible to use it to set type codes to arbitrary GUID values. Other tools can do this, too, or can set type codes in some other way. My own GPT fdisk (gdisk
), for instance, uses four-digit (two-byte) hexadecimal values as "shortcuts" to known GUID values; or you can enter GPT values "raw." See the gdisk
Walkthrough section of the documentation for information on how to do this. The libparted library (which is used by several Linux tools) sets type codes based on the filesystem you say will be used on a partition; but you can change them to a limited extent by setting "flags," some of which correspond to type codes and some to attributes. This is a rather confusing blending of two independent underlying data structures.