Multiple NTFS Partitions in one dynamic vhd

Jan 27, 2010 at 10:34 AM


when I want to create a second partition in a vhd, I always get the Exception "New partition overlaps with existing partition", but there is enough "space" in the vhd disk left to hold the partition.

I debugged a bit and found that "FindCylinderGap" always returns 1024 as startcylinder, which will later end inside the first partition ...
Do I do something wrong?

my code is more or less this:


private LogicalVolumeInfo createPartition(VirtualDisk destDisk, bool initialized, long partitionSize, WellKnownPartitionType type, bool active)
            BiosPartitionTable pt = null;
            int partitionIdx = -1;
            if (!initialized)
                pt = BiosPartitionTable.Initialize(destDisk);
                pt = new BiosPartitionTable(destDisk);

            partitionIdx = pt.Create(partitionSize, type, active);
            VolumeManager volMgr = new VolumeManager(destDisk);

            return volMgr.GetLogicalVolumes()[partitionIdx];



Jan 27, 2010 at 11:09 AM

I found out, that my first partition is to big for CHS, so CHS End is 1023, 254, 63. There comes the startCylinder 1024 from.
but then when the LBA stuff is calculated, a startCylinder of 1024 is not detected as "wrong" and will definitley used as THE start.

So I think the discutils can't work with partitions bigger then 1023, 254, 63 in the create NTFS partition part.

Please correct me if I'm wrong :(.

Ciao Ephraim

Jan 27, 2010 at 9:27 PM

Definitely sounds like a bug in the partition creation code.  I'll take a look, but will take a few days before I get to it.



Jan 27, 2010 at 9:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 26, 2010 at 11:48 PM

This is said to be fixed here:

I have downloaded version 0.8 and this does not seem to be completely fine. Creating a vhd with multiple partitions always creates a an extra 8MB of unallocated space for each partition. Am I doing something wrong or is this still buggy?





Mar 27, 2010 at 2:15 PM

You're probably just seeing the expected effects of DiscUtils aligning partitions on track boundaries.

Can you post the output of DiskDump on a suspect disk, that should reveal if there's an alignment problem.


I've been meaning to add a way to easily create partitions on large block boundaries (e.g. 2MB boundaries), rather than on track boundaries - since that's the technique used by modern OS's.  I've added a work item to track that, which may also help in your case.




Aug 9, 2010 at 7:44 AM
Edited Aug 9, 2010 at 7:50 AM
Hey Ken, this is still a problem of discutils. Just replace your code with the following code in your VHDCreate Example and you will get the exception. The parameters I used to test is "-sz 200GB -t dynamic c:\new.vhd" using (FileStream fs = new FileStream(_destFile.Value, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { VirtualDisk vd = Disk.InitializeDynamic(fs, Ownership.None, DiskSize, blockSize); BiosPartitionTable bpt = BiosPartitionTable.Initialize(vd); bpt.Create(100 * 1024 * 1024, WellKnownPartitionType.WindowsNtfs, true); bpt.Create(WellKnownPartitionType.WindowsNtfs, false); } Ciao Ephraim PS: I just saw the remark at the Create function of BiosPartitionTable ... not what I would expect when I use that function, I must say, but ok when you want to have it that way.
Aug 9, 2010 at 8:23 AM
But it is definitely not that easy to e.g. find the biggest gap. I think I will implement it as take the highest LastSector + 1 till end of disk ... much easier :) Ciao Ephraim