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 Workstation 12 Pro Released

    VMware has just released a new version of Workstation in VMware Workstation 12 Pro. Workstation 12 Pro provides full support for Windows 10, including features such as Cortana and universal applications. As well as even larger virtual machines with up to 16 vCPU’s and 64GB of memory. Workstation 12 Pro even supports 4K displays and DirectX 10 and OpenGL 3.3

    You can even seamlessly drag and drop virtual machines between your PC and your internal cloud running vSphere, ESXi or another instance of Workstation. In addition, easily connect to vCloud Air and upload, run, and view virtual machines right from the Workstation 12 Pro interface.

    Read More “VMware Workstation 12 Pro Released”

  • How to create a bootable VMware ESXi installer USB flash drive

    I’ve mentioned how to create a bootable VMware ESXi installer USB flash drive in an older post, but wanted to detail the steps I use to create an ESXi bootable install drive.

    Creating a bootable flash drive is very useful for machines without a CD-Rom or remote access like an iDRAC where you can virtually mount an ISO image – such as the Intel NUC.

    The process is very easy with just one tool needed, Rufus – if you don’t already have it go ahead and download it now!

    Read More “How to create a bootable VMware ESXi installer USB flash drive”

  • VMware ESXi 5 home lab upgrade

    In the past I’ve been using a single server to run my VMware ESXi home lab. it was slow, old, big and loud. I’ve been meaning to upgrade my home lab for a while and just never got around to it, until now! When looking for new hardware I wanted the servers to be as compact as possible, quiet, and low energy usage as possible while still having some horsepower.

    I debated on going the whitebox solution as I build all my own desktops anyway, I also looked at several other solutions such as the HP ML310e server, Shuttle XH61V barebones machine, but ultimately decided to go with two Intel NUC i5’s.

    Intel NUC i5 and 16GB ram

    Intel NUC i5 DC53427HYE Features:

    • Uses very little energy
    • Completely quiet
    • Supports up to 16GB RAM
    • A dual core CPU that scores nearly 3,600 in PassMark benchmarking
    • Includes vPro which allows me to easily run both NUC’s headless
    • Extremely small, nearly 4 1/2″ inch square footprint

    Read More “VMware ESXi 5 home lab upgrade”

  • VMware Update Manager U3e upgrade failing? Un-install it!

    VMware Update Manager U3e error

    I was recently upgrading a VMware environment from vCenter Server Update 3b to Update 3e and during the scheduled change I had also planned on upgrading VMware Update Manager to Update 3e and ran into the following error:

    VMware Workstation unrecoverable error: (vthread-3)
    GetProcAddress: Failed to resolve ENGINE)load_aesni: 127
    You can request support.

    Looking for a possible solution at the VMware Knowledge Base came back with no results and to error message wasn’t overly useful either with “VMware Workstation unrecoverable error: (vthread-3)” as Workstation wasn’t installed on this server.

    Read More “VMware Update Manager U3e upgrade failing? Un-install it!”

Leave a Reply to IT_Architect Cancel 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?