Wednesday, May 2, 2012

How to Rename a Virtual Machine with the CLI in esxi 5.0

With the release of esxi/vsphere 5, storage vmotion no longer renames the files of a vm if the vm was previously renamed. It only updates the folder to reflect the new name. If a person wants to rename a virtual machine and make sure that the virtual machine reflects the new name in the folder and files, follow these steps.

Warning: Try this on a non-production environment. We are not talking about what is supported, just what works. Also, be aware that you may have more files involved, such as an rdm, snapshot and so forth. Proceed at your own risk.

Step # 1:

Access the directory that contains the folder with the files. In this case, the vm is called machinex and it is located in datastore1. The vm needs to be powered off.

# cd /vmfs/volumes/datastore1

Step # 2:

Rename the folder

# mv machinex machiney

Step # 3:

Access the new directory

# cd machiney

Step # 4:

Rename all the files manually

# mv machinex.vmx machiney.vmx
# mv machinex.vmsd machiney.vmsd
# mv machinex.nvram machiney.nvram
# mv machinex.vmdk machiney.vmdk
# mv machinex-flat.vmdk machiney-flat.vmdk
# mv machinex.vmxf machiney.vmxf

Note: In this case, there were no snapshots so the .vmsd file was empty.

Step # 5:

Edit the contents of the .vmx file using vi. Use a global search and replace.

# vi machiney.vmx
:%s/machinex/machiney/g

Step # 6:

Edit the contents of the .vmdk file

# vi machiney.vmdk
:%s/machinex/machiney/g

Step # 7:

Get the vmid of the original vm and unregister the vm
 
# vim-cmd vmsvc/getallvms
# vim-cmd vmsvc/unregister 5

Step # 8:

Register the new virtual machine

# vim-cmd solo/registervm /vmfs/volumes/datastore1/machiney/machiney.vmx


Note: This was eventually taken care off in 5.0 u2 and 5.1 u1:

If using those versions, this can be taken care of via the vsphere client.
There is a parameter called provisioning.relocate.enableRename which is set to false. Just change it to true and restart the vcenter service.

Here are the steps:
  1. Log into the vSphere Client as an Administrator.
  2. Click Administration > vCenter Server Settings.
  3. Click Advanced Settings.
  4. Add this advanced parameter Key:

    provisioning.relocate.enableRename=true

2 comments:

  1. I read your post when it was fresh. I stumbled on this link again while searching for something else. Since this appears to be favored by Google it is worth pointing out MS has changed its mind.

    The demand for IT professionals with professional skills is increasing every day. VMware certification provides a touchstone for validating virtualization, cloud and network virtualization skills - the core of modern data centers. Getting VMware certification can help you stand out from the crowd and make you more attractive to existing and potential employers.
    KILLERDUMPS offers VMware Exam Dumps Files and Practice Test Simulator on discounted price with 100% Guaranteed Success. We provide continuous after sale support for VMware Question and Answer Files and Practice Software to counter any inconvenience.

    You can get VMware Exam Dumps

    ReplyDelete
  2. Passing the VMware Certified Professional 6.5 - Data Center Virtualization PSE at first attempt can be made possible through our VMware Certified Professional 6.5 - Data Center Virtualization PSE dumps. For a candidate not to waste money, time and efforts and Our 2V0-622PSE dumps is ready to help you out. All you just need to do is download and practice with VMware Certified Professional 6.5 - Data Center Virtualization PSE exam dumps.

    ReplyDelete