Convert VMDK to VirtualBox VDI  and compact disk

Convert VMDK to VirtualBox VDI and compact disk

Convert VMDK to VirtualBox VDI and compact disk 2 vdiI have been testing out  Solarwinds MSP backup, and one of the features this has is that you can restore the backup to a virtual disk, which is in VMware vmdk format.

I have tended to use Oracle VirtualBox locally for my virtual machines since it is compatible with a lot of appliance templates and vhd images you can download online and is free and has a small footprint. Although Windows 10 now does include a cut down version of hyper-v allowing you to run virtual machines, you do need the PRO version of Windows, which I did not have at the time of writing this, I was running Windows home edition.

While the vmdk file does work with VirtualBox natively,  I discovered that it does require some work to get it to boot and you cannot do much else with it, which includes shrinking it. This is one thing I needed to do in order to reduce the amount of space used by my restored virtual disk image.

Firstly in order to get the vmdk to boot I had to enable EFI mode in virtualbox settings.
I then had to run bootrec/rebuildbcd

To compact the disk, I discovered I have to convert the vmdk to a VDI file. thankfully this turned out to be quite simple.

If you will not be using a dynamic disk, and do not need to shrink it, then you can skip these first 3 steps obviously.

 1. Delete Unnecessary Files from the VM

  • The best way to do this is to run the Windows disk cleanup tool, including the option to “clean up system files”

2. Defragment the Disk

  • If you want to also shrink the disk, then Using the Windows defrag tool will help with the shrink process.

3. Clean any free disk space

After the disk has been defragmented, the virtual Windows drive will still have unused space containing garbage bits and bytes. These garbage bits and bytes are from the contents of files that used to occupy that space but that are no longer there.

The most effective way to clean free disk space on a Windows drive is to overwrite the unused space with a bitstream of zeros or to zero-fill any free space.

Windows does not come with a native utility to zero-fill unused space but you can find the excellent SDelete tool at Microsoft’s TechNet: https://technet.microsoft.com/en-us/sysinternals/bb897443.aspx

4. Convert the disk

If your vmdk image file is already connected to a guest VM, then you need to remove it, otherwise, the process will not work.

  • shutdown the VM
  • go into the virtual media manager and remove the vmdk file from the guest VM

Open CMD prompt, and navigate to your  VirtualBox folder, from here you will execute VBoxManage, using the coneMEdium command to clone the VHD and convert to VDI.

c:\Program Files\Oracle\VirtualBox> VBoxManage clonemedium disk --format VDI [drive]:[\path_to_file\sourceFile.vmdk] [drive]:[\path-to\destinationFile.vdi]

Obviously, replace the [drive]:[\path_to_file\myserver.vmdk] with your source and destination paths.

This conversion process will actually shrink  down the VHD by default if you are using a dynamic disk,  and should get it down the minimum required. If it hasn’t sufficiently reduced it, then you can try to run this command.

VBoxManage modifyhd --compact "[drive]:\[path_to_image_file]\[name_of_image_file].vdi"