ESXi Command Line Tools
Contents
- 1 Scope of This Document
- 2 Troubleshooting driver versions on ESXi Host
- 3 Install Dell OpenManage agent on ESXi Host
- 4 Specifying the Default iSCSI Multipathing Mode
- 5 VMWare ESXi Commands For Managing Guests
- 6 Moving .vmdk Files From Store to Store, Retain Thin Format
- 7 Configuration Backup and Restore of a Single Host
- 8 Migrate a VM From One Host to Another
- 9 Updating the Hypervisor Using Command Line
- 10 Killing a stuck VM
- 11 Installing 3ware 96550SE Driver in ESXi 5.1
- 12 Setting SNMP
- 13 SSH keys
Scope of This Document
I keep forgetting the command line syntax for ESXi console, so I document the commands I use most often here, hopefully so they will eventually be committed to memory... if not I know where to quickly find them now.
Note that this document assumes you have Enabled SSH Techsupport mode.
Troubleshooting driver versions on ESXi Host
Get a list of all nics in the host
esxcli network nic list
Show what version a specific driver is currently running or loading at bootup
vmkload_mod -s DRIVER | grep Version
Get vendor information about a Device that can be cross-checked on the ESXi HCL
vmkchdev -l | grep DEVICENAME
Install Dell OpenManage agent on ESXi Host
esxcli software vib install -d /vmfs/volumes/SAS_RAID6/PATCH/OM-SrvAdmin-Dell-Web-8.5.0-2372.VIB-ESX60i_A00.zip
esxcli software vib list
Specifying the Default iSCSI Multipathing Mode
For Synology: For Equallogic: For Compellent:
esxcli storage nmp satp set --default-psp=VMW_PSP_RR --satp=VMW_SATP_ALUA esxcli storage nmp satp set --default-psp=VMW_PSP_RR --satp=VMW_SATP_EQL esxcli storage nmp satp set --default-psp=VMW_PSP_RR --satp=VMW_SATP_DEFAULT_AA
VMWare ESXi Commands For Managing Guests
The main command is 'vim-cmd'. It has many uses via its subcommands and switches.
To get a list of all VM guests on a host, use:
vim-cmd vmsvc/getallvms
this will print a list of all VMs, their Vmid, common names, VM Guest OS, and file system locaion of the .vmx configuration file.
From that output, you take the Vmid of the host you want to manage, and check its power state like this:
vim-cmd vmsvc/power.getstate 2
The options for managing the power state of a guest VM are:
power.getstate power.hibernate power.off power.on power.reboot power.reset power.shutdown power.suspend power.suspendResume
To give a VM the command to gracefully shutdown, use:
vim-cmd vmsvc/power.shutdown 2
Moving .vmdk Files From Store to Store, Retain Thin Format
Power the VM Guest off. Remove from ESXi inventory.
Convert the vmdk file to thin:
vmkfstools -i SERVERNAME.vmdk -d thin SERVERNAME-thin.vmdk
Add the VM Guest back to inventory, and power on. Save the original disk file for just in case. After the system boots successfully, remove the thick vmdk file.
UPDATE - I have since found, that on the free version, if you create a target folder in the target file system, and then copy the contents of the actual Host folder (not the host folder itself), then the thin state will copy with the file. The above re-thining of the disk, was due to when copying the entire host folder, the disk would copy to thick format in the destination file system. One extra step, to pre-create the destination folder, but it saves a heck of a lot of time later when you dont have to re-thin several hundred gigs of vmdk files. :)
Configuration Backup and Restore of a Single Host
Syncronize all settings:
vim-cmd hostsvc/firmware/sync_config
Dump all the settings:
vim-cmd hostsvc/firmware/backup_config
Upon completion, the host will print out:
Bundle can be downloaded at : http://*/downloads/configBundle-[FQDN].tgz.
Enter the URL into a browser and substitute in the FQDN for the * and download the file to your system.
To restore from a previously saved config, scp the backup file from your system to the host, move it to the /tmp folder, and rename the file to configBundle.tgz.
mv configBundle-[FQDN].tgz /tmp/configBundle.tgz
Put the host in maintenance mode.
vim-cmd hostsvc/maintenance_mode_enter
Restore the previous configuration.
vim-cmd hostsvc/firmware/restore_config /tmp/configBundle.tgz
Upon completion of the reload, the host will reboot. Note, that if you rebuild the ESXi server, you will need to reinstall the same version, or patch up to the version that was running when the config dump was made.
Migrate a VM From One Host to Another
note: ensure that the VM that is being moved does not have any .iso file mounted to the cdrom drive. ie... anything it cannot take with it in the migration.
note also: if youre are moving a RHEL6 system, it would be helpful to remove the /etc/udev/rules.d/70-persistent-net.rules before you do the final shutdown on the VM you are going to move.
ovftool -ds=DEST-DATASTORE vi://root@SOURCE-ESXi/VMNAME vi://root@DEST-ESXi
Updating the Hypervisor Using Command Line
Search the profile list and grep by the version and year you need to pull from:
esxcli software sources profile list --depot=https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml|grep ESXi-6.5.0-2019 esxcli software sources profile list --depot=https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml|grep ESXi-6.7.0-2019 esxcli software profile update -d https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml -p PROFILE-NAME-UPDATING-TO
Killing a stuck VM
esxcli vm process list esxcli vm process kill --type=force --world-id=10561
Installing 3ware 96550SE Driver in ESXi 5.1
First, I copied the driver to the path below, and attempted to run the command against the .vib file.
/vmfs/volumes/5335f7d7-a4d74ff0-24f9-c80aa9881e26/DRIVER # esxcli software vib install -v ./scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib [VibDownloadError] ('./scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib', , "[Errno 4] IOError: <urlopen error [Errno 2] No such file or directory: '/var/log/vmware/scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib'>") url = ./scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib Please refer to the log file for more details.
Since it seemed to be expecting the file to be in /var/log/vmware (dont ask me why), i copied the file there.
/vmfs/volumes/5335f7d7-a4d74ff0-24f9-c80aa9881e26/DRIVER # cp scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib /var/log/vmware/ / vmfs/volumes/5335f7d7-a4d74ff0-24f9-c80aa9881e26/DRIVER # esxcli software vib install -v ./scsi-3w-9xxx-2.27.08.036-1OEM.500.0.0.472560.x86_64.vib Installation Result Message: The update completed successfully, but the system needs to be rebooted for the changes to be effective. Reboot Required: true VIBs Installed: LSI_bootbank_scsi-3w-9xxx_2.27.08.036-1OEM.500.0.0.472560 VIBs Removed: VIBs Skipped:
Finally, I reboot the host.
/vmfs/volumes/5335f7d7-a4d74ff0-24f9-c80aa9881e26/DRIVER # reboot
Setting SNMP
esxcli system snmp set -c mycomunity esxcli system snmp set -l warning esxcli system snmp set -e yes
SSH keys
SSH keys should be placed here:
/etc/ssh/keys-root/authorized_keys