Skip to content

Becoming An ESXi Shell Ninja

by Chris Wahl on Aug 1st, 2012 | 2,528 views
spongebob-ninja

After writing up a post on “Becoming An ESXi Direct Console User Interface (DCUI) Ninja“, I wanted to follow up with some content that revolves around the ESXi Shell. The details outlined here are meant to serve as a good stepping off point for those who are a curious as to what the ESXi Shell can do, especially for those intimidated by CLI or “Linux like” commands.

While the hope is that you never really have to jump onto the ESXi Shell – typically, this means something has gone wrong – it’s good to have a comfort level and familiarity with how to navigate around in the shell. Additionally, there are still a hefty number of actions that require using the shell in one way or another, either directly on the console of your host, or via vCLI or the vSphere Management Assistant (vMA).

Getting In The Shell

The first step is to access the ESXi Shell. There are a few ways to accomplish this. If the network to the host is not operational, you’ll have to use the Direct Console User Interface (DCUI) to enable the ESXi Shell (see the previous post in this series for details). However, if the host is available on the network, you can switch over to SSH. The easiest way to do this is simply start the service on the host.

Enabling The SSH Daemon (Service)

The first step is to navigate to the security profile of your host. Click “Properties…”

From there, select the SSH service and click the “Options…” button.

Finally, click the “Start” button to start the daemon.

Reaching The Shell From The DCUI

Reaching the ESXi Shell from the DCUI is simple. Once the ESXi Shell is enabled, Press Alt + F1 to reach the ESXi Shell window. To switch back to the DCUI, Press Alt + F2.

Ninja ESXi Shell Commands

Now that you have access to the shell, let’s go over some of the commands I feel you should know without hesitation to get the job done.

Tailing Logs

The tail command looks at the end of a file, and is my most commonly used tool. Let’s look at what happens when I do:

tail /var/log/hostd.log

I see the last several lines of the log. This helps when you are troubleshooting an issue that happened recently.

A really cool arguement for the tail command is -f (follow). This will actively follow the newly written lines and present them on the screen.

tail -f /var/log/hostd.log

Reading Logs

If you just need to dump the contents of a log to your screen, use the cat command. This will then let you scroll up (Shift + PageUP) and down (Shift + PageDOWN) to find what you need.

cat /var/log/hostd.log

Searching A Log

If you have a huge log or are looking for a specific event, I recommend the grep command. I often pipe (output) my tail or cat command into a grep command, which then searches the results for a string that I am looking for.

In this command below, I first tail the hostd.log to get the last few lines, and then I pipe the results into grep with a search for the word Power. The -i argument ignores case, so that it will search for any variation of the word Power.

tail /var/log/hostd.log | grep -i Power

Restarting Services

If you’ve found that the host services could use a restart, there’s a script ready to rock that will handle this for you. (Also: Reference KB 1003490)

services.sh restart

Managing A Host: Esxcfg-Commands

The esxcfg- commands are an assortment of tools that are VMware specific. Ranging from managing the nics, vswitches, and vmkernel ports, esxcfg- commands are the bread and butter of an ESXi Shell experience. Take note that these are slowly being phased out in favor of the new esxcli commands, but are still available and offer some features that are not yet available with esxcli.

Let’s say you had an issue where you were concerned about the MTU value on your nics. You could issue this command to quickly see what the configuration of all your nics are:

esxcfg-nics -l

Managing a Host: Esxcli Commands

The final tools of a Ninja that I will cover involve the newest kid on the block: esxcli. Introduced with vSphere 5, this new command is an attempt to organize host management underneath a logical syntax. Instead of having to memorize a lot of root commands with esxcfg- , you now just start with esxcli and begin branching out.

So, for the MTU example above where I used esxcfg-nics -l, you could instead do:

esxcli network nic list

Thoughts

These are just a small handful of very simple yet powerful commands that are available to you. There are literally hundreds of commands and variations at your disposal, but I selected the ones above because I use them so often.

Do you have a handy, often used ESXi Shell command that you want to share? Feel free to put the command or link to an article / post you’ve written describing one!

From → Tech Guides

4 Comments
  1. Juan Manuel permalink - Aug 1st, 2012

    Nice post. On the cat command I suggest to less command instead or pipe the output to less. It will allow you to navigate through the log file using the arrow keys from your keyboard.

    Also tail by default only display the last 10 lines of a file so for search would be better to use:

    - grep

    or

    - cat | grep

    The Shift+PageDown Shift+PageUp tip is useful in a SSH session from Putty or a Linux box (in fact is a Bash feature) but it will not work in a ESXi Shell DCUI session, from the iLO or iDRAC of the server for example.

    Following are also some of my articles about ESXi shell commands, hope you like them :)

    - List packages installed in ESXi 4.1 and 5.0: http://jreypo.wordpress.com/2011/10/27/list-packages-installed-in-esxi-4-1-and-5-0/

    - DNS configuration with esxcli: http://jreypo.wordpress.com/2011/10/17/dns-configuration-with-esxcli/

    - Change ESXi hostname with esxcli: http://jreypo.wordpress.com/2011/11/15/change-esxi-5-0-hostname-with-esxcli/

    - List ARP table entries of an ESXi: http://jreypo.wordpress.com/2011/09/13/list-arp-table-entries-of-an-esxi/

    - Change ESXi 5.0 shell keyboard layout with esxcli: http://jreypo.wordpress.com/2011/11/14/change-esxi-5-0-shell-keyboard-layout-with-esxcli/

    - Getting network card driver version in ESXi 5.0 (also useful for other VMkernel modules/drivers): http://jreypo.wordpress.com/2011/11/15/getting-network-card-driver-version-in-esxi-5-0/

    - How to get network connections of an ESXi server: http://jreypo.wordpress.com/2011/08/16/how-to-get-the-network-connections-of-an-esxi/

    - Put ESXi in maintenance mode from TSM using vim-cmd: http://jreypo.wordpress.com/2011/08/17/put-esxi-server-in-maintenance-mode-from-tech-support-mode-using-vim-cmd/

    Again nice work, and hope you like my posts.

    Juanma.

  2. Jonathan Frappier permalink - Aug 3rd, 2012

    Reblogged this on Jonathan Frappier's Blog.

Trackbacks & Pingbacks

  1. Getting to know ESXCLI commands and how to use - Virtualization Tips

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS