Useful command line interface collection for the ESXi shell. Only use in lab and never in production environment.
Working with VMs
List all VMs registered to this host (This reveals the VMID needed for other commands)
1 |
vim-cmd vmsvc/getallvms |
Unregister a VM
1 |
vim-cmd /vmsvc/unregister <Vmid> |
Register a VM
1 |
vim-cmd /solo/register /path/to/file.vmx |
Get power state of a VM
1 |
vim-cmd /vmsvc/power.getstate <Vimid> |
Power off a VM
1 |
vim-cmd /vmsvc/power.off <Vmid> |
Power on a VM
1 |
vim-cmd /vmsvc/power.on <Vmid> |
Get snapshot info of a VM
1 |
vim-cmd /vmsvc/snapshot.get <Vmid> |
Take snapshot of a VM
1 |
vim-cmd /vmsvc/snapshot.create <Vmid> name description 0 1 |
Get overview for snapshot troubleshooting
1 |
egrep 'retries|retry|unstun|idaterate|branch' /vmfs/volumes/path/to/vm/vmware.log |
List VMs running on host and get world id
1 |
esxcli vm process list |
Kill process
1 2 3 4 5 |
esxcli vm process kill –type=soft –world-id=<worldid> esxcli vm process kill –type=force –world-id=<worldid> esxcli vm process kill –type=hard –world-id=<worldid> (Soft (SIGTERM) is the most graceful, hard (SIGKILL) performs an immediate shutdown, and force should be used as a last resort) |
Block mapping for VMDK
1 |
vmkfstools -f0 vmname.vmdk |
Networking
Capture all traffic on vmnic0
1 |
pktcap-uw --uplink vmnic0 |
NIC driver/firmware check
1 |
ethtool -i vmnic0 |
NIC Details (Speed, MTU, MAC Address)
1 |
esxcfg-nics -l |
vmNIC Details (Names, MTU, MAC address, Netmask, Broadcast, TCP stack)
1 |
esxcfg-vmknic -l |
vmNIC Stats
1 |
vsish -e get /net/pNics/vmnic0/stats |
Unload Driver (example: QLogic driver)
1 |
vmkload_mod -u qlcnic |
1 2 3 4 5 6 7 8 9 10 |
vmkping -I vmk0 x.x.x.x -s 8972 | MTU 9000 (Jumbo Frames) -s 1472 | MTU 1500 -d | Don't fragment package -6 | use IPv6 -c | set package count -D | TCP Stack debug mode -i | set interval in seconds -v | Verbose |
vmNIC ping
1 |
esxcli network diag ping –netstack=vxlan –host <vmknic IP> –df –size=<packet size> |
List vSwitch settings
1 |
vim-cmd hostsvc/net/vswitch_info | grep -E '(name|allowPromiscuous|macChanges|forgedTransmits)' |
List all switchports
1 |
net-stats -l |
vmkernel port Packet Capture Example
1 2 3 4 5 6 7 8 9 10 |
pktcap-uw -c 100 --switchport 67108869 --dir 0 --ng -o /scratch/67108869_rx.pcapng & pktcap-uw -c 100 --switchport 67108869 --dir 1 --ng -o /scratch/67108869_tx.pcapng & # Capturing all tx and rx traffic on vSwitch port 67108869 into separate files, limited to 100 packets # esxtop (n) to get switchport ID # If needed: # Stop Packet Capture: kill $(lsof |grep pktcap-uw |awk '{print $1}'| sort -u) # Check if stopped: lsof |grep pktcap-uw |awk '{print $1}'| sort -u |
Example to capture vmnic traffic
1 2 3 4 5 |
pktcap-uw --uplink vmnic0 --capture UplinkSnd --dir 0 --outfile /scratch/vmnic0_Snd_dir0.pcapng --ng --count 1000 && pktcap-uw --uplink vmnic0 --capture UplinkSnd --dir 1 --outfile /scratch/vmnic0_Snd_dir1.pcapng --ng --count 1000 && pktcap-uw --uplink vmnic0 --capture UplinkRcv --dir 0 --outfile /scratch/vmnic0_Rcv_dir0.pcapng --ng --count 1000 && pktcap-uw --uplink vmnic0 --capture UplinkRcv --dir 1 --outfile /scratch/vmnic0_Rcv_dir1.pcapng --ng --count 1000 # Additional filters: # Capture only packets from 10.0.1.10 --srcip 10.0.1.10 |
Example to capture Rx/Tx on switchport 67108904 of a VM, plus Rx/Tx of vmkernel vmk0
1 |
pktcap-uw -c 10000 --switchport 67108904 --dir 0 --ng -o /scratch/67108904_rx.pcapng & pktcap-uw -c 10000 --switchport 67108904 --dir 1 --ng -o /scratch/67108904_tx.pcapng & pktcap-uw --vmk vmk0 --dir 0 -o /scratch/vmk0_dir0.pcapng --ng -c 1000000 & pktcap-uw --vmk vmk0 --dir 1 -o /scratch/vmk0_dir1.pcapng --ng -c 1000000 & |
Stopping all pktcap-uw processes
1 |
lsof |grep pktcap |cut -d" " -f1 |sort |uniq |xargs kill |
Test open port and specify source IP address (.42 = source | .41 = target | 8000 = port)
1 |
nc -z -s 192.168.100.42 192.168.100.41 8000 |
Storage
List storage latency in logs (show in microseconds)
1 |
egrep -i 'deteriorated.' /var/log/vobd.log |awk '{print $1 ” ” $5 “ ” $6 “ ” “from” “ ” $17 “ ” “ms” “ ” “to” “ ” $20 “ ” “ms”}' |
SCSI device info
1 |
esxcfg-scsidevs -l |
SCSI HBA info
1 |
esxcfg-scsidevs -a |
SCSI naa. to datastore mapping info (shows naa, UUID, datastore names)
1 |
esxcfg-scsidevs -m |
List SCSI devices
1 |
esxcfg-scsidevs -u |
1 |
<span style="font-size: 80%;">vim-cmd /hostsvc/summary/scsilun</span> |
Show all Volumes
1 |
vim-cmd /hostsvc/summary/fsvolume |
Check filesystem with voma (get disk IDs in naa.000000000:1 format with # esxcfg-scsidevs -m)
1 2 |
voma -m vmfs -f check -s /var/log/voma.log -d /vmfs/devices/disks/<diskID> use -f fix (instead of -f check) to attempt fix (ESXi 6.0 and later) |
Perform LUN reset against device (3x to force)
1 |
vmkfstools -L lunreset /vmfs/devices/disks/naa.0000000000000000 |
Break LVM lock on device
1 |
vmkfstools -B /vmfs/devices/disks/naa.0000000000000000000000000000:1 |
Storage Rescan
1 2 3 4 5 6 |
esxcfg-rescan -A -a Scan for only newly added devices. -d Scan for only deleted devices. -A Scan all adapters. -u Scan existing paths only and update their state. |
Show partition table of device (list with esxcfg-scscidevs -m)
1 |
partedUtil getptbl /vmfs/devices/disks/naa.65823cfg000000ddd34n3n5bha |
Working with Hosts
List all hardware details (Server info, PCI, heap sizes)
1 |
esxcfg-info |
Show all licensing infos
1 |
vim-cmd vimsvc/license –show |
List all current tasks on host
1 |
vim-cmd vimsvc/task_list |
Show info about task
1 2 3 |
vim-cmd vimsvc/task_info <taskname> where <taskname> is full name between quotes from task_list |
Show files/directories using most space
1 |
du -c |sort -n |awk '{print $1/1024,"MB", " " , $2}' |
List Modules (such as drivers)
1 |
esxcfg-module -l |
Get Module info (such as drivers)
1 |
esxcfg-module -i modulename |