VMware Cloud Community
jravnsba1
Contributor
Contributor
Jump to solution

Script to convert VM from thin to thick eager zeroed while it is powered on

My VM has two disks located on Datastore_005 and Datastore_006

The disk located on Datastore_005 is Thin

The disk located on Datastore_006 is EagerZeroedThick

I can convert the VMs disks from thin to thick eager Zeroed by:

move-vm MyVM01 -datastore Datastore_007 -DiskStorageFormat  EagerZeroedThick

Is it possible to convert on the disk located on Datastore_005 to Thick Eager Zeroed without moving it to another Datastore while the VM is online ?

Joern Ravnsbaek
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm afraid so.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, if a number of conditions are met:

  • VM needs to be powered off
  • VM may not have snapshots
  • The harddisk must Thin
  • There should be sufficient free space on the datastore where the VMDK is located

In that case, you can use the InflateVirtualDisk method.

$vmName = 'MyVM'

$datastoreName = 'Datastore_005'


$vm = Get-VM -Name $vmName

if($vm.PowerState -ne 'PoweredOff'){

    Write-Host "The VM needs to be powered off"

}

if(Get-SNapshot -VM $vm){

    Write-Host "There may not be snapshots on the VM"   

}


$si = Get-View ServiceInstance

$vmdkMgr =  Get-View -Id $si.Content.VirtualDiskManager

$dc = Get-Datacenter -VM $vm


Get-HardDisk -VM $vm | where{$_.StorageFormat -eq 'Thin' -and $_.Filename -match $datastoreName} |

ForEach-Object -Process {

    Write-Host "Inflating $($_.Name) on $($vm.Name)"

    $vmdkMgr.InflateVirtualDisk($_.Filename,$dc.ExtensionData.MoRef)

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jravnsba1
Contributor
Contributor
Jump to solution

Hi Luc

Yes but the VMs has to remain powered on. (it +1000 VMs and lots of them are in production with no downtime available in normal business hours)

So I guess that I need to move the thin disk to another datastore to be able to do it while its online.

Or migrate the thin disk to a temporary datastore and then move (convert) it back to source datastore.

Joern Ravnsbaek
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid so.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jravnsba1
Contributor
Contributor
Jump to solution

I guess I should use something like this from one of your other great solutions:

$vmdkMgr.MoveVirtualDisk($srcVMDK,$srcDC.ExtensionData.MoRef,$dstVMDK,$dstDC.ExtensionData.MoRef,$force,$null)

But I'm not sure how to use it ?

Joern Ravnsbaek
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just thought of this, did you already try with Set-Harddisk and the StorageFormat and Datastore parameter?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we convert VM's having Thick provisioned to Thin provisioning ? Please let me know if yes what are the possible way to do.

Thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, that will only work with a Move-Harddisk cmdlet and the StorageFormat parameter.
I don't think there is an option to do this in-place.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vmk2014
Expert
Expert
Jump to solution

Thank you, LucD. We have data store provisioned and we are planning to get rid of thick provisioned disk.

thanks

vmk

Reply
0 Kudos
scorpion20
Contributor
Contributor
Jump to solution

Hi All,

Did we get this sorted yet please?

We have Think disk VM's in infra which we need to convert to Thick eager zeroed while doing the SVmotion of the VM's and moving them to a spedified cluster. The Vm's should be powered ON all time. Can this be scripted somhow please. There are lot of VM's and doing this manually will take month's to complete.

Thanks for any assistance anyone could provide.

~Nitin

Reply
0 Kudos