Friday, February 20, 2015

ESXi - moving VMs with thin provisioned disks to different datastore without vCenter

If you have tried to move a VM from one datastore to another on the same ESXi host, without vCenter, you might have realized that your thin provisioned disk files have a nasty tendency to end up as thick provisioned disks. Meaning that the copy process will be that much longer, and the target space needed that much bigger.

Google this, and your in for a ride! You will find advice ranging from using VMware Converter to accepting that your disks will end up thick provisioned.

Sparse files

Thin provisioned disks are kept as sparse files in your datastore volumes. Sparse files means that the filesystem takes care of keeping them "thin". Some of the tools we can use on these files are aware of this, some are not. For those tools that are not aware of this filesystem feature, the files appear as normal files, and will be read and written as such. Disk read time is still fast, but write time will be slower, as every little empty bit will be written to disk.

What not to do

The first method that comes to mind for moving a VM, is to first remove it from the inventory, then copy the VM's folder from one datastore to another, and finally add the vmx file to the inventory again. This method will not keep your disk files sparse! Not if you copy using the datastore browser, neither if you use SSH shell command line.

A solution

There might be prettier solutions out there, but this one is simple, and fast.
Remove your VM from the inventory. Use your datastore browser, one for the source datastore, one for the target datastore. Create a new folder on the target, similar to the VM's folder on the source datastore.
Open your source VM's folder. Select all the files, right-click and choose copy. In the target folder, right-click and choose paste. Your disk file will now be copied as a sparse file, ending up as thin provisioned. The difference here is that we are not copying a folder, but individual files.
Finally add your target vmx to the inventory, and delete your source folder from disk when success is confirmed.

This trick does not work with cp from the command line.