• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Yellow Bricks

by Duncan Epping

  • Home
  • ESXTOP
  • Stickers/Shirts
  • Privacy Policy
  • About
  • Show Search
Hide Search

Howto: Rename a VM

Duncan Epping · Feb 10, 2008 ·

There are a couple of ways to rename a Virtual Machine, but there are two in my opinion that stand out:

  1. Shutdown the VM
  2. Rename the VM in VirtualCenter
  3. Migrate the VM and move it to another Datastore
  4. done!

And from the service console:

  1. vmware-cmd -s unregister /vmfs/volumes/datastore/vm/vmold.vmx
  2. mv /vmfs/volumes/datastore/vm-old /vmfs/volumes/datastore/vm-new
  3. cd /vmfs/volumes/datastore/vm-new
  4. vmkfstools -E vm-old.vmdk vm-new.vmdk
  5. find . -name ‘*.vmx*’ -print -exec sed -e ‘s/vm-old/vm-new/g’ {} \;
  6. mv vm-old.vmx vm-new.vmx
    for every file that hasn’t been renamed (.vmsd etc.)
  7. vmware-cmd -s register /vmfs/volumes/datastore/vm-new/vm-new.vmx
  8. done!

Related

Server 2.0.x, 2.5, 3.0.x, 3.5, ESX

Reader Interactions

