Introduction
VHDX is the virtual hard disk format of Microsoft’s Hyper-V, introduced with Windows Server 2012 and Windows 8 as the successor to VHD. A VHDX disk can be up to 64 TB, against about 2 TB for VHD, and it keeps a log of changes to its own tables so that a power failure does not corrupt it.
Windows can attach a VHDX file as an ordinary drive, and can even start from one. Microsoft publishes the specification as MS-VHDX.
Structure
The file is divided into regions aligned to 1 MB. It starts with a 64 KB file type
identifier, which begins with the signature vhdxfile and the name of the
program that made it. Two copies of the header follow, at 64 KB and 128 KB, each starting
head and carrying a sequence number, so that the newer valid copy wins. Two
copies of the region table, at 192 KB and 256 KB, start regi and give the
position of the block allocation table and of the metadata region (see
header section).
The metadata region holds the disk’s settings: its virtual size, block size, sector sizes and, for a differencing disk, the location of the parent. The block allocation table (BAT) maps each block of the virtual disk, between 1 MB and 256 MB in size, to its place in the file. The log records changes to these structures before they are made.
0File type identifiervhdxfileand the creator’s name64 KB0x10000Header 1head, sequence number, log position64 KB0x20000Header 2 the second copy64 KB0x30000Region table 1regi, where the BAT and metadata are64 KB0x40000Region table 2 the second copy64 KB…Log, BAT, metadata and data blocksvaries
In the explorer
Drop a .vhdx file on this site. The structure tree shows the file type identifier (signature and
creator), both headers (every field, the CRC-32C checked, the current one marked), both region tables (every
entry, the checksum checked), the metadata region (the table, the system items decoded: block size, disk size,
disk ID, logical and physical sector size, and the parent locator with its keys and values), the block
allocation table (every entry as a node for the first 200, all in a table: payload block or sector bitmap
state, and where the block is) and the log (every entry with its descriptors and data sectors, checksums and
GUIDs checked, and the active sequence found). When the log is not empty the active sequence is
replayed in memory, never written: the metadata, the block
allocation table and the disk are read from the replayed state, and the Log replay section and the Replayed
changes table list every descriptor, the file offset it writes, what lies there and how many bytes it changes.
The payload blocks, the virtual disk’s own data, are not drawn in the tree because a disk can be terabytes;
instead the disk is offered as a file of its own (name.img, in the Virtual disk table), made on demand from the
blocks the block allocation table maps, so the partition and file system viewers can open it. The Block
allocation table says for every payload block what it reads as: this file, zeros (zero, unmapped or undefined
blocks; the Blocks not present option at the top of the viewer can read them from their stored offset
instead, see the block allocation table page), or the parent. The
open-time checks also name two entries that share a file offset, blocks that overlap each other, a region or the log,
blocks that run past the end of the file, reserved fields that are not zero, and the version rules. A differencing disk’s parent is another file: drop it together with the child (select both files, or drop their folder) and
the viewer finds it by the paths in the parent locator, then by file name, checks that its data write GUID is the one the child
names, and reads the blocks and sectors the child leaves to the parent from it (a parent that is itself differencing
is followed up the chain). Without the parent those blocks and sectors read as zeros and are marked “parent unavailable”.
Only the structures are read, each from where the file says it is, so a very large file opens at once. Damaged
or missing structures are reported and the rest is still shown.
Not described
Written against [MS-VHDX] revision 8.0 as the pages on this site follow it, and checked against QEMU’s
block/vhdx.c and vhdx-log.c. It opens files written by Windows (a dynamic disk written by Windows 6.2),
by Disk2vhd (test-disk2vhd.vhdx, whose first sector reads back as the disk’s master boot record) and QEMU’s test image with
a dirty log (iotest-dirtylog-10G-4M.vhdx), which opens and replays correctly, and files built from these pages. The viewer scans the whole
log in windows (a log of any size, up to the 4 GiB the format allows), finds the active sequence by the seven steps of
[MS-VHDX] 2.3.3, lists every entry (the tree opens in groups of 500 entries; the Log entries and Replayed changes tables
page through all of them) and replays in full without holding the log in memory. Only a damaged size (a block size outside 1 to 256 MiB,
a metadata item over 1 MiB, a replayed file over 1 PiB, damaged log entries that add up to over 2 GiB of reading) is reported as a problem
instead of being read.
Also checked against 7-Zip’s VhdxHandler.cpp and Fox-IT’s dissect.hypervisor. Nothing in the
format is left unread, unchecked or undescribed.
Links
Software
- Hyper-V – Microsoft’s virtualisation, built into Windows and Windows Server (Windows)
- Windows Disk Management – creates VHDX files and attaches them as drives (Windows)
- QEMU and qemu-img – run and convert VHDX files (Windows, macOS, Linux)
Developers
- libguestfs – library and tools for reading and changing the files inside disk images (C)
Reference
- [MS-VHDX]: Virtual Hard Disk v2 (VHDX) File Format – Microsoft’s specification, with PDF downloads