Virtualisation and VMWare

Useful Web Links:

http://vlp.vsphere-land.com/ - This link takes you to a whole host of useful VMWare Blogs etc

http://www.rtfm-ed.co.uk/ - Mike Lavericks Blog



Useful Commands and General Information


Useful Commands on ESX


Checking nics on ESX

#esxcfg-nics –l

Other switches for the esxcfg-nics command include:

-s|--speed <speed>                  Set the speed of this NIC to one of 10/100/1000/10000.
-d|--duplex <duplex>              Set the duplex of this NIC to either ‘full’ or ‘half’.
-a|--auto                                   Set speed and duplexity automatically. Requires a NIC parameter.
-l|--list                                      Print the list of NICS and their settings.
-r|--restore                                Restore the nics configured speed/duplex settings (INTERNAL ONLY)
-h|--help                                   Displays help message with the above info.

Changing Default Gateway.

Edit the /etc/sysconfig/network file to reflect the correct Gateway address.

You can do this by browsing to /etc/sysconfig/

Then use less network,

Then press the insert key followed by vi

This will make the file editable, you can then overwrite the GATEWAY address with the correct one.

Once this is done type escape then :wq! Press enter, then press q to get back to command line.

Then type service network restart to restart the network services.


Checking Switch Configuration on ESX

#esxcfg-vswitch –l

Other switches for the esxcfg-vswitch command include:

esxcfg-vswitch [options] [vswitch[:ports]]
  -a|--add                                  Add a new virtual switch.
  -d|--delete                              Delete the virtual switch.
  -l|--list                                    List all the virtual switches.
  -L|--link=pnic                        Set pnic as an uplink for the vswitch.
  -U|--unlink=pnic                    Remove pnic from the uplinks for the vswitch.
  -p|--pg=portgroup                  Specify a portgroup for operation
                                                Use ALL for operation to work on all portgroups
  -v|--vlan=id                           Set vlan id for portgroup specified by -p
                                                0 would disable the vlan
  -c|--check                               Check to see if a virtual switch exists.
                                                Program outputs a 1 if it exists, 0 otherwise.
  -A|--add-pg=name                Add a new portgroup to the virtual switch.
  -D|--del-pg=name                  Delete the portgroup from the virtual switch.
  -C|--check-pg=name              Check to see if a portgroup exists.  Program
                                                outputs a 1 if it exists, 0 otherwise.
  -r|--restore                              Restore all virtual switches from the configuration file
                                                (FOR INTERNAL USE ONLY).
  -h|--help                                 Displays help message with the above info.

Removing a VLAN ID from the Service Console Switch

#esxcfg-vswitch –p “Service Console” –v 0 vSwitch0


ESX Firewall Command

#esxcfg-firewall

Switches for the esxcfg-firewall command are:

esxcfg-firewall <options>
-q|--query                                                         Lists current settings.
-q|--query <service>                                        Lists setting for the
                                                                        specified service.
-q|--query incoming|outgoing                          Lists setting for non-required
                                                                        incoming/outgoing ports.
-s|--services                                                      Lists known services.
-l|--load                                                            Loads current settings.
-r|--resetDefaults                                             Resets all options to defaults
-e|--enableService <service>                           Allows specified service
                                                                        through the firewall.
-d|--disableService <service>                          Blocks specified service
-o|--openPort <port,tcp|udp,in|out,name>       Opens a port.
-c|--closePort <port,tcp|udp,in|out>                Closes a port previously opened
                                                                        via --openPort.
   --blockIncoming                                           Block all non-required incoming
                                                                        ports  (default value).
   --blockOutgoing                                           Block all non-required outgoing
                                                                        ports (default value).
   --allowIncoming                                           Allow all incoming ports.
   --allowOutgoing                                           Allow all outgoing ports.
-h|--help                                                           Displays help message with the above info.


TAR file unpack command:

#tar –xvzf name_of_file.tgz (This command needs to be run from the location of the file)

Copy command

#scp –r* /folder1/folderA /folder2/folderB

The above command will copy the entire contents of folderA to folderB, to copy a specific file substitute the * for the file name.




Create a Directory

#mkdir /tmp/FolderA

The above command would create a Directory called FolderA with the TMP directory, substitute as necessary.

Mounting the CD ROM Drive.

#cd mnt
#mount cdrom
#cd cdrom

Unmounting the CD ROM Drive.

#cd ..
#umount cdrom

Installing ESX Patch command.

Firstly browse to the relevant folder where the patch has been unpacked, the issue the following command:

#esxupdate update

Viewing/Amending text files. (Useful for amending the HOSTS file and the sshd_config file)

In the following example I will use the HOSTS file, but the principle can be applied to any viewable file.

#cd etc
#less hosts

This will then show you the hosts file, to make this file writable type vi, you can then make the relevant amendments. Once complete press the escape key, then shift colon, then type wq! Save the file. You then just press to quit out of the hosts file.

The above is also useful for amending the sshd_config file to allow ssh connections to the ESX server.


VMware ESX, killing a virtual machine that won’t die.

Sometimes the Virtual Center won’t do the job.  You virtual machine has hung and you need to kill it. Here are 2 examples of how you can kill the vm from within the service console:
  1. The ‘VMWARE-CMD’ command
  • Log on to the service console and issue the following command ‘vmware-cmd /vmfs/volumes/<datastorename>/<vmname>/<vmname>.vmx stop’ you must not use the friendly datastore name.  If you need to know the location of all vm’s type ‘VMWARE-CMD -l’ that will list on vm’s and the location for the corresponding vmx file.
  • If that fails, then try it with the hard option, ‘vmware-cmd /vmfs/volumes/<datastorename>/<vmname>/<vmname>.vmx stop hard’ this command will just try and kill it without shutting it down.
2. Kill it using the PID command

  • Run the following command: ps auxfww | grep <vmname> to locate the correct PID of the virtual machine,  the first number to appear in the output is your vm’s PID. Use the PID number to terminate the process by issuing kill -9 <PID NO>



Renaming VMDK disks

1.)    Power off the Virtual Machine that you want to rename the vmdk file on.
2.)    Remove the hard-drive associated with the vmdk file that you want to rename using VI Client.
3.)    Putty onto the ESX Server that hosts the Virtual Machine.
4.)    Use the CD and LS commands to browse to /vmfs/volumes to find out the Binary Storage Name.
5.)    Run the below command to rename the relevant vmdk file.

Vmkfstools –E vmfs/volumes/<Binary Storage Name>/<VM Name>/<Disk Name>.vmdk vmfs/volumes/<Storage Name>/<VM Name>/<New Disk Name>.vmdk

6.)    Use the VI Client to reconnect the renamed vmdk file as a Hard-drive on the relevant Virtual Machine.
7.)    Power on the Virtual Machine to confirm the Hard Disk is connected correctly.


Removing Empty Virtual Machine Directories

Putty onto any of the ESX Servers

Browse to the relevant storage lun

Then use the rm –r [DirectoryName] command

RESTART MANAGEMENT SERVICES

You can restart the management services on the ESX host – it won’t affect any running VMs.

Logon as root on the host locking the VM and type:

Service mgmt-vmware restart

*******************************************

Could not power on VM : No swap file. Failed to power on VM

 

"Could not power on VM : No swap file. Failed to power on VM" - This issue is caused when a VM guest tries to power on and some other ESX host has one or more guest files open. This is usually due to a crash or fault in the ESX Cluster that HA did not complete successfully.