How 7-Zip Processes VHD and VHDX Files

7-Zip processes Virtual Hard Disk (VHD) and VHDX files by treating these virtual disk images as standard multi-volume or partitioned archive containers. Rather than requiring the host operating system to mount the disk as a block device, 7-Zip parses the internal headers, block allocation tables, and embedded file systems directly. This allows users to inspect the partition layout, navigate directories, and extract individual files without running hypervisors, virtual disk services, or administrative mounting utilities.

Header Detection and Metadata Parsing

When a .vhd or .vhdx file is opened, 7-Zip reads the beginning and ending sectors of the file to identify the container signature.

  • VHD Processing: 7-Zip locates the 512-byte footer—located either at the very end of dynamic/differencing images or at the beginning of fixed images—which identifies disk geometry, disk type (fixed or dynamic), and points to the dynamic header.
  • VHDX Processing: 7-Zip parses the 1 MB file header region, verifying the vhdxfile signature. It processes the log replay metadata and reads the active metadata table to determine block size, sector size, and disk geometry.

Block Allocation and Sector Mapping

Virtual disk images often use dynamic sizing, meaning data blocks are not stored contiguously on the physical drive. 7-Zip resolves this using an internal translation layer:

  1. Reading the Block Allocation Table (BAT): 7-Zip loads the BAT to map logical disk blocks to their physical offsets within the container file.
  2. Dynamic Reconstruction: For dynamic disks, empty or unallocated blocks are treated as zeroes on the fly, eliminating the need to expand the disk to its full virtual capacity in system memory.
  3. Differencing Disks: If a disk is a differencing image, 7-Zip reads the modified blocks referenced in the child image's BAT. However, complete reconstruction requires access to the parent image chain.

Partition and File System Analysis

Once 7-Zip constructs a coherent virtual byte stream from the BAT mapping, it scans the virtual sector zero for partition tables:

  • MBR and GPT Decoding: 7-Zip identifies Master Boot Record (MBR) or GUID Partition Table (GPT) structures. If multiple partitions exist, 7-Zip exposes each partition as an individual item or virtual folder (e.g., 0.fat, 1.ntfs).
  • File System Parsing: Inside each partition, 7-Zip utilizes its native file system decoders. It reads the master file tables and directory trees for common formats, including NTFS, FAT, exFAT, and Linux file systems like ext2, ext3, and ext4.

Read-Only Extraction Pipeline

7-Zip handles VHD and VHDX formats strictly in read-only mode. Once the file system tree is loaded into the user interface or command-line buffer, operations follow the standard archive extraction path. When a user extracts a file, 7-Zip queries the file's data run in the internal file system, translates those logical offsets through the virtual disk's BAT, and reads the raw sectors directly from the container file to write them to the destination path.