VMware Cloud Community
rdicaire
Contributor
Contributor

Hot add RDM to a VM NOT using windows powershell

Scenario: All commandline based, using perl vmware tools, and direct ssh commands. ESXi 5 cluster.

On a SAN I take snapshots of a volume, I export the snapshot to vmware, rescan all HBAs, retrieve path to device,

vmkfstools -z args to map the RDM to a vmdk file.

All working thus far.

The next step (if my procedures are correct, if not please detail steps I may be missing) is to hot add this vmdk to a

running VM:

vim-cmd help vmsvc/device.diskaddexisting

Usage: device.diskaddexisting vmid disk file controller number unit number
Add an existing disk to this virtual machine.
Running the following on the esxi host that contains the VM.
~ # vim-cmd vmsvc/device.diskaddexisting 15 /vmfs/devices/disks/naa.50002ac001750dbd 0 4
Reconfigure failed

Also tried above command using full path to the vmdk I created with vmkfstools -z:

~ # vim-cmd vmsvc/device.diskaddexisting 15 /vmfs/volumes/VmWareRDM/QA02/VC-database.vmdk  0 4

Reconfigure failed

This can be done successfully using vSphere gui client. Surely this can be done using vmware cli tools.
Use of PowerShell is not an option as this operation is part of a larger script that gets executed in a cron job on a linux host.
So how can I hot add this RDM to a running VM, is there another command I can use instead of vim-cmd?

1 Reply
Prime2099
Contributor
Contributor

We do this through a ssh script to the VM Host so I have provided the commands we use, this is for ESX 4 so if you are on ESXi 5.x you will need to update the commands to use esxcli and not esxcfg ones.

#rescan hba and for vmfs
esxcfg-rescan vmhba1
vmkfstools  -V
#get old UUID and resig
xUID=$(esxcfg-volume -l | grep UUID | awk '{print $3}' | awk -F\/ '{print $1}')
esxcfg-volume --resignature $xUID
#find ID of VM_GUEST_NAME
vID=$(vmware-vim-cmd vmsvc/getallvms | grep VM_GUEST_NAME | awk '{print $1}')
#find new Datastore name (changes each time)
newDS=$(ls -laF /vmfs/volumes/snap* | awk '{print $9}')
echo $newDS
#wait for disks to show up
sleep 30
#add disk to VM to controller 0 and disk 1
vmware-vim-cmd vmsvc/device.diskaddexisting $vID $newDS/VM_GUEST_NAME/VM_GUEST_NAME_1.vmdk 0 1