How to create missing .VMX file and missing .VMDK file

If you see your VC console and find your VM’s files missing (due to host having been shut down ungracefull e.g.) not all is lost. You will probably  need to recreate vmx configuration file (easy peasy, just create a new VM with your old VM’s specifications) but also .vmdk virtual disk file might be missing.

Ok, a few words of theory. Your virtual disk is composed of two files: VM-flat.vmdk (extent file) and VM.vmdk (descriptor, we will try to recover this one as it may be missing). If your -flat.vmdk is lost, well, not much can be done as it is the file that contains the disk’s data. You did backup your VMs, didn’t you?

However, if it is the header / descriptor file that is missing, it can be fixed quite quickly. In this tutorial we assume that both your vmx and .vmdk are lost.


                      
1. Create a new virtual machine. We will call it VM_recovered. Specify the settings as for your original VM. Do not add the disk yet. Login via ssh / local console or browse the datastore and confirm that a new .vmx file is there. Copy it to the folder where your original VM is changing the vmx’s name to your original machine’s name.



Don't add any disk now

New temporary VM is ready



And its files


So we copy vmx
2. Check the size of your original vdisk extent file with the following command:

ls -al | grep flat



Note down the extent's size
3. In your original VM’s directory create a new vdisk with the exact size of your old one. It can be thin-provisionved as the data part we will delete anyway soon.

vmkfstools -c xxxxx -d thin -a lsilogic temporary_disk.vmdk

where you replace xxxxx with disk’s size obtained in point 2.


Create a new, temporary virtual disk
4. Remove extent file of the newly created temporary disk:

rm ./temporary_disk-flat.vmdk

5. Change the name of the new .vmdk file:

mv ./temporary_disk.vmdk ./VM.vmdk

You’ve just re-created your VM virtual disk’s header. Now let’s finish its customization.

6. Use your favorite editor to edit the descriptor file. You can use nano (ESX only) or vi to do it directly on your host or download the file to your workstation, edit it and upload it again (here are instructions for both vi and nano). Find the line starting with RW and change the name of the extent file (1) from temporary_disk-flat.vmdk to VM-flat.vmdk (the name that maches the existing extent file you found in point 2, Workstation 1-flat.vmdlk in my example). You may also remove the thin provisioning configuration (2). Save the file.



Editing the vmx file
 7. Edit your VM settings and add an existing disk. Point to the VMFS datastore where you have got your VM. After the change is commited run the VM.



Your VM is back alive


                               

Comments

Post a Comment

Popular Posts