What are the three 3 types of virtual hard disk?

A virtual hard disk (VHD or VHDX) is a file that behaves like a physical hard disk drive when connected to a virtual machine. VHD files are used in virtualization software like Microsoft Hyper-V and VMware to provide virtual machines with virtual hard disks that function just like physical disks.

There are three main types of virtual hard disks that can be created and used with virtual machines:

Dynamic VHD

A dynamic VHD starts small in size and expands as data is added to it. For example, you may create a 50GB dynamic VHD, which would initially occupy only a small amount of physical disk space. As applications and data are added to the VHD, it can grow up to its maximum capacity of 50GB.

The main advantage of a dynamic VHD is efficient use of physical disk space. You don’t have to allocate the full VHD size upfront – it uses only the space it needs. This allows hosting more VMs with larger VHDs than would fit on the available physical disks.

The downside is that dynamic VHDs have slower performance than fixed VHDs. As the VHD expands, the files become fragmented on the physical disk, leading to longer read/write times. Dynamic VHDs are best used for system disks containing the OS, where high performance is not as critical.

When to Use Dynamic VHDs

  • When you want to minimize upfront disk space usage
  • For system/boot VHDs that do not require high disk performance
  • When the final disk space needed is unknown or likely to change

Fixed VHD

A fixed VHD allocates all its storage space at creation time. For example, a 100GB fixed VHD will occupy 100GB of physical disk space immediately. The VHD file size does not change even if the actual data written to it is only a fraction of the total capacity.

The main advantage of fixed VHDs is performance – read/write times to a fixed VHD are excellent because the files are contiguous on the physical disks. The drawback is wasted storage space since the full VHD size is allocated even if only a portion is used.

Fixed VHDs are best suited for data VHDs where high performance is critical, like database data files or server applicaton data. The high perfomance outweighs the larger storage footprint.

When to Use Fixed VHDs

  • When maximum disk performance is needed
  • For data VHDs like databases, web/file servers where fragmentation impacts perf
  • When the full storage footprint is already known

Differencing VHD

A differencing VHD acts as an overlay on top of a parent VHD, storing only the changes made to the parent. This allows multiple VMs to use one common parent VHD file with their own differencing disks to hold their individual data.

For example, a parent VHD may contain a standard OS and application image that is common across multiple VMs. Then each VM uses its own differencing VHD to store any user customizations, app data etc. The differencing VHDs only hold the changes from the parent image.

This saves storage space since the common parent image is shared between VMs rather than each having their own full copy. It also simplifies deploying updates – updating the parent VHD automatically updates all VMs using it. Differencing VHDs provide large storage optimization for similar VM workloads.

When to Use Differencing VHDs

  • When you want to deploy multiple VMs from a common image
  • To optimize storage usage with a common base image
  • When VM images need to be patched/updated frequently

Comparing the 3 Types of VHDs

Here is a summary of the key differences between dynamic, fixed, and differencing VHDs:

VHD Type Allocation Performance Storage Efficiency Use Cases
Dynamic Allocates storage on-demand as VHD file grows Poor due to fragmentation Excellent, uses only space needed OS/system disks where perf matters less
Fixed Preallocates all storage at creation time Excellent, no fragmentation Poor, unused space is wasted Data disks where high perf matters
Differencing Overlays a parent VHD and stores changes Similar to parent VHD Excellent, leverages common parent VMs with common base image

Dynamic VHD Operations

Here are some of the key operations related to dynamic VHDs:

  • Creation – Specify size (e.g. 100GB) when creating dynamic VHD. Only a small amount of space is initially used on host machine.
  • Expansion – As data is added, the VHD file grows dynamically to max capacity. Free space on host disk required.
  • Contraction – If data is removed and free space increases inside VHD, the VHD file can shrink down if compacted.
  • Snapshotting – Snapshots freeze the state of a dynamic VHD. Useful for backups.
  • Storage Migration – Dynamic VHDs can be moved to new storage locations, although may impact performance.

Overall, dynamic VHDs provide flexible, thin-provisioned virtual disks to VMs at the cost of reduced performance.

Fixed VHD Operations

Here are some key operations related to fixed VHDs:

  • Creation – Full VHD capacity is allocated immediately when created.
  • Expansion – To increase size, VHD must be converted to dynamic type first.
  • Contraction – If data is removed, free space remains unused. VHD fixed size does not shrink.
  • Snapshotting – Snapshots are instant since layout never changes.
  • Storage Migration – Can be moved to new storage, but requires sufficient free space for full VHD size.

Overall, fixed VHDs deliver high performance at the cost of less flexibility and storage efficiency compared to dynamic VHDs.

Differencing VHD Operations

Here are some key operations related to differencing VHDs:

  • Creation – Created by pointing to an existing “parent” VHD containing a common image.
  • Expansion – Grows dynamically as changes are made to the parent VHD.
  • Merge – Can merge changes back to parent VHD to consolidate images.
  • Reconnect – Can be reconnected to a different parent VHD as needed.
  • Orphan – If parent is lost, differencing VHD becomes an independent fixed VHD.

Overall, differencing VHDs optimize storage usage for multiple related VMs with a common base image.

VHD Performance Optimization

There are several ways to optimize VHD performance regardless of type:

  • Defragment VHDs periodically to improve read/write times
  • Align VHD partitions to underlying physical disks
  • Use SSD or high speed storage for most active VHDs
  • Distribute VHDs across multiple physical disks if possible
  • Set appropriate caching mode on VHD files (cache reads, avoid caching writes)

Optimizing performance is most critical for fixed and dynamic VHDs where fragmentation can be an issue over time. For differencing disks, the parent VHD optimization is most important.

VHD Storage Optimization

There are also several ways to optimize VHD storage usage:

  • Use dynamic VHDs for OS/system disks to use only needed space
  • Use differencing VHDs where multiple VMs share common data
  • Compact dynamic VHDs periodically to recover unused space
  • Evaluate if VHD sizes can be reduced based on actual usage
  • Convert idle fixed VHDs to dynamic type to reclaim unused space

The most impactful optimization is using differencing VHDs where possible to avoid redundant copies of common parent images.

VHD Management Best Practices

Some best practices for effectively managing VHDs include:

  • Use fixed VHDs for high performance data disks; Dynamic for flexibility
  • Leverage differencing disks to optimize multiple VMs with common images
  • Monitor disk usage within VMs to right-size VHD capacities
  • Schedule regular compaction of dynamic VHDs to reclaim unused space
  • Defragment VHDs periodically to maintain contiguous layouts
  • Test backup/recovery processes regularly by restoring VHDs

Following structured VHD management practices maximizes performance, efficiency, and recoverability for virtualized workloads.

Conclusion

In summary, the three main types of virtual hard disks are:

  • Dynamic VHD – Grows on-demand, efficient use of storage but lower performance
  • Fixed VHD – Preallocates full capacity, highest performance but less efficient
  • Differencing VHD – Overlays parent image, optimized storage for similar VMs

Each type has its advantages and use cases. Combining dynamic, fixed, and differencing VHDs together provides a balance of high performance, storage efficiency, and flexible management for virtualized environments.