Unfortunately there came a time where I had to repair a virtual machine and I quickly started running out of hope. But I found one thread which described my predicament and followed the following steps to get the VM back and running (phew!).
SureshKumarMuth explains the basics very well here:
Basically, each virtual disk will have two files
1. Descriptor file
2. Data file
for a disk without snapshot , you will have the file in this naming convention (taken your server name as example)
Webserver0.vmdk — is the descriptor file of base disk
Webserver0-flat.vmdk — actual data file ( if we delete this then we cannot recover data if we do not have any proper back up or using proper recovery tool)
In case if you have snapshot , you will find many disks in the following naming convention depends on the number of snapshots you have . in your case if appears that you have 6 snapshots
Webserver0-000001.vmdk — descriptor file, can be recovered using the delta disk.
Webserver0-000001-delta.vmdk (data disk)
In your case, fortunately you deleted only the descriptor file which can be recovered using the steps given in the following video and kb article
How to recreate a missing Virtual Machine Disk Descriptor File (VMDK) – YouTube
Waiting for the output from ESXi ssh session for further steps
From the KB article above I was successful in doing the following:
- Identify and record the exact size of the -flat file using this command:
ls -l vmdisk0-flat.vmdk
-rw------- 1 root root 4294967296 Oct 11 12:30 vmdisk0-flat.vmdk
- Use the vmkfstools command to create a new temp virtual disk:
# vmkfstools -c 4294967296 -d thin temp.vmdk
The command uses these flags:- -c size
This is the size of the virtual disk. - -d thin
This creates the disk in thin-provisioned format.
- -c size
The temp.vmdk and temp-flat.vmdk files are created as a result.
Note: To save disk space, we create the disk in thin-provisioned format using the type thin. The only consequence, however, is that the descriptor file contains an extra line that must be manually removed in a later step if the original disk is not Thin provisioned.
- Delete temp-flat.vmdk, as it is not needed. Run this command:
rm -i temp-flat.vmdk
- Rename temp.vmdk to the name that is required to match the orphaned -flat file (or vmdisk0.vmdk , in this example):
mv -i temp.vmdk vmdisk0.vmdk
- Edit the descriptor file using “vi” text editor ( vi vmdisk0.vmdk, in this example)
- Under the Extent Description section,
- Use command “Insert” to allow modifications on the descriptor file.
- Locate and change the name of the -flat file to match the orphaned -flat. Once completed – hit “Esc” to exit this mode.
- Find and remove the line
ddb.thinProvisioned = "1"
if the original .vmdk was not a thin disk. If it was, retain this line. Use command “:wq!
” to save and exit “vi” editor.
- Under the Extent Description section,
Hope this helps you out if you (unfortunately) find yourself in this situation.