The first megabyte of a VHDX file is the header section: five 64 KiB blocks, then
reserved space. This page follows Microsoft’s specification, [MS-VHDX]: Virtual Hard
Disk v2 (VHDX) File Format, revision 8.0 (April 2024), section 2.2. All numbers
are little-endian, and checksums are CRC-32C (Castagnoli polynomial
0x1EDC6F41). The specification stores GUIDs “in their binary form”;
QEMU’s VHDX driver reads them as Microsoft’s GUID structure (a 32-bit and two
16-bit little-endian numbers, then 8 bytes as written), which is how the example below
is laid out.
Layout
0x00000File type identifiervhdxfileand the creator64 KiB0x10000Header 164 KiB0x20000Header 264 KiB0x30000Region table 164 KiB0x40000Region table 264 KiB0x50000Reserved704 KiB
File type identifier
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 8 | text | Signature | vhdxfile (76 68 64 78 66 69 6C 65). |
8 | 512 | UTF-16 | Creator | Optional; identifies the program that made the file, and may be zero-terminated. For diagnosis only: programs must not change their behaviour because of it. |
520 | rest | – | Reserved | To the end of the 64 KiB block. Nothing in the first 64 KiB is rewritten after the file is created. |
Headers
There are two 4 KiB headers, at 64 KiB and 128 KiB, so that one is always intact while the other is being updated. A header is valid when its signature and checksum are right; the current header is the only valid one, or the valid one with the higher sequence number. With no current header the file is corrupt. A writer updates the out-of-date header (sequence number plus one, new checksum), flushes, and should then update the other too.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 4 | text | Signature | head. |
4 | 4 | uint32 | Checksum | CRC-32C (Castagnoli polynomial) of the first 4 KiB of the block, computed with this field as 0. |
8 | 8 | uint64 | Sequence number | Raised with each update; the higher valid header is current. |
16 | 16 | GUID | File write GUID | Changed to a new value on each open, before the first change of any kind to the file (metadata or log replay); may be left alone on read-only media. |
32 | 16 | GUID | Data write GUID | Changed before the first change a reader of the virtual disk could see: metadata, block data, disk size or block states. Moving blocks within the file does not change it. A differencing child records its parent’s data write GUID (see parent locator). |
48 | 16 | GUID | Log GUID | All zero: the log is empty and must not be replayed. Otherwise, only log entries carrying this GUID are valid. |
64 | 2 | uint16 | Log version | 0. Otherwise the file must not be processed, unless the log GUID is zero. |
66 | 2 | uint16 | Version | 1. Otherwise this specification does not apply. |
68 | 4 | uint32 | Log length | Bytes of log, a multiple of 1 MiB. |
72 | 8 | uint64 | Log offset | Where the log is, a multiple of 1 MiB; it must not overlap anything else. |
80 | 4016 | – | Reserved | Zeros, to the end of the 4 KiB checksum area. |
Region tables
Two identical copies. A region table lists the big structures in the file and where they are.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 4 | text | Signature | regi. |
4 | 4 | uint32 | Checksum | CRC-32C of the whole 64 KiB table, computed with this field as 0. |
8 | 4 | uint32 | Entry count | At most 2,047. |
12 | 4 | – | Reserved | 0. |
16 | 32 each | entries | Entries | See below. |
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
0 | 16 | GUID | Region GUID | What the region is; see below. |
16 | 8 | uint64 | File offset | Where it starts, a multiple of 1 MiB, at least 1 MiB. |
24 | 4 | uint32 | Length | Its size, a multiple of 1 MiB. |
28 | 4 | bits | Required | 1: a reader that does not recognise this region must refuse to open the file. |
| GUID | Region |
|---|---|
2DC27766-F623-4200-9D64-115E9BFD4A08 | The block allocation table; required. |
8B7CA206-4790-4B9A-B8FE-575F050F886E | The metadata region; required. |
The log, BAT, metadata and data blocks can be anywhere after the first megabyte, each on a 1 MiB boundary.
Region rules
- Each region GUID MUST be unique within the table.
- All objects in the table must not overlap each other, nor the log (given in the header), nor the payload and sector bitmap blocks (given in the BAT).
- The table’s space after the last entry, up to the 64 KiB boundary, is reserved; a writer may set it to zero.
- Updates to the region table structures must be made through the log, unlike the headers.
- An implementation MUST keep the structures it does not support intact (without corrupting them), and MUST fail to open a file that has a region marked required which it does not understand.
- The two regions known in this version are the BAT and the metadata region, both required; the specification says future revisions can add regions without breaking other implementations.
Write GUID and Log GUID rules
All from [MS-VHDX] revision 8.0, 2.2.2 and 2.2.2.1.
- On every open that allows writing the headers MUST be updated before any other part of the file is modified. The first header update after the open MUST generate a new random File Write GUID; the File Write GUID MUST be new and unique before the first modification of any kind, including system and user metadata and log replay. It may be skipped if the media is read-only or the file is opened read-only.
- Data Write GUID. It MUST change to a new unique value on every open before the first modification of user-visible data, and in any case when the user of the virtual disk could observe the change through a read: changes to system or user metadata, raw block data, the disk size, and any block state transition that makes a sector read differ from an earlier read. Moving blocks within the file does not count (physical layout only). Timing: an implementation SHOULD NOT update it until the user has requested an operation that could affect the contents or user-visible metadata such as disk size or sector size, so a file that is opened and closed without such a request keeps its value. Note 2 explains why: the Data Write GUID is used for the integrity check of a differencing chain, so it must be updated as specified.
- Log GUID. Zero means no log to replay. Upon open the writer MUST change it to a new non-zero value before overwriting existing space in the log region (see writing through the log).
- Procedure to update a header (specification’s suggested procedure): identify the current and non-current header; build a new header in memory with sequence number = current + 1 and the other fields as before or updated (using a new File Write GUID if it is the first update of the session); compute its checksum; overwrite the non-current header and flush. The non-current header is now current; the update SHOULD be repeated so that both copies are up to date and one corrupt copy still leaves the file openable.
- The header’s Log Length and Log Offset are multiples of 1 MB and the log MUST NOT overlap any other structure; the Version field MUST be 1 and the Log Version 0 (else, unless the Log GUID is zero, the file must not be processed).
In the explorer: a header with a Version other than 1, or a Log Version other than 0 with a log, is reported and its log is not replayed. When both headers are valid with the same sequence number but different contents, neither is current, the specification gives no rule, and the explorer reports it and uses header 1 (two identical headers, as Disk2vhd writes them, are not a problem). The region tables are changed through the log, so they are read after the log is replayed, and a table the log changes is marked as replayed. Every reserved field is checked for zero; the 704 KiB after the second region table is drawn as a reserved node.
Example
A region table entry for the BAT. The GUID’s first three groups are stored byte reversed.
00030010 66 77 C2 2D 23 F6 00 42 9D 64 11 5E 9B FD 4A 08 fw.-#..B.d.^..J.
00030020 00 00 30 00 00 00 00 00 00 00 10 00 01 00 00 00 ..0.............
Reading it: the BAT GUID 2DC27766-F623-4200-9D64-115E9BFD4A08; file
offset 0x300000 (3 MiB); length 0x100000 (1 MiB); flags 1,
required.