VMware vSphere ESXi
To rebuild the virtual machine's .vmx file using a shell script which parses the information from the vmware.log file:
Notes
touch vmxrebuild.sh && chmod +x vmxrebuild.sh
vi vmxrebuild.sh
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. 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}
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}
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)
.vmx
file with the new one:if [ "${NEWUUID}" ] then sed -i "s/uuid.location = .*$/uuid.location = \"${NEWUUID}\"/" ${VMXFILENAME} fi
./vmxrebuild.sh
For more information, see Recovery of a lost or deleted virtual machine configuration file .vmx on an ESXi/ESX host (1002294).
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
从 vmware.log 重新构建虚拟机的 .vmx 文件