A. Mikkelsen

VMware ESX scripts, commands, tools and other nice to know things that will make your virtualization days easier!!!!

Dafa has added / edited:

– Added Show PermitRootLogin from /etc/ssh/sshd_config
– Added tabs to ntp output
– Added esxcfg-vmknic -l
– Added esxcfg-nics -l
– Added printhead function + small cleanup

Dafa has added / edited:

NTP edited
esxcfg-vswif -l
esxcfg-vswitch -l
logfile moved to /var/log and filename based on my_date

I have put together a script that can monitor a service (Only Windows OS).

If it registeres that the service is not running, it starts it and sends a mail to the administrator.

 Download the script here.

I have updatet the script so it displayes the information in a more readable way.

Download the script here.

During an upgrade of an ESX 2.5.4 environment to ESX 3.0.1 I had a problem with one of the VM’s.
Every time I tried to clone or migrate a specific VM I got the same error over and over.
“Host does not support the virtual hardware version of the virtual machine”I realized that the VM originally was build on a GSX server.
I opened the vmx file and saw that the hardware versions were not updated properly.
The 2 hardware parameters in the vmx file is config.version = “x” and virtualHW.version = “x”. Where x is a number based on the host OS.
For a GSX these numbers are 6 and 2.
For an ESX 2.5.x these numbers are 6 and 3.
This meant that when the VM was moved from GSX to ESX 2.5.x the virtual hardware wasn’t upgraded properly.

The resolution was to completely uninstall the VMware Tools in the VM and make a complete reinstallation of the VMware Tools. Here after it is possible to upgrade the Virtual Hardware.
Now the migration of the VM to an ESX 3.0.1 host will run smoothly.

I created this small script to gather some info from a ESX 3.X host.
This script is still in it’s early stage.

Download it here.

Together with the danish VMware user forum, we have created at script that helps with the doll task of applying updates to an ESX VI 3.x host.

  1. Download each update from the VMware web site (http://www.vmware.com/download/vi/)
  2. Unpack each TGZ file with WinZip or 7-Zip
  3. Copy all extracted updates to a folder reachable by the ESX VI 3.x host.
  4. Download and extract esx-update.zip to 
    /tmp/
  5. Make the file executable
    chmod 777 /tmp/esx-update.sh
  6. Open the extracted file with vi (vi /tmp/esx-update.sh) and edit the following variables, so they reflect the server environment they will be running on.
    1. update_dir
    2. update_file
    3. log_file

To run the script it is a good idear to put the host in maintenance mode.

  1. Set the host in maintenance mode
    vimsh
    hostsvc/maintenance_mode_enter
  2. Now you can start the script 
    ./tmp/esx-update.sh
  3. Exit the host from maintenance mode
    vimsh
    hostsvc/maintenance_mode_exit

Download the file here.

To list only the directories in a directory use the following:

ls -v

To only list the directories that starts with ESX use the following

ls -v |grep “ESX”

If you want to mount a NAS / NFS share in ESX 3.0, then you are not given the option to choose a username and password.
This presented me with a small challange because i needed to mount /vmimages/vmiso/ to a share on a W2K3 server.

SoI created this small script, that mounts /vmimages/vmiso/ to a NFS share on a W2K3 server.
The script is intented to run as part of the Service Console’s startup routine.
I have implemented a simpel log feature, that logs the date and time the script is run and any errors if any.

Create a file S99mount with the following content: (Download it here)

echo “****************************************” >> /tmp/mount.log
date >> /tmp/mount.log
sleep 30
echo “Start the mount” >> /tmp/mount.log
mount -t smbfs -o username=myusername,password=mypassword //myservername/myshare /vmimages/vmiso/ >> /tmp/mount.log
echo ” ” >> /tmp/mount.log

Copy the file to /etc/rc3.d/
Make the file executable
chmod 777 /etc/rc3.d/S99mount
Create the directory vmiso under /vmimages/
mkdir /vmimages/vmiso
Change the firewall to allow outbound traffic for the SMB Client
esxcfg-firewall –enableService smbClient