• Advertisement

vSphere all - ESXi 3.5+ - Rename virtual machine folder/files on a datastore

Anything related to VMware vSphere. Articles are posted in "vSphere Version - vSphere Component - Subject" format.

vSphere all - ESXi 3.5+ - Rename virtual machine folder/files on a datastore

Postby lmmtux » Fri Mar 07, 2014 4:29 pm

Sometimes a virtual machine's folder name or VMDK file is named incorrectly. There is a way to fix these, but it involves taking the virtual machine offline.


Renaming a virtual machine disk file (VMDK):

  1. Navigate to the virtual machine in vSphere Client.
  2. Right-click on the virtual machine, and select "Remove from Inventory". Note: Do not select "Delete from Disk"!
  3. Open a ESXi shell either locally on the ESXi host or with SSH. Note: You may need to enable the ESXi Shell or SSH first. Check the VMware documentation on steps to do this.
  4. Change directory (cd) to the virtual machine folder (cd /vmfs/volumes/datastorename/virtualmachinefolder).
  5. Run a vmkfstools command to perform the VMDK file rename:
    Code: Select all
    vmkfstools -E "originalname.vmdk" "newname.vmdk"

    Where "originalname.vmdk" is the current filename, and "newname.vmdk" is the name to rename to.
  6. Optional: If you need to also rename the .vmx file (virtual machine settings file), use the Unix mv command. For example:
    Code: Select all
    mv originalname.vmx newname.vmx
  7. Use the "vi" utility to edit the .vmx file to update the VMDK references. Check online for vi commands if you are not familiar with it. While the .vmx file is open in vi:
    • Locate each instance in the file that references the old VMDK file name, and rename it to the new VMDK file name.
    • Be careful with the .vswp file as it contains extra characters. Leave the extra characters in the file name, and only change the text that contains the old file name, with the new file name. Leave the extra characters in the file name.
  8. If you also need to rename the virtual machine folder, follow the instructions in the next section. Otherwise skip to the bottom section for "adding the virtual machine back to the host".


Renaming a virtual machine folder:

  1. Navigate to the virtual machine in vSphere Client.
  2. Right-click on the virtual machine, and select "Remove from Inventory". Note: Do not select "Delete from Disk"!
  3. Open a ESXi shell either locally on the ESXi host or with SSH. Note: You may need to enable the ESXi Shell or SSH first. Check the VMware documentation on steps to do this.
  4. Change directory (cd) to the datastore that contains the virtual machine folder (cd /vmfs/volumes/datastorename).
  5. Rename the folder with the Unix mv command. For example:
    Code: Select all
    mv originalfoldername newfoldername


Adding the virtual machine back to the host

  1. In vSphere Client, browse to the datastore where the virtual machine files are located.
  2. Navigate to the folder of the virtual machine.
  3. Right-click the .vmx file and select "Add to Inventory".
  4. The virtual machine should be added back to the host and can be powered on as normal.
lmmtux
 
Posts: 55
Joined: Mon Jul 30, 2012 9:40 pm
Reputation: 0

Return to VMware vSphere

cron