52918.fb2 Mastering VMware® Infrastructure3 - читать онлайн бесплатно полную версию книги . Страница 8

Mastering VMware® Infrastructure3 - читать онлайн бесплатно полную версию книги . Страница 8

Chapter 6Creating and Managing Virtual Machines

The ESX Servers are installed, VirtualCenter is running, the networks are blinking, the SAN is carved, and the VMFS volumes are formatted… and so the virtualization begins. With the virtual infrastructure in place, the attention and focus of the administrator shifts to the deployment of virtual machines.

In this chapter you will learn to:

♦ Create a virtual machine

♦ Install a guest operating system

♦ Install the VMware Tools

♦ Manage and modify a virtual machine

♦ Create templates and deploy virtual machines

Creating a Virtual Machine

Before we get too deep into the virtual machine creation and management process, we must first establish a few distinctions with regard to the terminology we will use. It is common for IT folk to commonly refer to a Windows or Linux system running on an ESX Server host as a virtual machine. Technically, the statement is not 100 percent accurate. I am not here to change the world, so I won't try to force a change; however, a virtual machine actually deserves a separate distinction from the guest operating system. The assembly of a set of virtual hardware that makes up the virtual machine is still a virtual machine prior to the installation of the guest operating system, just as a physical server without an operating system is still a physical machine. So, from a technical perspective, a virtual machine is a set of virtual hardware selected for the purpose of running a guest operating system. However, from a practical perspective you can go on calling the Windows or Linux system a virtual machine.

A virtual machine can consist of different virtual hardware components that utilize drivers written by VMware. These drivers are not as complex as using manufacturer-released drivers for specific hardware components. For example, the drivers for the VMware SVGA II are not as heavy or invasive as the drivers for an ATI Radeon video adapter. Figure 6.1 shows virtual hardware identified in the Device Manager of a virtual machine. Noticeably, much of the third-party device driver installation is replaced with the virtualized hardware that the ESX Server is providing.

Figure 6.1 The drivers for hardware in a virtual machine are much lighter than the third-party drivers found on physical computers.

The lighter and less intrusive drivers found in a virtual machine result in an easier hardware maintenance schedule and reduced opportunity for server failures due to driver incompatibilities.

A virtual machine consists of several types of files; the two most common are the configuration file and the virtual hard disk file. The configuration file is identified by a .vmx extension and functions as the structural definition of the virtual machine. The VMX file defines the virtual hardware that resides in a virtual machine. The number of processors, the amount of RAM, the number of network adapters, associated MAC addresses, and the number, names, and locations of all virtual hard drives are stored in the configuration file.

The virtual hard disk file (identified by a .vmdk extension) holds the data stored by a virtual machine. Typically the first VMDK file is the storage location for the C drive of the virtual machine that holds the operating system. Additional virtual hard disks (VMDK files) can be added to provide additional storage locations for the virtual machine.

A virtual machine, as shown in Figure 6.2, can consist of the following virtual hardware devices:

♦ Processors — one, two, or four processors with VMware Virtual SMP

♦ Memory — Maximum of 16GB of RAM

♦ SCSI adapter — Maximum of four SCSI adapters with 15 devices per adapter

♦ Network adapter — Maximum of four network adapters

♦ Parallel port — Maximum of three parallel ports

♦ Serial port — Maximum of four serial ports

♦ CD/DVD ROM — Maximum of two CD/DVD ROM drives

♦ Floppy drive — Maximum of two floppy disk drives

♦ Keyboard, video card, and mouse

Figure 6.2 A virtual machine consists of virtual processors, SCSI adapters, network adapter, CD/DVD drives, memory, and more.

Hard drives are not listed in the virtual hardware because virtual machine hard drives are added as SCSI devices. With up to four SCSI adapters and 15 SCSI devices per adapter, it is possible to attach 60 hard drivers to a virtual machine. Keep in mind, however, that the size limit for a virtual hard drive is 2TB.

Perform the following steps to create a virtual machine:

1. Use the VI Client to connect to a VirtualCenter server or an individual ESX Server host.

2. In the inventory tree, right-click on the name of a cluster or an individual ESX Server host and select the New Virtual Machine option, as shown in Figure 6.3. Alternatively, use the File menu or the Ctrl+N keyboard shortcut to launch the wizard.

3. When the New Virtual Machine Wizard opens, select the Custom radio button, shown in Figure 6.4, and then click Next. The Custom selection lets you configure input/output (I/O) adapters during the virtual machine creation process.

4. As shown in Figure 6.5, type a name for the virtual machine in the Virtual Machine Name text box, select a location in the inventory where the virtual machine should reside, and click Next.

Real World Scenario

Virtual Machine Naming

The display name given to a virtual machine might seem like a trivial assignment, but you must ensure an appropriate naming strategy is in place. As a rule, the display names of virtual machines should, but don't have to, match the hostnames configured in the guest operating system being installed. For example, if the intention is to name the guest operating system host Server1, then the virtual machine display name should match with Server1. If spaces are used in the virtual display name, which is allowed, then using command-line tools to manage virtual machines becomes a bit tricky because the spaces will have to be quoted out in the command-line use. In addition, since DNS hostnames cannot include spaces, using spaces in the virtual machine name would create a disparity between the virtual machine name and the guest operating system hostname. Ultimately, this means you should avoid using spaces and special characters that are not allowed in standard DNS naming strategies to ensure similar names both inside and outside the virtual machine.

The display name assigned to a virtual machine also becomes the name of the folder in the VMFS volume where the virtual machine files will live. At the file level, the associated configuration (VMX) and virtual hard drive (VMDK) files will assume the name supplied in the display named text box during virtual machine creation.  

