How to change GPT partition type on windows?

17,355

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.

Share:
17,355

Related videos on Youtube

user2284570
Author by

user2284570

Currently spending my spare time in Ethereum security. Was rewarded by GitHub and Google.

Updated on September 18, 2022

Comments

  • user2284570
    user2284570 almost 2 years

    The GPT format introduce far more place to metadata.
    To set a partition type in diskpart, one use :

    DISKPART> create partition msr
    

    or

    DISKPART> create partition efi
    

    or

    DISKPART> create partition primary
    

    But how to do change the type after partition creation like changing primary to efi ?

    • user2284570
      user2284570 over 8 years
      note it doesn’t have to be done with diskpart, other built‑in tools can be used.
    • Mokubai
      Mokubai over 8 years
      Please could you stick to standard ANSI text and refrain from using Unicode "lowercase capitals" or similar. It makes it impossible to search for your questions as "normal" search terms (non Unicode) will not be matched in your questions. This makes it harder for future visitors to find your question and thus reduces the audience of people who might be able to help you.
    • Ramhound
      Ramhound over 8 years
      Change the type to what exactly? There is only one type of GPT partition.
    • user2284570
      user2284570 over 8 years
      @Ramhound : for example convert unknown to efi. A ɢᴘᴛ partition have types set has flags (you can combine several types) ; associated ᴏꜱ ; id ; and guid.
    • Ramhound
      Ramhound over 8 years
      I don't believe diskpart has the capability.
    • user2284570
      user2284570 over 8 years
      @Ramhound : you can already do things likegpt attributes=0x8000000000000001with diskpart (where will set GPT_ATTRIBUTE_PLATFORM_REQUIRED GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER which will prevent all kind of methods for assigning a drive letter, making it more restrictive as hidden). However, the type isn’t stored in the 64 bits in partition type. I also already commented it doesn’t have to be done with diskpart.
    • Ben N
      Ben N over 8 years
      Why do you want to do this, exactly? If you just want to read or change a partition's data, you don't need to change its type. Knowing what you're trying to accomplish may let us solve the problem rather than answer the question.
    • user2284570
      user2284570 over 8 years
      @BenN : because of this reason.
  • user2284570
    user2284570 over 8 years
    Ok, I thoughtset idwas referring to an unique identifier much like ɢᴜɪᴅ instead of a type.
  • user2284570
    user2284570 over 8 years
    The microsoft reserved partition need to to carry a name in more the specific id. If it don’t you won’t be able to upgrade the windows® version without re‑installing.
  • user2284570
    user2284570 over 8 years
    The Microsoft windows® reserved partition need to to carry a name or it will won’t be possible to upgrade the windows® version without re‑installing. id and ɢᴜɪᴅs are 2 different independent things with 2 different values for each partition.
  • starfry
    starfry almost 6 years
    If you just want to see these values in gdisk without looking anywhere else: gdisk /dev/sdX. Select the extra functionality (experts only) menu (press x) and then press i to show detailed information on a partition. You need to do it one partition at a time (perhaps there is a better way?)
  • Simon Mourier
    Simon Mourier over 5 years
    Note a full list of Microsoft-documented guids for GPT partitions is available here: magnumdb.com/search?q=PARTITION_%2A+AND+valuetype%3ASystem.G‌​uid