January 2007 - Posts

 

VHD compaction is a process that reduces the size of a virtual hard disk file on the physical disk. Virtual Server 2005 R2 SP1 comes with a compaction tool that only achieves minor reductions in virtual hard disk file size, if used by itself. A three-step process that includes defragmentation, precompaction, and compaction will provide better results. The defragmentation and precompaction prepare the virtual hard disk file for the compaction process, resulting in greater reductions in virtual hard disk file size.

VHD compaction can only be performed on dynamically expanding disks. Fixed size virtual hard disks have to be converted to a dynamically expanding disk prior to being compacted. Special dynamically expanding virtual hard disks, like differencing or undo disks, cannot be directly compacted. Differencing disks and undo disk changes must be merged into their parent disk, and the parent disk can be compacted, if it is a dynamically expanding disk.

Because of processor and disk resource requirements, use a non-production server, when possible, to perform the virtual hard disk compaction process. In Virtual Server 2005 R2 SP1, you can perform the defragmentation step within the virtual machine or offline. However, unless you have a good reason, perform defragmentation, precompaction and compaction with the virtual hard disk file offline.

Step 1: Defragmenting the Virtual Hard Disk File

The first step in the process to reduce the size of a virtual hard disk file is defragmentation. As new information is written to disk, data can be saved in non-contiguous disk blocks. In time, as you delete data on the disk, empty blocks will be randomly filled with file fragments. Performance is adversely affected when disk fragmentation is excessive since it takes longer to retrieve data spread across a disk than if it were located in contiguous disk blocks. Defragmentation reduces or eliminates the number of fragmented files on a disk, resulting in larger areas of empty contiguous blocks.

In order to defragment a virtual hard disk offline, you can use the new VHDMount command-line tool to mount the virtual hard disk file. Once the virtual hard disk file is mounted, use the Windows Defrag utility (or your favorite defragmentation tool) to defragment the virtual hard disk file. The time required to defragment the virtual hard disk file will depend on several factors, including the degree of fragmentation, file size, and disk characteristics.

Step 2: Precompacting the Virtual Hard Disk File

The second step in the process is precompaction. Virtual Server 2005 R2 SP1 includes a Virtual Disk Precompactor tool that is designed to write zeros in empty disk blocks of a virtual hard disk file. This step is crucial to ensure that the compaction tool can make the virtual hard disk file as small as possible.

The Virtual Disk Precompactor tool is contained in the Precompact.iso disk image located in the %systemdrive%\Program Files\Microsoft Virtual Server\Virtual Machine Additions folder. Use your favorite virtual CD tool, to mount the precompact.iso image on your Virtual Server 2005 R2 SP1 host and retrieve the precompact.exe tool.

Virtual Disk Precompactor Command Line Options

-Help

  • Displays the help dialog box that lists the command line options, product version, and syntax examples.

-Version

  • Displays the help dialog box that lists the command line options, product version, and syntax examples.

-Silent

  • Executes the precompactor in unattended mode and suppresses all dialog boxes.

-SetDisks:<list>

  • <list> is an optional parameter that represents one or more drive letters. Defines the list of virtual hard disks to precompact. If this option is not specified, all virtual hard disks attached to a virtual machine are compacted.

Below is an example of using precompact.exe to precompact virtual hard disks mounted to drive letters F and G, in unattended mode:

  • Precompact –Silent –SetDisks:FG

If you want to precompact virtual hard disk files from within a virtual machine, once you capture the precompact.iso to the virtual machine CD or DVD drive, you can double-click on the drive to launch the Virtual Disk Precompactor. However, you can not specify which virtual hard disks to precompact. Instead, the precompaction tool will precompact all virtual hard disks attached to the virtual machine.

Step 3: Compacting the Virtual Hard Disk File

The third and final step in the process is virtual hard disk compaction. After running the Virtual Disk Precompactor tool, empty disk blocks in the virtual hard disk file contain zeros. The Virtual Server compaction process will find the disk blocks that contain zeros and remove them, reducing the virtual hard disk file size.

The Virtual Server compaction tool requires that you have enough disk space to concurrently store the original virtual hard disk file and an additional temporary file that contains the compacted virtual hard disk. The original virtual hard disk file will be deleted at the end of the compaction process and replaced with the compacted virtual hard disk file. If the disk runs out of space before completing the compaction process, an event will be recorded in the Virtual Server event log.

To use the Virtual Server compaction tool, follow these steps:

1. Open the Virtual Server 2005 R2 SP1 Administration Website.