Figure 6.3 You can launch the New Virtual Machine Wizard from the context menu of an ESX Server cluster or an individual ESX Server host.

5. Select a datastore where the virtual machine files should be located, as shown in Figure 6.6, and then click Next.

Figure 6.4 The Custom option lets you adjust the type of I/O adapter in the virtual machine. 

Figure 6.5 The name provided for the display name of the virtual machine becomes the name of the folder it resides in and the prefix for all of the corresponding virtual machine files (i.e., VMX and VMDK).

6. As shown in Figure 6.7, select the radio button that corresponds to the operating system vendor, select the correct operating system version, and then click Next.

7. As shown in Figure 6.8, select the number of virtual processors to include in the virtual machine, and then click Next.

8. Configure the virtual machine with the determined amount of RAM by adjusting the slider bar or typing the value, as shown in Figure 6.9, and then click Next. 

The amount of RAM configured on this page is the amount of RAM the guest operating system reflects in its system properties. The setting on this page is not a guarantee that physical memory will be used to achieve the configured value. As discussed in later chapters, memory for a virtual machine can be physical RAM, VMkernel swap file space, or a combination of both.

Figure 6.6 Virtual machines can be stored in any of the datastores available to an ESX Server host as long as the space requirements meet the needs of the virtual machine.

Figure 6.7 Selecting the appropriate operating system vendor and version ensures that the correct I/O adapter is automatically chosen for the virtual machine.

9. As shown in Figure 6.10, select the number of network adapters to include in the virtual machine, configure each NIC for the appropriate network, and then click Next.

10. Select the radio button that corresponds to the appropriate SCSI adapter for the operating system selected on the Guest Operating System page of the New Virtual Machine Wizard. The correct default driver should already be selected based on the previously selected operating system. 

Virtual Machine SCSI Controllers 

Typically, Windows 2000 and Windows XP have built-in support for the BusLogic SCSI controller, while Windows Server 2003 and later operating systems have built-in support for the LSI Logic controller. Choosing the wrong controller will result in an error during the operating system installation. The error states that hard drives cannot be found. Choosing the wrong SCSI controller during a physical to virtual (P2V) operation will result in an “inaccessible boot device blue screen error” inside the virtual machine. 

Figure 6.8 You can configure virtual machines with one, two, or four processors with VMware Virtual SMP (which is included in the VMware Standard and Enterprise editions).  

Figure 6.9 The RAM configured on the Memory page of the New Virtual Machine Wizard equates to the amount of RAM the guest operating system reflects when viewing the system properties.

Figure 6.10 A virtual machine can be configured with up to four network adapters that reside on the same or different networks as needed. 

11. Select the appropriate radio button for the virtual disk to be used, as shown in Figure 6.11, and then click Next.

Figure 6.11 A virtual disk can be created as new, from an existing virtual disk, or with access to a raw SAN LUN. 

The option Use an Existing Virtual Disk allows a virtual machine to be created from a virtual disk that is already configured with an operating system and residing in an available datastore. 

The option Raw Device Mappings allows a virtual machine to have raw SAN LUN access. We will discuss this in more detail later in the book. 

Adding Existing Disks 

The existing virtual disk doesn't have to contain an OS; it can contain data that perhaps will serve as a secondary drive inside the virtual machine. The ability to add existing disks with data makes virtual hard drives extremely portable as they can be moved from virtual machine to virtual machine without repercussions. 

12. As shown in Figure 6.12, configure the desired disk size for the virtual machine hard drive and specify the location where the file should be stored; then click Next. The disk size configuration cannot exceed the maximum file size as defined by the format of the VMFS volume on which the file is being stored.

Figure 6.12 A virtual machine disk will consume the full amount of disk space by default. The size of the virtual machine's hard drive should be carefully considered. 

The option Store with the Virtual Machine will place the file in the same subdirectory as the configuration file and the rest of the virtual machine files. This is the most commonly selected option and makes managing the virtual machine files administratively easier. 

The option Specify a Datastore allows you to store the virtual machine file separately from the rest of the files. You'd typically select this option when adding new virtual hard disks to a virtual machine and when you need to separate the operating system virtual disk from a data virtual disk.

13. As shown in Figure 6.13, the Advanced Options page lets you specify the SCSI node the virtual disk is connected to and also allows you to configure a virtual disk in Independent mode. As noted in the wizard, this page is normally not altered and can be accepted by clicking Next.

The Node drop-down list reflects the 15 different SCSI nodes available on each of the four SCSI adapters a virtual machine supports.

Figure 6.13 The virtual device node defines where in the virtual SCSI adapter the virtual hard disk is connected, while the virtual disk node defines the characteristics of the data storage. The Snapshots (Allowed) disk mode is the default configuration, which permanently writes to the disk and permits snapshots.

By not selecting the Independent mode option, you ensure that the virtual disk remains in the default state that allows virtual machine snapshots to be created. If you select the Independent checkbox, you can configure the virtual disk as a Persistent disk, in which changes are written immediately and permanently to the disk, or as a Nonpersistent disk, which discards all changes when the virtual machine is turned off.

14. As shown in Figure 6.14, complete a final review of the virtual machine configuration and then click Finish.

Figure 6.14 Reviewing the configuration of the New Virtual Machine Wizard ensures the correct settings for the virtual machine and prevents mistakes that require deleting and re-creating the virtual machine.

Building Scalable Virtual Machines 

Although many configuration options are available for creating virtual machines, there are some best practices that facilitate the management, scalability, and backup of virtual machines. First and foremost, virtual machines should be created with multiple virtual disk files as a means of separating the operating system from the custom user data. Separating the system files and the user data will make it easier to increase the number of data drives in the future and will allow for a more practical backup strategy. A system drive of 25GB to 30GB, for example, will provide ample room for the initial installation and continued growth of the operating system. The data drives across different virtual machines will vary in size due to the installed applications, the function of the system, and the number of users who connect to the computer. However, due to the fact that the extra hard drives are not operating system data, it will be easier to make adjustments to those drives when needed.

