How To – Properly Rename a VMware virtual machine
How To – Properly Rename a virtual machine:
This wiki describes the process in which a virtual machine should be properly renamed in the virtual infrastructure
and does not consider the over all process of renaming a server (DNS, monitoring, backups, AD, OS name, etc.).
1) Power off the virtual machine.
2) Make note of the Datastore the virtual machine resides in. Example Datastore:(VM_DATA_C000_01)
Note all Datastore examples need to be replaced with the actual Datastore your virtual machine is in.
3) Right-click the virtual machine you want to rename in VMCenter and remove it from inventory. This unregisters the virtual machine from VMCenter. (Do not delete the files from disk).
4) SSH (Putty) into one of the hosts of the cluster the virtual machine is in.
5) Switch your user context to root with sudo su –
6) Create a new directory to hold the virtual machine files and move them with mv /vmfs/volumes/VM_DATA_C000_01/OLD_VIRTUAL_MACHINE_NAME /vmfs/volumes/VM_DATA_C000_01/NEW_VIRTUAL_MACHINE_NAME
Example:
mv /vmfs/volumes/VM_DATA_C000_01/VMWEB01VD /vmfs/volumes/VM_DATA_C000_01/VMWEB01VT
This will move your vmdk, vmx, vmsd, vmxf, and nvram files to the new directory
7) Navigate to the virtual machine's new folder with cd /vmfs/volumes/VM_DATA_C000_01/VMWEB01VT
8) Rename the virtual disk file(s) with vmkfstools -E VMWEB01VD.vmdk VMWEB01VT.vmdk
This command renames the .vmdk, flat.vmdk, and updates the .vmdk pointer. You may have to run this for any additional virtual disks present.
9) Use nano to modify the .vmx and .vmxf files to reflect the new virtual machine name. Nano is similar to VI editor so pay attention to the menu legend at the bottom of the screen for options. Be careful with NANO; it can put an inadvertent carriage return in the file, which then keeps the vmx file from being properly seen as a vmx file. Example: nano /vmfs/volumes/VM_DATA_C000_01/VMWEB01VT/VMWEB01VT.vmx
and
nano /vmfs/volumes/VM_DATA_C000_01/VMWEB01VT/VMWEB01VT.vmxf
Find all virtual machine name references in these files and replace them with the new virtual machine name.
Also, rename the files themselves after editing them. Refer to the vmx, vmxf, vmsd, nvram files.
10) Register the virtual machine in VMCenter.
Navigate to any of the hosts in the target cluster.
Right click on the datastore the virtual machine is in.
Choose “Browse Datastore”.
Open the virtual machines folder and right click on the [servername].vmx file and choose “Add to Inventory”. Follow the steps in the wizard.
Refer to Appendix A of the Virtual_Machine_Migration.doc if you have any issues getting console access to the virtual machine in VMCenter once it is back into inventory.