A virtual hard disk (VHD) is a disk image file format for storing the entire contents of a computer’s hard drive. The disk image, sometimes called a virtual machine (VM), replicates an existing drive, including all data and structural elements. It can be stored in any location accessible to the physical host, and it is also transportable, meaning it can be stored and moved with a USB flash memory device.
What does a virtual hard disk do?
A virtual hard disk is not the same as a virtual hard drive. In fact, a VHD represents a virtual hard drive. It is a disk image file format that mimics the functionality of a physical hard drive, so users can store data on the virtual drive just as they would on the physical drive.
VHDs play an important role in virtualization environments. To create a VM, a logical disk must be associated with a VM. To do that, the image of a virtual hard disk must be created. This image is the VHD. When a VHD is created and made available to the system, the contents of a computer’s drive can be virtualized to create a VM with its own operating system (OS), applications and data.
What is a virtual hard disk used for?
The VHD image file format is mainly used to virtualize a computer’s hard drive, i.e., to create VMs. The image lives as a file on the host OS in one of four configurations:
- Fixed hard disk image.
- Dynamic hard disk image.
- Differencing hard disk image.
- Pass-through hard disk image.
Regardless of its type, a VHD is used to easily create preconfigured VMs and to simplify data backup and restoration. Differencing VHDs can also be used to set up multiuser isolation and to ensure that OS instances remain unaffected even if one instance happens to crash.
The VHD format is a standard format for Microsoft’s virtualization products, including the Hyper-V hypervisor. Since Windows 2012, the default VHD format for Microsoft Hyper-V is VHDX. Sharing a VHDX file provides shared storage for a Hyper-V guest failover cluster. The shared VHD must use the .vhdx file format for the data drive.
It is important to note that, while it is called a virtual hard drive, a VHD can be created using solid-state storage resources.
Virtual hard disk vs. physical hard disk: Similarities and differences
A virtual hard disk has similar functionality to a physical hard disk drive. For example, it often contains the same hard drive sectors, such as a file system, disk partitions, etc. It also appears and operates like a hard disk that’s physically connected to the system. As with a hard disk, you can do the following with a VHD:
- Create disk sectors, files and folders.
- Run an OS.
- Execute user applications.
What differentiates a VHD from a physical hard disk is that it is designed for use by VMs and is installed on a VM infrastructure, such as VMware Workstation or Microsoft Hyper-V VMs.
While a VHD is created on a physical drive, it is a virtualized file and has its own logical distribution. Its size can be fixed or flexible. This size is managed by the OS or virtualization manager. The OS communicates with the device drivers to access the VHD.
Types of virtual hard disk
As noted, the main types of VHD formats are fixed, dynamic, differencing and pass-through.
Fixed virtual hard disk
In this VHD format, the VHD consumes a fixed amount of space on the host machine drive. In effect, it mirrors the size of the virtual disk. There is no block allocation table, so any extra input/output load only occurs within the virtualization stack. Fixed VHDs support fast processing speeds and a constant fragmentation level as at the time of its creation. Also, the potential for overcommitment collisions is almost nonexistent.
Dynamic virtual hard disk
Dynamic or expandable VHDs with varying disk sizes can also be created. With dynamic VHDs, the storage space starts at a particular minimum size and grows as data is added to the VHD until it reaches a predetermined maximum size. The main advantage of dynamic VHDs is high-speed storage space allocation. Also, the VHD file can be created quickly due to its small size. The size also speeds up backup and reduces the backup data size. Two key drawbacks of dynamic VHDs are the higher potential for VHD fragmentation and slower processing speeds.
Differencing virtual hard disk
A differencing VHD is used to create a copy (clone) of an existing disk. Two VHDs are used: a parent and a child. With a differencing VHD, it is possible to make changes to a parent VHD without altering that disk.
Pass-through virtual hard disk
A pass-through VHD is linked to a physical hard drive. The term mainly refers to a physical disk used as a storage source in a single, dual or mirrored virtual disk. One of the main uses of a pass-through VHD is to migrate data from one storage architecture to another with minimal disruptions, while maintaining access to the current disk.
Benefits of a virtual hard disk
There are numerous benefits when using a VHD, including the following:
- Easy deployment. A VHD has provisions for prebuilt and standard configurations in the VHD files for working on specific OS environments, simplifying deployment.
- Efficient backup and restore. If VHD data is accidentally deleted or affected by a malicious file injection, it can be recovered.
- Snapshot recovery. A snapshot of an existing VHD configuration can be recovered, enabling a user to revert to a previous state if there are installation problems and troubleshooting isn’t successful.
- Swift replication. The work or file in one system can be replicated to another system. This is especially useful for developers who collaborate.
- Isolation for users. Users can work on their chosen OS without interference from other users.
- Cost-effectiveness. VHD technology eliminates the need for multiple hardware components and OSes, reducing the cost of storage and deployment.
Process to create a virtual hard disk in Windows
In Windows OSes — 8.1, 10, 11, Server 2016, Server 2012 R2 and Server 2012 — VHDs appear like physical disks in the Disk Management utility. When a VHD is attached, it appears blue. If it is detached, the icon turns gray.
Steps to create a VHD
Admin access is required to do the following by selecting Computer Management and then Disk Management:
- From the Action menu of Disk Management, select Create VHD.
- The Create and Attach Virtual Hard Disk dialog box opens.
- Specify the location on the physical computer where the VHD file will be stored.
- In the File name field, enter a name for the drive.
- Specify the size of the VHD in the Virtual hard disk size field.
- Under the Virtual hard disk type section, select Fixed size or Dynamically expanding.
- Click OK.
Steps to attach a VHD
Attaching the VHD makes it available for use:
- From the Action menu of the Disk Management utility, select Attach VHD.
- When the Attach Virtual Hard Disk dialog box opens, select the VHD (.vhd) file.
- Click OK.
Steps to detach a VHD
Detaching a VHD makes it unavailable to applications and users, but it doesn’t delete the VHD:
- In the Disk Management utility, right-click on the VHD.
- Select Detach VHD.
- Click OK.
VHD vs. VHDX file formats
The VHD file format was originally introduced with Connectix Virtual PC and was eventually adopted by Microsoft Hyper-V. It works with many versions of Microsoft’s Windows OSes.
VHDX is functionally equivalent to VHD. However, it is an advanced version of VHD that supports larger storage capacity, larger logical sectors and live disk resizing. VHDX also provides the following advantages over VHD:
- Metadata updates tracking.
- Data protection against power failures.
- More adaptability to newer hardware.
- Support for custom metadata.
Both VHD and VHDX disk images are prone to file system corruption, which could result from corrupted hard disk storage, suboptimal network conditions during file transfers or interference from antivirus programs. If a VHD or VHDX file is corrupted, a recovery tool can help recover some or all data.
Virtualization functions by separating physical hardware and devices from the applications operating on that hardware. Learn the difference between Type 1 vs. Type 2 hypervisors and their specific use cases. Explore the key differences between containers vs. VMs, and see what to know for your virtualized storage selection process. Become familiar with storage virtualization software options, and check out virtual server management best practices.