Additional virtual hard drives will pick up on the same naming scheme as the original virtual hard drive. For example, a virtual machine named SERVER1 that has an original virtual hard disk file named SERVER1. vmdk will name the new virtual hard disk file SERVER11.vmdk. Each additional file will increment the last number, making it administratively easy to identify all virtual disk files related to a particular virtual machine. This image shows a virtual machine configuration with operating system hard drives and an extra hard drive added for storing user nonsystem data:

Later in this chapter, we will revisit this concept to see how templates can be used to implement and maintain an optimal virtual machine configuration that separates the system data from the user data.

Installing a Guest Operating System

A new virtual machine is analogous to a physical computer with an empty hard drive. All the components are installed but there is no operating system. Once the virtual machine has been created, a supported guest operating system can be installed. Some of the more commonly installed guest operating systems supported by ESX 3.0 include:

♦ Windows Vista

♦ Windows Server 2003 Web/Standard/Enterprise/Datacenter

♦ Windows Small Business Server 2003

♦ Windows XP

♦ Windows 2000

♦ Windows NT 4

♦ Red Hat Enterprise Linux 2.1/3.0/4.0

♦ SUSE Linux Enterprise Server 8/9/10

♦ NetWare 5.1/6.0/6.5

♦ Solaris 10 operating system for x86 platforms

Installing any of these supported guest operating systems follows the same common order of steps for installation on the physical server, but the nuances and information provided during the install of each guest operating might vary greatly.

Perform the following steps to install a guest operating system using an ISO file on a shared datastore:

1. Use the VI Client to connect to a VirtualCenter server or an individual ESX Server host where a virtual machine has been created.

2. In the inventory tree, right-click the new virtual machine and select the Edit Settings menu option. The virtual machine properties window will open.

3. Select the CD/DVD Drive 1 hardware option.

4. Select the Datastore ISO File radio button and enable the checkbox Connect At Power On.

5. Click the Browse button to browse a datastore for the ISO file of the guest operating system.

6. Navigate through the available datastore options to find the ISO file of the guest operating system to be installed. Once the ISO file is selected, the properties page will be configured similar to Figure 6.15.

7. Right-click the virtual machine and select the Open Console option. Alternatively, you can use the Console in the details pane of the VI Client application.

8. Click the green Power On button from the toolbar of the console session. Alternatively, you can click the VM menu and select the Power On option. The virtual machine will boot from the mounted CD-ROM ISO file and begin the installation of the guest operating system, as shown in Figure 6.16.

Figure 6.15 A CD-ROM or an ISO file must be configured for the virtual machine to install a guest operating system.

Figure 6.16 When the new virtual machine is turned on for the first time, it will boot from the CD-ROM to begin the installation of the guest operating system.

9. Follow the onscreen instructions to complete the guest operating system installation. After installing the guest operating system, you should then install the VMware Tools. We will discuss the VMware Tools installation and configuration in the next section.

Microsoft Licensing and Windows Activation for Virtual Machines 

In the fourth quarter of 2005 Microsoft announced a radical change in the licensing of Windows Server 2003 operating system within a virtual infrastructure. To date, there is still confusion about the virtualization licensing available for the Windows Server 2003 operating system. The following list of licensing data is a culmination of information from both Microsoft and VMware:

♦ A single licensed copy of Windows Server 2003 R2 Datacenter Edition can be use to install and run an unlimited number of virtual machines on a single physical server. The following image shows the Windows Server 2003 R2 Enterprise and Datacenter Edition licensing schemes:

♦ Windows Server 2003 Web Edition and Windows Server 2003 Standard Edition are not affected by the new licensing terms and must be licensed on a per-virtual machine basis to maintain compliance with the Microsoft Licensing agreement.

♦ VMotion, moving a running virtual machine to a new host, does not violate a Microsoft Licens ing agreement as long as the target ESX Server host is licensed for the post-VMotion number of virtual machines. For example, if an ESX Server host named SILO101 has four running virtual machines and a second ESX host named SILO102 has three running virtual machines, it is within the licensing agreement to perform a VMotion of one virtual machine from SILO101 to SILO102. However, a VMotion from SILO102 to SILO101 would violate the licensing agreement. The next image exemplifies this scenario:

♦ Microsoft applications licensed on a per-processor basis must be licensed per virtual processor. For example, installing SQL Server 2005 in two virtual machines with two virtual processors requires four licenses for SQL Server 2005.

With the new licensing structure in place, using ESX Server with multicore processors and a hefty helping of RAM provides a substantial return on investment.

If your licensing structure for a Windows Server guest operating system does not fall under the umbrella of a volume licensing agreement, you will be required to activate the operating system with Microsoft within 60 days of installation. Activation can be done automatically over the Internet or by calling the provided regional phone number. With Windows Server operating systems specifically, the activation algorithm takes into account the hardware specifications of the server. In light of this, Windows must be reactivated when enough hardware changes have been made to significantly change the operating systems. To facilitate the activation process and especially to reduce the possibility of reactivation, the VMware Tools installation, memory adjustments, and processor adjustments should be made prior to performing the activation. 

In addition to installing the VMware Tools, you should perform any necessary tweaks or adjustments to enhance the performance of the virtual machine. For example, in a Windows guest operating system, configuring the hardware acceleration to its maximum setting provides a much smoother console session performance. 

Perform the following steps to adjust the hardware acceleration in a Windows guest operating system:

