Hi,
I'm running powercli 5.0.1 build 581491 and i'm trying to write a powercli script to:
1) create an RDM
2) assign that RDM to VM1
3) assign the same RDM to VM2
I'm able to create the RDM and assign it to VM1, but I'm unable to use "New-HardDisk" to assign it to VM2. Using the following command i'm able to create the RDM and assign it to VM1.
New-HardDisk -VM VM1 -DiskType RawVirtual -DeviceName /vmfs/devices/disks/naa.60000970000192603729533030353531
While trying to assign it to VM2, i'm doing the following:
New-HardDisk -VM VM2 -DiskPath "[san-datastore:1] vm1/vm1_1.vmdk"
And i get the following error:
New-HardDisk : 6/6/2012 2:13:19 PM New-HardDisk Incompatible device backing specified for device '0'.
What i realized is that if i create a regular vmdk file, then use the New-HardDisk using the "-DiskPath" option, then the command works ok. So my question is, what's the command to add an existing RDM to a VM?
Thanks in advance.
Did you configure physical bussharing on the controller for the ones you did manually ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes I did, but when I run the script it fails.
Can you perhaps attach the actual script you are using, so I can have a look ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Below is the script, add all the disks on controller 1 but fails on controller 2
$VM = get-view -ViewType VirtualMachine -filter @{"Name"="VM1"}
$Servers = get-content .\servers.txt
foreach ($Server in $Servers)
{
foreach($dev in $VM.Config.Hardware.Device)
{
if($dev.Backing.CompatibilityMode -eq "physicalMode")
{
If($Dev.UnitNumber -eq 0)
{
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (2)
$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = "add"
$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualDisk
$spec.deviceChange[0].device.key = -100
$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo
$spec.deviceChange[0].device.backing.fileName = $Dev.Backing.FileName
$spec.deviceChange[0].device.backing.compatibilityMode = ""
$spec.deviceChange[0].device.backing.diskMode = "persistent"
$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
$spec.deviceChange[0].device.connectable.startConnected = $true
$spec.deviceChange[0].device.connectable.allowGuestControl = $false
$spec.deviceChange[0].device.connectable.connected = $true
$spec.deviceChange[0].device.controllerKey = -101
$spec.deviceChange[0].device.unitNumber = 0
$spec.deviceChange[0].device.capacityInKB = 4194304
$spec.deviceChange[1] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].operation = "add"
$spec.deviceChange[1].device = New-Object VMware.Vim.VirtualLsiLogicSASController
$spec.deviceChange[1].device.key = -101
$spec.deviceChange[1].device.controllerKey = 100
$spec.deviceChange[1].device.busNumber = 1
$spec.deviceChange[1].device.sharedBus = "physicalSharing"
$_this = Get-View -Id $Server
$_this.ReconfigVM_Task($spec)
}
else
{
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)
$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = "add"
$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualDisk
$spec.deviceChange[0].device.key = -100
$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualDiskRawDiskMappingVer1BackingInfo
$spec.deviceChange[0].device.backing.fileName = $Dev.Backing.FileName
$spec.deviceChange[0].device.backing.compatibilityMode = ""
$spec.deviceChange[0].device.backing.diskMode = "persistent"
$spec.deviceChange[0].device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
$spec.deviceChange[0].device.connectable.startConnected = $true
$spec.deviceChange[0].device.connectable.allowGuestControl = $false
$spec.deviceChange[0].device.connectable.connected = $true
$spec.deviceChange[0].device.controllerKey = $Dev.ControllerKey
$spec.deviceChange[0].device.unitNumber = $Dev.UnitNumber
$spec.deviceChange[0].device.capacityInKB = 4194304
$_this = Get-View -Id $Server
$_this.ReconfigVM_Task($spec)
}
}
}
}
The device '0' is referring to a nonexisting controller '1,002'. which should be the second controller.
Sorry to bring back such an old thread, but this new-harddisk issue still exists for RDMs and so I'm trying to figure this alternative method out. I'm getting ready to use this technique for several pairs of VMs that use shared RDMs within each pair. Can anyone please expand a little bit on the device.key attributes on the storage controller and VMDK objects? It seems to me that most VMs start their Storage Controller key numbering at 1000 and increment from there. Each VM seems to start its VMDK key numbering at 2000 and move up from there.
Were the negative number key values selected in LucD's original script just to avoid conflicting with anything else that might be in these ranges (or any other ranges that were used by other objects)? When the script "clones" VM1's storage controller and VMDK configuration via the $spec, could it also use the same key values in order to keep those objects in their normal ranges?
The negative numbers are used to indicate that these are "new" devices.
You use different negative numbers to indicate different new devices.
Same goes for controllers, and you can refer to that negative controller number in a new disk, to make sure the new disk is attached to that new controller.
As an example, have a look at Re: Multiwriter Disk , not with RDM, but it shows how disks can be attached to the desired controller.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
i'm right now trying to add an HDD with a specific controller.
When i add a disk with the controller it's ok, i have my disk wich is in 1:0.
But i want to specify the unit number so that he can be at 1:2.
there is ths scipt that i use:
$VM = Get-VM -Name $VirtualMachine
$controller = Get-ScsiController -VM $VirtualMachine | where{$_.ExtensionData.BusNumber -eq $BusNumber}
while(-not $controller){
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$device = New-Object VMware.Vim.VirtualLsiLogicController
$device.BusNumber = $BusNumber
$device.Key = -1
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange.Device = $device
$devChange.Operation = 'add'
$spec.DeviceChange += $devChange
$vm.ExtensionData.ReconfigVM($spec)
$controller = Get-ScsiController -VM $vm | where{$_.ExtensionData.BusNumber -eq $BusNumber}
}
# Add the VMDK
$hd = New-HardDisk -VM $VirtualMachine -StorageFormat Thin -CapacityGB $DiskCapacity -Datastore $DatastoreName -Controller $controller -Confirm:$false
i try to use what you did in your scipt but i get some error when i try.
Clearly i'm stuck i don't have other idea to achieve what i want to do, if it's possible..
Can you help find a solution please?
Best Regard
Afaik you can't have this control with the cmdlets, you will have to call the ReconfigVM method, and set the UnitNumber.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey guys, new here and read through this thread. Do a lot of rdm in company deployments but not much scripting. No sure if scripting is practical anyway, I know smart folks on my automation team have tried. Basically said screw it, do it manually even though it 40 RDMs across four nodes.
To add raw disks in VMware for Microsoft clustering across nodes using GUI:
On Server1
1) Add physical mode controller to server1 ex.SCSI_1
1 ) create RDM on server1 from list of free luns, A corresponding mapping file will be created in the vm's datastore ex. vmServer1_1.vmdk
2) On server1 assign a unique slot on the controller SCSI_1 ex.. SCSI_1:0 to the new disk.
On Server2
1)Add physical mode controller SCSI_1 to server2
1) add a new disk to the server2 vm via "add exisitng disk"
2) will need to browse to server1 vm datastore folder and select vmServer1_1.vmdk
3) assign SCSI_1:0 to disk
Done
Seems easy to script but it's not...also don't forget those Perennial reservations set to "true" on rdm luns via the cli..