Skip to content
Gabor Szarnyas edited this page Jan 29, 2020 · 12 revisions

Renaming a VMware virtual machine

There is an official VMware tutorial, which recommends using the vmkfstools, which is not installed by default. Instead of using that, simply perform some search-and-replacing and rename the files. For example, to rename the Rete-Lab-2017 image to IVT-Lab-2017, follow this guide:

  1. Edit the vmx and vmdk files:

    sed -i "s/old_substring/new_substring/" *.vmx
    sed -i "s/old_substring/new_substring/" *.vmdk
  2. Rename the files. Use the dry run (-n) switch for testing and remove it for the final run:

    rename -f "s/old_substring/new_substring/" *

Be careful as both sed and rename use regex matching, and even their regex syntax (standards vs. extended vs. Perl) can differ.

An automated version with environment variables is listed below. Careful, this will actually perform the rename.

export VM_PREFIX*=
export OLD=
export NEW=
sed -i "s/$OLD/$NEW/" $VM*.vmx
sed -i "s/$OLD/$NEW/" $VM*.vmdk
rename -f "s/$OLD/$NEW/" $VM*.*

An example configuration:

export VM=Rete-Lab-2017
export OLD=Rete-Lab
export NEW=IVT-Lab
Clone this wiki locally