Monday, February 1, 2016

Some useful VMware Esxi commands

In this two part series I will summarize some useful Esxi commands that we use time to time. We can run any of these commands from local or remote console.
To run any of these cmd, first connect to host over ssh using putty  (I believe ssh is already enabled on host), once connected to host then, you can run the given command to complete the respective task:

To restart management agents:
#/etc/init.d/hostd restart
#/etc/init.d/vpxa restart
or
To restart all agents at once
#Services.sh
Note: this cmd restart all agents so could take a long time to complete that is why its preferable to restart individual agent

To Power off / Reboot an unresponsive VM: 
Using vim-cmd,
#vim-cmd vmsvc/getallvms  This command will give you the VM Name and respective VM ID.

Now, to see the power state of VM,
#vim-cmd vmsvc/power.getstate VMID

To shutdown the VM,
#vim-cmd vmsvc/shutdown VMID

If the above doesn't work then, use fowwing command to power off the VM,
#vim-cmd vmsvc/poweroff VMID
Using esxcli:
To get VM name and respective wordNumber
#esxcli vm process list 

To power off a VM : There are three power-off methods available with esxcli. Soft is the most graceful, hard performs an immediate shutdown, and force should be used as a last resort.
#esxcli vm process kill -t [ soft,hard,force] -w WorldNumber

Reload a vmx file without removing the virtual machine from inventory: First get to VMID as described above, then 
#vim-cmd vmsvc/reload VMID

To get a list of running tasks on the host,
#vim-cmd vmsvc/task_list 

To get a list of tasks associated with a specific VM,
#vim-cmd vmsvc/get.tasklist VMID

To get information about the status of a particular task, run the command
#vim-cmd vimsvc/task_info task_identifier 

We can also use ps command to find VM related running processes.
#ps |grep VM_name    this command will give you process id and if you want to kill the process, then
#kill process_id   wait for some time, if process is still there then use
#kill -9 process_id

To ping Any host/VM etc: 
#vmkping ip_or_hostname

To enter maintenance mode using the command line interface
vimsh -n -e /hostsvc/maintenance_mode_enter      or   vim-cmd /hostsvc/maintenance_mode_enter or  esxcli system maintenanceMode set --enable true
To check if host is in maintenance mode
#vim-cmd /hostsvc/hostsummary | grep inMaintenanceMode     or 
vimsh -n -e /hostsvc/hostsummary | grep inMaintenanceMode or
esxcli system maintenanceMode get
To exit maintenance mode
#vimsh -n -e /hostsvc/maintenance_mode_exit    or   
vim-cmd /hostsvc/maintenance_mode_exit or
esxcli system maintenanceMode set --enable false

To install an update or any third party vib file stored in any datastore:
#esxcli software vib install -d /vmfs/volumes/..../downloaded.vib or downloaded_vib_bundle.zip

To list the software and drivers currently installed on the ESXi host: 
#esxcli software vib list
 
To avoid slow host boot,  
1. Mark RDM device as perennially reserved: First get the naa.id of respective RDM LUN and use below command to mark it perennially then host wouldn't look for it during boot,
#esxcli storage core device setconfig -d naa.id --perennially-reserved=true

#To verify that the device is perennially reserved, run this command:
#esxcli storage core device list -d naa.id
2. If you are not intended to use USB then you might like to stop usbarbitrator services as it slowdowns host startup 
#chkconfig usbarbitrator off
To check the status of the USB arbitrator, run the following command:
#chkconfig --list | grep -i usb

And if you want to start the usbarbitrator service, replace the Off with on
#chkconfig usbarbitrator off

Note: For ESXi 5.1 and 5.5, a restart is not required. Restarting the management agents on the system will allow for accessing the devices

To check the status of physical NIC connectivity, run this command:
# esxcfg-nics –l

To check installed Esxi version :
#esxcli system version get
or
#vmware -vl

I will add more command to this list in future

That's it... :)


9 comments:

  1. Another good work by Noor, I will be waiting for your next commands post.

    ReplyDelete
  2. Are these 5.5 or 6.0 specific.or both.

    ReplyDelete
  3. Great share Noor, keep sharing.

    ReplyDelete
  4. good and looking ahead for other commands..

    ReplyDelete
  5. wonder full explanation.i ever seen this kind of simple understanding.thanks a lot..keep posted scenario based questions...have a bright future

    ReplyDelete