Mud: kvm vm clone

Source: Internet
Author: User

This article is first published in the dark world.

The previous article introduced the creation and restoration of kvm vm snapshots. This article introduces the cloning of kvm vm.

You can perform the following steps to clone a kvm vm:

1. Use the virt-clone command to clone

2. Run the virsh edit command to modify the virtual machine's VNC connection port after cloning.

3. Configure the NIC of the cloned Virtual Machine

To clone a KVM Vm, run the virt-clone command. For instructions on how to use the virt-clone command, see the help documentation, for example:

650) This. width = 650; "Title =" clip_image001 "style =" 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 =" clip_image001 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227505eTA5.png "width =" 555 "Height =" 723 "/>

We strongly recommend that the original VM be shut down before cloning the VM.

Now we can use the following command to create a clone server of the Virtual Machine centos:

Virt-clone-O centos-N centos2-F/vhostdisk/centos2.img

This command is based on the virtual machine centos, the cloned virtual machine is centos2, and the hard disk of the virtual machine is/vhostdisk/centos2.img

650) This. width = 650; "Title =" clip_image002 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image002 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227506c7Xd.png "width =" 1200 "Height =" 83 "/>

650) This. width = 650; "Title =" clip_image003 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image003 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227506Z723.png "width =" 705 "Height =" 143 "/>

After cloning, you can view the information about centos2.

List -- all

650) This. width = 650; "Title =" clip_image004 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image004 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227506qUfr.png "width =" 445 "Height =" 242 "/>

You can see that centos2 already exists in the system. Now you can view the hard disk of centos2.

650) This. width = 650; "Title =" clip_image005 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image005 "src =" http://img1.51cto.com/attachment/201408/5/526870_14072275079SAo.png "width =" 551 "Height =" 361 "/>

Qemu-IMG info/vhostdisk/centos. img

We can clearly see that the hard disk format and size of the Virtual Machine centos2 are the same as that of the Virtual Machine centos.

Now the cloning is complete, but we cannot directly use the Virtual Machine centos2. First, edit the centos2 configuration file. Modify the connection Port Number of the VNC.

Edit centos2

650) This. width = 650; "Title =" clip_image006 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image006 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227507hTpW.png "width =" 505 "Height =" 59 "/>

650) This. width = 650; "Title =" clip_image007 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image007 "src =" http://img1.51cto.com/attachment/201408/5/526870_14072275071wwO.png "width =" 479 "Height =" 59 "/>

After the VNC port is modified, start the Virtual Machine centos2 as follows:

650) This. width = 650; "Title =" clip_image008 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image008 "src =" http://img1.51cto.com/attachment/201408/5/526870_14072275073B8Z.png "width =" 187 "Height =" 88 "/>

650) This. width = 650; "Title =" clip_image009 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image009 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227508Jyk7.png "width =" 659 "Height =" 546 "/>

After centos2 is started, run the ifconfig command as follows:

650) This. width = 650; "Title =" clip_image010 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image010 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227508mqma.png "width =" 596 "Height =" 312 "/>

We can clearly see that there is no Nic information.

Why is this happening? Because the VM centos2 is cloned through the VM centos, the NIC information of the VM centos2 is the same as that of the VM centos, so we need to modify the NIC information of centos2.

First, check the 70-persistent-net.rules file, which is used to store information about the NIC.

VI/etc/udev/rules. d/70-persistent-net.rules

650) This. width = 650; "Title =" clip_image011 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image011 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227508FXDw.png "width =" 745 "Height =" 427 "/>

We can clearly see the information about eth0 and eth1 Nic.

Now we can view the NIC configuration file information as follows:

More/etc/sysconfig/network-scripts/ifcfg-eth0

650) This. width = 650; "Title =" clip_image012 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image012 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227509zvpg.png "width =" 537 "Height =" 440 "/>

Note that the MAC address of the network adapter is the same as that of the eth0 network adapter in the 70-persistent-net.rules file. This is where we need to modify it.

It is inconvenient to edit two files now in the system, but we can append the content in the 70-persistent-net.rules file to the ifcfg-eth0 file through the following command and then modify it. As follows:

More/etc/udev/rules. d/70-persistent-net.rules>/etc/sysconfig/network-scripts/ifcfg-eth0

650) This. width = 650; "Title =" clip_image013 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image013 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227509NkG5.png "width =" 758 "Height =" 86 "/>

650) This. width = 650; "Title =" clip_image014 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image014 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227509cgzF.png "width =" 764 "Height =" 450 "/>

What we need to do now is allocate the MAC address of the eth1 Nic In the 70-persistent-net.rules file to the eth0 Nic, and then modify the IP address of the eth0 Nic.

650) This. width = 650; "Title =" clip_image015 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image015 "src =" http://img1.51cto.com/attachment/201408/5/526870_14072275102353.png "width =" 762 "Height =" 288 "/>

The final information of eth0 Nic configuration is as follows:

650) This. width = 650; "Title =" clip_image016 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image016 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227510uVl6.png "width =" 298 "Height =" 185 "/>

Eth0 Nic information, after modification. Now let's modify 70-persistent-net.rules. All we need to do is to comment out eth0 Nic In this file and change eth1 to eth0. As follows:

VI/etc/udev/rules. d/70-persistent-net.rules

650) This. width = 650; "Title =" clip_image017 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image017 "src =" http://img1.51cto.com/attachment/201408/5/526870_14072275107M5O.png "width =" 756 "Height =" 239 "/>

After the preceding modification, We need to restart the VM centos2. You can run the following command:

Shutdown-R now

650) This. width = 650; "Title =" clip_image018 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image018 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227511mTk0.png "width =" 454 "Height =" 141 "/>

After the system is restarted, log on to the system again and run the ipconfig and ping commands to view the information.

650) This. width = 650; "Title =" clip_image019 "style =" border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px; "Border =" 0 "alt =" clip_image019 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227511AplP.png "width =" 707 "Height =" 388 "/>

650) This. width = 650; "Title =" clip_image020 "style =" 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 =" clip_image020 "src =" http://img1.51cto.com/attachment/201408/5/526870_1407227511hb3X.png "width =" 589 "Height =" 124 "/>

Through this, we can see that the virtual machine centos2 is now working normally.

Now we have finished introducing the cloning of KVM virtual machines.

This article from the "muddy world" blog, please be sure to keep this source http://ilanni.blog.51cto.com/526870/1536032

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.