Command to find Primary partition

Jan 27, 2015 at 8:24 AM
Does DiskUtils expose a command to find Primary partition for the VHD or VHDX? I am currently working to add support for VHDX (Gen 2) and getting stuck with an issue. The VHDX that I am using has 4 partitions (as per DiskPart tool) as below. When I mount the VHDX, I see only two partitions (Primary and System). My code has to access a file (answer file for unattend installation) in Primary partition and do further processing. My assumption was DiscUtils automatically detects the Primary partition as first usable partition. So I tried to open the partition with partionId=0 (zero based index) and then tried to detect the fileSytem for that partition using below which of course fails. It works fine if I use partitionId=3 as it finds the Prmary partition which is formatted with NTFS format.

The question is, how do I automatically detect which is Primary partition?

var partition = disk.Partitions.Partitions[partitionId];
var partitionStream = partition.Open();

Partition 1 -------------- Reserved
Partition 2 -------------- System
Partition 3 -------------- Reserved
Partition 4 -------------- Primary
Jan 27, 2015 at 7:31 PM
For BIOS partitions, look at BiosPartitionInfo.IsActive.
For GPT partitions, look at GuidPartitionInfo.Attributes - bit 2 probably is what you're looking for.

Wikipedia has info on both partition types.

Jan 27, 2015 at 10:55 PM
Thanks much. Wondering how to I use GuidPartitionInfo? I was trying different things to initialize the class with little success? The help file Discutils doesn't provide any detail on how to use the class. Any simple example will greatly help.