Skip to content

VMware ESX/ESXI

VMware ESXi is an enterprise-class, type-1 hypervisor developed by VMware, a subsidiary of Broadcom, for deploying and serving virtual computers.

Find ESX/ESXi Version

ESXi 4.x, 5.x, 6.x, 7.0.x and 8.x

With Console

  1. Log in to the ESX/ESXi host at the console as root.
  2. Type vmware -v and press Enter.
  3. Make note of the build number displayed in the output.

With SSH

vmware -v
~ # vmware -v
VMware ESXi 5.5.0 build-1623387

ESXi SSH/CLI commands

Registered Machines

The vim-cmd vmsvc/getallvms command can be used to list each registered virtual machine

vim-cmd vmsvc/getallvms
Something like this should be returned.
Vmid    Name                             File                                    Guest OS        Version   Annotation
33     vm1.example.com   [datastore_VMs] vm1.example.com/vm1.example.com.vmx     centos64Guest   vmx-11
37     vm2.example.com   [datastore_VMs] vm2.example.com/vm2.example.com.vmx     centos64Guest   vmx-11
54     vm3.example.com   [datastore_VMs] vm3.example.com/vm3.example.com.vmx     fedora64Guest   vmx-13

The first ( leftmost ) column of the output shows the vmid.

Power On/Off state

The vim-cmd vmsvc/power.getstate [id] command can be used to determine if a virtual machine is currently powered on or off.

vim-cmd vmsvc/power.getstate 33
In this example, the vm1.example.com virtual machine is currently powered off.
Retrieved runtime info
Powered off

Machine Power on

The vim-cmd vmsvc/power.on [id] command can be used to power on a virtual machine.

vim-cmd vmsvc/power.on 33
Something like this should be returned.
Powering on VM:

Below is a list of most common CLI commands for VMWare ESXi. Type these in directly in an ESXi or SSH shell.

ESXi 4.x, 5.x, 6.x, 7.0.x and 8.x

List all VMs running on the host. Also provides vmid, required for commands below

vim-cmd vmsvc/getallvms
Power off specified VM.
vim-cmd vmsvc/power.off vmid
Power on specified VM.
vim-cmd vmsvc/power.on vmid
Reboot specified VM.
vim-cmd vmsvc/power.reboot vmid
Register the VM stored at location on the ESX host inventory
vim-cmd solo/registervm /vmfs/volume/datastore/subdir/vm-file.vmx
Unregister VM from the host. Does not remove the VM's files from the datastore.
vim-cmd vmsvc/unregister vmid
Delete the specified VM. The VMDK and VMX files will be deleted from storage as well.
vim-cmd vmsvc/destroy vmid
Initiates an installation of VMWare Tools on the VM
vim-cmd vmsvc/tools.install vmid
Put the host into maintenance mode.
vim-cmd hostsvc/maintenance_mode_enter
Take the host out of maintenance mode.
vim-cmd hostsvc/maintenance_mode_exit
Show networking information of the host.
vim-cmd hostsvc/net/info
Show services running on the host. Can also be used to change startup configuration.
chkconfig -l
VMWare - List datastores on the command line (esxcli)
esxcli storage vmfs extent list

vim-cmd depends on hostd working properly. If hostd is stopped, you might see the following error after executing vim-cmd:

Failed to login: Connection refused: The remote service is not running, OR is overloaded, OR a firewall is rejecting connections.

ESXi VM Power State Management via SSH

In an ESXi environment, managing virtual machines (VMs) via SSH can be a powerful way to automate tasks and streamline administration. In this guide, we'll walk through the process of listing VMs, checking their power state, powering them on, gracefully shutting down their guest OS, and finally powering them off using command-line tools.

VMWare commands

Listing VMs This command provides a list of VMs along with their IDs, making it easy to identify the VMs we want to manage. vim-cmd vmsvc/getallvms

Getting Power State This command returns whether the VM is powered on, off, suspended, etc., allowing us to determine its current state before taking further action. vim-cmd vmsvc/power.getstate VMID

Powering On a VM This command initiates the boot process for the VM, allowing its guest OS to start up vim-cmd vmsvc/power.on VMID

Shutting Down a VM This command sends a shutdown signal to the VM, allowing its guest OS to perform a clean shutdown before the VM powers off. vim-cmd vmsvc/power.shutdown VMID

Powering Off a VM This command immediately powers off the VM without waiting for its guest OS to shut down vim-cmd vmsvc/power.off VMID.

Enabling root SSH login on an ESX host

Since ESX 3.0, for increased security, SSH is disabled by default for the root account on an ESX host. That is, the actual sshd service does not allow root logins. Non-root users are able to login with SSH. This is another layer of protection in addition to the host firewall.

Each SSH connection to an ESX host uses additional Service Console resources. Use caution when using scripts or third party software that create multiple SSH sessions to the ESX Service Console. Excessive use of SSH on an ESX machine may cause the service console to exhibit symptoms of memory exhaustion

1. To enable root login for SSH and SCP clients

If you have physical access to the ESX host, login to the console of your ESX host as the root user. If you can only connect to the ESX host over the network, connect using an SSH client (such as PuTTY) and log in as a user other than root.

To create a user in ESX host for using a SSH client:

  • Log in to the vSphere Client as a root user.
  • Click Users & Groups.
  • Right-click on a blank area and click Add.
  • Enter a username and password. Confirm your password.

Starting in ESX 4.0, the password needs to be at least 8 characters in length

  • Select Grant shell access to this user.
  • Select root group from the dropdown and click Add > OK.

By default it assigns to the users group and does not allow SSH access

2. After you are logged in SSH session, switch to the root user with the command

su -

If you do not have any other users on the ESX host, you can create a new user by connecting directly to the ESX host with VMware Infrastructure (VI) or vSphere Client. Go to the Users &Groups tab, right-click on the Users list and select Add to open the Add New User dialog. Ensure that the Grant shell access to this user option is selected. These options are only available when connecting to the ESX host directly. They are not available if connecting to vCenter Server

3. Edit the configuration file for SSH with the command:

nano /etc/ssh/sshd_config

4. Find the line that starts with PermitRootLogin and change the no to yes. You can find this line about 2 pages down from the top

5. Save the file by first pressing Ctrl-O and then Enter.

6. Exit with Ctrl-X

7. Restart the sshd service with the command

service sshd restart

Alternatively, use the command

/etc/init.d/sshd restart

VMWare - Enable SSH connections to ESXi

In the ESXi Hypervisor bare bones console (that's the console you access by connecting a monitor and keyboard to the physical ESXi Hypervisor machine), select Troubleshooting Options and then Enable SSH.

Replace vmid with the value you retrieved from the getallvms command (first one in the table). Replace path with the full path and file name of a VMX-file (= configuration file of a VM).

External Reference

VMWare - Power on or off Virtual Machine on the command line (vim-cmd)

VMWare - List virtual machines on the command line (vim-cmd esxcli)

VMWare - Resolve "vmfs volumes vmdk was not found"

https://knowledge.broadcom.com/external/article/345049/powering-on-a-virtual-machine-from-the-c.html

https://www.vmlab.com.pl/50-esxcli-commands-for-managing-an-esxi-host/

Powering on a virtual machine from the command line when the host cannot be managed using VMware vSphere Client