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 Workstation 11 released

    VMware Workstation 11 Unmatched OS Support

    At the start of October VMware announced Workstation 11, along with VMware Player 7 Pro and said both products would be available sometime in December. Well today is the day, VMware has now officially released VMware Workstation 11!

    Workstation 11 adds support for the latest version of Windows and Linux, as well as the latest processors and hardware, and also adds the ability to connect to VMware vCloud Air.

    Read More “VMware Workstation 11 released”

  • Installing VMware vCenter Server Appliance 6.5

    VMware has announced that VMware vSphere 6.5 has gone general available this week. Now installing VMware vCenter Server Appliance 6.5 (VCSA) is even easier as the requirement for the client integration plugin has been removed and now the VCSA appliance is delivered via an ISO image with an installation wizard that’s been broken up into two stages.

    The VCSA 6.5 ISO offers two types of installation methods, CLI and GUI install – both availalbe for Windows, Mac and Linux machines. In this guide I’ll walk through the steps of installing VCSA 6.5 using the Windows GUI install.

    Read More “Installing VMware vCenter Server Appliance 6.5”

  • Install ESXi 5.1 from a USB Flash Drive

    Many servers already come with a DVD/CD-ROM drive or some kind of ability to virtually mount an ISO image from a network share onto your server to then install ESXi. However, not all do or you just want to have your ESXi image readily available. Here’s a quick step by step instructions on how to use a USB flash drive to install ESXi.

    1. Download ESXi 5.1 from VMware (if you haven’t already) as well as UNettbootin.
    2. Plug in your USB Flash Drive.
    3. Open UNetbootin and select “Diskimage”, set Type to “USB Drive”, select Drive letter of your USB flash drive, and set the path of your ESXi 5.1 ISO image. Then click on “OK”.
      unetbootin setup
    4. Read More “Install ESXi 5.1 from a USB Flash Drive”

  • vSphere 5.1 Release Date leaked, maybe?

    Looks like Sammy Bogaert over at Boerlowie’s Blog has possibly found the release date of vSphere 5.1… maybe?

    I was about to download vSphere Update Manager PowerCLI 5.0.

    I followed the main site and wanted to check the documentation first. So I clicked the Documentation button.

    vmware update manager

    This lead me to the Docs of Update Manager PowerCLI 5.1! That’s right, 5.1! With a release date of 10 September 2012.

    vsphere5.1 release date

    None of the links for 5.1 work, so no news on any new features…

    Guess somebody at VMware was a bit too fast to update the website

    Nice find Sammy, guess time will tell if the Sept. 10th date is the actual release date or not.

  • Thank you VMware Community!

    VMware vExpert 2014

    So far, 2014 has been a very rewarding year for a number of reasons, two of which has happened in just a week or two span. First, Eric Siebert (@ericsiebert) announced on March 27th, this years results of the 2014 Top VMware & Virtualization Blog voting. My first year entered into voting and made it to 71st place! A huge thanks goes out to not only Eric but just as much so to everyone who voted for me!

    To top it off, yesterday VMware announced 2014’s first quarter VMware vExpert list. While vExpert isn’t a technical certification or even a general measure of VMware expertise. The VMware judges selected people who were engaged with their community and who had developed a substantial personal platform of influence in those communities. There were a lot of very smart, very accomplished people, even VCDXs, that weren’t named as vExpert this year. VMware awarded this title to 754 people this year and on that list of many impressive names you’ll find yours truly, Michael Tabor!

    I’m both honored and humbled by both lists. It’s a great feeling to be recognized by not only my peers through the voting in the Top vBlog but also by VMware themselves through the vExpert title.

    So again THANK YOU very much to the entire VMware community, a spectacular community indeed, and congratulations to everyone else that made the Top vBlog and vExpert lists!

  • Easy ESXi 5.5 upgrade via command line

    ESXi 5.5 was just released general availability (GA) on Sunday (9/22) and I’m itching to upgrade the home lab to run the latest version with all it’s goodies. I wanted to try upgrading my hosts without having to go through the same process that I followed setting up ESXi on the NUC in the first place, injecting custom NIC drivers, etc.

    Enter the command line…

    1. Move all VM’s from the host and then put the host into Maintenance Mode.
    2. Go to the Configuration tab > Security Profile and Enable SSH under Services.
      ssh enabled
    3. Under Firewall, enable httpClient (outbound http).
      httpClient enable
    4. Open PuTTY (or other SSH client) and SSH into your host.
    5. Read More “Easy ESXi 5.5 upgrade via command line”

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