VMware {code} Community
kung-foo
Contributor
Contributor

Using an unmodified VHD file as a VMDK file

Using an unmodified VHD file as a VMDK file

I had a situation where I wanted to have a small disk image that I could use to store configuration information. I wanted to easily be able to mount the image on my local workstation, make changes, and reattach it to a VM. One obvious solution was to just mount a VMDK file using vmware-mount.exe, but I have been having a bear of a time getting that to work correctly under Windows 7 x64. Additionally, if I wanted someone else to work on the image, they would have to have the VDDK installed. A new feature in Windows 7 is the ability to mount VHD images without any additional tools. So I thought wouldn't it be cool to just mount the VHD, do my stuff, umount and then turn it over to ESX? Since both the VHD and VMDK formats support "raw" or "flat" images, there should be a way to get them to play nice with each other. After a little playing around I got it to work.

1) Create a new VHD with "Fixed Size" (my_disk.vhd)

2) Create a empty VMDK config file (my_disk.vmdk)

3) add to my_disk.vmdk

version=1

CID=738ec070

parentCID=ffffffff

createType="vmfs"

RW 33554432 VMFS "my_disk.vhd" # assuming 32M

ddb.geometry.cylinders = "65536" # 32M/512

ddb.geometry.heads = "1"

ddb.geometry.sectors = "1"

ddb.adapterType = "lsilogic"

ddb.virtualHWVersion = "4"

4) done!

This works because the VHD format uses a file footer as opposed to a header. So the last 512 bytes contain the stuff Microsoft needs to load the file (magic, size, etc...). VMware just ignores the footer becuase we specify the size of the VMFS file as the size of the raw disk image.

To go the other way (existing flat vmdk file to a VHD file) you would just need to append the correct 512 byte footer to the vmdk file. I haven't tested this part yet but I'll post back here with the results.

-jonathan

0 Kudos
2 Replies
admin
Immortal
Immortal

Very nice.

-Sudarsan

0 Kudos
bboule
Contributor
Contributor

Hey Guys,

Not sure is this would be of interest, my company (StarWind Software) just released a free utility that aids in these types of conversions. I thought you might want to check it out http://www.starwindsoftware.com/converter

Hope you find it helpful!

Bob

0 Kudos