1. Right-click an empty area of the Windows desktop and select the Properties option.

2. Select the Settings tab and click the Advanced button. 

3. Select the Troubleshooting tab.

4. As shown in Figure 6.17, move the Hardware Acceleration slider bar to the Full setting on the right.

Figure 6.17 Adjusting the hardware acceleration feature of a Windows guest operating system is a common and helpful adjustment for improving mouse performance. 

Virtual Machine Guest Operating Systems 

For a complete list of guest operating systems and all respective information regarding installation notes and known issues, please refer to the PDF available from the VMware.com website at http://www.vmware.com/pdf/GuestOSguide.pdf. 

Installing the VMware Tools 

Although the VMware Tools are not installed by default, they are an important part of a virtual machine. The VMware Tools offer several great benefits without any detriments. In other words, installing the VMware Tools should be a standard practice and not a debatable step in the deployment of a virtual machine. The VMware Tools provide for:

♦ Optimized SCSI driver

♦ Enhanced video and mouse performance 

♦ Virtual machine heartbeat

♦ Virtual machine quiescing for snapshots and backups

♦ Enhanced memory management

The VMware Tools are available for both Windows and Linux guest operating systems; however, the installation methods vary due to the differences in the operating systems. In either case, after you select the option to install the VMware Tools, the guest operating system will reflect a mounted CD-ROM that has the VMware Tools install bits. The VMware Tools ISO images are located in the /vmimages directory in the root file system on the ESX. They do not have to be downloaded or obtained from the installation CD-ROM.

Follow these steps to install the VMware Tools in virtual machines with a Windows guest operating system:

1. Use the VI Client to connect to a VirtualCenter server or an individual ESX Server host.

2. Right-click the virtual machine in the inventory tree and select the Install VMware Tools option.

3. If a warning message is displayed, click OK.

4. If the VMware Tools installation process does not begin automatically, open Windows Explorer, navigate to the CD/DVD drive, and double-click the file named setup.exe.

5. Click Next on the VMware Tools installation wizard welcome page.

6. Select the appropriate setup type for the VMware Tools installation and click Next. The Typical radio button will suffice for most situations. The Complete installation option installs more features than are used by the current product, while the Custom installation option allows for the greatest level of feature customization.

7. Click Install.

8. Once the installation is complete, click Finish.

9. Click Yes to restart the virtual machine immediately or click No to manually restart the virtual machine at a later time.

Once the VMware Tools installation is complete and the virtual machine is rebooted, the system tray will display an icon of the VMware logo. The logo in the system tray, shown in Figure 6.18, indicates a successful VMware Tools installation.

By double-clicking on the VMware logo in the system tray, you open the VMware Tools Properties, shown in Figure 6.19. Here you can configure time synchronization, hide the VMware Tools from the taskbar, and create scripts to suspend, resume, shut down or turn on a virtual machine.

Use caution when enabling time synchronization between the guest operating system and the console operating system host since Windows domain members rely on Kerberos for authentication and Kerberos is very sensitive to time differences between computers. A Windows-based guest operating system that belongs to an Active Directory domain is already configured with a native time synchronization process against the domain controller of its domain that functions as the PDC Emulator operations master. If the Service Console time is different from the PDC Emulator operations master domain controller, the guest operating system could end up moving outside the five-minute window that Kerberos will allow. Once the five-minute window is exceeded, Kerberos begins to experience errors with authentication and replication.

Figure 6.18 Once the VMware Tools are installed on a Windows-based virtual machine, an icon of the VMware logo will be displayed in the system tray. 

Figure 6.19 Use the VMware Tools to configure time synchronization with the Service Console. 

There are a few different approaches you can take to manage time synchronizations in a virtual environment. The first approach involves not using the VMware Tools time synchronization and relying instead on the W32Time service and a PDC Emulator with a registry edit that configures a synchronization with an external time server. Another approach involves disabling the native time synchronization across the Windows domain and then relying on the VMware Tools feature. 

A third approach might be to synchronize the ESX Server hosts and the PDC Emulator operations master with the same external time server and then to enable the VMware Tools option for synchronization. In this case both the native W32Time service and the VMware Tools should be adjusting the time to the same value. 

Configuring NTP on ESX Server 

By tweaking the Service Console firewall and editing a few files, you can configure an ESX Server to consistently synchronize with an external time server. Perform the following steps to synchronize an ESX host with a set of external time servers:

1. From a console with root permission, enter the following command to open the required ports

for allowing the NTP daemon to communicate with an external time server:

# esxcfg-firewall --enableService ntpClient

or

# esxcfg-firewall -e ntpClient

where -e is shorthand for -enableService).

2. Once the firewall port has been opened, you must edit the /etc/ntp.conf file to include

the address or addresses of the external time server(s). Edit ntp.conf to include the following

uncommented lines:

Restrict 127.0.0.1

Restrict default kod nomodify notrap

server name.of.time.server.1

server name.of.time.server.2

driftfile /var/lib/ntp/drift

3. Edit the /etc/ntp/step-kickers file to include all of the names of the time servers that were configured in the ntp.conf file.

4. Edit the /etc/hosts file to define name to IP addresses for the time servers. If an existing DNS server is capable of providing the name resolution, the last step does not have to be performed.

Use the following steps to install the VMware Tools on a Linux host: 

1. Use the VI Client to connect to a VirtualCenter or an individual ESX Server host.

2. Right-click the virtual machine in the inventory tree and select the Install VMware Tools option.

3. If a warning message is displayed, click OK.

4. Open a terminal window and change directories to the location of the VMware Tools mount point using the following commands:

[root@rhel5-1 /]# cd /media/"VMware Tools" 

