{"id":2104,"date":"2017-05-12T18:59:16","date_gmt":"2017-05-12T18:59:16","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2104"},"modified":"2017-05-12T18:59:16","modified_gmt":"2017-05-12T18:59:16","slug":"cloning-vms-in-hyper-v","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2104","title":{"rendered":"Cloning VMs in Hyper-V"},"content":{"rendered":"<div class=\"Mu SP\">It\u2019s a common enough scenario: build one template machine and then mirror that to make a testlab, so you\u2019d think this would be a built-in feature of Hyper-V, but its not.<\/div>\n<div class=\"Mu SP\"><\/div>\n<div class=\"Mu SP\">Luckily, it\u2019s not too hard to do once you know how, and I\u2019ll guide you through the tough parts<\/div>\n<h4 class=\"Mu SP\">Overall process<\/h4>\n<div class=\"Mu SP\">We\u2019ll be following these steps to get clones of our master VM.<\/div>\n<ul>\n<li class=\"Mu SP\">Create a source\/master VM and install all common software and features on it<\/li>\n<li class=\"Mu SP\">Prepare it for imaging using sysprep<\/li>\n<li class=\"Mu SP\">Shutdown the source VM and remove it from Hyper-V<\/li>\n<li class=\"Mu SP\">Create differencing disks using the Source VM\u2019s VHD as the parent disk<\/li>\n<li class=\"Mu SP\">Create new VMs, using the newly created differencing disk<\/li>\n<\/ul>\n<h5>CREATE A SOURCE VM<\/h5>\n<p>To begin,\u00a0create a new VM and name its VHD something like master or template. \u00a0We\u2019ll be building this one as the source for our VMs, and will eventually have to shut it down and never turn it back on again. \u00a0If we accidentally delete the VHD for it, or start it up again, we can make changes to it which will break all of our clones.<\/p>\n<p>So make sure you give it a name that will remind you to not delete this guy!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-3734\" src=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=636\" sizes=\"(max-width: 530px) 100vw, 530px\" srcset=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png 530w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=150 150w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=300 300w\" alt=\"master\" data-attachment-id=\"3734\" data-permalink=\"https:\/\/foxdeploy.com\/2016\/06\/08\/cloning-vms-in-hyper-v\/master\/\" data-orig-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=636\" data-orig-size=\"530,229\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"master\" data-image-description=\"\" data-medium-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=636?w=300\" data-large-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/master.png?w=636?w=530\" \/><\/p>\n<p>Install Windows and whatever common apps you\u2019ll want your source machine to use, and when you\u2019ve got it to the point that you\u2019re ready to copy it out\u2026<\/p>\n<h5>SYSPREP OUR VM<\/h5>\n<p>In our scenario here, we\u2019ve built a source image and want to put it on other VMs. \u00a0Imagine if we wanted to push it down to multiple different laptops and desktops, however. \u00a0In that case, we\u2019d need to ensure that all Hyper-V specific drivers and configurations are removed. \u00a0We also need Windows to run through the new user Out of Box Experience (OOBE), when Windows detects hardware and installs the right drivers, etc.<\/p>\n<p>In the Windows world, particularly if machines are in an Active Directory Domain, you need to ensure that each machine has a globally unique identifier called a System Identifier, or SID. \u00a0This SID is created by Windows automatically during the OOBE process. \u00a0If you try joining two machines with the same SID to an AD Domain, you\u2019ll get an error and it won\u2019t be allowed, as a potential security risk.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-3733\" src=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=636\" sizes=\"(max-width: 485px) 100vw, 485px\" srcset=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png 485w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=150 150w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=300 300w\" alt=\"duplicateSID\" data-attachment-id=\"3733\" data-permalink=\"https:\/\/foxdeploy.com\/2016\/06\/08\/cloning-vms-in-hyper-v\/duplicatesid\/\" data-orig-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=636\" data-orig-size=\"485,263\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"duplicateSID\" data-image-description=\"\" data-medium-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=636?w=300\" data-large-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/duplicatesid.png?w=636?w=485\" \/><\/p>\n<p>To avoid this, and because it\u2019s a best practice, we\u2019re gonna sysprep this badboy.<\/p>\n<p>Also, I should note that there\u2019s no going back. \u00a0Once we sysprep this machine, it will shutdown and we\u2019re done with it. \u00a0If we turn it back on, we\u2019re \u2018unsealing\u2019 the image and need to sysprep again.<\/p>\n<h6>HOW TO SYSPREP A MACHINE<\/h6>\n<p>Once all of the software is installed, launch an administrative command prompt and browse to C:\\windows\\system32\\sysprep.exe, and then select \u2018Enter System Out of Box Experience\u2019 and Generalize. \u00a0Under Shutdown Options, choose \u2018Shutdown\u2019<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-3736\" src=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=636\" sizes=\"(max-width: 349px) 100vw, 349px\" srcset=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png 349w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=150 150w, https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=300 300w\" alt=\"sysprep\" data-attachment-id=\"3736\" data-permalink=\"https:\/\/foxdeploy.com\/2016\/06\/08\/cloning-vms-in-hyper-v\/sysprep\/\" data-orig-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=636\" data-orig-size=\"349,270\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sysprep\" data-image-description=\"\" data-medium-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=636?w=300\" data-large-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/sysprep.png?w=636?w=349\" \/><\/p>\n<p>When this completes, your VM will shutdown.<\/p>\n<h5>SHUTDOWN AND REMOVE<\/h5>\n<p>At this point, remove the source VM from Hyper-V. \u00a0This will leave the files on disk, but delete the VM configuration. \u00a0You\u00a0<strong>could\u00a0<\/strong>leave the VM in place, just remember to never boot it again. \u00a0If you boot the parent vm, it will break the chain of differencing.<\/p>\n<h5>CREATE DIFFERENCING DISKS &amp;\u00a0CREATE NEW VMS<\/h5>\n<p>You could do this by hand in the console, or you could just run this PowerShell code. \u00a0Change line 2 <code>$srcVHDPath<\/code>\u00a0to point to the directory containing your parent VHD.<\/p>\n<p>Change line 4 <code>$newVHDPath<\/code>\u00a0to point to where you want the new disk to go. \u00a0This will create a new Differencing VHD, based off of the parent disk. \u00a0This is awesome because we will only contain the changes to our image in the differencing disk. \u00a0This lets us scale up to having a LOT of VMs with a small, small amount of disk space.<\/p>\n<p>Finally, change line 8 <code>-Name NewName<\/code>\u00a0to be the name of a VM you\u2019d like to create.<\/p>\n<div>\n<div id=\"highlighter_566271\" class=\"syntaxhighlighter  powershell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell comments\">#Path to our source VHD<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"powershell variable\">$srcVHDPath<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell string\">\"D:\\Virtual Hard Disks\\Master.vhdx\"<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"powershell comments\">#Path to create new VHDs<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"powershell variable\">$newVHDPath<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell string\">\"D:\\Virtual Hard Disks\\ChildVM.vhdx\"<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"powershell functions\">New-VHD<\/code> <code class=\"powershell color1\">-Differencing<\/code> <code class=\"powershell color1\">-Path<\/code> <code class=\"powershell variable\">$newVHDPath<\/code> <code class=\"powershell color1\">-ParentPath<\/code> <code class=\"powershell variable\">$srcVHDPath<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"powershell functions\">New-vm<\/code> <code class=\"powershell color1\">-Name<\/code> <code class=\"powershell string\">\"NewName\"<\/code> <code class=\"powershell color1\">-MemoryStartupBytes<\/code> <code class=\"powershell plain\">2048MB<\/code> <code class=\"powershell color1\">-VHDPath<\/code> <code class=\"powershell variable\">$newVHDPath<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"Mu SP\">That\u2019s all folks!<\/div>\n<div class=\"Mu SP\"><\/div>\n<div class=\"Mu SP\">If you wanted to create five VMs, you\u2019d just run this:<\/div>\n<div class=\"Mu SP\"><\/div>\n<div class=\"Mu SP\">\n<div>\n<div id=\"highlighter_440761\" class=\"syntaxhighlighter  powershell\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"powershell keyword\">ForEach<\/code> <code class=\"powershell plain\">(<\/code><code class=\"powershell variable\">$number<\/code> <code class=\"powershell keyword\">in<\/code> <code class=\"powershell plain\">1..5){<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"powershell comments\">#Path to our source VHD<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"powershell variable\">$srcVHDPath<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell string\">\"D:\\Virtual Hard Disks\\Master.vhdx\"<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"powershell comments\">#Path to create new VHDs<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"powershell variable\">$newVHDPath<\/code> <code class=\"powershell plain\">= <\/code><code class=\"powershell string\">\"D:\\Virtual Hard Disks\\ChildVM0$number.vhdx\"<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"powershell functions\">New-VHD<\/code> <code class=\"powershell color1\">-Differencing<\/code> <code class=\"powershell color1\">-Path<\/code> <code class=\"powershell variable\">$newVHDPath<\/code> <code class=\"powershell color1\">-ParentPath<\/code> <code class=\"powershell variable\">$srcVHDPath<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"powershell functions\">New-vm<\/code> <code class=\"powershell color1\">-Name<\/code> <code class=\"powershell string\">\"ChildVM0$number\"<\/code> <code class=\"powershell color1\">-MemoryStartupBytes<\/code> <code class=\"powershell plain\">2048MB<\/code> <code class=\"powershell color1\">-VHDPath<\/code> <code class=\"powershell variable\">$newVHDPath<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"powershell plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"Mu SP\"><\/div>\n<div class=\"Mu SP\"><img decoding=\"async\" class=\"alignnone wp-image-3737 size-full\" src=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/fivevmsinfivesecs.gif?w=636\" alt=\"FiveVmsinFiveSecs\" data-attachment-id=\"3737\" data-permalink=\"https:\/\/foxdeploy.com\/2016\/06\/08\/cloning-vms-in-hyper-v\/fivevmsinfivesecs\/\" data-orig-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/fivevmsinfivesecs.gif?w=636\" data-orig-size=\"859,433\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"FiveVmsinFiveSecs\" data-image-description=\"\" data-medium-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/fivevmsinfivesecs.gif?w=636?w=300\" data-large-file=\"https:\/\/foxdeploy.files.wordpress.com\/2016\/06\/fivevmsinfivesecs.gif?w=636?w=636\" \/><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s a common enough scenario: build one template machine and then mirror that to make a testlab, so you\u2019d think this would be a built-in feature of Hyper-V, but its not. Luckily, it\u2019s not too hard to do once you know how, and I\u2019ll guide you through the tough parts Overall process We\u2019ll be following [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,53],"tags":[],"class_list":["post-2104","post","type-post","status-publish","format-standard","hentry","category-server-virtualization-hyper-v-2","category-virtualization-virtual"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2104"}],"version-history":[{"count":1,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2104\/revisions"}],"predecessor-version":[{"id":2105,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2104\/revisions\/2105"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}