Skip to content

Resizing Thin and Thick Virtual Machine Disk VMDK Files

March 5, 2012

I was recently working for a government customer who was running out of disk space in the VMFS datastores that were hosted on their EMC VNX storage array.  The customer informed me that they had originally created several Windows virtual machines using Thick provisioning because they were under the impression that there are performance issues associated with Thin provisioned disks.  I asked the customer if he had a chance to read Duncan Epping’s bLOG post Death to false myths: The type of virtual disk used determines your performance, Frank Denneman’s bLOG post Thin or thick disks? – it’s about management not performance or the VMware Performance Study of VMware vStorage Thin Provisioning. After I returned from lunch the customer asked if I could help assist them with modifying several of the virtual machine templates they had created and some of the virtual machines they were using in their QA environment.

We started with the templates that the customer had created, I opened the vSphere client and viewed the Virtual Machine Properties for Hard disk 1.  Immediately I noticed that the Disk Provisioning Type was Thin, in fact almost all of the templates that the customer had created were Thin.  The customer replied, “That’s strange, when I look in the Datastore Browser I see that the provisioned space is almost equal to the allocated space.”  I e-mailed the customer VMware KB: Using thin provisioned disks with virtual machines and asked if I could see the process used to create the Templates.

Although the customer didn’t have any documentation he was familiar with the process and walked me through the steps they took to build templates, during the conversation he said “and then before I convert it to a Template, I run the Windows Disk Defragmenter”.  Ughh….The Windows Disk Defragmenter inflates a Thin provisioned disk to its full size.

To clean up the disks I had the customer download and run SysInternals SDelete v1.61. On the first Template sdelete -z was the command I asked him to run.  Since the customer’s Thin provisioned disk was already inflated I didn’t have to worry about it consuming any more disk space within the VMFS datastore.  Executing Sdelete can be very time consuming, the customer reported that a Template with a 40GB virtual disk took almost 2.5 hours to complete.  Once the customer had finished, I executed the commands in the screenshot below to perform a technique known as hole punching.  The specific command required is vmkfstools -K nameofdisk.vmdk IMPORTANT: The K is case sensitive, it must be UPPERCASE.  The hole punching process was very quick, it only took seven minutes to complete.  The process restored the virtual disk size from 36.3 GB to 8.8 GB, a savings of 27.5 GB on a single template!  With over 100 more templates remaining this customer was going to relaim a significant amount of disk space.  Please don’t be mad at me EMC, they are still going to buy another VNX.

PuTTyVMKFSTOOLS-KHolePunchingThe customer wanted to tackle the virtual machines in the QA environment next. Again, I opened the vSphere client and viewed the Virtual Machine Properties for Hard disk 1.  This time I noticed that the Disk Provisioning Type was indeed Thick.

Our first step was to change the disk from thick to thin.  To do so, I typically follow the steps outlined in the VMware Knowledge Base article Changing the thick or thin provisioning of a virtual disk (2014832)  If the customer is running low on Datastore space I will have them select the local Datastore temporarily, and then copy it back to the original datastore.

In this case since we still had PuTTY opened and had plenty of disk space I cloned the disk to the existing datastore using the following command: vmkfstools -i nameofsrcdisk.vmdk -d thin nameofdstdisk.vmdk.  Once the cloning process was complete I had the customer edit the Virtual Machine settings and Remove Hard disk 1 from the virtual machine IMPORTANT: DO NOT DELETE THE FILES FROM DISK YET!  Next I had the customer add Hard disk 1 and select the cloned .vmdk from the datstore, if the virtual machine powers on successfully I have the customer delete the original .vmdk file.  You could also rename the target .vmdk file after deleting the src, however my customer wanted to leave the letter A at the end of the .vmdk file as a marker that the disk had been fixed.

If you are looking for a way to automate the process Conrad Ramos of vNoob posted a Powershell script in the Microsoft Technet Gallery and on his bLOG vNoob.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: