Pages

Friday, September 16, 2011

How to add / register / inventory a virtual machine to an ESXi host through console commands

I ran into an interesting challenge over the weekend while being a part of a datacenter move when we noticed that the vCenter for the environment started blue screening just as we were ready to bring the virtual machines back up.  Since the vCenter in this environment was a physical server and the time it will take to reinstall the operating system would take quite a bit of time, we knew that we would have to connect to each host to power on the VMs.  What made this a challenge was that the environment had a high secure server that locked down all of the ports within the network which meant would could not SSH or vSphere Client over to the hosts.  The only access we had was either through iLO (they’re HP blades) or direct monitor, mouse and keyboard to the servers.  To add to an already tedious process, some of the ESXi hosts had hardware problems and therefore could not be powered up.

With all of these issues in mind, I suggested that we gain access to the console through iLO and use the vim-cmd vmsvc command to power on the VMs on the hosts that we could connect to and also figure out the command to inventory the virtual machines onto the accessible hosts that are currently mounted on the inaccessible hosts.  Powering on the virtual machines wasn’t going to be a problem because I’ve done it before (see the following blog post for the console commands: http://terenceluk.blogspot.com/2011/08/powering-on-and-off-virtual-machines.html) but I did not know the command to inventory virtual machines so after figuring out how to do it, I thought it would be a good idea to write this post to help others who may be searching for this as well giving me something to reference to in the future.

Registering a VM

The console command for registering a VM is as follows:

vim-cmd solo/registervm

Simply typing in this command will display the following:

~ # vim-cmd solo/registervm
Insufficient arguments.
Usage: registervm vm path [name] [resourcepool]

registervm [cfg path] [name(optional)] [resourcepool(optional)]

Register the vm

~ #

image
The arguments to note here are as follows:

cfg path – this should be the path with the filename of your virtual machine’s VMX file which will almost always start with:

/vmfs/volumes/

Example

~ # vim-cmd solo/registervm /vmfs/volumes/vmfs01/vSphere\ Management\ Assistant/vSphere\ Management\ Assistant.vmx
336
~ #

image

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

name(optional) – this parameter sets the logical name of the virtual machine and as indicated by the enclosing brackets, you don’t necessarily need to specify a name because if you don’t, ESXi will simply use the VMX’s filename for the virtual machine.

Example

~ # vim-cmd solo/registervm /vmfs/volumes/vmfs01/vSphere\ Management\ Assistant/vSphere\ Management\ Assistant.vmx test
352
~ #

image

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

resourcepool(optional) – this optional parameter allows you to place the virtual machine into an existing resource pool.  What’s interesting about this parameter is that it is not as simple as specifying a resource pool name.  I won’t go into the details here but examples can be found here: http://www.virtuallyghetto.com/p/vmware-vimsh_9940.html.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hope this helps anyone who may find themselves in the same situation as I did.

No comments: