加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

KVM――复制xml文件与磁盘文件克隆虚拟机

发布时间:2020-12-16 00:07:44 所属栏目:百科 来源:网络整理
导读:kvm虚拟机克隆有如下两种方式: 1.KVM本机虚拟机直接克隆 2.通过复制xml文件与磁盘文件复制克隆 (适用于异机的静态迁移和状态保存便于以后使用)。 本次主要介绍如何复制xml文件与磁盘文件克隆虚拟机: 简易版原理图:A(模板)B(克隆)diskdiskxmlxml需要更

kvm虚拟机克隆有如下两种方式:

1.KVM本机虚拟机直接克隆

2.通过复制xml文件与磁盘文件复制克隆 (适用于异机的静态迁移和状态保存便于以后使用)。


本次主要介绍如何复制xml文件与磁盘文件克隆虚拟机:


简易版原理图:
A(模板)B(克隆)
diskdisk
xmlxml
需要更改内容会变的内容

udev-macuuid
yumname
console=ttyS0mac
网卡配置里的macdisk

注释:

A为模板,为了不和B(克隆机)起冲突,主要是硬盘和网卡冲突,需要把A的udev注释,顺手配置好yum,console=ttyS0支持命令行操作,把网卡的uuid,mac信息删掉。

B为克隆机,为了区分出来,不和A起冲突,需要把uuid和mac删掉,把name和disk路径改成B的名字。

1.开机,进入模板主机,打开udev文件,注释里面内容,防止网卡复制为eth1
2.配置/etc/grub.conf里加console=ttyS0支持命令行console模式开启虚拟机
3.cd/var/lib/libvirt/images/
4.ls一下查看是否为qcow2模式
5.yum可配可不配
6.关机
7.qemu-imgconvert-fraw-Oqcow2sourcename.rawcentos.qcow2
virsheditcentos6(把raw修改qcow2)
注:如果是硬盘类型是raw类型的,不支持克隆,需要转化,如果是qcow2类型,此步则忽略。


实验步骤:

1.复制配置文件与磁盘文件克隆

[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

2.对比文件,备份模板虚拟机的配置文件

[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.编辑克隆虚拟机的配置文件

(更改name,删除UUID,修改source路径名,删除mac)
[root@localhostimages]#vi/etc/libvirt/qemu/ghost.xml
[root@localhostimages]#vi/etc/libvirt/qemu/clienta.xml
[root@localhostimages]#vi/etc/libvirt/qemu/clientb.xml
[root@localhostimages]#
注:由于都需要进配置文件,就不贴出来了,反正就是更改这四个地方。

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

结束语:

本次实验适用于在没有图形化的条件下如何实现克隆虚拟机,做技术就是需要拥有一颗永不磨灭的好奇心。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读