The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,387 other followers

finding and deleting Windows EFI partitions with wmic and diskpart

Posted by jpluimers on 2016/01/05

DiskMgmt.msc does not allow you to delete EFI partitions.

I tried with WMI first.

wmic has a nice assoc mode that allows you to find associated classes like the logical drive association to physical partitions.

But lets start simple: physical partitions and logical drives.

C:\temp>wmic partition get DeviceID, DiskIndex, Index, Type
DeviceID               DiskIndex  Index  Type
Disk #1, Partition #0  1          0      GPT: System
Disk #0, Partition #0  0          0      Installable File System

C:\temp>wmic logicaldisk get Caption, DriveType, FileSystem, ProviderName, VolumeName
Caption  DriveType  FileSystem  ProviderName  VolumeName
C:       3          NTFS
D:       5

These Associations:

They can be hard to use.

LogicalDisks are bound to a Partition, but a Partition does not need to have a Logical Disk.

I wanted the other way around: finding partitions not having a LogicalDisk association. But that does not seem to be possible with WMI at all.

Heck, detecting EFI partitions with WMI seems to be impossible.

DiskPart

Even though there needs to be a 15 second delay between DiskPart invocations:

you must allow at least 15 seconds between each script for a complete shutdown of the previous execution before running the DiskPart command again in successive scripts

it seems to be the only way to go.

But it is hard, as there seems to be no way to convert from volume (which lists the EFI partition as ESP), to disk+partition.

So a way to automate what How to delete a protected EFI disk partition with Windows 7 or 8 | WinAbility Software describes seems impossible.

Any thoughts on that?

This is what I have done so far

  1. diskpart
  2. list volume
    1. now note the volume that has ESP
  3. list disk
  4. for each disk
    1. select disk #
    2. list disk
      1. to confirm you selected the correct disk
    3. list partition
    4. select partiton #
    5. list partition
      1. to confirm you selected the correct partition
    6. list volume
      1. to confirm the partition indeeds corresponds to the EFI volume
    7. delete partition override
    8. list volume
    9. list partition
    10. for each partition coming after the EFI partition
      1. select partition #
      2. list partition
        1. to confirm
      3. delete partition
      4. list partition
        1. to confirm

Now you can create a new partition on the disk.

–jeroen

via:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: