Updating ESXi / vSphere 5 using the CLI (Command Line Interface)

In a previous article, I blogged on how to update ESXi 4.0 to 4.1. The pricipals I described could be applied to all updates of version 4 of ESXi / vSphere that followed thereafter.

Unfortunately, with the release of version 5 of ESXi, the method I described previously no longer works when patching the system. If you attempt it, you get the following error message:

“This operation is NOT supported on 5.0.0 platform.”

Instead, you now need to use a different command line tool, which I shall now describe.

First off, you need the newest release of the CLI install package from VMware, which can be freely downloaded here.

Having installed, I highly recommend a restart of the workstation you using the CLI on. On my system, some of the Perl related libraries the CLI depends on didn’t seem to work till I did a restart.

Having restarted, bring up a Windows command line prompt, ideally in elevated admin mode (to make sure you have unrestricted access to your own system). Normal mode should be ok, as long as your update files have been downloaded to a local file system that can be accessed by your user account.

You also need to have the VMware vSphere Client installed, which you should be able to get (if you don’t have it already) just be entering the IP address of your ESXi host in a web browser window. The web server running on there should give you a download link.

Finally, go on the VMware website, and download the latest patches you want to apply to your ESXi 5 setup. At this present moment in time, I was applying the major Nov 2011 update, which brought me up to ESXi 5.0.0 build 515841.

For simplicity, having downloaded the latest ‘vib’ update (VMware’s terminology for an update archive, normally in the form of a ZIP file), I renamed it to Update.zip.

Having done this, you will need to upload the file into one of your storage volumes via the vSphere client. Note the path location to where you put the file. Furthermore, make a note of the full storage mount location of the actual data store, which can be found by selecting the datastore under Configuration -> Storage in vSphere client, and looking in the bottom panel labelled Datastore Details. As much as a pain it might be, my findings were that it was easiest to take the whole entry next to ‘Location’ and not substituting the common name of the datastore (so the entry you need will have a long GUID type path entry).

Go back to the Windows command line and type one of the following from the command prompt in order to get in to the CLI script folder:

For 32-bit OS:
cd C:\Program Files\VMware\VMware vSphere CLI\bin

For 64-bit OS:
cd C:\Program Files (x86)\VMware\VMware vSphere CLI\bin

You may also wish to enter your host in to maintenance mode before doing the update, which can be easily done from the vSphere Client.

Finally type the following command:

esxcli -s 192.168.0.10 -u root -p password software vib install -d
/vmfs/volumes/4ff41a22-76ab1cd3-2516-001ed2a2e4dc/Updates/Update.zip

In the above, I’ve put my personal entries in unboldened italics. You will need to put in your own entries as follows:

-s    Your Server IP or Hostname
-u    Your ESXi host admin user name, normally ‘root’
-p    Your ESXi host password
-d    The location of your Update.zip file, using the location of the datastore, and the further folder location you may have created to put the update in (the ‘d’ stands for ‘depot’, by the way).

When you hit enter, the cursor will drop for a time, and nothing may appear to happen for several minutes. If the update is successful, you will eventually get an installation result message confirming all is ok, with a list of all updates applied. If it fails, I assume it will tell you, but it has yet to fail for me :)

You will then need to go back in to the vSphere client, restart the ESXi server, and then take it out of maintenance mode. Then manually fire up any virtual machines you have. You should then be done.

There may be a way of applying multiple updates simulteneously, but I’ve yet to need to do that. Doing one file at a time should work ok though (I suggest oldest updates first).

Upgrading ESXi 4.0 to ESXi 4.1 via the VMware CLI (Command Line Interface)

Today I had cause to upgrade my firm’s ESXi server from version 4.0 to 4.1. Unless you are lucky enough to own a license of VMware vCentre (and use the update mechanism in this, which I confess I’ve never even looked at) your best option to run the update is from the command line, via VMware’s CLI. Once you get going with this, it really is quite a nice method.