2. Turn off the virtual machine associated with the dynamically expanding virtual hard disk that you want to compact.

3. In the navigation pane, under Virtual Disks, click Inspect.

4. In Known Virtual Hard Disks, select the virtual hard disk to compact. If the virtual hard disk file does not appear in the list, type the fully qualified path to the virtual hard disk in Fully Qualified Path To File.

5. Click Inspect.

6. Under Actions, click Compact Virtual Hard Disk.

7. In Compact Virtual Hard Disk, click Compact.

The VHD compaction process can also be scripted using the Virtual Server 2005 R2 COM API. This allows you to compact the virtual hard disk files outside of the Virtual Server Administration Website.

 

Share this article in del.icio.us | Digg | reddit

The Virtual Server 2005 R2 network architecture was designed to allow default isolation of virtual machine network traffic from other virtual machines, the Virtual Server host, and external networks. However, using the Microsoft Loopback Adapter, you can configure virtual machines to be connected to each other, the Virtual Server host, corporate networks, or the Internet. 

Using the Microsoft Loopback Adapter

The Microsoft Loopback Adapter is a built-in, software-based network interface. When you use it, network traffic between connected virtual machines and the Virtual Server host is constrained to the internal virtual network, remaining isolated from external, physical networks.

Installing the Microsoft Loopback Adaptor

Here are the steps to install the Microsoft Loopback Adaptor on Windows Server 2003 R2:

  1. On the Virtual Server host, click Start, and then click Control Panel.
  2. In the Control Panel, click Add Hardware, then click Next.
  3. In the Is The Hardware Connected dialog box, click Yes (I have already connected the hardware), and then click Next.
  4. In the Installed hardware list, click Add a new hardware device, and then click Next.
  5. In the What Do You Want The Wizard To Do check list, click Install the hardware that I manually select from a list (Advanced), and then click Next.
  6. In the Common Hardware Types list, click Network adapters, and then click Next.
  7. In the Manufacturer list, click Microsoft.
  8. In the Network Adapter list, click Microsoft Loopback Adapter, then click Next.
  9. In the Hardware To Install dialog box, click Next.
  10. In the Completing the Add Hardware Wizard dialog box, click Finish.

You must be a member of the administrators group in order to install a new network adapter in the host operating system.

Configuring the Microsoft Loopback Adaptor

The Microsoft Loopback Adaptor must be bound to Virtual Machine Network Services to allow communications through a virtual network. Follow these steps to configure the Microsoft Loopback Adaptor bindings on the Virtual Server 2005 R2 host:

  1. On the Virtual Server 2005 R2 host, click on Start and select Control Panel.
  2. Select Network Connections, right-click the local area connection associated with the Microsoft Loopback Adapter, and then select Properties.
  3. In This connection uses the following items, ensure that the Virtual Machine Network Services check box is selected.
  4. Click Internet Protocol (TCP/IP), and then click Properties.
  5. On the General tab, click Use The Following IP Address, and then type the IP address and subnet mask, but do not enter a gateway address.
  6. Click OK, and then click Close.
Creating a Virtual Network and Connecting Virtual Machines to the Host

After the Microsoft Loopback Adapter has been installed and configured on the Virtual Server host, you can create a new virtual network and connect the virtual machines.

  1. Open the Virtual Server 2005 R2 Administration Website.
  2. In the navigation pane, under Virtual Networks, click Create.
  3. In Virtual network name, type a name for the virtual network.
  4. In Network adapter on physical computer, select the Microsoft Loopback Adapter.
  5. In Disconnected virtual network adapters, select the Connected check box for any virtual machine network adapter that you want to attach to the new virtual network.
  6. In Virtual network notes, type in a description for the new virtual network, then click OK.

You can now boot the virtual machines, configure the network address for the new local connection, and configure firewall settings to enable resource sharing, as required.

Make sure to use non-routable TCP/IP addresses when you configure the Microsoft Loopback Adaptor network address properties. The network address and network mask must match between the Virtual Server host and the virtual machines.

Enabling Virtual DHCP Server on a Virtual Network

If you intend to connect several virtual machines, you can configure the Virtual DHCP Server option on the virtual network to manage and supply network configuration options to connecting virtual machines.

  1. Open the Virtual Server 2005 R2 Administration Website.
  2. In the navigation pane, under Virtual Networks, select Configure and then click the appropriate virtual network.
  3. In Virtual Network Properties, click DHCP server.
  4. Click in the Enabled check box and configure the DHCP server options as needed
  5. Click OK.


Share this article in del.icio.us | Digg | reddit