So you have created many virtual machines in Hyper-V manager and suddenly you want to move one of them in a new HDD or just rename the folder holding it, you will find that this is not a trivial task! Hyper-V management service holds an open handle to the XML file describing the virtual machine settings so you cannot change it in any way. The out of the box method is to export the VM to another folder and then re-import it from that folder to a new one, while this works great sometimes it is not applicable specially if the VM size is huge and you have no disk space to replicate it (since the export would replicate the VHD of the VM) so how to do it, well here you go follow these steps:
1. Stop or shut down your VM (you cannot save its state!)
2. Stop the Hyper-V management service from the management console
3. Once it is stopped browse to the folder “C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines”
4. You will find a symbolic link file to the XML settings file of the VM with the same name just rename it to any other name:
5. Then move the VM to the new folder or rename the folder (do your thing).
6. Once the VM is moved then open a new command prompt as an administrator and then type the command
C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines>mklink 0B142A56-4B3F-4AE5-88E5-AC21B33CE290.xml "<VM new path>\0B142A56-4B3F-4AE5-88E5-AC21B33CE290.xml"
7. Then right click on the newly created symbolic link file and then click security tab and edit. You need to give the local users full control over this created file as shown below:
8. Now go back to the computer management and start the service again
9. Now you will find your VM moved and ready to start.
The only limitation here is that you lose any saved states (I still do not know why but I am planning to look it over).
Great post. Thanks for sharing.
Awesome. Worked like a champ. You are the man!
Thank you Mohamed, this just saved me a lot of heartache.
Mohamed, did you ever find out how to preserve the Saved States ? or how you can get them back after your procedure above ?
If i just want to rename the VM, can I just stop the Hyper-V services and rename the folder and files? In this case do I need to do anything with the .xml file? Thanks.
If you want to rename the VM you can just do this from the administration console. Right click and then rename. and in this case you should not do anything to the files or folders.
thanks for your response. We need to change all of our VM's and server's names and would like to the folders and files have the same new names for future management. Do I need to mslink the .xml file if I just rename the folders and vhd file. Thanks.
In this case yes you need to change the mslink as this would be a move of the VM from a location to another.
One comment regarding the snapshots, If there are some snapshots you must make the same changes. You must rebuild the symbolic links from C:\ProgramData\Microsoft\Windows\Hyper-V\Snapshots.
Mohamed, Thanks for your information. This is very helpful and I have successfully renamed my test VM. This is better than the import and export method.
tremendous... simply tremendous. I had come very close to this. Excpect i used explorer to create the link and didn't permission users. i'm saving this post as a PDF for later. There will be lots of occasions.
update: i was getting errors trying to star the VMs after having moved the VM/VHD to another volume. The creation of the Symbolic links as stated above worked for me to import the VM into the Hyer-V console, however, when attempting to start the VM, i would get access denied or "General" access errors. When comparing NTFS perms on the original symbolic links with the symbolic links i created i noticed that the original links had the VM GUID permissioned with Full control.
So i did a bit of digging around and it turns out that the VM's guid needs to be permissions on the new symbolic link AND the moved VHD, apparently you can only do this via icacls.
such as, for the symbolic links (assuming working directory is "%programdata%\microsoft\windows\hyper-v\virtual machines"):
icacls .xml /grant "NT VIRTUAL MACHINE\":F
and for the VHD (assuming workding directory is the folder containing the VHD):
icacls .vhd /grant "NT VIRTUAL MACHINE\":F
here's a reference related to perms on the VHD (http://support.microsoft.com/kb/2249906)
Christmas came early this year...
What a pain in the rear... Thanks MS... well thought out. You build in a Wizard to move to different HOSTS yet it is exceedingly tiresome to simply move to another folder on the same machine :(
Use Import virtual machine, you dont have to export it. IF you already have moved the VHDs and xmls 1) Rename files in C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines 2) Import virtual machine, point to new location where files already are etc.
Choose option "Register" (not restore or copy) Thats it. (unless I missed what the real problem was)