This guide is based on using the free CLI from VMware, running on Windows 7 x64, alongside the vSphere client (version 4.0, from the start off). Please note this is an upgrade guide only, and I won’t be going in to installing ESXi from scratch in this article.

Start by safely shutting down all running virtual machines on your live ESXi server.

Load up the vSphere client (version 4.0) and put the ESXi server into maintenance mode.

Visit www.vmware.com to download the Zip file update of ESXi 4.1. If you haven’t already, you will need to create a free account with VMware, in order to obtain access to all ESXi 4.1 and older downloads (as well as your free license code). Look on the site for the free download of “VMware vSphere Hypervisor”. Note that VMware have decided to change the name in some documentation and site pages to this, but for the sake of this blog I will refer to the new release still as ESXi 4.1. The file you need to download is listed as “ESXi 4.1 (upgrade ZIP from ESXi 4.0)”. I recommend you save this update directly to the C: drive root on your computer, as I have done for this tutorial.

If you don’t already have it, download and install the VMware vSphere CLI (Command Line Interface) from http://communities.vmware.com/community/vmtn/vsphere/automationtools/vsphere_cli and install on your local Windows client. This installer includes ActivePerl – an environment needed for CLI to work.

From your Windows client load up the Windows command line (cmd), ensuring you have full admin rights applied if running Vista or later. Type one of the following from the command prompt in order to get in to the CLI script folder:

For 32-bit OS:
cd C:\Program Files\VMware\VMware vSphere CLI\bin

For 64-bit OS:
cd C:\Program Files (x86)\VMware\VMware vSphere CLI\bin

To list all patches already applied to your ESXi install, type in the following command:

vihostupdate.pl –query server 192.168.1.17 username root password PASSWORD

This will list all patches and updates already installed on your ESXi server (since the last major update), as below. (In the above command, substitute the server IP address to your own ESXi server’s IP, and PASSWORD to be your case sensitive root access password you use).

To analyse the contents of the zip file update you’ve downloaded VMware, and compare it to the patches already installed on your ESXi 4 server, run the following command (same substitution rules apply):

vihostupdate.pl –server 192.168.1.17 –username root –password PASSWORD –scan –bundle c:\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip

This will produce an output, somewhat similar to the below. Note, this will list all patches within the update that your ESXi server doesn’t already have installed.

This output tells us that the bundle contains the two patches that upgrade us from 4.0 to 4.1, and that these aren’t currently evident as part of your existing install.

Now you’re ready to run your update. Needless to say, by the time you’ve got this far make sure you have backed up all your virtual machines (and their contained data), and your current ESXi install. Things can go wrong, and you must always have a fall back plan. You’ve been warned!

So from here, run the command below (with substitutions as before) to start the update…

vihostupdate.pl –server 192.168.1.17 –username root –password PASSWORD –install –bundle c:\upgrade-from-ESXi4.0-to-4.1.0-0.0.260247-release.zip

A message should be returned and read:

“Please wait patch installation is in progress …”

Be patient. It can take quite a few minutes for the install to complete. Once it does a message should read:

“The update completed successfully, but the system needs to be rebooted for the changes to be effective.”

If you haven’t already, fire up your vSphere client and reboot ESXi from the GUI.

Post a reboot of ESXi, attempt to re-logon from the vSphere client, and you will be prompted to update your vSphere client. Either run the installer, or download and install the client update manually – you won’t be able to access ESXi till you do.

Back to the command line, run the following query command again to verify updates:

vihostupdate.pl –query –server 192.168.1.17 –username root –password PASSWORD

A result should be returned as follows:

This shows the update has applied successfully, and you are running ESXi 4.1. You can also check build versions from the ‘About’ menu option in the vSphere client software.

Finally, take your newly upgraded ESXi 4.1 server out of maintenance mode in the vSphere client, and start all your live virtual machines. Upgrade Vmtools in each VM (with reboots), then you’re done!