Shrink a thin provisioned VMDK disk

When maintaining a Horizon View environment I like to keep my parent images as small as possible and over time a thin provision disk can start to grow on you if you don’t watch it – be it from downloading installers, updates, or even running disk defrag. While there isn’t a simple, one click button in the View Administrator Console there is a fairly easy manual method using vmfkstools.

Before we can use “vmkfstools” to shrink the VMDK file we must zero out any unused space on the thin provisioned disk. A simple way of doing this is by using a free utility called SDelete from Sysinternals.

  1. Download SDelete onto the VM you want to shrink and run the following command, replacing [DRIVE:] with the actual drive letter to be reduced:
    sdelete.exe -z [DRIVE:]

    Note: In Linux VM’s you’ll want to run this command, replacing [PATH] with the actual path of the storage:

    dd if=/dev/zero of=/[PATH]/zeroes bs=4096 && rm -f /[PATH]/zeroes
  2. Power off the VM and SSH into your ESXi host and navigate to the VMDK’s datastore -> directory and check the VM’s current size by typing:
    Check virtual disk size:

    ls -lh *.vmdk

    current vmdk size
    Check actual size:

    du -h *.vmdk

    actual vmdk size

  3. Now we’ll punch all the zeroed blocks out of the VMDK file by typing, replacing [DISK] with the name of the VM VMDK file:
    vmkfstools --punchzero [DISK].vmdk
  4. Once complete, again check the size by repeating step 2. If all went well you should now have a smaller VMDK file and newly reclaimed space!
    resized vmdk size

If you do this on the parent image of a View Pool the changes won’t be “pushed” out to the VM’s within the Pool until your next recompose.

Similar Posts

  • VMware Recertification Policy

    VMware certified

    Starting today, March 10 2014, new VCP certifications must be re-certified within two years of it’s earned date. Anyone who currently has their VCP certification prior to March 10 2013 has until March 10, 2015 to re-certify.

    The new policy gives you three options to re-certify:

    1. Take the current exam for your existing VCP certification solution track. For example, if you are a VCP3, you could take the current VCP5-Data Center Virtualization (VCP5-DCV) exam.
    2. Earn a new VCP certification in a different solution track. For example, if you are a VCP-Cloud, you could recertify by earning VCP5-Desktop (VCP5-DT) certification.
    3. Advance to the next level by earning a VMware Certified Advanced Professional (VCAP) certification. For example, if you are a VCP5-DCV you could earn VCAP5-DCA certification.

    I can understand why they are doing this but I don’t agree with the changes. As per the announcement if you let your certification expire, “Your certification will be revoked,and you will no longer be entitled to use the certification logo or represent yourself as VMware certified“. Really? You mean everything that was done prior and after taking the exam means nothing?

    Read More “VMware Recertification Policy”

  • VMware Site Recovery Manager 8.2 – No more Windows

    VMware has just announced the release of Site Recovery Manager 8.2. There are a number of new items in SRM 8.2, such as enhancements to the HTML5 user interface, support for vSphere 6.7 Update 2, but most notably is Site Recovery Manager 8.2 virtual appliance!

    No more Microsoft Windows license needed! The SRM 8.2 virtual appliance runs on the Photon OS distro, which is similar to what the vCenter virtual appliance has been running on for years now.

    Read More “VMware Site Recovery Manager 8.2 – No more Windows”

  • VMware View client now availabe for Android!

    VMware has announced that they have released a View Client for Android tablets available on the Android Market now. Here are just a few of the features found on the new client.

    • A new look and feel – The View Client for Android features the NEW blue look and feel of the VMware View clients!
    • Multiple broker support – If you have more than one VMware View broker in your organization, you can can easily access your desktop from all of them via the Android client
    • Desktop Shortcuts – Quickly connect with as many as four recent desktop via shortcuts
    • Virtual trackpad – Control your desktop on a granular level just like you would control the mouse on a laptop
    • Custom keyboard toolbar – Super easy access to all of the special keys not found on the Android default keynboard
    • Honeycomb 3.x support – Made from the ground up for the new generation of Android tablets
    • Custom gestures – Invoke keyboard, scrolling, etc are as easy as ever and simple to use
    • VMware View Security Server support (best experience) – No need to have VPN when you use VMware View Security Server
    • Background tasking – Switch between apps on your tablet and come right back
  • VMware Horizon View 5.3 has been announced

    Horizon View 5.2 is receiving an update to 5.3! Doesn’t sound like much, but in that tiny dot number increase VMware has in fact brought a number improvements and features to Horizon View.

    In a nut shell, some features Horizon View 5.3 brings is the ability to connect to a virtual desktop from any HTML5 capable web browser (yes, even Chromebook!), ability to bring full workstation class user experience with 3D graphics, deploy Windows Server 2008 as a desktop, as well as completely rewritten the Windows client with support for Windows 8.1 and a new iOS7 client too.

    In more detail, Horizon View 5.3 brings…

    Read More “VMware Horizon View 5.3 has been announced”

  • How to upgrade vCenter server appliance

    Prior to VMware vCenter Server Appliance 6.x, upgrading or patching vCSA was as simple as a few button clicks in the appliance UI. Gone are those days, as VMware has replaced the appliance UI with a DCUI and the web based install wizard during setup.

    The good news is, upgrading or patching the vCSA 6.x is still pretty simple via the command line!

    Read More “How to upgrade vCenter server appliance”

Leave a Reply

Your email address will not be published. Required fields are marked *

8 Comments

  1. I only have the vsphere hypervisor. So then after performing these steps, could I simply do a clone of the changed image with vmkfstool -i -d thin to achieve the same result?

    Thanks!

  2. I tried to locate the vmdk file. but couldn’t find. when i tried it says permission denied or cannot locate. could you please guide me to find the vmdk file?

    1. Nuwan, are you able to view the directory listing when going to /vmfs/volumes/ ? Find the folder your VM is located, then CD into it and follow the steps above.

  3. Be aware that sdelete will inflate your thin provisioned disk before it can be shrunk using vmkfstools.
    I was running low on datastore space, so I deleted a bunch of files from a VM, and tried to run sdelete, which resulted in VM stop. Luckily this was just test setup :-)

    So you can’t use this to shrink your VM files if you are already low on datastore space (Chances are your VM will stop because your disks can’t expand enough).

  4. My Linux VM showing 6 GB filesystem size through linux cli using df command but i am unable to reduce the .vmdk size less than 16 GB at esxi cli level. I have used above mentioned workaround at both the levels. the VMOS is thin provisioned. So how i can reduce the 16 GB size for an linux VM .vmdk file. where as in Windows VM there are no such issues.

  5. Hi;
    After performing these steps, I found the vmdk file with new lower size through esxi web console; but within ssh by ls command the file still has its previous size. Although the du command also shows the lower size same as web console. What is the problem?