kvm虚拟机克隆有如下两种方式:
1.KVM本机虚拟机直接克隆
2.通过复制xml文件与磁盘文件复制克隆 (适用于异机的静态迁移和状态保存便于以后使用)。
注释:
A为模板,为了不和B(克隆机)起冲突,主要是硬盘和网卡冲突,需要把A的udev注释,顺手配置好yum,console=ttyS0支持命令行操作,把网卡的uuid,mac信息删掉。
B为克隆机,为了区分出来,不和A起冲突,需要把uuid和mac删掉,把name和disk路径改成B的名字。
实验步骤:
- [root@localhostimages]#qemu-imgcreate-fqcow2-brhel6.qcow2GHOST
- Formatting'GHOST',fmt=qcow2size=8589934592backing_file='rhel6.qcow2'encryption=offcluster_size=65536
- [root@localhostimages]#qemu-imgcreate-fqcow2-brhel6.qcow2ClientA
- Formatting'ClientA',fmt=qcow2size=8589934592backing_file='rhel6.qcow2'encryption=offcluster_size=65536
- [root@localhostimages]#qemu-imgcreate-fqcow2-brhel6.qcow2ClientB
- Formatting'ClientB',fmt=qcow2size=8589934592backing_file='rhel6.qcow2'encryption=offcluster_size=65536
- [root@localhostimages]#du-mrhel6.qcow2
- 223rhel6.qcow2
- [root@localhostimages]#du-mGHOST
- 1GHOST
- [root@localhostimages]#virshlist--all
- Id名称状态
- ----------------------------------------------------
- -rhel6关闭
- 克隆三个虚拟机,数量自己定
- [root@localhostimages]#virshdumpxmlrhel6>/etc/libvirt/qemu/ghost.xml
- [root@localhostimages]#virshdumpxmlrhel6>/etc/libvirt/qemu/clienta.xml
- [root@localhostimages]#virshdumpxmlrhel6>/etc/libvirt/qemu/clientb.xml
- [root@localhostimages]#
3.编辑克隆虚拟机的配置文件
4.定义新虚拟机的配置文件
- [root@localhostimages]#virshdefine/etc/libvirt/qemu/ghost.xml
- 定义域dhcp(从/etc/libvirt/qemu/ghost.xml)
- [root@localhostimages]#virshdefine/etc/libvirt/qemu/clienta.xml
- 定义域clienta(从/etc/libvirt/qemu/clienta.xml)
- [root@localhostimages]#virshdefine/etc/libvirt/qemu/clientb.xml
- 定义域clientb(从/etc/libvirt/qemu/clientb.xml)
5.使用虚拟机
- virshlist--all
- virshstartghost
- virshconsoleghost
结束语:
- 本次实验适用于在没有图形化的条件下如何实现克隆虚拟机,做技术就是需要拥有一颗永不磨灭的好奇心。