Command-line Methods to Extract Files from VMDK Virtual Disk Images


2 views

VMDK (Virtual Machine Disk) is VMware's proprietary virtual disk format used by virtualization products like VMware Workstation, ESXi, and vSphere. While WinImage provides GUI-based extraction, many sysadmins and developers prefer command-line tools for automation and scripting scenarios.

For VMware environments, the most reliable method is using VMware's own utilities:

vmware-mount -p example.vmdk  # List partitions
vmware-mount /mnt/mountpoint example.vmdk 1  # Mount partition 1

After mounting, you can access files normally through the mount point.

For cross-platform solutions, the QEMU ecosystem provides excellent tools:

# Convert VMDK to raw format first
qemu-img convert -f vmdk -O raw input.vmdk output.img

# Then mount or extract files
guestfish -a output.img -i
# Inside guestfish shell:
ls /
copy-out /path/to/file /local/destination

Surprisingly, 7-Zip can handle VMDK files in many cases:

7z x ubuntu.vmdk -o./extracted_files

Note this works best with monolithic VMDKs rather than split or compressed variants.

Windows administrators can use PowerShell with the VMware PowerCLI module:

Connect-VIServer -Server vcenter.example.com
Get-VM -Name "MyVM" | Get-HardDisk | Where {$_.Filename -match "vmdk$"} | 
Select -ExpandProperty Filename | Out-File vmdk_paths.txt

For programmatic access, pyvmdk provides Python bindings:

import pyvmdk

handle = pyvmdk.open("disk.vmdk")
with open("extracted_file.txt", "wb") as f:
    f.write(handle.read(offset=1024, length=4096))
handle.close()

For corrupted VMDKs, consider these specialized tools:

  • VMware vSphere CLI (vicfg-* commands)
  • Active@ Disk Editor for forensic recovery
  • TestDisk for partition repair before extraction

Virtual Machine Disk (VMDK) files are common in virtualization environments, but extracting individual files from them can be tricky when you need command-line solutions. While tools like WinImage offer GUI-based extraction, many developers prefer scriptable approaches for automation and server environments.

Here are several effective command-line methods for working with VMDK files:


# Using qemu-img and libguestfs tools
sudo apt-get install qemu-utils libguestfs-tools
qemu-img convert -O raw disk.vmdk disk.raw
guestmount -a disk.raw -m /dev/sda1 --ro /mnt/vmdk

For Windows environments, consider these alternatives:


:: Using 7-Zip (if VMDK is in stream-optimized format)
7z x disk.vmdk -oextracted_files

:: Using VMware's vdiskmanager (part of VMware Workstation)
"c:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager" -r disk.vmdk -t 0 disk.raw

For more control over the extraction process, you can use Python with the pyvmdk library:


import pyvmdk

handle = pyvmdk.open("disk.vmdk")
with open("extracted_file.txt", "wb") as f:
    f.write(handle.read(offset=1024, length=4096))
handle.close()

For encrypted VMDK files, you'll need additional parameters:


# Using vmware-mount (requires VMware Workstation)
vmware-mount -p disk.vmdk  # List partitions
vmware-mount /mnt/vmdk disk.vmdk 1 -o ro -p password123