5. Copy the gzip tar file to a temporary directory and then change to the temporary directory using the following commands:

[root@rhel5-1 VMware Tools]# cp VMwareTools-3.0.x-nnnn.tar.gz /tmp

[root@silo104 VMware Tools]# cd /tmp

6. Extract the contents of the tar file. By default, the file will extract to a directory named vmware-tools-distrib.

7. Change to the vmware-tools-distrib directory and run the vmware-install.pl Perl script using the following commands:

[root@rhel5-1 tmp]#cd vmware-tools-distrib

[root@rhel5-1 vmware-tools-distrib]# ./vmware-install.pl

Figure 6.20 shows the commands for steps 4 through 7.

Figure 6.20 Installing the VMware Tools for Linux from the command line involves extracting the tools and running the install file.

8. After the Perl script completes, restart the X session using startx.

9. Start the VMware Tools running in the background of an X server session using the following command:

[root@silo104~]# /usr/bin/vmware-toolbox &

10. Remove the tar file copy and the extracted directory using these commands:

[root@silo104~]# rm /tmp/VMwareTools-3.0.x-nnnn.tar.gz

[root@silo104~]# rm -rf /tmp/vmware-tools-distrib 

VMware Tools for Linux 

When installing the VMware Tools to a Linux guest operating system, the path to the tar file and the numbers in the tar filename will vary.

You can determine the existence of VMware Tools by checking for the icon displayed on the notification bar inside the guest operating system or by using the VI client. As shown in Figure 6.21, the Summary tab of a virtual machine object identifies the status of the VMware Tools as well as other information such as operating system, CPU, memory, DNS (host) name, IP address, and current host.

Figure 6.21 You can view details about VMware Tools, DNS name, IP address, and so forth from the Summary tab of a virtual machine object.

Managing and Modifying Virtual Machines

Just as physical machines require upgrading of hardware, a virtual machine may require scaling up on hardware due to performance demands. Perhaps a new memory-intensive client-server application requires an increase in memory, or a new data-mining application requires a second processor or additional network adapters for a bandwidth-heavy FTP site. In each of these cases, the virtual machine requires a modification of the virtual hardware configured for the guest operating system to use.

Modifying a virtual machine requires that the virtual machine exist in a powered-off state for all hardware — except when adding a new hard drive. You can add a new hard drive to a virtual machine with the machine turned off or on. This is a “hot add” process only because a hard disk cannot be removed while the virtual machine continues to run. CD and DVD-ROMs can be mounted and unmounted while a virtual machine is turned on, but new CD/DVD-ROM devices cannot be added. Floppy disk images can be mounted or unmounted while a virtual machine is turned on, but new floppy devices cannot be added. You can assign and reassign adapters to virtual networks while a virtual machine is running, but new adapters cannot be added. Figure 6.22 shows the CD/DVD mapping and the Add Hardware Wizard for a virtual machine. Note how the CD/DVD-ROM can be associated with a new ISO on a datastore; however, adding hardware to a running virtual machine is limited to adding virtual hard drives.

As administrators, we are consistently working with virtual machines, but on occasion we have to work directly with the files that make up the virtual machine. By browsing a datastore, as shown in Figure 6.23, or using an SSH session, you'll find there are many files that relate to a working virtual machine.

Most often, when dealing directly with virtual machine files, we deal with either the VMX configuration file or the VMDK virtual hard disk file. The VMX file identifies the configuration of the virtual machine with respect to the virtual hardware allocated to the virtual machine. Figure 6.24 shows a sample VMX file for a virtual machine named vdcSQL. Reading through the vdcSQL.vmx file, you will notice that the virtual machine uses the following configuration:

♦ A virtual machine named vdcSQL that runs Windows Server 2003 Standard Edition

♦ RAM: 1564 MB

♦ A single hard drive located at vdcSQL-000001.vmdk

♦ A single CD-ROM that starts connected but not mounted to an image

♦ A floppy drive that does not start connected 

♦ A single network adapter configured on the ProductionLAN168 virtual switch and a MAC address of 00:0C:29:9b:1e:b2

Figure 6.22 A new hard disk is the only hardware that can be added to a running virtual machine. CD/DVD-ROMs, floppy drives, and network adapters can be edited but not added. 

Figure 6.23 A virtual machine consists of many files that can be viewed by browsing a datastore using the VI Client. 

While the VMDK file is not human readable, it is arguably the most important file for a virtual machine. You can rebuild a VMX configuration file quite easily, but a VMDK is the data behind the virtual hard drive and is not as easy to rebuild. If you revisit Figure 6.23 and review the files that reside in the folder of a virtual machine's associated files, you will notice the existence of a file that ends with -flat.vmdk. The -flat.vmdk file for a virtual machine is where the actual virtual machine data is stored.

Figure 6.24 A virtual machine's configuration file (VMX) details the virtual hardware available for use by the guest operating system.

Although the -flat.vmdk and the VMDK are the same size, they do not actually both consume the full amount of disk space that is listed. Take, for example, the virtual machine vdcSQL. The virtual machine is configured with a 30GB hard drive. If both the VMDK and the -flat.vmdk files were holding 30GB of data, the total between the two would be 60GB. However, in looking at the total storage capacity and the free space of the datastore where vdcSQL resides, as shown in Figure 6.25, you will notice that the total capacity for the datastore is 62GB and that 7.83GB still remains. Figure 6.26 shows the contents of the storage1 datastore, which identifies the existence of two other virtual machines and a handful of ISO files on the datastore. The file size calculation of the vdcSQL virtual machine, coupled with a look at all of the other data in the datastore, clearly shows that both the VMDK and the -flat.vmdk do not store the full capacity of the space allocated to the virtual machine.