Comments

  1. richpo says

    11 February, 2009 at 21:40

    Thxs I thought I was going to have to do the cmd line because The app owner changed the name. I didn’t realize moving the VM to a different datastore would take care of this. Thanks

    -Richard Powers

  2. Sebastian Kayser says

    19 May, 2010 at 11:21

    Hi Duncan,

    thanks for the concise summary. Two things for those without Storage vMotion who need to go down to the SC. Step 5 should read ‘sed -i -e’ to actually replace the *.vmx* file contents inplace (-i) and might be abbreviated to

    sed -i -e ’s/vm-old/vm-new/g’ *.vmx*

    Further, the renaming for step 6 can be automated a bit to speed it up and make it less error-prone. At least for ESX3.5/ESX4.0 where the ‘rename’ utility is present (just checked), older platforms might not have it.

    shopt -s nullglob
    OLD=vm-old
    NEW=vm-new
    rename $OLD $NEW $OLD.{???,????,?????}

    Renames all $OLD files which have extensions ranging from 3 to 5 chars (.vmx, .vmsd, .vmxe, .vmxf, .nvram,. ..).

    HTH

    Sebastian

  3. Alfa-male, says

    24 June, 2011 at 10:57

    I need to rename a live w2k8 vm server both in windows and vcenter.

    I do not have a lot of space left in my data stores so option one seems out of reach.

    In considering option 2, is it a must to rename the VM files? What happens if I do not rename the vm files but only rename the vm by right clicking on it and selecting rename. I need to do this in the next 45 minutes please!

    • Duncan says

      24 June, 2011 at 15:27

      it is not a must, but it might make troubleshooting more difficult when you don’t,

  4. Gary Boy says

    24 September, 2011 at 03:52

    This “feature” no longer works in vSphere 5. The destination directory name is changed but the vm files do not. Is there a variable that can be set to turn it back on?

  5. Jon Kohler says

    28 September, 2011 at 03:44

    Agreed, the svMotion way does not rename the files of the VM anymore in vSphere 5. I have been rooting around in the advanced options to see if anything pops out, but I haven’t seen it.

    Do you know of a way to turn this back on?

    • Gary Boy says

      28 September, 2011 at 14:16

      I’ve had this question floating around the communities for better than week and I only had one response there and your comment here. Considering the seemingly hundreds of blogs that talked about this feature when it came out, I’m surprised it has so little attention now that it is gone.

      I’ll keep digging.

      gb

    • Duncan says

      28 September, 2011 at 14:52

      i will ask the engineer today 🙂

      • Gary Boy says

        29 September, 2011 at 16:22

        Thank you.

        gb

      • pat says

        18 October, 2011 at 06:03

        Any word from the engineer?

        • Duncan Epping says

          18 October, 2011 at 09:34

          Yes I spoke with him about it this morning over breakfast. They changed the behavior due to an issue with disk numbering. I am going to creat a feature request for this to see if we can get is back in.

          • Gary Boy says

            27 October, 2011 at 14:09

            Thank you.

          • Matt says

            29 November, 2011 at 09:36

            Hoping to see this in an upcoming update; I was racking my brain trying to figure out why this wasn’t working for me.

  6. Andreas Buhlmann says

    30 November, 2011 at 15:25

    Any Information about this in ESXi 5.0?

    • Duncan says

      30 November, 2011 at 15:45

      as stated 3 comments above this is a known issue in 5.0 and I have requested that his behavior is returned to “normal”. cannot comment on when,

  7. Johnny says

    17 May, 2012 at 18:12

    Does anybody know if this has been fixed in vsphere 5.0 update 1?

  8. Matt says

    18 May, 2012 at 07:19

    Nope, still the same problem with the latest release. Figured this would have been fixed, but no joy!

  9. Kandan. K says

    29 May, 2012 at 10:59

    I have successfully renamed the VM in ESXi 5.0 using CLI. The following URL will help me a lot.

    http://esx-guy.blogspot.com/2012/05/how-to-rename-virtual-machine-with-cli.html

    Thanks,
    Kandan.

  10. Matt says

    29 May, 2012 at 11:10

    This method worked before as well, but when they made it auto-magically work through Storage VMotion, it was a welcome addition. In my environment, it is next to impossible to bring a machine down for any reason unless absolutely necessary. Hoping they’ll “re-introduce” this much needed feature.

  11. Matt says

    12 July, 2012 at 17:50

    What if this is the scenario:

    I have a server named test that has 3 drives.

    drive 1 in store1 – test.vmdk
    drive 2 in store1 – test_1.vmdk
    drive 3 in store2 – test.vmdk

    I want to storage vmotion drives 1 and 2 into the newer datastore “store2”. The storage vmotion screen says validation succeeded, I haven’t hit finish yet, but if this renaming feature doesn’t work in 5 will there be a file name conflict after the storage vmotion with the two test.vmdk’s or will it rename the vmdk on the fly?

  12. SasiKiran says

    4 October, 2012 at 13:25

    Can we rename a vm in the ESX using python script??
    If yes, Can you please suggest me , how it can be done

    Thanks,
    Sasikiran

  13. SasiKiran says

    4 October, 2012 at 13:28

    Please provide me the apis for it, and one more question. Can we able to get the uuid for the vm through the esx apis using python

  14. Gregor says

    9 November, 2012 at 15:44

    Hi Duncan,

    Do you think using Converter (to perform a V2V) would be a viable option as well?

    It would take longer than the command line approach (by manually renaming the files) but may be easier for those not inclined to use the CLI.

    cheers,
    gm

  15. Jason Daniels says

    19 March, 2013 at 17:06

    One to avoid CLI, I usually just clone the oldname VM with the new name and boot up the clone. Seems to work well providing you have the extra space and the time to allow the clone. Server 2008 R2 is so resilient I’ve often done the clone while the source server was running to keep keep the added uptime. Probably not the prettiest solution, but until they bring back the storage vMotion solution it works for me.

  16. Vishal says

    7 October, 2014 at 07:47

    Can we rename the VM in Vcenter when the VM power on?

Primary Sidebar

About the author

Duncan Epping is a Chief Technologist in the Office of CTO of the Cloud Platform BU at VMware. He is a VCDX (# 007), the author of the "vSAN Deep Dive", the “vSphere Clustering Technical Deep Dive” series, and the host of the "Unexplored Territory" podcast.

Upcoming Events

May 24th – VMUG Poland
June 1st – VMUG Belgium

Recommended Reads

Sponsors

Want to support Yellow-Bricks? Buy an advert!

Advertisements

Copyright Yellow-Bricks.com © 2023 · Log in