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

  • Easy ESXi 6.0 upgrade via command line

    VMware has released ESXi 6.0 back in March and I recently posted a guide on how to upgrade your vCenter Server Appliance from 5.x to 6.0 – Now we’re going to look at two ways to upgrade a VMware ESXi 5.x host to ESXi 6.0 via command line.

    The first method will show you how to have each ESXi host download the update directly from VMware and then upgrade itself while the second method shows how to download the update, place it on a datastore accessible to the host, then upgrade the host.

    Read More “Easy ESXi 6.0 upgrade via command line”

  • How to update VMware Windows VM’s DNS using PowerCLI

    This post will show you how to update a VMware Windows virtual machine’s DNS IP addresses using PowerCLI.

    You’ll also see how I went from a starting point to a fully working script – all thanks to the awesome #vCommunity!

    Here at work we’ve been doing a number of networking, AD, and DNS changes. In doing so, our DNS IP address have changed. Changing the DNS settings for our workstations was easy, simply edit the DHCP scope.

    The servers on the other hand all had static IP’s and static DNS IP’s entered, each of which needed to be updated.

    Read More “How to update VMware Windows VM’s DNS using PowerCLI”

  • 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 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”

  • How to add Realtek R8168 to ESXi 5.5 Update 2 ISO

    Realtek

    Over the past weekend I was working on a whitebox ESXi host and wanted to upgrade it to ESXi 5.5 Update 2 from an older version of ESXi 5.1 using a realtek R8168 network card. While I could have performed an in place upgrade, such as via command line, a clean install was preferred. However, VMware has removed a number of NIC drivers from ESXi 5.x and trying to install with the base ESXi image would result in a “No Network Adapters” error during install.

    In order to do a clean install you have to re-add the Realtek R8168 NIC drivers back into the ESXi 5.5 image, otherwise a NIC will not be found and thus ESXi will not install. These are the steps to easily re-add the Realtek R8168 drivers into ESXi 5.5 ISO by making a custom ESXi 5.5 image.

    Read More “How to add Realtek R8168 to ESXi 5.5 Update 2 ISO”

  • 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”

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