Figure 6.25 The total size of the datastore is 62.5GB with 7.38GB of free space remaining.

Figure 6.26 The storage1 datastore houses three virtual machines and several ISO images. The existence of free space on the storage1 datastore indicates that the -flat.vmdk and VMDK files are not each consuming the total space of the virtual hard drive.

ESX 3.0 introduces a new snapshot feature that's found in the VMware Workstation product. Snapshots provide administrators with the ability to create point-in-time snapshots of a virtual machine. In addition, snapshots are used heavily by the VMware Consolidated Backup product. A snapshot is not a full copy of a virtual machine. VMware's snapshot technology allows for minimal space consumption while still reverting to a previous snapshot.

VMDK File Size Identification

The VMDK file size is misleading if viewed from the VI Client. Consider the virtual machine with a 30GB hard drive. Using the VI Client, it looks as if the virtual machine hard disk file consumes the exact amount that it was configured as. As noted, this is not the case. If you look at the VMDK file using an SSH client connection to the Service Console, the VMDK file is a few bytes in size, which is a more accurate reflection. However, the -flat.vmdk file is 30GB. 

Aligning Virtual Machine File Systems

In Chapter 4 I introduced the concept of aligning the VMFS file system, and I also suggested the virtual machine's file system should be aligned as well. If you construct virtual machines with separate virtual hard drives for operating system and data, then you are most concerned with the alignment of the file system for the data drive because the greatest amount of I/O will occur on that drive. For example, a virtual machine with Disk 0 (that holds the operating system) and a blank disk, Disk 1 (that holds data that will incur significant I/O), should have Disk 1 aligned.

Perform the following steps to align Disk 1 of the virtual machine:

1. Log in to the virtual machine using an account with administrative credentials.

2. Open a command prompt and type Diskpart.

3. Type list disk and press Enter.

4. Type select disk 1 and press Enter.

5. Type create partition primary align = 64 and press Enter.

6. Type assign letter = X, where X is an open letter that can be assigned.

7. Type list part to verify the 64 KB offset for the new partition.

8. Format the partition.

Perhaps you are thinking that this seems like a tedious task to perform for all your virtual machines. It is a tedious task; however, the benefit of doing this is realized most when there is a significant I/O requirement. Also keep in mind that you could also perform this task in the template that is used to provision new virtual machines. 

Figure 6.27 shows the details of a folder named SERVER1 that holds virtual machine files and resides on a datastore named LUN10. LUN10, at this point shows a 99.75GB capacity with 14.88GB of free space.

Figure 6.27 A datastore with all the virtual machine files that exist as a default.

Perform the following steps to create a snapshot of a virtual machine:

1. Use the VI Client to connect to a VirtualCenter or an individual ESX Server host.

2. Right-click on the virtual machine name in the inventory tree, select Snapshot, and then select Take Snapshot.

3. As shown in Figure 6.28 provide a name and description for the snapshot and then click OK.

Figure 6.28 Providing names and descriptions for snapshots is an easy way to manage multiple historical snapshots.

It is a common misconception for administrators to think of snapshots as full copies of virtual machine files. SERVER1 is a new virtual machine that runs Windows Server 2003 Enterprise Edition with the VMware Tools installed. The virtual hard drives have been created as a rather small 2GB hard drive for the operating system and a 2GB hard drive for data. For the purposes of explaining the snapshot technology, these smaller drives will suffice. SERVER1 is configured as follows:

♦ The C: drive maps to the SERVER1. vmdk file with a corresponding SERVER1-flat.vmdk file.

♦ The E: drive maps to the SERVER11.vmdk file with a corresponding SERVER11-flat.vmdk file.

To demonstrate snapshot technology, I took the following steps:

1. I created the virtual machine with a default installation of Windows Server 2003 with two hard drives (C and E) as outlined earlier.

2. I took a snapshot named SNAP1.

3. I added approximately 500MB of data to drive E (SERVER11.vmdk).

4. I took a second snapshot named SNAP2.

5. I once again added approximately 500MB of data to drive E (SERVER11.vmdk).

Review Table 6.1 for the results I recorded after each step.

Despite the storage efficiency that snapshots attempt to maintain, they can over time eat up a considerable amount of disk space. Therefore, you should use them as needed but also remove older snapshots on a regular basis. There are performance ramifications to using snapshots. Virtual machines will perform more slowly and LUNs will become locked each time the snapshot grows. Snapshot files grow in 16 MB increments to minimize the LUN locking that the ESX Server host performs to update the metadata files (.sf files) in order to prevent corruption by other ESX Server hosts (which see a change to the LUN and could want to update the metadata files at the same time).

Table 6.1: Snapshot Demonstration Results

 Post Step1VMFS SizeNTFS SizeNTFS Free Space
 SERVER1.vmdk2GB1.99GB855 MB
SERVER1-flat.vmdk2GB--
SERVER11.vmdk2GB1.99GB1.97GB
SERVER11-flat.vmdk2GB--
Post Step 2 (SNAP1)
 SERVER1.vmdk2GB1.99GB855 MB
SERVER1-flat.vmdk2GB--
SERVER11.vmdk2GB1.99GB1.97GB
SERVER11-flat.vmdk2GB--
Created by SNAP1SERVER1-Snapshot1.vmsn 805 MB--
SERVER1-000001.vmdk16MB--
SERVER1-000001-delta.vmdk16MB--
SERVER11-000001.vmdk16MB--
SERVER11-000001-delta.vmdk16MB--
Post Step 3 (Add 500 MB to Drive E)
 SERVER1.vmdk2GB1.99GB855
