Hi All
Had an interesting problem that I thought I would share. A customer today had deleted all the files associated with their VM except the flat-vmdk file. The resulted in the machine still running but was not being able to power the machine down or edit it in anyway.
They powered down the VM and attempted to recreate the VM and attach the flat=vmdk as a disk, but this is not possible. The flat-vmdk file contains the RAW data of the vmdk and is often not seen when using the datastore browser. What is used to connect disks is a vmdk file that is a metadata file and contains information mapping to the flat-vmdk. So without this you cannot connect any disks.
I have done a few of these on VI3 but this was my first vSphere and I wanted to check that nothing had changed in VM Hardware 7. So I found this article from VMware.
Gave it a quick going over and it all looks the same.
So I created a new VM with exactly the same disk layout, same size disks and everything. I created in on the same datastore as the original VM was located.
After this I powered on the VM, this is just to create the flat-vmdk file for the VM.
I then powered down the VM
logged onto the command line of the ESX sever and typed the following command to take me to
the VMFS locatation. cd/vmfs/volumes/datastorename/new_vm
From here I could remove the new VMs Flat-vmdk type ls to make sure you can see the file and then type rm new_vm-flat.vmdk You will be prompted to confirm
Once this has been removed you can then move the original flat-vmdk from the broken VM type cd ..
cd old_vm
You can then type the following to move the file. mv old_vm-flat.vmdk /vmfs/volumes/datastorename/new_vm
This will then move the flat-vmdk to the new VM working directory. You now need to browse to the new directory cd .. and then cd new_vm type ls to make sure the file is located in the directory.
now we need to change the name of the flat-vmdk to match the file in the vmdk header. we need to do a cat on the file to show us what it is looking for. type cat new_vm.vmdk you will see something like this.
-------------------------------------
# Disk DescriptorFile
version=1
CID=fb183c20
parentCID=ffffffff
createType="vmfs"
# Extent description
RW 8388608 VMFS "vmdisk0-flat.vmdk"
# The Disk Data Base
#DDB
ddb.virtualHWVersion = "4"
ddb.geometry.cylinders = "522"
ddb.geometry.heads = "255"
ddb.geometry.sectors = "63"
ddb.adapterType = "lsilogic"
ddb.thinProvisioned = "1"
-------------------------------------
We need to make a note of the line RW because we are going to change the name of our flat-vmdk to match this.
Once this has been noted type the following to change the name of the old flat-vmdk. mv old_vm-flat.vmdk new_vm-flat.vmdk This will then rename the file to that of the flat-vmdk listed in the file we ran cat against. you can check this by typing ls.
If there the same the VM will power on.
The customer I completed this for was very happy is going to delete file more carefully in future.