{"id":1771,"date":"2016-05-21T04:46:13","date_gmt":"2016-05-21T09:46:13","guid":{"rendered":"http:\/\/swildow.darktech.org\/wp\/?p=1771"},"modified":"2016-05-21T04:46:13","modified_gmt":"2016-05-21T09:46:13","slug":"relocating-a-hyper-v-vm-folder","status":"publish","type":"post","link":"http:\/\/www.wildow.com\/blog\/?p=1771","title":{"rendered":"Relocating a Hyper-V VM Folder"},"content":{"rendered":"<p>Relocating a Hyper-V VM Folder<\/p>\n<p><a href=\"https:\/\/doquent.wordpress.com\/2012\/09\/02\/relocating-a-hyper-v-vm-folder\/\">https:\/\/doquent.wordpress.com\/2012\/09\/02\/relocating-a-hyper-v-vm-folder\/<\/a><\/p>\n<p>In my Hyper-V setup, I had spaces in the VM names (what we see in the server manager), which by default, also added spaces in folder names where the VHD and the other VM files were stored. When I started using PowerShell to work with the VMs, I had to use quotes around VM names because of the spaces. After some time, I decided to rename the VMs to have the same name as the network names of the VM (the names that can be pinged), which had no spaces. This renaming appeared to be a simple task because there was a right-click &gt; Rename option.<\/p>\n<p>I renamed the VMs easily and got rid of the spaces in the names. However, the folder paths and the VHD names remained unchanged and continued to use the old names with spaces. While my original problem had been resolved, the discrepancy in the VM name and the file\/folder names was a new annoyance to me even though I could have ignored it quite easily. If I rename a folder\/file (portion of path), I essentially get a new path for the files\/folders.<\/p>\n<p>Now, there may be situations where I would actually want to move the VM files from one location to another. Suppose that the disk on which the VM files exist is getting filled up and I need to expand the disk for one of the VMs. In this case, I would like to relocate the files to another drive. In another situation, I might want to distribute my existing VMs to different physical disks to minimize the I\/O contention as multiple VMs run concurrently. In both these cases, I need to move the files for an existing VM from one location to another.<\/p>\n<p>There are probably other alternatives to the approach that I adopted. The steps described below just summarize what worked for me and may or may not work in other situations. The following steps accomplished this change for me:<\/p>\n<p>Shut down the VM<br \/>\nBack up the VM folder.<br \/>\nIf there are any snapshots for the VM, delete the snapshots. This step may or may not be necessary, but I suspect that there must be references to the AVHD files which are likely to be broken by path changes.<br \/>\nWait for merge to complete (A merge is indicated by a \u201cCancel Merge in progress \u2026\u201d button in the Actions pane for the VM. A merge combines the VHD and AVHD files into one VHD file. After the merge is complete, the cancel button disappears and the AVHD files also disappear from the disk.<br \/>\nCreate the new VM folder, and move the VHD file to the new folder.<br \/>\nRename the VHD file now, if renaming the VHD is desired for any reason.<br \/>\nIn the Hyper-V manager, open settings for the VM.<br \/>\nUnder Hardware &gt; IDE Controller x &gt; Hard Drive, change the path of the VHD file by browsing to the new location\/name of the VHD file.<br \/>\nUnder Management &gt; Snapshot File Location, select the new path to the base VM folder. Carefully look at the path before changing it so as to keep it at the same level.<br \/>\nStop Hyper-V service in Windows Services.<br \/>\nMove the remaining contents of the VM folder to the new location.<br \/>\nHyper-V internally tracks the location of the VM folder\/files using symlinks stored in C:\\ProgramData\\Microsoft\\Windows\\Hyper-V. The link to the VM under consideration needs to be updated.<br \/>\nUsing Windows Explorer or Command line, do the following<br \/>\nFind the symlink with its name matching the VM ID. It is a long ID with xml extension. It can be matched easily by looking at the file with identical name (as the symlink) in the VM folder.<br \/>\nMove this link out of this folder as a backup.<br \/>\nRemove the file with the same name from the cache folder \u2013 C:\\ProgramData\\Microsoft\\Windows\\Hyper-V\\Virtual Machines Cache<br \/>\nStart cmd (Run as Administrator), and run the following commands after inserting the correct VM ID and pathin the commands<br \/>\ncd C:\\ProgramData\\Microsoft\\Windows\\Hyper-V\\Virtual Machines<br \/>\nmklink &lt;VM_ID&gt;.xml &#8220;&lt;PATH_TO_VM_FOLDER&gt;\\Virtual Machines\\&lt;VM_ID&gt;.xml&#8221;<br \/>\nThe output of this command looks like:<br \/>\nsymbolic link created for &lt;VM_ID&gt;.xml &lt;&lt;===&gt;&gt; &lt;PATH_TO_VM_FOLDER&gt;\\Virtual Machines\\&lt;VM_ID&gt;.xml<br \/>\nFix permissions on the symlink and the file using the following commands:<br \/>\nicacls &lt;VM_ID&gt;.xml \/grant &#8220;NT VIRTUAL MACHINE\\&lt;VM_ID&gt;&#8221;:F<br \/>\nicacls &lt;VM_ID&gt;.xml \/grant &#8220;NT VIRTUAL MACHINE\\&lt;VM_ID&gt;&#8221;:F \/L<br \/>\nStart the Hyper-V service<br \/>\nIf VM renaming is desired, rename the VM using right-click &gt; Rename In Hyper-V Manager<br \/>\nStart the VM<br \/>\nVerify that everything is working normally.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Relocating a Hyper-V VM Folder https:\/\/doquent.wordpress.com\/2012\/09\/02\/relocating-a-hyper-v-vm-folder\/ In my Hyper-V setup, I had spaces in the VM names (what we see in the server manager), which by default, also added spaces in folder names where the VHD and the other VM &#8230; <a class=\"more-link\" href=\"http:\/\/www.wildow.com\/blog\/?p=1771\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1771"}],"collection":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1771"}],"version-history":[{"count":1,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions"}],"predecessor-version":[{"id":1772,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1771\/revisions\/1772"}],"wp:attachment":[{"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wildow.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}