Wednesday, 26 April 2017

Useful Esxi commands

When snapshot consolidation is getting failed.

To move the CTK files and consolidate snapshots:
Connect to the ESXi host that the virtual machine is running on using SSH. For more information, see Using ESXi Shell in ESXi 5.x and 6.0 (2004746).
Navigate to the virtual machine folder using this command:

cd /vmfs/volumes/datastore/virtual_machine/

List the contents of the directory using the ls command and look for .ctk files.
Create a temporary directory for the CTK files.

For example:

mkdir temp

Move the CTK files to this directory with this command:

mv *-ctk.vmdk temp/

Run the snapshot consolidation again. 

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 check the status of physical NIC connectivity, run this command:
# esxcfg-nics –l

To check installed Esxi version :
#vmware -vl

To lunreset :
vmkfstools -L lunreset /vmfs/devices/disks/naa.XXXXXXXXX

No comments:

Post a Comment