Difference between revisions of "ESXi Command Line Tools"
(Created page with "Category:VMWare ==Scope of This Document== I keep forgeting the command line syntax for ESXi console, so I document the commands I use most often here, hopefully so they w...") |
|||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category:VMWare]] | [[Category:VMWare]] | ||
==Scope of This Document== | ==Scope of This Document== | ||
− | I keep | + | 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.<br> |
<br> | <br> | ||
Note that this document assumes you have Enabled SSH Techsupport mode. | 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<br> | ||
+ | esxcli software vib list | grep Dell | ||
==Specifying the Default iSCSI Multipathing Mode== | ==Specifying the Default iSCSI Multipathing Mode== | ||
For Synology: | For Synology: | ||
− | |||
For Equallogic: | For Equallogic: | ||
− | |||
For Compellent: | 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 | esxcli storage nmp satp set --default-psp=VMW_PSP_RR --satp=VMW_SATP_DEFAULT_AA | ||
Line 41: | Line 54: | ||
vim-cmd vmsvc/power.shutdown 2 | vim-cmd vmsvc/power.shutdown 2 | ||
− | + | ==Get status of vmdk disk consolidation tasks== | |
+ | vim-cmd vimsvc/task_list | ||
+ | vim-cmd vimsvc/task_info haTask-31-vim.VirtualMachine.removeAllSnapshots-905604163 | ||
==Moving .vmdk Files From Store to Store, Retain Thin Format== | ==Moving .vmdk Files From Store to Store, Retain Thin Format== | ||
Line 52: | Line 67: | ||
'''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. :) | '''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== | ==Configuration Backup and Restore of a Single Host== | ||
Line 122: | Line 95: | ||
ovftool -ds=DEST-DATASTORE vi://root@SOURCE-ESXi/VMNAME vi://root@DEST-ESXi | ovftool -ds=DEST-DATASTORE vi://root@SOURCE-ESXi/VMNAME vi://root@DEST-ESXi | ||
− | ==Updating the Hypervisor Using | + | ==Updating the Hypervisor Using Command Line== |
− | + | Search the profile list and grep by the version and year you need to pull from: | |
− | + | <nowiki> | |
− | + | 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 | |
− | + | </nowiki> | |
− | esxcli software | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==Killing a stuck VM== | ==Killing a stuck VM== | ||
esxcli vm process list | esxcli vm process list | ||
esxcli vm process kill --type=force --world-id=10561 | esxcli vm process kill --type=force --world-id=10561 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Setting SNMP== | ==Setting SNMP== |
Latest revision as of 12:16, 17 June 2021
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 Get status of vmdk disk consolidation tasks
- 7 Moving .vmdk Files From Store to Store, Retain Thin Format
- 8 Configuration Backup and Restore of a Single Host
- 9 Migrate a VM From One Host to Another
- 10 Updating the Hypervisor Using Command Line
- 11 Killing a stuck VM
- 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 | grep Dell
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
Get status of vmdk disk consolidation tasks
vim-cmd vimsvc/task_list vim-cmd vimsvc/task_info haTask-31-vim.VirtualMachine.removeAllSnapshots-905604163
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
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