VMware Cloud Community
ChrisRu
Enthusiast
Enthusiast
Jump to solution

move only one disk per storage vmotion

Hi,

we have currently the problem that we have to move only one disk with Storage Vmotion. I've found the commandlet "move-VM" for this, but I didn't find any option to move only one vmdk and not the whole VM?

Can anybody help me.

Thanks,

Christian

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There seems to be some issues with the RelocateVM_Task method.

See also .

After some trial and error I discovered that when you give the target datastore twice (in the VirtualMachineRelocateSpec and in the VirtualMachineRelocateSpecDiskLocator object) the sVMotion seems to work.

$vmName = <VM-name> 
$vmDisk = <HD-name>               # Ex "Hard Disk 2"
$tgtDS = <datastore-name>

$vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName}
foreach($dev in $vm.Config.Hardware.Device){
	if ($dev.DeviceInfo.Label -eq $vmDisk){
		$diskId = $dev.Key
	}
}

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$diskspec = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$diskspec.Datastore = (Get-Datastore -Name $tgtDS | Get-View).MoRef
$diskspec.diskId = $diskId
$spec.Disk = @($diskspec)
$spec.Datastore = $diskspec.Datastore
$spec.Host = $vm.Summary.Runtime.Host

$task = Get-View ($vm.RelocateVM_Task($spec, "lowpriority"))
while($task.Info.Status -eq "running" -or $task.Info.Status -eq "queued"){
	$task.UpdateView()
	sleep 5
}


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

View solution in original post

Reply
0 Kudos
18 Replies
admin
Immortal
Immortal
Jump to solution

In PowerCLI 4.0, Move-VM can't do this. At some point we want to have a Move-HardDisk but that is in the future.

You can do this via PowerCLI, but you have to use the API and Get-View to do it.

The relevant call is RelocateVM_Task and the only really tricky part is constructing the right disk relocator specs.

LucD
Leadership
Leadership
Jump to solution

There seems to be some issues with the RelocateVM_Task method.

See also .

After some trial and error I discovered that when you give the target datastore twice (in the VirtualMachineRelocateSpec and in the VirtualMachineRelocateSpecDiskLocator object) the sVMotion seems to work.

$vmName = <VM-name> 
$vmDisk = <HD-name>               # Ex "Hard Disk 2"
$tgtDS = <datastore-name>

$vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName}
foreach($dev in $vm.Config.Hardware.Device){
	if ($dev.DeviceInfo.Label -eq $vmDisk){
		$diskId = $dev.Key
	}
}

$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$diskspec = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
$diskspec.Datastore = (Get-Datastore -Name $tgtDS | Get-View).MoRef
$diskspec.diskId = $diskId
$spec.Disk = @($diskspec)
$spec.Datastore = $diskspec.Datastore
$spec.Host = $vm.Summary.Runtime.Host

$task = Get-View ($vm.RelocateVM_Task($spec, "lowpriority"))
while($task.Info.Status -eq "running" -or $task.Info.Status -eq "queued"){
	$task.UpdateView()
	sleep 5
}


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

Reply
0 Kudos
timparkinsonShe
Enthusiast
Enthusiast
Jump to solution

LucD,

I tried this on a machine today and it ended up moving the whole machine (all disks + the VMX, etc) rather than just the specified disk. Any ideas?

