Finding thin-provisioned virtual disks with PowerShell

By default, all virtual hard disks in VI3 are thick disks — space is allocated on the VMFS datastore for the entire disk.  Thin disks, on the other hand, grow dynamically according to guest OS demand.  There is a slight performance penalty with thin disks, but the real risk when using them is inadvertently filling up datastores after overcommitting storage resources.

The VI Client interface will not let administrators create new virtual machines with thin-provisioned disks.  Even so, it is entirely possible that your environment contains such disks.  Let’s take a look at a couple of ways to create these disks and then use a VI Toolkit (for Windows) PowerShell script to see if any exist.

Manual VMDK Creation

One way that thin disks may be introduced into an environment is by manually creating a VMDK file and then attaching that file to a virtual machine.  This can be accomplished by the vmkfstools command with the -d thin option.  This procedure is not for beginners, so if you have used it you presumably evaluated the risks of overcommitting your storage.  But what if one of your colleagues did this without telling you?

Compact Clones

VI Client - Clone to templateAnother source of thin disks requires a little background first:

There is a prominent option in the VI Client interface to convert a virtual machine to template (and vice versa).  But if you right-click a VM in the inventory, you are presented with a variation of that feature:  Clone to Template.

The wizard that launches in response to that option allows an administrator to optionally choose the Compact disk format — this is a thin-provisioned disk.  If your template has a 50GB virtual disk but only 8GB are actually used, this feature can provide significant storage savings.

Clone to Template Wizard - Compact disk

So far so good.  Now, what do you suppose happens if you decide to convert that template to a VM?  Nothing happens — it just works.  You are free to use that VM just like any other in your inventory.  But this VM keeps its thin-provisioned disk, a fact that is not discernible through the user interface.

Find the Thin-Provisioned Disks

I wrote a small VI Toolkit (for Windows) PowerShell script that identifies latent thin disks in both VMs and templates.  I hope you find it useful:

# FindThinDisks.ps1
# Identifies VMs and templates that are using thin-provisioned
# virtual disks.

# Version 1.0  January 14, 2009
# Eric Gray

$vmtp = Get-VM
$vmtp += Get-Template

foreach($vm in $vmtp | Get-View){
  foreach($dev in $vm.Config.Hardware.Device){
    if(($dev.GetType()).Name -eq "VirtualDisk"){
      if($dev.Backing.ThinProvisioned -eq $true) {
        $vm.Name + "`t" + $dev.Backing.FileName

Thin-provisioning is a great tool to have in your toolbox, when used properly.

Script inspired by this thread.

(Visited 4,112 times, 1 visits today)
This entry was posted in Virtualizationism and tagged , , , , , , , . Bookmark the permalink.

3 Responses to Finding thin-provisioned virtual disks with PowerShell

  1. Sven Huisman says:

    Nice Powershell script. Here is a nice addition to your blogpost:

  2. Eric Gray says:

    Sven, thank you for the link — good info on thin disks.

  3. Pingback: » Thin Provisioning in ESX 3.5

Comments are closed.