Rebuild the virtual machine’s .vmx file from vmware.log

While attempting to diagnose a problem where there are a couple of (orphaned) virtual machines as identified by the VMware vSphere Client, one of interest seemed to have all the files in the datastore, however, upon closer inspection the .vmx file was zero byte.  The .vmx file can be rebuilt with the vmware.log file.

Basically, I downloaded the most recent of the vmware.log files. Copied it to a local CentOS 6 minimal install and followed the instructions provided below.

touch && chmod +x
  • Copy and paste the following into your new file.
VMXFILENAME=$(sed -n 's/^.*Config file: .*\/\(.\+\)$/\1/p' vmware.log)
echo -e "#\041/usr/bin/vmware" > ${VMXFILENAME}
echo '.encoding = "UTF-8"' >> ${VMXFILENAME}
sed -n '/DICT --- CONFIGURATION/,/DICT ---/ s/^.*DICT \+\(.\+\) = \(.\+\)$/\1 = "\2"/p' vmware.log >> ${VMXFILENAME}
  • Save the file, ensuring that it has an .sh extension.
  • If the uuid.location has changed due to operations such as cloning or Storage vMotion, run this command to get the new UUID:
NEWUUID=$(sed -n "s/^.*UUID: Writing uuid.location value: '\(.\+\)'.*$/\1/p" vmware.log)

Note: Whenever possible, use the latest vmware.log file.

Run this command to replace the old UUID in the .vmx file with the new one:

if [ "${NEWUUID}" ] then sed -i "s/uuid.location = .*$/uuid.location = \"${NEWUUID}\"/" ${VMXFILENAME} fi
  • Run the script using this command:

Here is a snippit of the rebuilt .vmx file that was generated by the script. When complete, just copy and paste it into the datastore where the corrupted or missing vmx file is to be, then hope for the best.

.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "7"
pciBridge0.present = "TRUE"
pciBridge4.present = "TRUE"
pciBridge4.virtualDev = "pcieRootPort"
pciBridge4.functions = "8"
pciBridge5.present = "TRUE"
pciBridge5.virtualDev = "pcieRootPort"
pciBridge5.functions = "8"
pciBridge6.present = "TRUE"
pciBridge6.virtualDev = "pcieRootPort"
pciBridge6.functions = "8"
pciBridge7.present = "TRUE"
pciBridge7.virtualDev = "pcieRootPort"
pciBridge7.functions = "8"
vmci0.present = "TRUE"