Rebuilding corrupt .vmx file using log file

To rebuild the virtual machine's .vmx file using a shell script which parses the information from the vmware.log file:

Notes:

  • VMware does not guarantee that this script will recover every .vmx file. This is only an option to try if the operation becomes necessary. For example, if the virtual machine configuration is changed after the last power on, then that information is not logged in the vmware.log and the .vmx may not be accurate.
  • Ensure to take a backup of the .vmx file before proceeding.
  • Ensure that you run the commands or the script from the virtual machine working directory. To determine the working directory, right-click the virtual machine and click Edit Settings, then click Options > Virtual Machine Working Location.
1.     Create a new file using a text editor. Name it, for example, vmxrebuild.sh.
2.     Copy and paste this script to the 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}
3.     Save the file, ensuring that it has an .sh extension.
4.     Run this command to give execute privileges to the file:

chmod +x filename

Where
 filename is the name of the saved shell script file.
5.     If 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.
6.     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
7.     Run the script using this command:

./filename.sh


Comments

Popular Posts