Sunday, November 21, 2010

Thin provisioning

Under vSphere, I have came across situations where I needed to quickly change the disk type from thick to thin or to check whether my virtual disks were preallocated on disk or not. Thin provisioning is something new to VMware vSphere which enables you to thin-provision your disks in order to optimize the utilization of available storage.

Changing disk format for a VMDK virtual disk can be done via the command line interface called vmkfstools; which let you manage your VMDK files (these are the actual virtual hard drives for the virtual guest OS). There are plenty of switches under vmkfstools, and some are exactly what we need to change the VMDK format. Let's have a look at...
them through a few examples.

First of all it is important to detect if your VMDK is thin, zeroedthick or eagerzeroedthick. Know that in a zeroedthick VMDK, the disk space required for the virtual disk is completely allocated at the moment of the creation but unused space will be progressively zeroed out at a later time during virtual machine read and write operations. In the vSphere Client, zeroedthick is the default option. In a eagerzeroedthick VMDK, the behavior is the same but, unlike with the zeroedthick format, the data remaining on the physical device is zeroed out during creation. Disks in this format usually take much longer to create than other types of disks but their write operation performances are a little better. This makes Eagerzeroedthick the required format for the Fault Tolerant (FT) virtual machine feature with vSphere.

So, ssh into your esx, move to the folder storing the files for your VM and and issue the following commands for all your virtual disks:

[root@esxserver]# cat vmware.log | grep 'scsi0:0′
[root@esxserver]# cat vmware.log | grep 'scsi0:1′
[root@esxserver]# cat vmware.log | grep 'scsi0:2′

This will print out a lot of information. Look for the "allocationtype" field that returns a number that represents each virtual disk format. There are three possible values:
  • allocation type: 0 – EagerZeroedthick Virtual Disk
  • allocation type: 1 – Zeroedthick Disk
  • allocation type: 2 – Thin Virtual Disk
Checking the number will tell you then how your VMDK was originally formatted. Easy, isn't it?

Now that you know this, let's learn how to convert for one disk format to another. Start by shutting down the guest VM, then follow one of these procedures according to your needs.

From thin to eagerzeroedthick, use the -j switch, aka inflatedisk (this can take some time, so, better safe than sorry, first test it in a non production environment):
vmkfstools -j yourdisk.vmdk

From zeroedthick to eagerzeroedthick, use the little -k switch, aka eagerzero:
vmkfstools -k yourdisk.vmdk

From any type of thick file to thin, use the capital -K switch, aka puchzero (cool name for a function!):
vmkfstools -K yourdisk.vmdk

Another simple solution to change a disk from thick to thin is to use the -clonevirtualdisk switch of vmkfstools.

Run: vmkfstools -i yourdisk.vmdk yourthindisk.vmdk -d thin
when done, edit with VI the vmx configuration file and replace
scsi0:0.filename = "yourdisk.vmdk"
scsi0:0.filename = "yourthindisk.vmdk" 

I hope this will help you.
Just a last note: two types of files store your hard drive content:
  • The -flat.vmdk file stores the content of the virtual machines actual hard disk drives.
  • The .vmdk file is the disk descriptor file. This file contains all the information about the associated flat file.
This last file is the file you have to pass to vmkfstool, not the -flat one.

For a better insight fo thin vs thick disk performance, read this interesting VMware paper.

Have a nice day!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...