Virtual machines HDD format conversion with vSphere PowerCLI

January 26, 2011 — 2 Comments

What I like the most of PowerCLI is the power that gives you, instead of relaying on a GUI every second you just issue a couple of commands and everything gets done. Of course thin provisioning is no exception to this and following is the way to convert from thin to thick a VM hard disk and vice versa.

The first task is to get the type of the hard disks. You can use the vSphere Client to check the format of the disk, just edit the VM setting and go the the hard disk as shown in the screenshot below.

However using the vSphere Client is slow since you can only check one VM at a time, fortunately for us PowerCLI can offer a clean and elegant way to retrieve type for every disk of every virtual machine.

Next we are going to convert from thin to thick the hard disk of the debian-vm1 virtual machine. To do so we are going to use the cmdlet Set-HardDisk.

Now that the disk is converted, how can we revert it using only PowerCLI? The way to do it is to move the disk to another datastore and convert it during the process.

The cmdlet to use is again Set-HardDisk with the -Datastore and -StorageFormat options. Take into account that these options can only be used if you are connected to the vCenter Server, you can’t do this when directly connected to the ESX(i) server.

Any other methods to execute the same operation are always welcome so please comment :-)

Juanma.

2 responses to Virtual machines HDD format conversion with vSphere PowerCLI

  1. 

    This is great stuff.

    What I need is to be able to only convert some of the VMDKs in each VM, specifically those attached to a particular controller (could match on those on a particular datastore).

    Is there an easy modification to your examples above to achieve this?

    Tom

    • 

      Hi Tom, thanks for the comment. Following is a quick change to my procedure using a vm with two disks:

      C:\
      [vSphere PowerCLI] % $hdd = Get-HardDisk -vm debian-vm1
      C:\
      [vSphere PowerCLI] % $hdd

      CapacityKB Persistence Filename
      ———- ———– ——–
      16777216 Persistent [SATA-1T] debian-vm1/debian-vm1.vmdk
      16777216 Persistent [SATA-1T] debian-vm1/debian-vm1_1.vmdk

      C:\
      [vSphere PowerCLI] %

      With this we a have a variable containing both disks. Now to list properties of the second disk.

      C:\
      [vSphere PowerCLI] % $hdd[1] | format-list

      StorageFormat : Thin
      Persistence : Persistent
      DiskType : Flat
      Filename : [SATA-1T] debian-vm1/debian-vm1_1.vmdk
      CapacityKB : 16777216
      ParentId : VirtualMachine-vm-341
      Parent : debian-vm1
      Uid : /VIServer=administrator@vc01.vjlab.local:443/VirtualMachine=VirtualMachine-vm-341/HardDisk=2001/
      ConnectionState :
      ExtensionData : VMware.Vim.VirtualDisk
      Id : VirtualMachine-vm-341/2001
      Name : Hard disk 2

      C:\
      [vSphere PowerCLI] %

      And inflate it to convert it to Thick format.

      C:\
      [vSphere PowerCLI] % Set-HardDisk -HardDisk $hdd[1] -Inflate

      Confirm
      Are you sure you want to perform this action?
      Performing operation “Setting .” on Target “Hard disk 2”.
      [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): y

      A similar procedure with the first disk, move it to another datastore and convert it to thin during the process. Hope this helps :-)

      Juanma.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s