Rebuilding the virtual machine's .vmx file from vmware.log
search cancel

Rebuilding the virtual machine's .vmx file from vmware.log

book

Article ID: 316605

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides steps to rebuilds the .vmx file from the vmware.log file using a shell script.
 
You may want to rebuild the .vmx file of a virtual machine and recover its contents if the .vmx is missing or has lost its configuration.
 


Environment

VMware vSphere ESXi 6.7
VMware vSphere ESXi 6.0
VMware vSphere ESXi 5.1
VMware vSphere ESXi 6.5
VMware vSphere ESXi 7.0.0
VMware vSphere ESXi 5.5
VMware vSphere ESXi 5.0

Resolution

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 file 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. SSH to an ESXi host
  2. Change directory into the virtual machine's working directory 
  3. Run this command to create a new file using a text editor and grant the execute permissions by running this command:

    touch vmxrebuild.sh && chmod +x vmxrebuild.sh
     
  4. Edit the vmxrebuild.sh file using vi editor and insert below script to the file:
    1. Run vi vmxrebuild.sh
    2. Press insert, copy and paste the below script (according to ESXi host version) and press ESC, type :wq! to save/write and quit the editor mode. 
ESXi 6.5/6.7/7.0
 
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}
 
ESXi 5.0/5.1/5.5/6.0
 

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}

For information on how to use a text editor, see Editing files on an ESX host using vi or nano (1020302).
 
  1. If the uuid.location has changed due to operations, such as cloning or Storage vMotion, run this command to get the new UUID. Otherwise, skip this step 3 and skip step 4.

    NEWUUID=$(sed -n "s/^.*UUID: Writing uuid.location value: '\(.\+\)'.*$/\1/p" vmware.log)


    Note: Whenever possible, use the latest vmware.log file.
     
  2. 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
     
  3. Run the script using this command:

    ./vmxrebuild.sh
Note: the script is lightweight and will completely almost immediately. Once the script completes, the prompt will return to the next line. There will be no message that indicates completion. 
  1. Confirm a new .vmx has been created in the VM's working directory.
 

For more information, see Recovery of a lost or deleted virtual machine configuration file .vmx on an ESXi/ESX host (1002294).


Additional Information

To be alerted when this document is updated, click the Subscribe to Article link in the Actions box in the Actions box.
Recovery of a lost or deleted virtual machine .vmx configuration file on an ESXi/ESX host
Editing files on an ESX host using vi or nano
vmware.log から仮想マシンの .vmx ファイルを再構築する
从 vmware.log 重新构建虚拟机的 .vmx 文件