ESXi 4.1 command line awesomeness

I spend a lot of time on the command line of ESXi 4.1 due to my development duties at Sumavi.  There are quite a few things you can do on the command line that make it pretty cool to work with.  As such, in many instances I don’t install vSphere Server nor vSphere client.  I just log in and do my duties.  Notice that everything I post below you can do without vSphere Server nor vSphere client.  Let me know if these are useful to you!

1.  Get a list of all VMs on the Hypervisor:

Notice the vmid.  That vmid is used in many commands that follow when you want to perform actions on individual VMs.

2.  Check which Physical NICS are up

There are a few commands in the esxcfg-* family that are used to configure the hypervisor network.  For example, if you want to see which NICs have network connections, you can use:

Notice that only vmnic0 and vmnic2 are up.  This mostly has to do with the way I configured my blades with the Flex-10 Virtual connect.  (A feature of HP Blades).  If I am now to configure the network, its best that I do only vmnic0 and vmnic2 since they’re the only ones that have a link.  For you Linux masters out there, there’s no ‘service network status’ nor restart that you can do.  It just always seems to be on.

3.  Creating a quick network connection

Since we know vmnic2 is up, let’s make a connection to it so that we can SSH into it, or at least ping out of it:

4.  Create a new vmdk and add to existing VM

Here we have a VM (vmid 32 ) that we want to add a 60GB vmdk to.  We run:

5.  Check/Toggle VM power stat

You can turn nodes off and on and check power status.  You need to know the vmid as shown in #1 above:

6.  Add the Physical USB Device to a VM

If you want to add the USB device that’s plugged into the physical machine to the virtual machine with vmid 16 you can do this:

Note that the VM should be powered off when you do this for best results.

7.  Register a VM to the Hypervisor

If you copied all the vmx and vmdk files to an ESXi 4.1 hypervisor you can simply register them with that hypervisor and turn them on:

8.  Enable SSH from the command line

This is an easy one:

9.  Add the license to the ESXi 4.1 hypervisor

This came  up in a few places and I already documented it in this blog, but figured I’d do it again.  If you have a license and you want to add it to your hypervisor because its about to expire in 1 day you can log in and just run:

10.  Writing output to main console

In your kickstart files, you may want to redirect output to the main console that people watch as an installation takes place.  This is /dev/tty2.  Therefore, if in your kickstart file you are cloning a vmdk using vmdkfstools, you can let people see how the progress is going by just piping it out.  Here’s an example:

This is cool in that you’ll see the percentage points pop up as you go along.  The thing to remember is that you’ll have to send some carriage return escape sequences a la echo -e “\r\n” to line things up better.