If your VMDK file is lost. How do I found out? It's simple, if you don't see your usual vmdk file through the VI browser, and you see some kind of file with yourfile-flat.vmdk, then you lost your descriptor file.
Then it happens that your VM does not want to start. Sure, you can restore from your yesterday's backup. But, if, for X reasons your last backup is like a week old or so and you do not want to loose the delta of your work, than the next several lines could be crucial for you…
In this example 2003srvis the name of the virtual machine, 2003srv.vmdk was the name of the descriptive file, and 2003srv-flat.vmdk as the content, or -flat file. Now you can actually see the 2003srv-flat.vmdk file throught your VI client's browser datastore. Your file you need to recreate is 2003srv.vmdk
To create a descriptive file (I suppose that the disk was thin provisioned) :
1. Login to console with putty. You have to enable SSH first (if not the case already).
2. Run this command:
# cd /vmfs/volumes/myvmfsvolume/mydir
3. Run this command to identify and record the exact size of the flat file:
# ls -l vm-vCenter-flat.vmdk
4. run the vmkfstools and create new virtual disk
# vmkfstools -c 85921274880 -d thin -a lsilogic temp2.vmdk
5. Like this there are 2 new files created: temp2.vmdk and temp2-flat.vmdk are created as a result.
6. You can delete temp2-flat.vmdk as it is not needed.
# rm temp2-flat.vmdk
7.Rename temp2.vmdk to the name that is needed to match the orphaned -flat file (vm-vCenter.vmdk in this example):
# mv temp2.vmdk vm-vCenter.vmdk
8. Edit the descriptor file (the vm-vCenter.vmdk)
find the line with RW ####### and change the name of the -flat to match the orphaned -flat file you have. So I chanded temp2.vmdk to vm-vCenter.vmdk as you can see on the image below.
9. Power up the virtual machine and access the disk drive. The drive contains the data from the old disk.
Source: VMware KB 1002511
Bouke Groenescheij says
This works fine as long as you know *exactly* how large the original virtual disk was. But I’ve had some cases where I change from ESX 3i to 3.5 and to ESX 4 and 4i, and it seemed that the size calculation changed somewhat. My virtual disk isn’t 15GB, but 14,99543 or something like that. Or my 3GB virtual disk is 2,93233…
I’ve spend some time, trial and error trying to get an header file, using an Excel sheet to extrapolate the correct setting :-s
Anyway, good post. Thanks for sharing…
Vladan SEGET says
Bouke,
great sharing your experience. It’s always count for me having different view points from differents sides. Thanks for the comment.
Vladan
Pawel says
Thanks! Worked out like a charm!
Eric_ says
Dumped my VM but forgot to copy one set of files. Managed to get the disks back with your solution and copy my files afterall.
Thanks
poya says
hi dear
what shuold i do for vmdk bigger than 4T?
thanks.