Convert a existing Virtual Disk on ESXi from Thick Provisioning to Thin Provisioning and vice versa

I was playing around on my ESXi server and noticed most of my servers were using under 10GB yet most where consuming between 20-45GB of datastore space. This is because when I set them up I went with the default setting of Thick Provisioning like many. So what do you do? I don’t want to reinstall my servers and loose everything. I also don’t want to waste space when I can afford new disks being unemployed at the moment.  After searching around I came across 2 nice articles on using vmkfstools to “convert” (it actually is cloning the disks) to Thin Provision and vice versa.

The command is:

mkfstools -i thick-disk-file thin-disk-file -d 'thin' -a lsilogic

The “thick disk file” would be your original VMDK while the “thin-disk-file” would be the resulting Thin Provisioned VMDK. The -i option will tell the sytem to export/clone the disk. The -d option will control the disk format, in this case setting as a Thin Provisioned disk. Finally, -a sets the controller type. You can read more about the various vmkfstools commands and options here. As far as the file locations, there are a few things to take into consideration. First, case  MUST match the file directories. If you have a machine named Remote (and therefore a directory by the same name) on a datastore named VM you must type the file path in exactly. For example, /vmfs/volumes/vm/remote/remote.vmdk would return an error on the example above.  The correct path would be /vmfs/volumes/VM/Remote/Remote.vmdk. Also, you will see alot of folders in your /vmfs/volumes folder with long alphanumeric names, ie. 4f83e0d7-1c8420e2-bb4f-0021703a6a48, or something similar. Unless you are feeling really bored or just like doing things the hard way, just use the simple datastore names. Additionally, avoid using naming your file <name>-flat.vmdk as that is a system created file used by ESXi.  Bad things will happen if you try that.

Now, to get this running you should power off your VM completely. Don’t use suspend. Type your command in  and let the command run. You should get a line with a percentage on the bottom of your screen. Wait for this to complete and it’ll return you to your command line. Your file should not be cloned.  Next step is to log into vSphere if you haven’t already and go to your VM. Open your Edit Settings dialog and remove the old hard disk. Now add a new disk. Select “Use an existing disk” and navigate to the VM under your datastore. You should have a file called <VM>-thin (or what ever you named yours) in the folder.  Select this file and finish adding it and confirm your settings. At this point it would be a good idea to boot up the VM and make sure it’s working. If everything checks out you can then delete the old virtual disk. That’s it.

To convert a disk from Thin to Thick (or any other disk type available) you would do the same command, change -d ‘disk type’ to your needs.

Verified by MonsterInsights