(p.s. thanks for all your posts here -they've been invaluable to me.)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you're right, it moved all the files.

There is something strange/wrong with the RelocateVm-Task method.

I consistently get an error about Independent disks ("IndependentDiskvMotionNotSupported") while I don't have any independent disks on the guest.

I'll continue looking for a solution.


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

Reply
0 Kudos
timparkinsonShe
Enthusiast
Enthusiast
Jump to solution

Just looking at: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.fault.IndependentDisk...

"An operation on a powered-on virtual machine requests that the virtual

machine's disks be moved without choosing a new home datastore for the

virtual machine, but the host does not have that capability."

I wonder whether the 'Independent' part is a bit of a terminology clash, as in not independent in regard to snapshots, but independent of the VM (vmx).

In which case I might try adding disk specs for the other disks in their source location, allowing the machine (vmx, etc) to move, add disk specs for all disks as they stand and try moving the machine back.

Reply
0 Kudos
olan025
Enthusiast
Enthusiast
Jump to solution

Anyone have a solution to this one?

I am trying to move VMDKs seperate from the VM configuration (home) directory.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you on vSphere ?


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

Reply
0 Kudos
mlubinski
Expert
Expert
Jump to solution

Yes this is possible (one trick), you must "fake move" (don't click ok) whole VM to destination datastore, then move whole VM back to original, and then move only one disk back to destination datastore, and finally press ok. This works for me Smiley Happy Just diring this fake move don't press ok (just drag&drop between datastores)

If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points

[I]If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points[/I]
Reply
0 Kudos
olan025
Enthusiast
Enthusiast
Jump to solution

not for the moment. 3.5/2.5..

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then I'm afraid I will have to disappoint you Smiley Sad

You could try the previous trick but that would be interactive, not scripted.


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

Reply
0 Kudos
ringjc
Contributor
Contributor
Jump to solution

It seems like the bug referenced here is now gone, so no need to specify the datastore twice. Thus, after I commented out:

#$spec.Datastore = $diskspec.Datastore

#$spec.Host = $vm.Summary.Runtime.Host

from the above code, I was able to use this code to successfully storage vMotion a single disk. This was with:

  • vCenter 4.0.0.

  • ESX 4.0.0, 175625

  • Windows 7 (has latest PowerShell)

  • vSphere PowerCLI

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks for sharing that with us.

Was on my ToDo list, you saved me some time Smiley Wink


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

Reply
0 Kudos
ringjc
Contributor
Contributor
Jump to solution

Saving time is good!

Ok, so now one can have a script that both nicely docuements where each disk lives and can do the moves too. Well, almost. Does anyone know how to vMotion the configuration files via PowerShell? I thought perhap it would show up as a hard disk with a special name, but as:

&gt; $vm = Get-VM &lt;machine name removed&gt;; Write-Host $vm.hardDisks
Hard disk 1 Hard disk 2 Hard disk 3 Hard disk 4

shows, such is not the case Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you're on vSphere you can do this

(Get-VM <VM-name> | Get-View).LayoutEx.File | where {$_.Name -like "*.vmx"}


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

Reply
0 Kudos
ringjc
Contributor
Contributor
Jump to solution

Yep, that works and returns associate attributes "key, name, type size, dynamicType and dynamicProperty". Unfortunately none of them is "diskId" that VirtualMachineRelocateSpecDiskLocator needs to trigger a storage vMotion Smiley Sad

In vCenter during a storage vMotion, in the "advanced" option that lists individual disks, in addition to each physical disk is the option to move the "configuration files". I'm pretty new using PowerShell, but I'm just not seeing a way to move those files via RelocateVM_Task. Am I missing something on that? Is there a different managed object to trigger moving those files? Or is this an over-sight in the SDK? Without it one really cannot fully script moving a VM that has multiple disks defined. Ok, one could first do a call to RelocateVM_Task to move everything, which does get the configuration files, and then issue individual calls to move the disks, but then you're moving data around more then necessary. Not really a good option. If I can't script moving the configuration files, I'll manually go though the GUI to take care of that final step.

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

A new release of PowerCLI is coming very soon, then you'll be able to do this with Set-HardDisk.

If you want a preview you can check out some code I demoed at the San Diego VMUG, which has an example of how this works. I posted it to the PowerCLI blog.

=====

Carter Shanklin

Read the PowerCLI Blog
[Follow me on Twitter|http://twitter.com/cshanklin]

Reply
0 Kudos
ringjc
Contributor
Contributor
Jump to solution

Ok, thank's, that's good to hear! For now I'll have to finish up my project by manually doing the configuration moves, but scripting the virtual drive moves saved me a good chunk of time so I'm not complaining Smiley Happy Just wanted to find out if I was overlooking an existing feature.

Reply
0 Kudos
Supal2009
Contributor
Contributor
Jump to solution

Thank you and Luc for all the help.

Reply
0 Kudos