VMware Cloud Community
malabelle
Enthusiast
Enthusiast
Jump to solution

Migration to a New SAN with HardDisk to separate LUNs

Hi,

thanks to LucD, I now have a CSV file containing on the same line

the VM name and Each Hard Disk and it's file name. I also have a field for each drive with a place to enter the name of the Destination Datastore for each one.

VM,VM_NewDS,HD1,LUN1,LUN1_NEWDS,HD2,LUN2,LUN2_NEWDS,HD3,LUN3,LUN3_NEWDS,HD4,LUN4,LUN4_NEWDS,HD5,LUN5,LUN5_NEWDS,HD6,LUN6,LUN6_NEWDS,HD7,LUN7,LUN7_NEWDS,HD8,LUN8,LUN8_NEWDS,HD9,LUN9,LUN9_NEWDS,HD10,LUN10,LUN10_NEWDS,HD11,LUN11,LUN11_NEWDS,HD12,LUN12,LUN12_NEWDS,HD13,LUN13,LUN13_NEWDS,HD14,LUN14,LUN14_NEWDS,HD15,LUN15,LUN15_NEWDS,HD16,LUN16,LUN16_NEWDS

From what I know about the Move-VM command, it will move EVERYTHING from the selected VM to the specified datastore.

What I need is to be able to move the VM files (vmx, nvram, vmxf, etc) to the VM_NewDS and Each Hard Drive to his LUN*_NEWDS datastore.

My LUNs will be forged to be really segregated (one lun, 8 vmdks).

If I use, Set-HardDisk $HDx -Datastore HDx_NEWDS it will not move the vmx, vmxf, etc...

Do you know any way?

Thanks

vExpert '16, VCAP-DCA, VCAP-DCD
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are 2 cmdlets that allow you to move a VM and it's harddisks, Move-VM and Set-Harddisk.

Like you discovered, the Set-Harddisk cmdlet does not move the .vmx and other VM related files.

The Set-Harddisk cmdlet only allows you move a harddisk.

One way of doing this is to first use the Move-VM and then the Set-Harddisk for each virtual harddisk.

The disadvantage is that your harddisk files will be moved two times and that you need enough storage space on the datastore specified on the Move-VM cmdlet to hosts the complete VM.

The alternative way is to use the RelocateVM_Task method.

There is a good example in the  Storage VMotion to multiple datastores thread.


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

There are 2 cmdlets that allow you to move a VM and it's harddisks, Move-VM and Set-Harddisk.

Like you discovered, the Set-Harddisk cmdlet does not move the .vmx and other VM related files.

The Set-Harddisk cmdlet only allows you move a harddisk.

One way of doing this is to first use the Move-VM and then the Set-Harddisk for each virtual harddisk.

The disadvantage is that your harddisk files will be moved two times and that you need enough storage space on the datastore specified on the Move-VM cmdlet to hosts the complete VM.

The alternative way is to use the RelocateVM_Task method.

There is a good example in the  Storage VMotion to multiple datastores thread.


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

Reply
0 Kudos
malabelle
Enthusiast
Enthusiast
Jump to solution

So I will use the script in PowerCLI.

i can import a CSV and specify the variables for the fields?

I uploaded the script in attachment.

what do you think about that?

I have Vm with 1 disks and some with as much as 16...

Do I need to have a script for vms with 1 disk, one for 2, one for 3,  etc?

I'm really not sure about the way I call it in the attached ps1 file

vExpert '16, VCAP-DCA, VCAP-DCD
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can shorten the script by using some of PowerShell's features.

Try it like this

$csvfile = Import-Csv "migration.csv" 
Connect-VIserver
$Args[0] | Out-Null foreach($line in $csvfile){     $vm = Get-VM $line.VMName     $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
#
Get MoRef for Destination datastore for Config files
    $spec.Datastore = (Get-Datastore $line.VM_NewDS).Extensiondata.MoRef #for each disk specify where the vmdk files should be placed.
#If a vmdk should NOT be moved, enter its CURRENT datastore
#
If you forget to specify a disks location, it will be moved to the datastore
#specified in $spec.Datastore
    1..16 | %{         $objDisk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator
       
$objDisk.DiskID = $vm.HardDisks[$_ - 1].Id.Split('/')[1]         $dsName = $line.("LUN" + $_ + "_NEWDS")         if($dsName -ne ""){             $objDisk.DataStore = (Get-Datastore $dsName).Extensiondata.MoRef             $spec.Disk += $objDisk
        }     }
#When all harddisks are specified call the RelocateVM_task()
    $vm.ExtensionData.RelocateVM_Task($spec, "defaultPriority") }


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