克隆KVM虚拟机

克隆KVM虚拟机


virt-clone --original daixuan2 --name daixuan3 --file /data/daixuan3.qcow2 
如果子机daixuan2还未关机,则需要先关机,否则会报错:
ERROR  必须暂停或者关闭有要克隆设备的域。
关闭子机的方法是:
virsh shutdown daixuan2

[root@daixuan ~]# virt-clone --original daixuan2 --name daixuan3 --file /data/daixuan3.qcow2

正在克隆 daixuan2.img                   |  10 GB     00:59


克隆完后,virsh list --all 就会发现daixuan3 这个子机,通过命令 
virsh start daixuan3 可以开启该子机


为了确保能够上网,必须让虚拟机配置文件中的uuid和mac 与 虚拟机内部的配置对应

关机状态,打开虚拟机配置文件

[root@daixuan ~]# virsh edit daixuan3

找到uuid和mac

82c8eda7-c875-18bb-34e3-3478c038cd38

52:54:00:a6:c7:6a


启动

[root@daixuan ~]# virsh start daixuan3 --console

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 //mac和uuid与配置文件对应

DEVICE="eth0"

BOOTPROTO="static"

BROADCAST="112.65.140.135"

DNS1="8.8.8.8"

GATEWAY="112.65.140.129"

HWADDR="52:54:00:A6:C7:6A"

IPADDR="112.65.140.132"

IPV6INIT="yes"

IPV6_AUTOCONF="yes"

NETMASK="255.255.255.248"

NM_CONTROLLED="yes"

ONBOOT="yes"

TYPE="Ethernet"

UUID="82c8eda7-c875-18bb-34e3-3478c038cd38"


[root@localhost ~]# vi /etc/udev/rules.d/70-persistent-net.rules //mac和uuid与配置文件对应

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

#

# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.


# PCI device 0x1af4:0x1000 (virtio-pci)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:A6:C7:6A", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"



如果需要daixuan3能够上网,需要配置IP地址,方法参考:

http://daixuan.blog.51cto.com/5426657/1722445

你可能感兴趣的:(虚拟机,kvm)