Hi,
In 5.0 version, with the GUI, when you want to svmotion a VM, you have three choices for storage: thin / thick lazy zero / thick eager zero.
We have a lot of VM in thin / thick lazy mode and want to convert it to thick eager without downtime.
In Powershell, smovtion is done by 'Move-VM" cmdlet. It has the 'DatastoreStorageFormat' option that only accept thin/thick for parameters (from the documentation).
After some tests, moving a thin VM with the cmdlet and 'thick' in parameter create a vmdk in 'thick lazy zero'.
Some try with 'EagerZeroVirtualDisk_Task' from the API too, but some problem with a lock on the file. It's not really clear in the documentation, but I think that VM must be poweredoff in order to use this function.
Is there a way in powercli to do a storage vMotion and (re)create vmdk in thick eager zeroed mode ?
Try it like this
$vm = Get-VM -Name MyVM
$destinationds = Get-Datastore -Name MyTargetDS
$HardDisks = @(Get-HardDisk -VM $vm) $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.Datastore = $destinationds.Extensiondata.MoRef
1..$HardDisks.Count | %{ $newFilename = "[" + $destinationds.Name + "]" + ($HardDisks[$_ -1].Filename.Split(']')[1]) $objBackinginfo = New-Object VMWARE.Vim.VirtualDiskFlatVer2BackingInfo
$objBackinginfo.DiskMode = "persistent"
$objBackinginfo.eagerlyScrub = $true
$objBackinginfo.FileName = $newFilename
$objDisk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$objDisk.DiskID = $HardDisks[$_ - 1].Id.Split('/')[1] $objDisk.DataStore = $destinationds.Extensiondata.MoRef
$objDisk.diskBackingInfo = $objBackinginfo
$spec.Disk += $objDisk } $vm.ExtensionData.RelocateVM_Task($spec, "defaultPriority")
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Thick Eager Zero mode is indeed not possible in the current PowerCLI build.
The only way is to use the API method.
Would you mind sharing the code you tried with the EagerZeroVirtualDisk_Task method ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For sure. Here's little powerCLI commands to test the API function:
Connect-VIServer -server esxiserver1 -user root $vm= Get-VM -Name "vm1"
$Dcenter = (get-view (($vm | Get-Datacenter))).moref
$vdiskMgr = Get-View (Get-View ServiceInstance).Content.VirtualDiskManager $vdiskMgr.EagerZeroVirtualDisk_Task((Get-Harddisk -VM $vm).filename,$Dcenter)
Output from vSphere GUI when connected to the ESXi:
Name: Zero out virtual disk
Target: [DS1] vm1/vm1.vmdk
Status: A general system error occurred: Failed to lock the file
That code works provided the VM is powered off.
See also my Scripts for Yellow Bricks’ advise: Thin Provisioning alarm & eagerZeroedThick post.
You find the same prerequisite when you look at vmkfstools command.
So I'm afraid, no way to do this without downtime of the VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, there is always a way but ... by the GUI
Anyone know how the GUI proceed to do the job ?
Indeed with svMotion it works, that uses a RelocateVM_Task
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Okay, will try to use it.
There is a sample in Storage VMotion 350+ Servers with 800+ associated vmdk files.
Use the diskBackingInfo property on the VirtualMachineRelocateSpecDiskLocator object to specify the format.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try to use this code:
$vm = Get-VM -Name "vm1"
$destinationds = Get-Datastore -Name "DS1"
$HardDisks = @(Get-HardDisk -VM $vm) $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
1..$HardDisks.Count | %{ $objBackinginfo = New-Object VMWARE.Vim.VirtualDiskFlatVer2BackingInfo
$objBackinginfo.DiskMode = "persistent"
$objBackinginfo.eagerlyScrub = $true
$spec.Datastore = $destinationds.Extensiondata.MoRef $objDisk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$objDisk.DiskID = $HardDisks[$_ - 1].Id.Split('/')[1] $objDisk.DataStore = $destinationds.Extensiondata.MoRef $objDisk.diskBackingInfo = $objBackinginfo $spec.Disk += $objDisk } $vm.ExtensionData.RelocateVM_Task($spec, "defaultPriority")
With no luck:Exception calling "RelocateVM_Task" with "2" argument(s): "
Required property fileName is missing from data object of type VirtualDiskFlatVer2BackingInfo
while parsing serialized DataObject of type vim.vm.device.VirtualDisk.FlatVer2BackingInfo
According to the doc, Filename is "Filename for the host file used in this backing".
I think that is the destination vmdk filename that is needed, but I don't see how to construct it
Try it like this
$vm = Get-VM -Name MyVM
$destinationds = Get-Datastore -Name MyTargetDS
$HardDisks = @(Get-HardDisk -VM $vm) $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.Datastore = $destinationds.Extensiondata.MoRef
1..$HardDisks.Count | %{ $newFilename = "[" + $destinationds.Name + "]" + ($HardDisks[$_ -1].Filename.Split(']')[1]) $objBackinginfo = New-Object VMWARE.Vim.VirtualDiskFlatVer2BackingInfo
$objBackinginfo.DiskMode = "persistent"
$objBackinginfo.eagerlyScrub = $true
$objBackinginfo.FileName = $newFilename
$objDisk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$objDisk.DiskID = $HardDisks[$_ - 1].Id.Split('/')[1] $objDisk.DataStore = $destinationds.Extensiondata.MoRef
$objDisk.diskBackingInfo = $objBackinginfo
$spec.Disk += $objDisk } $vm.ExtensionData.RelocateVM_Task($spec, "defaultPriority")
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It works like a charm.
Thanks LucD !
i would like to have something like 4 VM per vCenter server