Tuesday 17 April 2012

How to rename a Virtual Machine and its Files

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 the virtual machine's files:

  1. Log in to VMware vSphere 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 a console to the ESX or ESXi host
  6. Navigate to the directory containing the virtual machine. For example: cd /vmfs/volumes/DatastoreName/originalname/.
  7. Rename the virtual disk (VMDK) files using the vmkfstools -E command.                                                        # vmkfstools -E "originalname.vmdk" "newname.vmdk"
  8. Copy the virtual machine configuration file (.vmx) using the command:
    # cp "originalname.vmx" "newname.vmx"

  9. Open the file new virtual machine configuration (for example, newname.vmx) in a text editor. For more information, see Editing configuration files in VMware ESX (1017022).

    For example:


    # vi "newname.vmx"

  10.  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 these to adjust:
    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
    : Be sure to rename both the .vswp file and the directory name for the swap file, bolded above.
  11. Correct any other remaining lines referencing the original path or file names.
  12. Save the file and exit the editor.
  13. Rename all the remaining files, except for the.vmxconfiguration file, to the new names desired.

    For example:

    # mv "originalname.nvram" "newname.nvram"
  14. Change directory to the parent directory:
    # cd ..

  15. Rename the directory for the virtual machine:
    # mv "originalname" "newname"
  16. Using VMware vSphere Client, browse the datastore and navigate to the renamed virtual machine directory
  17. Right-click on the virtual machine's new configuration file (for example, newname.vmx) and choose Add to inventory.

    Alternatively, you can use this command to inventory the virtual machine:

    # vmware-cmd -s register "/vmfs/volumes/DatastoreName/newname/newname.vmx"

  18. Power on the virtual machine.
  19. 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 toward MAC address changes, and virtual machine backups that rely on UUIDs.

  20. Optionally, delete the original virtual machine configuration file.

    For example:
    # rm /vmfs/volumes/DatastoreName/newname/originalname.vmx

No comments:

Post a Comment