Thursday, April 22, 2010

delete lost snapshots

A very useful trick I learned today. If you have taken a snapshot of a virtual machine and the snapshot manager does not report that the guest does indeed have a snapshot ( ie a delta disk) then you can do the following to remove it. Take another snapshot of the guest. Then in snapshot manager delete all snapshots. Once the second snapshot is taken it now shows in snapshot manager and all the snapshots can be removed!

Tuesday, April 20, 2010

expand virtual hard disk of a guest in ESX 4

The full path must be specified or the command issued in the directory that the .vmdk file is located.

vmkfstools -X 1000m /vmfs/volumes/datastore/vmguest_name/vmguest_name.vmdk


UPDATE:
After wasting a couple of hours trying to figure out why this won't work I have the answer. the -X size is the total size of the disk not how much you want to expand it by! So the correct syntax should look like this:

vmkfstools -X 25000m /vmfs/volumes/datastore1/vmguest_name/vmquest_name.vmdk

Monday, April 19, 2010

Sophos antivirus won't install correctly on Windows 7

Sophos returns this error when trying to install on windows 7:

80070035 Could not start installation program on the computer. The network path was not found.

The fix is to enable the remote registry service in the control panel -> services or run services.msc

Go back to the console and re-run the protect computers again!

Monday, April 12, 2010

VMware ESX disk usage from command line

Even though ESX is based on Red Hat Linux a normal df -h does not show the amount of disk space used on the data stores. However if you use vdf -h you will get the human readable version of the output.

vdf -h

Thursday, April 8, 2010

copy to and from samba using ESX

You can mount samba shares ( windows or linux CIFS/samba) from an ESX box. This comes in very handy! I use it to copy on and off vmdk files when needed. Below is a example of the script I use for this. It is meant for ESX4. Earlier versions are slightly different.

#!/bin/bash
########################################################
#script to copy vmdk file to local datastore
########################################################

# enable samba client

esxcfg-firewall -e smbClient

##########################################
#make mount directory
##########################################
echo making directory /mnt/copy

mkdir /mnt/copy

###########################################
#mount samba share
##########################################
echo mounting directory to copy .vmdk file

mount -t cifs //ip or name/share /mnt/copy/ -o username=username,password=password

##########################################
#copy .vmdk files
#########################################

cp /mnt/copy/*.vmdk /vmfs/volumes/LocalStorage1/guestvm/

echo vmdk files have been copied.
#########################################
#unmount samba share
########################################
echo unmounting /mnt/copy

umount /mnt/copy


########################################################
#END script to copy vmdk file to local datastore
########################################################

Here are a couple of good links to talk about this topic:

Using Samba shares with vcbRestore on ESX Server Service Console using domain logins


Cannot mount Windows share in ESX 4.x with a mount_data version is not supported error


Connecting to a CIFS Share on a Windows Server from the Service Console

Saturday, April 3, 2010

Clear and Add network printers

Here is a handy VB script that I have cobbled together. Some from the web, etc.

set net = CreateObject ("WScript.Network")

'deletes all network printers
Set clPrinters = net.EnumPrinterConnections
For i = 0 to clPrinters.Count - 1 Step 2
clPrinters.Item(i)& " " & i+1
net.RemovePrinterConnection clPrinters.Item(i+1), true
Next

'maps new printers.
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.AddWindowsPrinterConnection "\\print_server_name\printer name", "description"
net.SetDefaultPrinter "\\print_server_name\printer name"

Wscript.Quit

Friday, April 2, 2010

VMware ESX 4 Kickstart setup

After a quite a long process of trying to find a way of taking the human error out of the equation while provisioning an ESX server my colleagues and I have come up with way that not only makes tracking a large ESX environment but allows for quick recover as well.

Before I document what we did a little primer on how ESX and kickstart files work should be in order. We actually use a bootable media such as a DVD or USB stick to start the deployment but PXE environments would work for this as well. This example will be using a USB thumb drive to start things off. The Thumb drive has been made bootable by a process of formatting it to a FAT32 file system and in fdisk making it bootable. Then we use syslinux to give us the boot to kickstart process. Syslinux provides a file called syslinux.cfg. By editing that file and appending a ks=http://somewebsite.com/ks.cfg.php?server=xxx line to the end of the initrd statement ( don't worry I will post an example in a little bit ) we are able to direct the kernel to look for kickstart file to read and process.


With these few lines of code and the contents of the VMware install CD copied to the USB drive we are able to now interact with a web page that will be dynamically generated with all the options for the new ESX server.

The kickstart file is actually a php web page. With the proper formatting of the page and a database query added to retrieve the correct fields we are ready to go. What this gives us is the at the heart of this. By having things like the server name, all network settings, drive partitions, root password, and time zone populated by the database we can not only manage and expand as needed our server information but be able to pull them on the fly when we need to re install a server or install a new one. Also the kickstart file allows for a post install section that can be executed after ESX is installed and the server has rebooted into a live ESX environment. This is quite powerful and allows for even greater flexibility. Plus by having this in one place all you need to do is maintain the code in one spot for every server!

I will post a copy of my kickstart file soon so that you can see how much work can be done with one file. Now I only need to enter the server name and let this handle the rest of the configuration for me!