Steps to recover a .vmdk file from flat.vmdk file

When a VMware virtual machine loses its descriptor file, the VM becomes unbootable even though the flat.vmdk file still exists. This can happen after storage corruption, snapshot failures, or accidental deletion.
VMware recommends restoring the missing descriptor file from a backup. But if a backup is not available, you can manually recreate the virtual disk descriptor file and recover the VM. This guide explains how to recover a VMDK file from a flat VMDK file safely using ESXi command-line tools.
What Is a Flat VMDK File?
A VMware virtual disk typically consists of two parts:
- Descriptor file (.vmdk) – metadata and configuration
- Flat file (-flat.vmdk) – actual disk data
If the descriptor file is missing, VMware cannot attach the disk even though the data still exists in the flat file. Recovery involves recreating the descriptor so the VM can recognize the disk again.
Before You Start (Important Checklist)
Before performing recovery, make sure you:
- Power off the virtual machine
- Enable SSH access to the ESXi host
- Create a backup copy of the -flat.vmdk file (recommended)
- Confirm sufficient free space on the datastore
Tip: If the flat file is large, at minimum take a snapshot/backup of the datastore (if available) or copy the VM folder to another datastore before making changes.
Step-by-Step: Recover VMDK from Flat VMDK File
Step 1: Connect to the ESXi Host
Login to the ESXi server using SSH as root:
ssh root@ESXi-IP
Step 2: Navigate to the VM Datastore Folder
Move to the directory where the flat VMDK file is stored:
cd /vmfs/volumes/DATASTORE_NAME/VM_NAME
Step 3: Check the Size of the Flat VMDK File
List files and note the exact size of the flat file:
ls -lh vmdisk0-flat.vmdk
You must use the correct disk size when recreating the descriptor file.
Step 4: Create a Temporary VMDK Descriptor File
Use vmkfstools to generate a new descriptor:
vmkfstools -c SIZE -d thin temp.vmdk
Example:
vmkfstools -c 40G -d thin temp.vmdk
This creates:
temp.vmdk(descriptor)temp-flat.vmdk(dummy disk)
Step 5: Delete the Temporary Flat File
The dummy flat file is not required. Delete it:
rm -i temp-flat.vmdk
Step 6: Rename the Descriptor File
Rename the descriptor file to match your original VM disk name:
mv -i temp.vmdk originalvmname.vmdk
Step 7: Edit the Descriptor File to Point to the Real Flat File
Open the descriptor file in an editor:
vi originalvmname.vmdk
Find the line that begins with RW. Update the referenced filename so it matches your actual flat disk file (for example, vmdisk0-flat.vmdk).
Example line format:
RW XXXXX VMFS "vmdisk0-flat.vmdk"
Save and exit the editor.
Step 8: Power On the VM and Verify
Start the virtual machine and verify:
- The OS boots normally
- No disk errors appear
- Files and data are accessible
If the VM boots successfully, the recovery is complete.
Common Recovery Errors and Fixes
Disk Size Mismatch
If the descriptor size doesn’t match the flat file size, VMware may reject the disk. Re-check the size and recreate the descriptor with the correct value.
Invalid Descriptor File
Ensure the filename inside the descriptor matches the flat file name exactly, including capitalization.
Permission Errors
Verify datastore permissions and ensure you are logged in as root (or have equivalent privileges).
How to Prevent VMDK Descriptor Loss
- Maintain regular VM backups
- Avoid abrupt shutdowns and power failures (use UPS)
- Monitor datastore and storage health
- Manage snapshots carefully and avoid long snapshot chains
Frequently Asked Questions
Can I recover a flat VMDK without a backup?
Yes. If the flat file is intact, you can recreate the descriptor file manually using vmkfstools.
Is this recovery method safe?
It is generally safe if you do not modify the flat file and you follow the steps carefully. Creating a backup copy first is strongly recommended.
What causes VMDK descriptor loss?
Common causes include storage corruption, power outages, interrupted snapshot operations, or accidental deletion.
Will I lose data during this process?
No—this process rebuilds metadata (the descriptor). Data loss typically occurs only if the flat file itself is damaged or overwritten.
Final Thoughts
Losing a VMDK descriptor file can look like a major failure, but the disk data often still exists inside the flat file. By rebuilding the descriptor and pointing it to the correct flat VMDK, you can restore access and bring your VM back online.
Tip: After recovery, implement a backup strategy and monitor storage health to reduce the chance of recurrence.
To get more updates you can follow us on Facebook, Twitter, LinkedIn
Subscribe to get free blog content to your Inbox
-
Previous Post
Manage multiple ESXi hosts & VM on the ESXi hosts
-
Next Post
Health Checks for Load Balancing
