Convert VMDK file to compressed RAW file

Carlo Zanocco picture Carlo Zanocco · Sep 20, 2018 · Viewed 11.3k times · Source

Explanation:

I created one virtual machine on my computer with VMWare. Now I need to move it on a VPS in Frankfurt.

Using the function provided by VMWare I created a snapshot (VMDK file)

On the hosting website I must upload a RAW format file.

To do the conversion I used qemu-img converter. According to the website, I tried to convert the vmdk to raw using this command:

qemu-img convert -f vmdk -O raw image.vmdk image.img

It works, but I obtained a largest file.

The VMDK image is 3.22GB and the RAW image after the conversion is 56.3GB

I have created the Virtual Machine with 60GB of disk size, so if I understood correctly:

  1. The VMDK file contains only the files that I created on the virtual machine.
  2. The RAW file have this big disk size because it get the size that I had indicated during the VM creation.

If this two observation are right the third question make sense.

Questions:

  • Is possible to reduce the RAW image size (compress it)?

  • I have to buy the VPS, but if I can't compress the RAW image, I have to buy it with 64GB of disk space?

  • Could be an idea to resize the allocated disk to the Virtual Machine ( eg. 10GB) and export it again as VMDK and after that convert to RAW?

EDIT 01/10/18:

After a lots of tests I figured out that is not possible to shrink the virtual disk size, the best solution is to create another VM with smaller disk and copy all the data on it (using rsync). If for you is important to not lost users, ssh ftp configuration etc.. I don't know how to do that. I have created again all the configuration.

I have tryed to convert in different format, VDI, HDD, RAW and reduce the virtual disk size is not possible on all the format.

Answer

oOo picture oOo · Jan 12, 2020

It might be possible to convert VMDK to VHD if the VMDK is just a simple/single partition/volume. If VMDK contains multiple partitions many tools will fail during conversion.

If it's convertable to VHD then Windows has disk management to shrink disks/partitions.

You could use this to shrink the VHD and then perhaps convert it back to VMDK.

I checked there is an option available: "shrink volume".

This might just be the thing you are looking for.