How to Use Hyper-V to quickly copy lab virtual machines in batches

Source: Internet
Author: User
Tags virtual environment

I haven't updated my blog for a long time. Of course, some of the reasons are due to the lazy inertia caused by my vacation. The more important reason is the need for work, recently, the design and research of the content and methods of the new phase of activities have been closed, and the script of some key parts has been completed; one of the most important parts is the architecture and design of the front and back-end work of the virtual lab. Today, I will share with you a blog about a technical problem that must be overcome and solved in our virtual lab and how to design and solve it. I hope it will inspire you. The specific project design is relatively complex. the technical part of the project involves the design of virtual network isolation, storage system, concurrent Remote Desktop Connection, automated deployment, front-end and back-end, and many other parts, here we only store one step in one Sub-Unit.) Our experiment takes into account the need to deploy the initial experiment environment to several backend Hyper-V server virtualization platforms through automated batch deployment, it takes GB to compute the source VHD and differential disk snapshot avhd with a complete training environment. It is very easy to import and export a single completely self-contained environment, using Powershell to export and import lelets can be easily solved. However, just imagine that a self-contained experiment environment on our experimental platform has a huge capacity of GB, if you run about 10 such environments on the server, the initial deployment scale will increase to nearly 3 TB, obviously, the space usage and the import speed during deployment become unacceptable. Is there any better way? In the early stage, I considered whether differential disks can be used to reduce the space investment and deployment time. However, new problems arise one after another. If a differential disk is used to create a new virtual machine, in this way, the configuration in each independent environment needs to be restored in the later script, which is highly complex. Finally, after thinking and testing, I found a solution. The general idea is as follows: I changed the environment of the above experiment to five full source full Virtual Disks (vhd), which correspond to five snapshot disks (avhd) or different disks respectively. Why? After reading this practice process, I believe you will be clear: :) it seems that if you need to create 10 sets of environments, this will not only save much space, but it seems to be superfluous and there is more space, which is obviously not worth the candle, however, at this time, the MKlink function provided by the OS will be used, and the speed will be very advantageous. How can this problem be solved? In fact, there is a parent-level relationship between a full disk and a different disk. Let's take a test environment: the interface shows that the environment containing snapshots is actually the same) 650) this. width = 650; "title =" image "style =" border-left-0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/19114a1b-0.png "width =" 510 "height =" 373 "data-pini T = "registered"/> through Powershell, you can also see: 650) this. width = 650; "title =" image "style =" border-left-0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911493613-1.png "width =" 664 "height =" 444 "data-pinit =" registered "/> If you export a configuration What is the virtual opportunity that sets differential disks? Let's test it and see: What are exported by visual testing? The Hyper-V Virtual Machine exports three directories, one snapshot directory, one disk directory, and the other XML file directory of the virtual machine configuration file for import. 650) this. width = 650; "title =" image "style =" border-left-0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911495262-2.png "width =" 713 "height =" 524 "data-pinit =" registered "/> the disk directory contains full parent disk win2008r2-30G.vhd and differential disk cdltmg. Vhd, what we need to do is to find a way to bypass copying the parent disk for 10 times. Remember, "although there is more than one character,"!" Drama "started:" What we need to do is to put the Parent disk in a directory separately. For example, to move the Parent disk to the Parent directory under the Parent directory, in this way, only the differential disk is retained under the Virtual Disk directory in the export directory. So, 10 identical experimental Virtual Machine environments need to be generated? Haha, just copy the Export directory 10 times! The copy time space is guaranteed (because we only need to copy the differential disk). Of course, there are two prerequisites: 1. because the differential disk system needs to read the master disk at startup, the stress of concurrent reading is very high in the disk system. Therefore, even if more virtual machines can be copied, the more space is saved, we cannot copy without limit. Because I use SSD for CacheCade, I have created 10 different disk environments. 2. in my environment, the virtual environment Used for copying can be the same host name, IP address, etc.), because for the purpose of the experiment, I only need to deploy the same environment for the user who is doing the experiment, when importing a virtual machine, I will import it in the same place and create an independent Private virtual switch for each virtual machine. However, if you do similar operations in the actual environment, well, you need to design how to import the copied virtual machine environment to the Host Name, IP address, and other factors that need to be reconfigured. Now let's look at my basic test cases. Later scripts are developed based on this experiment. 1. first, copy the parent disk to an independent directory 650 in the Export directory.) this. width = 650; "title =" image "style =" border-left-0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/19114a4C-3.png "width =" 712 "height =" 152 "data-pinit =" registered "/> 2. copy does not contain a copy of the exported files from the parent disk to the new directory. For example, copy cdltmg from the export to cdltmg1 650) this. width = 650; "title =" image "style =" border-left-0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201304/11/3377405_1365647990lC77.png "width =" 725 "height =" 205 "data-pinit =" registered "/> there are two branch implementation method: a) create a symbolic link for the parent disk for the copied directory. here we need to use the MKlink tool that comes with the system: MKlink is a self-carried symbolic link tool in Microsoft system, windows Server 2008/2008 R2/2012, Windows Vista/Windows 7/Windows 8 systems are available, please refer to http://technet.microsoft.com/en-us/library/cc753194 (v = ws.10 ). aspx we need to create a symbolic link to the source Parent disk at the virtual machine disk location in the copied directory and point it to the full Parent disk 650 in the Parent directory under the Parent directory) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201304/11/3377405_1365647993lQCP.png "height =" 638 "data-pinit =" registered "/> On the GUI, you can also see the symbolic link file. Observe its size and you will know why we are doing this: 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911495345-6.png "height =" 482 "data-pinit =" registered "/> B) using Hyper-V to Repair Disk tools or WMIWMI is a solution we will solve later through scripts or C # which will not be discussed here)

  • In the Hyper-V management interface, choose check disk 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911491008-7.png "height =" 272 "data-pinit =" registered "/>
  • Differential virtual disk in the exported directory of the copy
