Renaming a virtual machine and its files in VMware ESXi
search cancel

Renaming a virtual machine and its files in VMware ESXi

book

Article ID: 342208

calendar_today

Updated On:

Products

VMware vCenter Server VMware vSphere ESXi

Issue/Introduction

This article provides steps on how to rename a virtual machine and its files through SSH, System Management Interface, or directly at its console.

Renaming a virtual machine using the vSphere Client only changes the display name, not the corresponding files on the datastore. It may be useful to also rename the files of virtual machines to maintain consistency.


Environment

VMware vSphere 6.x
VMware vSphere ESXi 5.5
VMware vSphere ESXi 5.1
VMware vSphere 7.0.x
VMware vCenter Server 4.1.x

Resolution

A virtual machine's files can be renamed during a disk migration operation, such as Storage Migration, Storage vMotion or by manually renaming them in-place from the ESXi Shell. Select your preferred method.
 

Renaming virtual machine files using Storage vMotion

A virtual machine's files can be renamed on the fly during a Storage vMotion initiated from the vSphere Client. The renaming occurs with no downtime.
  1. Log in to the vCenter web client.
  2. Locate the virtual machine in your host inventory.
  3. Right-click the virtual machine and click Rename.
  4. Change the virtual machine name as required.
  5. Begin a Storage vMotion or an offline Storage Migration of the virtual machine. For more information, see:
 
Notes:
  • The Storage vMotion only changes the name of the virtual machine files when the destination datastore is different from the original.
  • After the migration completes, the virtual machine files match the virtual machine name configured in step 4.
  • If a virtual machine directory already exists on the datastore with the same name, then the target virtual machine is placed in a new directory with _1 appended.
  • Changing the name does not change the name of any virtual machine files or the name of the directory that the files are located in.
  • Migration with Storage vMotion changes the virtual machine filenames on the destination datastore to match the inventory name of the virtual machine. The migration renames all virtual disk, configuration, snapshot, and .nvram files. If the new names exceed the maximum filename length, the migration does not succeed.
 

Renaming virtual machine files in-place using the console

 Warning: Before proceeding, ensure that:
  • The virtual machine has a current backup and that it has been powered down.
  • The virtual machine does not have snapshots or virtual disks shared with other virtual machines.
To manually rename files of the virtual machine:
  1. Log in to the vCenter web client.
  2. Locate the virtual machine in your host inventory.
  3. Power down the virtual machine
  4. Right-click on the virtual machine and click Remove from inventory.
  5. Open SSH session to the ESXi/ESX host.
  6. Navigate to the directory containing the virtual machine.
For example:
cd /vmfs/volumes/DatastoreName/originalname
  1. Rename the virtual disk (VMDK) files using the vmkfstools -E command:
vmkfstools -E originalname.vmdk newname.vmdk

Notes:
  • In some cases, it may be required to clone (copy) a virtual disk. To clone a virtual disk to a new virtual disk, run this command:
vmkfstools -i originalname.vmdk newname.vmdk

This leaves the original virtual disk untouched. You need enough space available to clone the virtual disk in the destination directory. In the preceding command, the new virtual disk is created in the current directory but a different directory can be specified.
  • You need not rename the originalname-flat.vmdk file after running the vmkfstools command. The vmkfstools command renames both VMDK files and updates the reference within the descriptor.
  • Do not use the cp or mv commands to rename virtual disk files. Instead, use VMware utilities such as vmkfstools.
  1. Copy the virtual machine configuration file (.vmx) using the command:
cp originalname.vmx newname.vmx
  1. Open the file new virtual machine configuration (for example, newname.vmx) in a text editor.
For example:

vi newname.vmx
 
  1. Within the configuration file, modify all old instances of the virtual machine's file names to the new file names. At a minimum, modify these values (more may exist):
nvram = "newname.nvram"
displayName = "newname"
extendedConfigFile = "newname.vmxf"
scsi0:0.fileName = "newname.vmdk"
[...]
migrate.hostlog = "./newname-UUID.hlog"

Repeat this process for each virtual machine disk. For example:

scsi0:1.fileName = "newname_1.vmdk"
scsi0:2.fileName = "newname_2.vmdk"

Correct the VMkernel swap file reference.

For example:

sched.swap.derivedName = "/vmfs/volumes/DatastoreUUID/newname/newname-UUID.vswp

Note: Ensure that you rename both the .vswp file and the directory name for the swap file in bold.
  1. Correct any other remaining lines referencing the original path or file names.
  2. Save the file and exit the editor.
  3. Rename all the remaining files, except the .vmx configuration file, to the new names.
For example:

mv originalname.nvram newname.nvram
  1. Change directory to the parent directory:
cd ..
  1. Rename the directory for the virtual machine:
mv originalname newname
  1. Using the VMware vSphere Client, browse the datastore and navigate to the renamed virtual machine directory.
  2. Right-click the virtual machine's new configuration file (for example, newname.vmx) and select Add to inventory.
Alternatively, you can use this command to add the virtual machine to the inventory:

vim-cmd solo/registervm /vmfs/volumes/DatastoreName/newname/newname.vmx
  1. Power on the virtual machine.
  2. A question for the virtual machine displays in the Summary tab during power-on. To review the question:
    1. Click the Summary tab.
    2. Right-click the virtual machine in your inventory and select Answer question.
    3. When prompted, select I moved it, then click OK.
Warning: Selecting I copied it results in a change of the virtual machine's UUID and MAC address, which may have detrimental effects on guest applications that are sensitive to MAC address changes, and virtual machine backups that rely on UUIDs.
  1. Optionally delete the original virtual machine configuration file.
For example:
rm /vmfs/volumes/DatastoreName/newname/originalname.vmx


Additional Information

The CLI on ESX is case-sensitive and requires escaping of special characters used in some virtual machine file names. The examples above encourage the use of quotation marks around command arguments to ensure spaces and special characters are interpreted literally and do not require escape sequences.

For example, a virtual machine named "Original VM" is referenced either as "Original VM" (with quotation marks) or Original\ VM.

Special characters, such as opening and closing parentheses, also require character escaping. A virtual machine named "Original VM (1)" is referenced either as "Original VM (1)" (with quotation marks) or Original\ VM\ \(1\).

The former quotation method simplifies the process considerably and improves readability.

Additional information on escape characters can be found in the Bash Reference Manual.

Note: If you find the link is broken, provide a feedback and a VMware employee will update the link.

Renaming a virtual machine disk (VMDK) via the vSphere Management Assistant (vMA) or vSphere CLI (vCLI)
Unable to connect to an ESX host using Secure Shell (SSH)
Editing configuration files in VMware ESXi and ESX
vSphere 5.x Storage vMotion does not rename virtual machine files on completing migration
重命名 VMware ESXi/ESX 中的虚拟机及其文件
VMware ESXi/ESX で仮想マシンとそのファイルの名前を変更する
Umbenennen einer virtuellen Maschine und deren Dateien in VMware ESXi und ESX