Virtualisation 101 – Creating VMs Part 1

To continue the introduction to Virtualisation by Simon we now move on to Creating virtual machines.

Building a shiny new VMware cluster is only the start of the journey to virtualisation – the majority of time and effort will be actually be spent creating and managing the virtual machines that will run on this new infrastructure.

This article will give a high level overview of some of the methods available for creating new VMs, and how you can automate the process to work more efficiently.

New Virtual Machine Wizard

From the vSphere Client you can right click on a cluster, server, resource pool or folder and select New Virtual Machine from the context menu to launch a deployment wizard. This takes you through a series of questions that determine your requirements, and adds a new virtual machine object to the inventory. Values requests by the New Virtual Machine Wizard include :-

  • The name of the virtual machine – this sets the name of the underlying folder into which the configuration files will be written, and the name registered in the inventory.
  • The cluster, ESX host and resource pool that the new machine should be registered to (This can be changed afterwards with VMotion migrations)
  • The datastore that the VM’s files will be written to. (This can also be changed afterwards with Storage VMotion)
  • The flavour of Operating System that will be installed on the machine. This helps define default values for the resources provided to the server.
  • Hardware resources to provision: No. of vCPUs, amount of RAM and number of NICs required.
  • The number of hard disks required, the size of each disk and whether they should be thick or thin provisioned.

On completion of the Wizard a new folder is created on the selected datastore (for example SAN_LUN1\VM001) along with a number of data files that make up the virtual machine.

The configuration file (VM001.vmx in our example) is then registered on the chosen cluster or server and appears in the Inventory pane.

TIP: Avoid changing the name of the VM object after it has been created, otherwise the name of the folder gets out of sync with the name in the inventory, increasing admin overhead.

Although the wizard prompts for an OS type it doesn’t actually install anything into the new VM – if you open a console session and power the machine on you will see it go through a simple POST routine just like a physical server, concluding with a “No operating system found” message.

The next step in the manual creation of a virtual machine is to install the OS by mounting an operating system CD or DVD. This is done by mapping the CD drive of the VM to your workstation’s CD drive, by mounting an ISO image (a CD/DVD in software form) or using an imaging product that utilises PXE network booting (MAC addresses can be gleaned from the Edit Settings screen).

After installing the OS you should install the VMTools application, done from the console session’s VM > Guest > Install/Upgrade VMTools menu option. This mounts a small ISO to the guest for the install, automatically launching the setup wizard on Windows servers. (There is an RPM or manual install available on the Linux ISO)

This application allows you to shutdown or reboot the guest gracefully without having to log into it, sync the system time from the ESX host and sends a regular heartbeat back to the ESX host.

Cloning Virtual Machines

This is where vSphere really starts to save time and effort. It is possible to create copies of existing virtual machines by cloning them, even if the original is in use. Cloning helps when you need to deploy multiple servers from the same OS build level, or if you need to take a rollback copy before making a change (as an alternative to snapshots).

This functionality is provided by vCenter Server so this option isn’t available when connecting directly to an ESX or ESXi host.

To create a clone, right click the source machine in the inventory and select Clone to launch the wizard. Each dialog will take you through the options available within the cloning process :-

  • Name for the cloned virtual machine.
  • Host, cluster and resource pool to register the new machine with.
  • Datastore to write the copy to and format for the clone’s disks – since the process writes a copy of each disk file it is possible to have a thick provisioned source VM and a thin provisioned clone.
  • Whether to customise the cloned machine, helpful if it needs to be modified from the original, for example changing the hostname or networking. There are two options for this – to manually enter details within the cloning wizard, or to follow a template you’ve already defined.

The wizard then creates a new folder on the destination datastore with the name of the new machine and copies the files from the source VM’s folder over to the target, renaming as it goes. The new machine is registered against the chosen cluster, server or resource pool, and is then ready for use.

TIP: The new VM will be an exact duplicate of the source machine, including hostname & IP addresses, so disconnect the NICs to avoid clashing with the original.

Deploying Virtual Machines from Template

Templates take the concept of cloning and turn it into a repeatable process, allowing rapid deployment of multiple machines, each with a unique identity. Again this functionality requires a vCenter Server, and isn’t available on a standalone server.

A template is essentially a virtual machine that has been made Read Only and removed from the Inventory list so it cannot be accidentally modified. To manually create a template :-

  • Manually create a virtual machine and configure the OS to your desired build level. It will help with identification if you describe the build level in the VM name, for example “Windows -2008-R2-SP1-Template”
  • Shut the VM down.
  • Right click the VM and select Template > Convert To Template.

The object will no longer be visible in the Hosts & Clusters view, but can be found in the VMs and Templates view with a different icon.

If you have a virtual machine that you wish to create a template from, this can be done by right clicking on the VM and selecting Templates > Clone to Template from the menu.

Deploying new VMs from template is simply a case of choosing the template in the VMs & Templates view and click on the Deploy Virtual Machine from Template to launch the wizard. It will ask similar questions to the cloning wizard, and will change the identity of the server during deployment.

For Windows 2003 VMs the customisation is performed by a Microsoft utility called SYSPREP, which needs to be installed on the vCenter Server – see the link below for details. Windows 2008 has this functionality built in.

TIP: Wait 10 minutes after a newly deployed virtual machine first boots, as the SYSPREP wizard takes a while to apply the customisation data, performing a reboot when done.

Customisation Specifications

When deploying a new virtual machine from template the wizard asks a series of questions such as hostname, license key and networking settings. At the end of the wizard you have the option to save those choices to a Customisation Specification profile.

The profile can be selected in future deployments to avoid having to enter the same details again, speeding up deployment.

TIP: At the hostname option pick the “same as VM name” option.

Create Virtual Machine with PowerCLI

Another option for deploying virtual machines is to use the New-VM cmd-let in PowerCLI. This cmd-let has a large number of switches to cover the various deployment options. Use get-help new-vm for full details.

It can take advantage of templates and customisation profiles to easily deploy a new virtual machine from a single line :-

New-VM –Name VM001 –Template W2K8-R2-Tmp –OSCustomizationSpec W2K8-R2-Std

In the next part we will look at converting existing physical or virtual machines into vSphere, and look at the problems of VM sprawl and even Zombie VMs!

Links:

Installing SYSPREP on vCenter Server: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1005593

Advertisements