When I was renaming some virtual machines in my test lab, I discovered that the file names are not renamed with the virtual machine. In the future this may be causing some problems so I was looking for a method to rename the files also. On the VMware site I’ve found a knowledgebase article about it. It describes the correct way to rename also the files. See KB Article: 1029513. Original link: http://kb.vmware.com/selfservice/search.do?cmd=displayKC&docType=kc&externalId=1029513
Purpose
Resolution
Renaming the files
- Log into the VMware vSphere Client.
- Locate the virtual machine in your host inventory.
- Begin a Storage vMotion or an offline Storage Migration of the virtual machine.For more information, see :
- For ESX 4.x, see Cold Migration and Migration with Storage vMotion in the Datacenter Administration Guide.
- For ESX 3.5, see Cold Migration and Migration with Storage vMotion in the Basic Administration Guide.
- For other versions of VMware ESX, such as ESXi, see to the relevant product documentation in VMware Documentation.
- The destination copy’s file names are be updated to your desired values.
If this is not an option, you may also rename the files by hand after the virtual machine has been powered down.
Manually renaming virtual machine files
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 the virtual machine’s files:
- Log into the VMware vSphere Client.
- Locate the virtual machine in your host inventory.
- Power down the virtual machine.
- Right-click on the virtual machine and choose Remove from inventory.
- Connect to the terminal of the ESX server via SSH, System Management Interface, or directly at its console, and log in.Note: For additional instructions for ESXi, see Tech Support Mode for Emergency Support (1003677).
- Navigate to the directory containing the virtual machine. For example, cd /vmfs/volumes/<datastore>/<virtual machine>/.
- Run this command to rename the virtual disk files:vmkfstools -E “originalname.vmdk” “newname.vmdk”Note: Is it unnecessary to once again rename the originalname-flat.vmdk file after running the vmkfstools command.
- Copy the virtual machine configuration file (.vmx) using the command:cp “originalname.vmx” “newname.vmx”
- Edit the copied configuration file, such as (newname.vmx), using the vi editor:vi “newname.vmx”Note: For VMware ESX hosts, the nano editor is also available. If you are uncomfortable using the vi editor, seek assistance from a Linux/Unix administrator or file a Support Request and contact VMware Technical Support.
- Within the configuration file, modify all old instances of the virtual machine’s file names to the new file names. There should be at least the following to adjust:nvram = “originalname.nvram”
displayName = “originalname”
extendedConfigFile = “originalname.vmxf”
scsi0:0.fileName = “originalname.vmdk”
[…]
migrate.hostlog = “./originalname-UUID.hlog”Repeat this process for each virtual machine disk. Such as:
scsi0:1.fileName = “originalname_1.vmdk”
scsi0:2.fileName = “originalname_2.vmdk”Correct the VMkernel swap file reference:
sched.swap.derivedName = “/vmfs/volumes/DatastoreUUID/originalname/originalname-UUID.vswp
To
sched.swap.derivedName = “/vmfs/volumes/DatastoreUUID/newname/newname-UUID.vswp
Note: Be sure to rename both the .vswp file and the directory name for the swap file, bolded above.
- 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 for the .vmx configuration file, to the new names desired. For example:mv “originalname.nvram” “newname.nvram”
- Change directory to the parent directory using cd .. and rename the directory for the virtual machine:mv “originalname” “newname”
- Using the VMware vSphere Client, browse the datastore and navigate to the renamed virtual machine directory.
- Right-click on the virtual machine’s configuration file (.vmx) and choose Add to inventory.Alternatively, you can use this command to inventory the virtual machine:vmware-cmd -s register “/vmfs/volues/DatastoreName/newname/newname.vmx”
- Power on the virtual machine.
- A question for the virtual machine displays in the Summary tab during power-on. Review the question by:
- Clicking the Summary tab
- Right-clicking the virtual machine in your inventory and selecting 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 towards MAC address changes, and virtual machine backups that rely on UUIDs.
Additional Information
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. For a virtual machine named “Original VM (1)”:
“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.
Disclaimer.
The information in this article is provided “AS IS” with no warranties, and confers no rights. This article does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.