This project is read-only.

VB.NET - Need to get and set adaptertype from VMDK

Nov 18, 2011 at 9:43 PM

Ok, we have given up on the idea of using Powershell to accomplish the previous idea and have switched to using VB .NET to move forward.

We are trying to make a disk exactly like an existing disk, but without copying the contents of the disk.  Long story...

Anyway, we have succeeded at opening the existing disk:
       Dim sourceDisk As VirtualDisk = VirtualDisk.OpenDisk(args(1).ToString(), FileAccess.Read, "", "")

And creating a new disk:
       Using destinationDisk As VirtualDisk = VirtualDisk.CreateDisk("VMDK", "vmfsfixed", args(2).ToString(), sourceDisk.Capacity.ToString(), Nothing, New Dictionary(Of String, String)())

Using parameters from the source to set parameters in the destination:
       destinationDisk.Signature = sourceDisk.Signature

And have gotten all initialization, offsets, and sizing to work.

But we need to make sure that the destination .vmdk has the same
adapter type as the source vmdk.  Granted, we could do that by editing
the text in the vmdk, but sloppy...

Can you give us a get/set of adaptertype so we could do this:
       destinationDisk.adapterType = sourceDisk.adapterType

Or otherwise allow us to interact (get and set) aspects of the descriptor file?

Nov 19, 2011 at 1:29 PM


You should be able to just do this:

            VirtualDisk orignalDisk = VirtualDisk.OpenDisk(@"original.vmdk", FileAccess.Read);

            VirtualDisk vmdk = VirtualDisk.CreateDisk("VMDK", "vmfsfixed", @"new.vmdk", orignalDisk.Parameters, null, null);



Nov 19, 2011 at 8:03 PM



I think he's asking how to get the type so it matches the original.  These are stored as extended parameters in a dictionary object.  @Electricd7 the last parameter of the CreateDisk above is where you can set the extended params.  The disk you opened (if it is a VMDK disk) will have an additional attribute (ExtendedParameters I believe but would need to go check the source) from which you can read the adapter type from..




Nov 19, 2011 at 8:56 PM

bsobel, that is exactly what I am trying to do.  The problem is that it appears that the adaptertype is not available as any portion of the open disk properties.  Am I missing something?

Nov 19, 2011 at 10:25 PM

The code should do exactly that, if not let me know.


If you look inside originalDisk.Parameters, you should see an extended parameter like this:

"VMDK.AdapterType" --> "LsiLogicScsi"

The string value is just the result of converting the enum DiscUtils.Vmdk.AdapterType, in string form.  VirtualDisk.CreateDisk then honours that parameter and injects it into the new VMDK.  Passing in originalDisk.Parameters to VirtualDisk.CreateDisk is just a more convenient way of passing in a bunch of parameters (including the 'extended' ones) from the original disk that you probably want to preserve in this case - such as the Physical and BIOS geometries, etc.

The intention is to avoid creating more overloads of VirtualDisk.CreateDisk in future - and instead, just extend the VirtualDiskParameters class with new fields and/or define new extended parameters.



Nov 21, 2011 at 2:23 PM

When I do this:

sourceDisk = VirtualDisk.OpenDisk(args(1).

ToString(), FileAccess.Read, "", "")

autosense provides the following sourceDisk. attributes:

BiosGeometry, BlockSize, Capacity, Content, CreateDifferencingDisk,
CreateDisk, Dispose, Equals, Geometry, GetHashCode,
GetMasterBootRecord, GetSupportedDiskVariants, GetType, IsPartitioned,
Layers, OpenDisk, Partitions, ReferenceEquals, SetMasterBootRecord,
Signature, SupportedDiskFormats, SupportedDiskTypes, ToString

I am importing:
Imports DiscUtils
Imports DiscUtils.Vmdk
Imports DiscUtils.Fat
Imports DiscUtils.Partitions
Imports DiscUtils.PhysicalVolumeInfo
Imports DiscUtils.DiskImageBuilder
Imports DiscUtils.VolumeInfo
Its like the .Parameters attribute is missing or I am not importing something that is necessary to make it usable.
Nov 22, 2011 at 12:32 AM


It has been added since the last release - so you'll need to build a copy of DiscUtils from the latest source code.




Nov 22, 2011 at 4:31 PM



The new source code worked!  The signature, however, didn't get set correctly on the destination disk using just sourceDisk.Parameters.  I added an extra line to my code which was:

destinationDisk.Signature = sourceDisk.Signature

And that made the resulting disk correctly and set the signature.  Not sure if the line you provided:

VirtualDisk vmdk = VirtualDisk.CreateDisk("VMDK", "vmfsfixed", @"new.vmdk", orignalDisk.Parameters, null, null);

Was supposed to also set the signature or not, but without setting it manually the resulting disk would not come up with the correct letter.  Other than that issue (which we worked around) the code did exactly what we wanted.  Thanks!