Converting VMware VMDK Files to Microsoft’s VHD Format and VHD to VMDK

Overview

VMware’s virtualization products, such as ESXi and Workstation, all use versions of the VMDK file format for their virtual hard disk files – essentially an entire hard disk in a .vmdk file. In contrast, Microsoft has standardized on the VHD file format for the same purpose, used by Virtual PC and Hyper-V, as well as being natively supported by the Windows 2008/7 file system. You can mount a vmdk file within Windows but you need to have the VMware Disk Mount utility installed, whilst if you have Windows 2008 or 7 then you can “attach” a VHD file and give it its own drive letter.

When Should You Use This Guide?

Don’t use this guide if you are looking to convert an operating system boot drive, e.g. to migrate a Virtual PC VM to an ESXi server, as there are several additional steps you would need to carry out to make the virtual disk bootable. Instead, use a dedicated conversion utility such as the VMware Converter Standalone, or the Converter plug-in for vSphere as explained in this Petri article: “Importing Hyper-V VMs Into vSphere.”

However, if it’s just the data files you need to access, then this is a quick and easy way to do it – for example, if you have a corrupted Windows 2008 ESXi VM that no longer boots and you want to access the system disk in order to replace some dll files. Alternatively, you might have a data drive on a Hyper-V VM that you want to copy to an ESXi VM, but for security or speed reasons a network copy is not an option. In both scenarios, the ability to convert from VMDK to VHD or vice-versa can be a real time saver.

The Starwind V2V virtual disk conversion utility

For this task, we will be using the Starwind V2V Image Converter, which is a free utility available from the Starwind website. If you haven’t encountered them before, Starwind is best known for their software iSCSI SAN solution, which allows you to present storage space on a Windows system as a shared iSCSI target – essential for advanced virtualization features such as VM High Availability. Apart from anything else, it means that they have an in-depth knowledge of storage systems and virtual disks, enabling them to produce this handy tool.

StarwindV2V

It’s only a small file so it shouldn’t take you long to download. When it’s completed, run it to launch the installer and follow the installation wizard; you should be fine with all the default options. Once it is installed, launch the program and you should see a window like the image above. For this example, we will take a drive from an ESXi hosted Windows 7 VM, convert it to a Microsoft VHD file, and then attach it as a new drive on a Windows 2008 Server.

Browse Datastore

To start the process, you need to download the virtual disk vmdk file from the ESXi server to the computer you installed the V2V Converter on. Connect to the ESXi Server with your vSphere Client, select the VM, and make sure you are on the “Summary” tab in the right-hand pane; then in the “Resources” box, right-click on the datastore and select “Browse Datastore.”

This will open a new file browser type window showing the contents of the datastore, with separate folders for each VM stored in it, so browse to the one you want to work on. Depending on the number of virtual disks attached to your VM there may be several VMDK files listed, but you can often spot the correct one by just checking the size, unless they are identical. If this is the case, you can confirm the file name by selecting “Edit Settings” on the VM, and then selecting the drive from the hardware list; it will then show the file path and name. When you are happy you have found the correct file, click to highlight it and left-click the “download file” icon in the toolbar above. You will then be asked to choose where you want to download it to; select a suitable location, but make sure you check that there is enough free space first, as the downloader won’t do it for you. It’s annoying to have a large download fail after 30 minutes because the drive is full!

Now that you have downloaded your VMDK file, close the datastore browser and return to the Starwind V2V Converter, click “Next” to move onto the “Select Source File” window, and use the file browser to select the file you just downloaded. You may find that there are two VMDK files in the location, one of which has “_flat” appended to its name and is the right size for the drive you downloaded, but you need to select the other file with the unaltered file name (if you choose the wrong one then the utility will tell you it can’t read the file anyway). Now the utility should show the VMDK file you have selected with a brief description including the total size for the virtual disk it represents:

select source

Now click “Next,” and in the next window you will be asked to select what format you want to convert your virtual disk into. The first part should be obvious – “MS Virtual PC,” but you also have to choose between “growable” and “pre-allocated,” which are Starwind’s terms for thin and thick provisioning respectively. If you’re not that familiar with virtual disk terms, “thin” provisioning means that the disk file only uses enough storage space to contain the actual data in the virtual disk, whereas “thick” automatically creates a file that is the size of the virtual disk, even if 95% of it is empty space. Thick provisioned disks have better write performance and you don’t have to worry about them not working if the host disk runs out of space, but for this operation it will be much easier to keep the file as small as possible, so select the “growable” option. Click “Next” to start the conversion process and wait until it completes. You should see a window like this:

conversion

Now you can click “Finish” and the V2V utility will close; browse to the location you selected for the converted file and you should see the .vhd file there. Now for the final step to gain access to the files: If you wish, you can attach the VHD virtual disk to a Microsoft VM, but for this example, we want to mount it as another drive on our computer. Note that this procedure will only work in Windows 2008 or Windows 7; if you have an older version, you will need to use a utility called VHDmount.

To mount the VHD file as a drive, you need to open the Disk Management snap-in; you can either get to this via the Server/Computer Management console, or just click “Start” and enter diskmgmt.msc to open it. You should then see the list of volumes and disks attached to your computer in the console; click the “Action” menu and select “Attach VHD,” and you will then be prompted to select the file:

attach VHD

Note that you also have the option to mount the virtual disk as Read-only; this may be useful in some situations, but we will leave it unchecked this time and just click “OK.” After a brief pause, you should then be able to see that your virtual disk has appeared in both the list of disks and volumes, and if you open Windows Explorer, you will be able to use it like any other drive. Since we selected the “growable” (thin provisioned) format, you will also find that if you save any new files to this drive, then the .vhd will correspondingly grow in size.

What has actually happened when we attached the VHD, is that Windows has first just mounted it as a drive, and then it inspects the partition table to see if it can recognize the data. Since this VHD started off as a Windows drive originally, the current OS recognizes it as a valid volume and mounts the file system, assigning the next available drive letter (you can easily change the drive letter if you want by right-clicking on the volume). In comparison, if this VHD came from a Linux virtual disk originally, then it might well be formatted using the ext3 file system which Windows cannot read; then it does not assign a drive letter and shows the partition as “unknown.” For some foreign filesystems, you can download third party extensions for Windows, which allow it to recognize the volume and assign a drive letter, so you can then access like a normal volume.

When attached like this, Windows treats the virtual disk just like any other physical disk that you might have installed in the PC; you can, in fact, format and partition it from scratch if you feel like it!

Conclusion

You might be thinking at this point that the whole procedure is over-complicated; after all, you could achieve the same result by copying all the files to an external USB drive and plugging that into your computer. However there are many situations, especially with virtualization, where various factors may prevent that from being an option. The single file virtual disk format, whether VMDK or VHD, is flexible and portable, especially when moving from virtual to physical platforms. Being able to easily convert from one format to the other with this V2V utility means that it doesn’t matter whether the virtual platform is Microsoft or VMware.