.VHD
Virtual Hard Disk
Introduction
VHD is a file that acts as the hard disk of a virtual machine. It was created by Connectix for Virtual PC, which Microsoft bought in 2003, and Microsoft later published the specification. VHD files are used by Hyper-V and Azure, and Windows can attach one as an ordinary drive.
A VHD can be at most about 2 TB. Its successor, VHDX, lifts that limit and is more resilient to power failures, but VHD remains widely supported.
Software
- Hyper-V, built into Windows and Windows Server
- Windows Disk Management, which attaches VHD files as drives
- VirtualBox (Windows, macOS, Linux)
- QEMU and qemu-img, which run and convert VHD files (Windows, macOS, Linux)
- 7-Zip, which opens VHD files like an archive (Windows)
Structure
Every VHD ends with a 512-byte footer that starts with the cookie
conectix. Its fields are big-endian and include the creator application,
the size of the disk, its geometry, a checksum, a unique ID and the disk type: 2 for a
fixed disk, 3 for a dynamic disk and 4 for a differencing disk.
A fixed disk is simple: the raw contents of the disk, sector by sector, followed by the
footer. A dynamic disk only stores the parts that have been written. It starts with a copy
of the footer, then a 1024-byte dynamic disk header beginning cxsparse, then
a block allocation table that maps each block of the disk, 2 MB by default, to its place
in the file. Each stored block begins with a bitmap of which sectors in it hold data. A
differencing disk has the same layout and records only the changes from a parent disk.
0Footer copy cookieconectix, sizes, disk type512 bytes512Dynamic disk header cookiecxsparse, table offset, block size1,024 bytes1536Block allocation table one entry per block of the diskvaries…Data blocks each a sector bitmap then the block’s sectorsrepeatedendFooter the last 512 bytes of the file512 bytes