650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911494229-8.png "height =" 475 "data-pinit =" registered "/>
  • The system prompts that the connection to the Parent disk of the differential disk is lost. Of course, because the Parent disk is stored in the Parent directory, We need to click "reconnect ".
650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911495963-9.png "height =" 437 "data-pinit =" registered "/>
  • Specify the Parent disk in the Parent directory, and select the effect after reconnecting and completing the connection.
650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911493494-10.png "height =" 410 "data-pinit =" registered "/> 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911496242-11.png "height =" 406 "data-pinit =" registered "/> OK, after completing any of the branch steps, there is still a problem. The copied virtual machines all have a unified Virtual Machine Global ID, therefore, this will cause the Virtual Machine for batch copy import to be considered by Hyper-V as the same virtual machine and the import is rejected! 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911494918-12.png "height =" 424 "data-pinit =" registered "/> therefore, another small Trick must be launched. We all know that the UUID and name of this Virtual Machine are saved in the XML file generated in the Virtual Machine during export. Therefore, we need to analyze the file format and make differentiated changes to complete the import, and then use the script in the actual project to complete the Parse and modification of the XML file, here is an example. You only need to modify these three locations! Configuration-> Properties-> global_id (modify the unique Virtual Machine ID) Configuration-> Properties-> name (modify the name of the imported virtual machine) settings-> Global-> logical_id (modify the unique ID of the VM) 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg /131227/1911493127 -13.png "height =" 448 "data-pinit =" registered "/> 4. OK, all the modifications are complete. The last mile of work is to import the virtual machine. See if it meets expectations? In this step, I am a little lazy and didn't take the entire import process. The import method is roughly described. You only need to import and register a new Virtual Machine ID in the same place, the import is completed in an instant! (Why is the speed so fast and you do not need to copy the Virtual Machine and register a new Virtual Machine ID? You must have the answer.) Now, let's take a look at the following. A virtual machine generated by fast replication has been successfully deployed at.) If you need to deploy it in batches, you can do the above. In fact, the above method also has a variant, that is, to directly generate a different disk as needed, in addition to combining the modified virtual machine environment, you also need to change each disk in each virtual machine environment to a different disk, and then copy it and import it. This method is essential for basic environments with no disk differences !) 650) this. width = 650; "title =" image "style =" border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; padding-right: 0px "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131227/1911492114-14.png "height =" 208 "data-pinit =" registered "/>
At the end of the article, the hard work I have done is only the design of a special quick deployment experiment environment case, in actual projects, we should consider using a sysprep System VM as the source point, and use mature System Center technology to build and customize service templates; however, what I have to say is to address some special environmental requirements at this stage. Sometimes some work ing practices can also achieve twice the result with half the effort! There is no final implementation script provided here. In fact, I feel that the problems encountered and solutions seem more meaningful!
HTH, Hope This Help :-)

This article is from the "walking in the cloud" blog, please be sure to keep this source http://3387405.blog.51cto.com/3377405/1175886

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.