I was asked by a customer the other day how to find out, using the ESXi command line, how much disk space a thin provisioned virtual machine disk consumes. Back in the ESX days you used the du command to query the virtual machine disk and in ESXi, version 5.5, you need to use the stat command.
Fot this example i created a virtual machine, vcdx56-01, and added 2 virtual disks with 2 GB capacity each.
Hard disk 1 uses the provisioning mode “Thick provision lazy zero” meaning all the space is allocated on the VMFS datastore but no zeroes are written to the disk.
Hard disk 2 uses the provisioning mode “Thin provisioning”
By running the command “ls -l *-flat.vmdk” in the the virtual machine home directory we can see that both disk files are listed with the size of approximately 2 GB.
The thin provisioned disk is the “vcdx56-01_1-flat.vmdk” file. There are actually two disk files per virtual disk:
- vcdx56-01_01.vmdk – Disk descriptor file
- vcdx56-01_01-flat.vmdk – The virtual machine data
I decided to only show you the -flat.vmdk file in the example above since these files contains the actual virtual machine data.
In the virtual machine we can see that our thin provisioned disk uses about 432 MB of the available 2 GB.
Now we can use the ESXi stat command to determine the disk space usage from the ESXi perspective. Run the following commands:
- stat vcdx56-01_1-flat.vmdk – This command will give you the below output and the interesting thing are the numbers next to the “Blocks” section:
- stat -c %B vcdx56-01_1-flat.vmdk – This command will give you the block size:
Now you can easily determine the disk space usage by multiplying the blocks and the block size. In my case:
884736 * 512 = 452984832
This is the actual disk space usage in bytes and to make it easier to read, you can divide it two times with 1024 to get the disk space usage in MB. In my case it will be 432 MB and this matches what we saw from within the virtual machine.
I also told my customer, my first reply before getting into the stat command discussion, that he could verify the same thing by using the vSphere Web Client by browsing the datastore where the virtual machine is placed. The below picture shows pretty much the same disk usage value as determined by the stat command earlier.Remember that the “browse datastore” section in the vSphere Web Client does not include the virtual machine flat disk file. It only lists a combination of, in my case, the vcdx56-01_01.vmdk and vcdx56-01_1-flat.vmdk files. However, when you try to download the vmdk file via the vSphere Web Client “browse datastore” section you’ll get both files.
4 pings