How to rename a VMWare ESXi 5 VM physically

virtual-machinesvmware-esxivmware-vsphere

When I create a VM on a VMWare ESXi 5 server naming it "MyVM" then "MyVM" directory is created on a data store and files like "MyVM.vmx", "MyVM.vmdk" etc. in it.

I've renamed the VM and would like all the files to be renamed to follow the change. How to achieve this?

Best Answer

This is possible, but not really necessary. You should only care about the virtual machine's name as displayed in the vSphere console.

Suppose your datastore's name is "datastore1" and the VM is named "zimbra". You wish to change its name to "mail". From the ssh console, you can descend into /vmfs/volumes/datastore1 directory, then the virtual machine's directory.

/vmfs/volumes/0170cf28-62cf5d0c/zimbra # ls -al
drwxrwxrwx    1 -2       -2                   15 Sep 25  2011 .
drwxr-xr-x    1 root     root                 11 Aug  8 15:23 ..
-rw-rw-rw-    1 -2       -2                72171 Sep 25  2011 vmware.log
-rw-------    1 -2       -2          77309411328 Sep 25  2011 zimbra-flat.vmdk
-rw-------    1 -2       -2                 8684 Sep 25  2011 zimbra.nvram
-rw-------    1 -2       -2                  543 Sep 25  2011 zimbra.vmdk
-rw-r--r--    1 -2       -2                    0 Sep 25  2011 zimbra.vmsd
-rwxr-xr-x    1 -2       -2                 2955 May  2 09:35 zimbra.vmx
-rw-r--r--    1 -2       -2                  261 Jul 19 22:51 zimbra.vmxf

You can rename each of the files with the mv command. For instance, mv zimbra.vmx mail.vmx will rename that specific file. Repeat for all of the files.

Once the files are renamed, you'll need to edit the virtual machine's configuration file (.vmx) and the disk descriptor file (.vmdk).

vi zimbra.vmx - From there, you can manually replace the instances of the old name with the new, or run a search-replace (%s/zimbra/mail/g).

Save the .vmx file. For each .vmdk file, look for the "Extent description" line, e.g.

# Extent description
RW 150994944 VMFS "zimbra-flat.vmdk"

Change the name to reference the new name. Save the file.

That's it...