CesarTabares
Enthusiast
Enthusiast

Change the name of files and folders in datastores

Jump to solution

Is it safe while a VM is running to change the name of VMDK files and folders in a datastore?

I discovered that a VMs VMDK files have a different name than the VM itself, so someone must have changed the name of the VM after creating the disks

0 Kudos
1 Solution

Accepted Solutions
fugrat1
Enthusiast
Enthusiast

I have had to do this a few times so will try to document the process I followed.  If you have numerous datastores then make a note of which datastore the machine sits in.  The next step is to unregister the VM from vCenter / ESXi

Then you need to enable SSH on your ESXi host

Use Putty or something similar to connect to the ESXi host

Run the following commands (in italics)

cd /vmfs/volumes/<datastore name> ie if the datastore containing the VM is named datastore1 then you would run cd /vmfs/volumes/datastore1

Next run ls to check that the VM folder is there

Rename the folder using mv <oldVMFoldername> <newVMFoldername>

Change into the folder with cd <NewVMFoldername>

Rename the nvram, vmsd, vmx and <VMname-xxxx.hlog> files by running mv again ie

mv oldname.nvram newname.nvram

mv oldname.vmsd newname.vmsd

mv oldname.vmx newname.vmx

mv oldname-1234.hlog newname-1234.hlog

Rename the vmdk file with vmkfstools -E oldname.vmdk newname.vmdk

Edit the vmx file with vi newname.vmx

Change the references from oldname to newname within this file

Register the VM with the ESXi server and it should power on ok

This link gives more detail and other methods VMware KB: Renaming a virtual machine and its files in VMware ESXi and ESX

View solution in original post

0 Kudos
5 Replies
fugrat1
Enthusiast
Enthusiast

I don't think you will be able to change the names whilst the VM is running as the files will be in use.  If you want to rename the VM files you will need to use vmkfstools to rename the disk files and will need to modify the relevant files within the vmx file

If you are just renaming the folder that contains the VM I think you will just need to unregister the VM, rename the folder then re-register

0 Kudos
martinriley
Hot Shot
Hot Shot

KB1002491 gives more details

Hope this helps

vM

-----------------------

VCAP-DCD / VCAP-DCA / VCP-CLOUD / VCP-DT / VCP5 / VCP4

-----------------------

vMustard.com

0 Kudos
CesarTabares
Enthusiast
Enthusiast

What you say looks correct. I tested with a VM not in use, and renaming the files is only possible offline, but after renaming, the new filepath is not registered in the VM settings so that has to be changed aswell. It just says it cannot find the VMDK file when I try to start the VM.

Is it possible to do this change within the vSphere Web client? I tried uploading a modified version of the VMX file, but that did not work. I haven't used vmkfstools before. It would be nice if someone could send a link to the documentation for this in particular.

0 Kudos
fugrat1
Enthusiast
Enthusiast

I have had to do this a few times so will try to document the process I followed.  If you have numerous datastores then make a note of which datastore the machine sits in.  The next step is to unregister the VM from vCenter / ESXi

Then you need to enable SSH on your ESXi host

Use Putty or something similar to connect to the ESXi host

Run the following commands (in italics)

cd /vmfs/volumes/<datastore name> ie if the datastore containing the VM is named datastore1 then you would run cd /vmfs/volumes/datastore1

Next run ls to check that the VM folder is there

Rename the folder using mv <oldVMFoldername> <newVMFoldername>

Change into the folder with cd <NewVMFoldername>

Rename the nvram, vmsd, vmx and <VMname-xxxx.hlog> files by running mv again ie

mv oldname.nvram newname.nvram

mv oldname.vmsd newname.vmsd

mv oldname.vmx newname.vmx

mv oldname-1234.hlog newname-1234.hlog

Rename the vmdk file with vmkfstools -E oldname.vmdk newname.vmdk

Edit the vmx file with vi newname.vmx

Change the references from oldname to newname within this file

Register the VM with the ESXi server and it should power on ok

This link gives more detail and other methods VMware KB: Renaming a virtual machine and its files in VMware ESXi and ESX

View solution in original post

0 Kudos
CesarTabares
Enthusiast
Enthusiast

I have not tested this, but I trust this as the correct way to do it. I have tried a few steps via the Web client, but it seems from all articles I have found that command based tools is the way to do this. Thank you for the help

0 Kudos