Virtual Hard Disk (VHD) Architecture explained

A virtual hard disk (VHD) is a file that encapsulates a hard disk image. VHDs can be used in new and interesting ways. VHDs first were created to be the storage media for virtual machines (VMs). Today, VHDs are used to ship trial versions of software, used in backup solutions, used for bug triage (e.g. customers can convert a physical disk to virtual and share it), and even used to store multiple boot environments. VHDs are a very flexible storage container and are not tied to any single file system format. Since June 2005, Microsoft has made the VHD Image Format Specification available to third parties under the Microsoft Open Specification Promise (OSP).

Microsoft began using VHD technology in Microsoft Virtual PC around 2003, and then continued its use in Microsoft Virtual Server release in 2005. The next major release happened as part of Hyper-V in Windows Server 2008. Currently VHD support is made as part of Windows Server 2008 R2 and high-end client SKUs of Windows 7. VHDs were limited to use by virtual machines running in Virtual PC/Virtual Server/Hyper-V and loopback mounting of VHDs in the parent partition sometimes referred to as the management operating system. The integration of VHD support into the operating system was drastically improved in Windows Server 2008 R2 which added native support. Native support means the technology is integrated into the operating system and no longer requires a virtualization solution such as Hyper-V to be available. Native support added the following features:

  1. Boot from VHD
  2. Integrated support for attaching and detaching VHDs via inbox APIs (virtdisk.dll) and the “Disk Management” control panel (diskmgmt.msc or command line tool DiskPart (“attaching” is the term used to describe the action of mounting a VHD so it can be used by Windows directly, or as a disk in the guest operating system of a virtual machine).
  3. Attaching VHDs from inside VHDs, and many performance improvements.

There are three VHD formats each with different performance characteristics. The three formats of VHD are fixed, dynamic and differencing.

image

A fixed sized VHD uses a file in which the space to store the file is allocated on the physical storage when the virtual hard disk is created. The file size is the same as the size specified for the virtual hard disk. As their name implies, fixed sized VHDs occupy the same space on the underlying physical storage device as their specified size. However, once a fixed sized VHD is created, the size can be increased when the disk is offline by editing the disk to expand it. Reducing the size is not supported. Because the physical storage required for a fixed size VHD is allocated when the VHD is created, there is a better chance at optimal placement and organization on-disk which yields the best performance. The disadvantage is the space is committed even if it is not used.

image

A dynamically expanding VHD is a file that at any given time is as large as the actual data written to it plus the size of on-disk meta-data. Dynamically expanding disks are useful because they do not require all the storage needed to contain the maximum size of the disk to be reserved up front. The VHD file starts quite small (e.g. 42KB is a typical physical size of an empty 20GB disk) and grows as new blocks in the disk are used. There are a number of optimizations around dynamically expanding disks that improve performance; however, in general their read/write performance is slower than fixed disks. One optimization is the selection of data block size which can be either 512KB or 2MB; another is skipping allocation of all-zero blocks.

image

A differencing VHD is a file representing the current state of the virtual hard disk as a set of modified blocks in comparison to a parent virtual hard disk. Differencing VHDs can be associated with either a fixed sized or dynamically expanding VHD. Differencing VHDs can also be associated with another differencing VHD but they cannot be associated with a physical disk. Differencing VHDs are used to prevent changes from being made in their parent VHD to which they are applied and are used to implement a number of additional features. In Hyper-V, differencing VHDs are also created automatically whenever snapshots are taken of a virtual machine. Note differencing VHDs used for snapshot purpose are named with an AVHD file extension to help users easily distinguish them from regular differencing VHDs. Differencing VHDs may also be used to deploy a “golden” or “master” image, because you can associate multiple differencing VHDs to one parent VHD. Some disadvantages of differencing VHDs are increased caching needs and the inability to grow or shrink the VHD size. You can however compact differencing VHDs to reclaim physical space usage.

There are several important limitations for VHDs:

  1. VHDs can be mounted only on NTFS volumes (although you can still save a VHD file on FAT/FAT32 assuming the maximum file size limit is not violated). For example, if you have a differencing VHD chain, then every VHD along the chain must sit on an NTFS volume to make VHD attaching work.
  2. VHDs cannot be mounted within a compressed folder in Windows Server 2008 R2. This was possible in Hyper-V role in Windows Server 2008, but this capability was explicitly blocked in the Hyper-V role in Windows Server 2008 R2 since the compressed file size limit is relatively small. A dynamically expandable VHD can easily outgrow that limit and get corrupted.
  3. In addition to the maximum file size of NTFS, dynamic or difference VHDs cannot exceed 2040GB. The reason for the 2040G limit is the length of each Block Allocation Table entry is set to 4 Bytes and the maximum valid value is 0xFFFFFFFE (0xFFFFFFFF means an unused entry). If you multiply that value by 512B sector size and then subtract the overhead of on disk meta-data structures, 2040G will be the maximum size of dynamically or differencing VHDs.

 

 

Technorati Tags: VHD,Windows 7,Windows Server 2008 R2,performance,disk