Virtual machine 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.
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.
- Log in to the vCenter vSphere Client.
- Locate the virtual machine in the inventory.
- Right-click the virtual machine and click Rename.
- Change the virtual machine name as required.
- 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:
- Log in to the vCenter vSphere Client.
- Locate the virtual machine in the inventory.
- Power down the virtual machine
- Right-click on the virtual machine and click Remove from inventory.
- Open SSH session to the ESXi/ESX host.
- Navigate to the directory containing the virtual machine.
For example:
cd /vmfs/volumes/DatastoreName/originalname
- 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. There needs to be 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.
- Renaming the
originalname-flat.vmdk
file after running the vmkfstools
command is not needed. 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
.
- Copy the virtual machine configuration file (.
vmx
) using the command:
cp originalname.vmx newname.vmx
- Open the file new virtual machine configuration (for example, newname.vmx) in a text editor. For more information, see Editing configuration files in VMware ESXi and ESX
For example:
vi newname.vmx
- 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 both the .vswp file and the directory name for the swap file are renamed.
- Correct any other remaining lines referencing the original path or file names.
- Save the file and exit the editor.
- Rename all the remaining files, except the .
vmx
configuration file, to the new names.
For example:
mv originalname.nvram newname.nvram
- Change directory to the parent directory:
cd ..
- Rename the directory for the virtual machine:
mv originalname newname
- Using the vSphere Client, browse the datastore and navigate to the renamed virtual machine directory.
- Right-click the virtual machine's new configuration file (for example, newname.vmx) and select Add to inventory.
Alternatively, use the below command to add the virtual machine to the inventory:
vim-cmd solo/registervm /vmfs/volumes/DatastoreName/newname/newname.vmx
- Power on the virtual machine.
- A question for the virtual machine displays in the Summary tab during power-on. To review the question:
- Click the Summary tab.
- Right-click the virtual machine in the inventory and select Answer question.
- 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.
- Optionally delete the original virtual machine configuration file.
For example:
rm /vmfs/volumes/DatastoreName/newname/originalname.vmx