2.2.2.1 Updating the Headers
On every open of a VHDX file that allows the VHDX file to be written to, the headers MUST be updated before any other part of the file is modified. While the VHDX file is in use, the headers can also be updated when an operation on the virtual disk or the VHDX file impacts one of the fields contained in the header.
The first time the headers are updated after the open of a VHDX file, the implementation MUST generate a new random value for the FileWriteGuid field. The implementation SHOULD NOT update the DataWriteGuid field until the user has requested an operation that could affect the virtual disk contents or user-visible virtual disk metadata such as the disk size or sector size.
An implementation can follow the following procedure to change the out-of-date header to the current header:
Identify the current header and noncurrent header.
Generate a new header in memory. Set the SequenceNumber field to the current header's SequenceNumber field plus one.
Set the other fields to their current values or updated values. If this is the first header update within the session, use a new value for the FileWriteGuid field.
Calculate the checksum of the header in memory.
Overwrite the noncurrent header in the file with the in-memory header. Issue a flush command to ensure that the header update is stable on the host-disk storage media.
After this procedure, the noncurrent header becomes the current header. The implementation SHOULD perform the update procedure a second time so that both the current and noncurrent header contain up-to-date information; this ensures that if one header is corrupted, the file can still be opened.