Ah, command line. You might love it or hate it, but at the end of the day – there’s nothing you can do really to get around it. Sometimes you just have to use it and no GUI or fancy-dancy wizard will help you out. In my personal opinion, CLI/shell/SSH will always be a superior method of controlling anything in IT. While it might be preferable for some to funnel changes and modifications through vCenter server, there comes a time in every VMware administrator’s career where vCenter is simply not available. Getting to know your way around the ESXi shell is crucial in those times of troubleshooting, and having a basic understanding of some of the most common Linux and ESXi commands is never a bad skill to list on your resume.
Linux Shell Commands
First up on our list – Linux shell commands. As ESXi is based on Linux, you can use most of the command you’d also expect to find on most Linux distributions (i.e. RedHat, CentOS, Arch etc.).
grep– These three commands can be used to view the content of a file. First up, the
findcommand will locate a specific file, based on either a filename or a pattern;
catis used to simply display the contents of a file; lastly,
grepcan be used to search for specific text within a single or group of files.
find /path/to/vm/folder –iname delta– list all
deltadisks of a VM.
cat hostd.log | grep error– search occurrences of
cat /etc/chkconfig.db– view current running status of all ESXi services.
cat /etc/resolv.conf– view current DNS settings on ESXi.
tail– While the
catcommand is great for displaying the complete contents of a file,
tailcan be used to show either just the beginning or end part of the file, skipping the contents in the middle.
tailcan be extremely useful in times of troubleshooting; for example – to only view the latest logs in the log file.
tail -f /var/log/vmkernel.log– watch the
vmkernel login real time
cat /var/log/vpxa.log | less– output
vpxa.logto the screen with a paging fashion
vdf– These two commands deal with presenting information about free space within file systems. The
dfcommand, now showing VMFS data stores, will show the size, used and available space within both our file system and our data stores. To view the usage of the different ramdisks within an ESXi host, you must use the
kill– These commands are your weapons of mass destruction – able to kill any process within ESXi host. The
pscommand contains many command line switches, but is most commonly used to retrieve the running world ID of a process in order to send to the
killcommand then respectively terminates that process.
vicommand is a text editor that is used to modify the contents of a file – a must-have skill for any vSphere administrator performing troubleshooting from the command shell. Keep in mind
viis not a WYSIWYG editor, so getting used to it will take some time for a newbie. The most important things to remember for a beginner are:
:q– exit the file
:w– write changes to the file
:i– switch from view to input mode
nc– Coupled with
vmkping(more on that later), the
nccommand (netcat) can be useful when confirming network connectivity to a certain IP from an ESXi host. We can use it, when we’d like to confirm connection on a specific TCP port (think iSCSI connections on port 3260 or SSH on 22).
nc –z 10.10.10.10 3260– test connectivity to 10.10.10.10 on port 3260
ESXi Shell Commands
Next, let’s look at some of the most common tasks performed while sitting on the ESXi command shell. These ESXi commands will help you not just with troubleshooting, but with your day to day maintenance as well as performance monitoring. Needless to say, you won’t find these commands anywhere outside VMware environment.
services.sh– While Linux services are normally handled using the
servicescommand, ESXi services are handled much the same way utilizing the
Services.shcan be passed with a
restartflag to perform the respected operation on all ESXi services.
services.sh restart– restart all ESXi services
services.sh stop servicename– stop a service with a name servicename
/etc/init.d– The scripts located in
/etc/init.dcan be used to start/stop their respective services one at a time. If you just wanted to restart the vCenter Server Agent (also known as the vpxa service), you could run
/etc/init.d/vpxa restartto restart it.
/etc/init.d/vpxa restart– restart vCenter Agent on ESXi host
vmkping– We are all familiar with the functionality of the age old
vmkpingtakes this one step further and allows you to use the IP stack of the VMkernel to send Internet Control Message Protocol (ICMP) packets through specified interfaces. Meaning, you could send a ping packet out through the vMotion network, rather than over the management network.
vmkping –I vmk1 10.10.10.1– send ICMP request to 10.10.10.1 through
vmkfstoolscommand allows you to create, clone, extend, rename and delete VMDK files. In addition to the virtual disk options, you can also create, extend, grow and reclaim blocks from our file systems with vmkfstools.
vmkfstools –i test.vmdk testclone.vmdk– clones
esxtop– When it comes to performance monitoring and troubleshooting on an ESXi host, few tools can give you as much information as esxtop. With similar functionality to the Linux
esxtopgoes one step further by gathering VMware-specific metrics as they compare to CPU, interrupt, memory, network, disk adapter, disk device, disk VM and power management. The usage is quite similar to the
topcommand, so you might want to take a look at this detailed guide.
vscsiStatscommand will help you gather a collection of data and metrics that pertain to a VM’s disk I/O workload. Using
vscsiStatscan prove to be invaluable when capacity planning or migrating your back end storage as well.
vim-cmdis a command space that is built over top of the hostd process, allowing the end user to script and command almost every vSphere API. The vim-cmd command has a number of sub ESXi commands dealing with different portions of the virtual infrastructure and is very easy to use compared to its counterpart,
vim-cmd vmsvc/getallvms– gets a list of all VMs running on ESXi; useful for getting the VM ID
vim-cmd vmsvc/reload vmid– reloads the VMX for given VM; replace
vmidwith an actual ID of the VM in question
vim-cmd vmsvc/power.on vmid– powers on the VM with given VM ID
dcui– The VMware Direct User Console Interface (DCUI) is the menu-based option listing that you see when you initially log into an ESXi host. There are many different options available to you from the DCUI, such as root password maintenance, network and maintenance. Sometimes you may only have SSH access to the host, but thankfully, you can still get to the DCUI menu-based system by simply executing
dcuifrom the command line. This might be your last resort if you really want to avoid using command line interface.
vm-support– Ever feel like grabbing a complete bundle of all the support and log information that you have inside of your ESXi host? That is exactly what
vm-supportdoes. This tool is invaluable, and if you have ever been on a support call with VMware, you have probably already ran this.
Few words about the holy grail – esxcli command
esxcli command contains many different namespaces allowing you to control virtually everything that ESXi offers. Listed below are some (but certainly not all) of the commonly used namespaces:
esxcli esxcli– Yeah, that’s not an error – the
esxclicommand has a namespace called “esxcli.” By using the esxcli namespace, you are able to get further information on any or all the commands that lie within the esxcli utility.
esxcli esxcli command list– list out every esxcli command on the system along with the functions it provides
esxcli hardware– The hardware namespace of esxcli can prove extremely useful when you are looking to get information about the current hardware and setup of your ESXi host
esxcli hardware cpu list– retrieve CPU information (family, model and cache)
esxcli hardware memory get– retrieve information about memory (available and non-uniform memory access)
esxcli iscsi– The iscsi namespace can be used to monitor and manage both hardware and software iSCSI setups.
esxcli iscsi software– can be used to enabled/disable the software iSCSI initiator
esxcli iscsi adapter– can be used to setup discovery, CHAP and other settings for both your hardware and software iSCSI adapters
esxcli iscsi sessions– can be used to list established iSCSI sessions on the host
esxcli network– The
esxcliis extremely valuable when looking to monitor and make changes to anything and everything dealing with vSphere networking, including virtual switches, VMKernel network interfaces, firewalls and physical network interface cards (NICs).
esxcli network nic– list and modify NIC information, such as name, wake on LAN, and speeds
esxcli network vm list– list networking information about your VMs that have an active network port.
esxcli network vswitch– Commands to retrieve and manipulate options on VMware’s standard and distributed virtual switches
esxcli network ip– Commands to manage VMkernel ports, including management, vMotion and Fault Tolerance networks. Also contains the ability to modify any of the IP stack in regard to the host, including DNS, IPsec and routing information
esxcli software– The software namespace can be used to retrieve and install different pieces of software and drivers on your ESXi host.
esxcli software vib list– list the software and drivers currently installed on the ESXi host
esxcli storage– This is perhaps one of the most used esxcli command namespaces and contains everything and anything you need in order to manage the core storage attached to vSphere.
esxcli storage core device list– list the current storage devices
esxcli storage core device vaai status get– get the current status of VAAI support on your storage devices
esxcli system– This command gives you the ability to control ESXi advanced options, such as setting up syslog and managing host status.
esxcli system maintenanceMode set –enabled yes– set the host into maintenance mode
esxcli system settings advanced– View and change ESXi advanced settings (Hint: Use
esxcli system settings advanced list –dto view the settings that deviate from the default)
esxcli system syslog– Syslog information and configuration
esxcli vm– The
VMnamespace of ESXi can be used to list out various tidbits of information about the VMs running on the host and shut them down forcibly if needed.
esxcli vm process list– List out process information for powered on VMs
esxcli vm process kill– Terminate running VM process, essentially shutting down or forcibly powering off a VM
esxcli vsan– The vSAN namespace of ESXi contains a ton of commands dealing with VSAN setup and maintenance, including data store, network, fault domain, and policy configuration.
esxcli vsan storage– commands for configuring local storage for use with VSAN, including adding and removing physical disks and modifying auto claim.
esxcli vsan cluster– commands to leave/join vSAN clusters on the local host
Certainly the above commands and examples are not all ESXi has to offer. All of these ESXi commands have multiple switches and options available which server various functions. Most of them can be displayed by passing a
–h to the original command to bring up the help options.
I understand this might be a tedious task for some to learn all of the above commands, but trust me – once you get used to using them, you will be well on your way to solving almost any issue that arises.