VMWare Esxi Shell

From FroggDev - En
Jump to: navigation, search

source : http://www.vmnerds.fr/2012/01/13/liste-des-commandes-utiles-en-esxi/

VM Operations

List of registered VMs (it display the VMid)

vim-cmd vmsvc/getallvms

List of running VM (it display WorldID)

esxcli vm process list

Stop properly a VM

esxcli vm process kill -t soft -w <WorldID>

Kill a VM

esxcli vm process kill -t force -w <WorldID>

Display VM state

vim-cmd vmsvc/power.getstate <VMid>

Shutdown a VM

vim-cmd vmsvc/power.off <VMid>

Start a VM

vim-cmd vmsvc/power.on <VMid>

Restart a VM

vim-cmd vmsvc/power.reboot <VMid>

Reload a VM configuration (after modification of .vmx file)

vim-cmd vmsvc/reload <VMid>

Delete all VM snapshot

vim-cmd vmsvc/snapshot.removeall <VMid>

Estimate size to consolidate Vm snapshot

vim-cmd vmsvc/get.spaceNeededForConsolidation <VMid>

Register a vm on the host

vim-cmd solo/registervm /vmfs/volumes/datastore/VM2/VM2.vmx

Unregister a vm on the host

vim-cmd hostsvc/unregister <VMid>

Display VM summary

vim-cmd vmsvc/get.summary <VMid>

Virtual Disk operation

Create a virtual disk

vmkfstools -c 10G /vmfs/volumes/datastore1/VM3/VM3_1.vmdk

Add a virtual disk to an existing VM (in SCSI0:1):

vim-cmd vmsvc/device.addexisting <VMid> /vmfs/volumes/datastore1/VM3/VM3_1.vmdk 0 1

Add a disk to a VM (like 2 previous command in a row)

vim-cmd vmsvc/device.diskadd <VMid> 10G 0 1 datastore1

Convert virtual disk from Thin to Thick

vmkfstools -j /vmfs/volumes/datastore1/VM1/VM1.vmdk

Convert virtual disk from Thick to Thin

vmkfstools -K /vmfs/volumes/datastore1/VM1/VM1.vmdk

Increase VM disk size

vmkfstools -X 15G /vmfs/volumes/datastore1/VM1/VM1.vmdk

Host operation

Reset the whole configuration (like when freshly installed)

/sbin/firmwareConfig.sh –reset

Add a liscence to the host

vim-cmd vimsvc/license –set XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Enable maintenace mode

vim-cmd hostsvc/maintenance_mode_enter

Disable maintenance mode

vim-cmd hostsvc/maintenance_mode_exit

Synchronize & save host config (file saved in /scratch/downloads)

vim-cmd hostsvc/firmware/sync_config
vim-cmd hostsvc/firmware/backup_config

Restore host config (from /tmp/configBundle.tgz file)

vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz

Display installed patch list

esxcli software vib list

Manually install a patch (requier maintenance mode)

esxcli software vib update –depot=/vmfs/volumes/datastore1/ESXi500-201109001.zip

Allow a service on the firewall

esxcli network firewall ruleset set -r snmp -e true

Disable firewall

esxcli network firewall set -e false

Display error list of VMkernel:

vmkerrcode -l

Display host version

esxcli system version get

Display advanced paramters

esxcli system settings advanced list

start DCUI (can be usefull in SSH), Ctrl + C to quit


Services Operations

check « hostd » service

/etc/init.d/hostd status

restart « hostd »:

/etc/init.d/hostd restart

restart vCenter agent (« vpxa »):

/etc/init.d/vpxa restart

Restart all services

services.sh restart

Enable SSH until next reboot

/etc/init.d/SSH start

Enable SSH

vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

Display all service start on boot

chkconfig -l

Network Operations

Display physical network list

esxcli network nic list

Create a vSwitch

esxcli network vswitch standard add -v vSwitch1

Add a physical interface to a vSwitch

esxcli network vswitch standard uplink add -u vmnic1 -v vSwitch1

Add a PortGroup to a vSwitch

esxcli network vswitch standard portgroup add -p LAN -v vSwitch1

Add a physical interface to a PortGroup

esxcli network vswitch standard portgroup policy failover set -a vmnic0,vmnic1 -p LAN

Define the VLAN for a PortGroup

esxcli network vswitch standard portgroup set -v 40 -p LAN

Set a VMkernel nterface for a PortGroup

esxcli network ip interface add -i vmk1 -p NFS

Set an IP for a VMkernel interface

esxcli network ip interface ipv4 set -i vmk1 -I -N -t static

Enable CDP for a vSwitch

esxcli network vswitch standard set –cdp-status both -v vSwitch1

Modify the MTU of a VMkernel interface

esxcli network ip interface set -m 9000 -i vmk1

Modify the MTU of a vSwitch

esxcli network vswitch set -m 9000 -v vSwitch1

Storage Operation

Display LUNs list

esxcli storage nmp device list

Display path

esxcli storage nmp path list

Display LUNs & VMFS links

esxcli storage filesystem list

Rescan of SAN on all HBAs

esxcli storage core adapter rescan –all

Or do a Rescan of SAN

vim-cmd hostsvc/storage/vmfs_rescan

Refresh the LUNs

vim-cmd hostsvc/storage/vmfs_refresh

Display the list of volumes not shown (cause detected as snaphot)

esxcli storage vmfs snapshot list

Force to mount a VMFS

esxcli storage vmfs snapshot mount VMFS1

Resign a VMFS

esxcli storage vmfs snapshot resignature VMFS2

Display VAAI volumes compatibility

esxcli storage core device vaai status get

Enable iSCSI software initiateur

esxcli iscsi software set -e true

iSCSI discovery

esxcli iscsi adapter discovery rediscover -A vmhba33

disaply all NFS volumes mounted:

esxcli storage nfs list

Add a NFS volume

esxcli storage nfs add -H -s /vol/share -v Vol_NFS

Avoir la liste des VMs allumés avec leur WorldGroupID et leur disques: Display running VMs with them WorldGroupID and disks

vscsiStats -l

Start to collect stats for a VM (stop automatically after 30 min)

vscsiStats -w <WorldGroupID> -s

Display an histogram of latency of collected performances

vscsiStats -w <WorldGroupID> -p latency

Stop stats collect for a VM

vscsiStats -x <WorldGroupID> -s

ESXi Log files

It can be usefull to know where log are stored and what role they have. This table show all logs for Esxi 5.x

Log files Content
/var/log/auth.log logs authentification to shell ESXi (successfull or not)
/var/log/dhclient.log dhcp client log and all linked to it
/var/log/esxupdate.log ESXi patch and updates Logs
/var/log/hostd.log « Host management » service logs, VMs & hosk task & events, link between vSphere clients & vCenter agent (vpxa), and the SDk connexions
/var/log/shell.log ESXi shell command log
/var/log/sysboot.log VMkernel startup logs and module loading
/var/log/syslog.log service Management, watchdogs, scheduled task and DCUI logs
/var/log/usb.log usb logs, as found & VMS usb tranfert
/var/log/vob.log VMkernel event viewer , like vob.component.event
/var/log/vmkernel.log VMkernel Core logs, with hardware, storage, network,vm starts and events linked to them
/var/log/vmkwarning.log alert & error summary for the VMKernel
/var/log/vmksummary.log summary of start/stop sequence, heartbeat, uptime, started VMS, ressources used by services
/var/log/vpxa.log vCenter agent (vpxa) logs, with vCenter Server & « Host Management » (hostd) communication
/var/log/fdm.log High Availability module logs, by the service « fdm »