I recently came up against a problem with a VM that had been restored from backup. It appeared that the xxxxx.vmdk file had become corrupt.This meant that the ESX host couldn’t start the virtual machine as it didn’t know what to do with the xxxxx-flat.vmdk file (which is the actual virtual disk). In order to get the virtual machine to boot, the xxxxx.vmdk file had to be recreated. These are the steps that I took to get it back up and running.
First of all, we start by establishing an SSH connection to the host and browsing to the location of the VMs files:
(rather than delete the newdisk.vmdk for the purposes of this example, I have just renamed it to newdisk.vmdkold – the effect is the same)
Ok, so here we have a bunch of virtual machine files, including the virtual disk (newdisk-flat.vmdk), but no valid newdisk.vmdk file to go with it. To start we need to examine the .vmx file to see what type of scsi controller the disk was using, as we will need that information to recreate the descriptor file. Looking at the .vmx file, we can see the following:
We can see from the scsi0.virtualDev line that the disk is using the lsilogic controller. The next piece of information that we need is the exact size of the virtual disk file. We can get this by running ‘ls -l newdisk-flat.vmdk‘:
Armed with the scsi controller type and the disk size, we can now use vmkfstools to create a new disk and descriptor file by running ‘vmkfstools -c 4294967296 -a lsilogic -d thin temp.vmdk‘.
As a result of running that command two new files have been created – temp.vmdk and temp-flat.vmdk. We’re only interested in the descriptor file, so we can delete the disk file by running ‘rm temp-flat.vmdk‘.
The next step is to rename temp.vmdk to newdisk.vmdk, in order for it to match our original disk. We can do this by running ‘mv temp.vmdk newdisk.vmdk‘.
The final part of the process is to edit the newly created newdisk.vmdk file. When we first open the file it looks like this:
We need to change the line referencing the flat vmdk file as follows:
We should now be able to power on the virtual machine!