SERVER1-flat.vmdk2GB--
SERVER11.vmdk2GB1.99GB1.5GB*
SERVER11-flat.vmdk2GB--
SERVER1-Snapshot1.vmsn800 MB--
SERVER1-000001.vmdk16MB--
SERVER1-000001-delta.vmdk16MB--
SERVER1 1-000001.vmdk512MB*--
SERVER1 1-000001-delta.vmdk512MB*--
Post Step 4 (Snap 2)
 SERVER1.vmdk2GB1.99GB855 MB
SERVER1-flat.vmdk2GB--
SERVER11.vmdk2GB1.99GB1.5GB
SERVER1 1-flat.vmdk2GB--
SERVER1-Snapshot1.vmsn800 MB--
SERVER1-000001.vmdk16MB--
SERVER1-000001-delta.vmdk16MB--
SERVER11-000001.vmdk512MB--
SERVER11-000001-delta.vmdk512MB--
Created by SNAP2SERVER1-Snapshot2.vmsn800 MB--
SERVER1-000002.vmdk16MB--
SERVER1-000002-delta.vmdk16MB--
SERVER11-000002.vmdk16MB--
SERVER11-000002-delta.vmdk16MB--
Post Step 5 (Add Another 500 MB to Drive E)
 SERVER1.vmdk2GB1.99GB855 MB
SERVER1-flat.vmdk2GB--
SERVER11.vmdk2GB1.99GB1.02*
SERVER11-flat.vmdk2GB--
SERVER1-Snapshot1.vmsn800 MB--
SERVER1-000001.vmdk16MB--
SERVER1-000001-delta.vmdk16MB--
SERVER11-000001.vmdk512MB--
SERVER11-000001-delta.vmdk512MB--
SERVER1-Snapshot2.vmsn800 MB--
SERVER1-000002.vmdk16MB--
SERVER1-000002-delta.vmdk16MB--
SERVER1_1-000002.vmdk496 MB*--
SERVER1_1-000002-delta.vmdk496 MB*--

Snapshots are an excellent addition to the feature set of ESX 3.0. You'll find snapshots helpful when making risky changes to production servers (such as renaming the domain or installing service packs). You use the Snapshot Manager to view and delete snapshots or revert to an earlier snapshot.

Perform the following steps to access the Snapshot Manager:

1. Use the VI Client to connect to a VirtualCenter or an individual ESX Server host.

2. In the inventory tree, right-click on the name of the virtual machine to restore a snapshot.

3. Select Snapshot and then click Snapshot Manager.

4. Select the appropriate snapshot to fall back to and then click the Go To button, as shown in Figure 6.29.

Reverting to a Snapshot

Reverting back to a snapshot incurs a loss of data. Any data that was written since the snapshot has occurred will no longer be available, along with any applications that were installed since the snapshot was taken. Therefore, revert to snapshots only if you have determined that the loss of data is acceptable. 

Creating Templates and Deploying Virtual Machines 

If you've ever wished there were a faster way to provision a new server into your environment, then VMware fulfills that wish in a big way. In a VI3 environment, what would traditionally take several hours to do is now reduced to a matter of minutes. With the templates feature of VirtualCenter, you can roll out new virtual machines quickly and easily with limited administrative effort.

Figure 6.29 The Snapshot Manager can revert to original virtual machines, but all data written between now and the last backup will be lost.

VirtualCenter offers two different options for creating templates: Clone to Template and Convert to Template. As the name suggests, the Clone to Template feature copies a virtual machine to a template format, leaving the original virtual machine intact. Similarly, the Convert to Template feature involves a virtual machine that is changed to a template format, thereby removing the ability to turn on the virtual machine without converting back to a virtual machine format.

Virtual machines that become templates should not be critical servers for production environments. The idea behind a template is to have a pristine system configuration that can be customized as needed for deployment to the target environment. Any information stored on a virtual machine that becomes a template will become part of the new system that is deployed from that template. Thus, if a template is updated, all of the virtual machines previously deployed from that template do not experience the same update.

You can convert a virtual machine to a template using the right-click menu of the virtual machine or the Convert to Template link in the Commands list. Figure 6.30 shows two ways an existing virtual machine can be converted into a template format. To make updates to a template, you must first convert the template back to a virtual machine, then update it, and finally convert it back to a template.

The Clone to Template feature provides the same end result as the conversion method in creating a template that can be deployed as a new virtual machine, but it differs from the conversion method in that the virtual machine remains intact. By leaving the virtual machine in a format that can be turned on, the Clone to Template feature facilitates making updates to the template. This means you don't have to store the template object definition in the same datastore from which the virtual machine was built.

Follow these steps to clone a virtual machine into a template format:

1. Use the VI Client to connect to a VirtualCenter server or an individual ESX Server host.

2. Right-click the virtual machine to be used as a template and select the Clone to Template option.

3. Type a name for the new template in the Template Name text box, select a location in the inventory to store the template, and then click Next, as shown in Figure 6.31.

4. Select the host or cluster where the template should be hosted and click Next.

5. Select the datastore where the template should be stored and click Next.

6. Select the disk format for the template, shown in Figure 6.32, and click Next. The Normal template disk format allows for quicker conversion back into a running virtual machine. The Compact template disk format creates a more compact template, which is a benefit when portability is a key requirement.

7. Review the template configuration information and click Finish.

Figure 6.30 A virtual machine can be converted to a template.

A completed template is signified by a different icon than the one used to identify a virtual machine in the VirtualCenter inventory. The template objects are available by clicking on a datacenter object and then selecting the Virtual Machines tab, or by adjusting the inventory view to the Virtual Machines & Templates view.

Once you've created a library of templates, provisioning a new virtual machine is as simple as right-clicking on the template required as the system image baseline. For virtual machines running Windows as the guest operating system, VMware has included a component within the template processes that eliminates the need for administrators to perform tasks that force uniqueness on the virtual machine upon which the template is created. The catch is that the component must extract sysprep and its associated files to a directory on the VirtualCenter server that was created during the installation. If these files are not extracted before you deploy a virtual machine, the guest customization page of the Deploy Template Wizard will be unavailable. Figure 6.33 shows the Guest Customization page of the Deploy Template Wizard on a VirtualCenter that has not had the sysprep files extracted.

Figure 6.31 Templates should have meaningful names that describe the pristine environment provided by the template.

Figure 6.32 Templates can be stored in a format that supports quicker provisioning or that provides greater portability.

Perform these steps to allow guest operating system customization of Windows guest operating system templates:

1. Insert the Windows Server 2003 CD into the disk drive of the VirtualCenter server.

2. Navigate to the ../support/tools/deploy.cab directory on the Windows Server 2003 CD.

Figure 6.33 If the sysprep files are not extracted and stored on the VirtualCenter server, you won't be able to customize the guest operating system when you deploy from a template.

3. Copy the sysprep.exe and setupcl.exe files to this directory:

C:\Documents and Settings\All Users\Application Data\VMware\VMware Virtual Center\svr2003

As shown in Figure 6.34.

Figure 6.34 Customizing the Windows guest operating system requires the extraction of the sysprep.exe and setupcl.exe files to an existing directory on the VirtualCenter server.

Follow these steps to deploy a virtual machine from a template:

1. Use the VI Client to connect to a VirtualCenter server.

2. Locate the template object to be used as the virtual machine baseline.

3. Right-click the template object and select Deploy Virtual Machine from This Template.

4. As shown in Figure 6.35, type a name for the new virtual machine in the Virtual Machine Name text box, select a location in the inventory to store the virtual machine, and then click Next. Click the Advanced button if you want to specify an alternate storage location for virtual machine disk files.

Figure 6.35 The virtual machine's display name is the friendly name reflected in the VirtualCenter inventory and should match the guest operating system's hostname.

5. Select a host on which the virtual machine should run and then click Next.

6. Select a datastore location for the virtual machine files, as shown in Figure 6.36.

Figure 6.36 Select a datastore for a new virtual machine based on the VMotion, DRS, and HA constraints of your organization.

7. For first-time template deployments, as shown in Figure 6.37, select the Customize Using the Customization Wizard option to create a new XML-based answer file, and then click Next.

Figure 6.37 The Guest Customization Wizard allows you to create an answer file that provides zero-touch installs of a guest operating system. The answer file data is stored in the Virtual-Center database.

8. Provide a name and organization to be used for virtual machines built from the customization file.

9. For simplicity and consistency, as shown in Figure 6.37, select the Use the Virtual Machine Name option to specify that the guest operating system hostname be the same as the display name, and then click Next.

10. Enter a valid Windows product key, configure the licensing mode, and click Next.

11. Enter an administrator password and click Next.

12. Enter the appropriate time zone for the new virtual machine and click Next.

13. Enter any commands that should run one time at the end of setup and click Next.

14. Configure the Network Interface Settings for DHCP obtained addressing (Typical) or static addressing (Custom) and then click Next.

15. Specify the workgroup or domain membership of the new guest operating system and click Next.

16. For mass virtual machine deployments, ensure that the Generate New Security ID (SID) checkbox is selected. Select the Delete All User Accounts checkbox as needed to clear the local security accounts manager (SAM) of the new guest operating system to allow for a change to the administrator password. Click Next.

17. As shown in Figure 6.38, ensure the Save This Customization Specification for Later Use checkbox is selected, provide a name for the customization file, enter a description as needed, and then click Next.

Figure 6.38 Customizations can be saved for zero-touch deployments of new guest operating systems.

18. Review the customization information and then click Finish.

19. Review the template deployment information, select the Power On the New Virtual Machine After Creation option as needed, and then click Finish.

Virtual Machine Cloning

While templates might be the most common means of deploying a new virtual machine, it is possible to clone any virtual machine in a powered-off state. The right-click menu of a powered-off virtual machine provides a Clone option that allows you to make a copy without first converting to a template. The Clone to New Virtual Machine option from the Commands list on a virtual machine summary page accomplishes the same task. The wizard that initiates this will provide similar options to the wizard you use when cloning from a template. Keep in mind that unless you customize the guest operating system, an exact copy of the original virtual machine will be made. This could be especially useful when you're looking to create a test environment that mirrors a live production environment. 

The Bottom Line 

While company policy should ultimately drive virtual machine creation, there are best practices that can be followed to ensure performance and ease management. Virtual machines should always start as single virtual CPU systems with a minimum of two hard drives for separating the operating system from the user data.

Install a guest operating system. Installing a guest operating system on a set of virtual machine hardware is similar to an installation on physical hardware and requires the same licensing considerations.

Install the VMware Tools. The VMware Tools provide valuable additions to virtual machines and, although they are not installed by default, they should not be treated as an optional component. The VMware Tools install drivers and features for better memory management, optimized SCSI drivers, and enhanced video and mouse, among other benefits.

Master It Install the VMware Tools into a guest operating system.

Manage and modify a virtual machine. A running virtual machine is limited in its modifications. Only a hard disk can be added to a running virtual machine, but CD/DVD-ROM drives, floppy drives, and network adapters can all be configured while the virtual machine is in a powered-on state.

Master It Add a new network adapter to a virtual machine.

Master It Add a new hard drive to a virtual machine.

Create templates and deploy virtual machines. Templates save administrators a great deal of time when deploying new virtual machines. Not only will templates reduce deployment times, but they also help reduce mistakes for new machines.

Master It Prepare VirtualCenter for guest operating system customizations.