KVM——复制xml文件与磁盘文件克隆虚拟机
2016-04-10 03:10
405 查看
kvm虚拟机克隆有如下两种方式:
1.KVM本机虚拟机直接克隆
2.通过复制xml文件与磁盘文件复制克隆 (适用于异机的静态迁移和状态保存便于以后使用)。
本次主要介绍如何复制xml文件与磁盘文件克隆虚拟机:
A为模板,为了不和B(克隆机)起冲突,主要是硬盘和网卡冲突,需要把A的udev注释,顺手配置好yum,console=ttyS0支持命令行操作,把网卡的uuid,mac信息删掉。
B为克隆机,为了区分出来,不和A起冲突,需要把uuid和mac删掉,把name和disk路径改成B的名字。
实验步骤:
1.复制配置文件与磁盘文件克隆
1.KVM本机虚拟机直接克隆
2.通过复制xml文件与磁盘文件复制克隆 (适用于异机的静态迁移和状态保存便于以后使用)。
本次主要介绍如何复制xml文件与磁盘文件克隆虚拟机:
简易版原理图: A(模板) B(克隆) disk disk xml xml 需要更改内容 会变的内容 udev-mac uuid yum name console=ttyS0 mac 网卡配置里的mac disk注释:
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-img convert -f raw -O qcow2 sourcename.raw centos.qcow2 virsh edit centos6(把raw修改qcow2) 注:如果是硬盘类型是raw类型的,不支持克隆,需要转化,如果是qcow2类型,此步则忽略。
实验步骤:
1.复制配置文件与磁盘文件克隆
[root@localhost images]# qemu-img create -f qcow2 -b rhel6.qcow2 GHOST Formatting 'GHOST', fmt=qcow2 size=8589934592 backing_file='rhel6.qcow2' encryption=off cluster_size=65536 [root@localhost images]# qemu-img create -f qcow2 -b rhel6.qcow2 ClientA Formatting 'ClientA', fmt=qcow2 size=8589934592 backing_file='rhel6.qcow2' encryption=off cluster_size=65536 [root@localhost images]# qemu-img create -f qcow2 -b rhel6.qcow2 ClientB Formatting 'ClientB', fmt=qcow2 size=8589934592 backing_file='rhel6.qcow2' encryption=off cluster_size=655362.对比文件,备份模板虚拟机的配置文件
[root@localhost images]# du -m rhel6.qcow2 223 rhel6.qcow2 [root@localhost images]# du -m GHOST 1 GHOST [root@localhost images]# virsh list --all Id 名称 状态 ---------------------------------------------------- - rhel6 关闭 克隆三个虚拟机,数量自己定 [root@localhost images]# virsh dumpxml rhel6 > /etc/libvirt/qemu/ghost.xml [root@localhost images]# virsh dumpxml rhel6 > /etc/libvirt/qemu/clienta.xml [root@localhost images]# virsh dumpxml rhel6 > /etc/libvirt/qemu/clientb.xml [root@localhost images]#3.编辑克隆虚拟机的配置文件
(更改name,删除UUID,修改source路径名,删除mac) [root@localhost images]# vi /etc/libvirt/qemu/ghost.xml [root@localhost images]# vi /etc/libvirt/qemu/clienta.xml [root@localhost images]# vi /etc/libvirt/qemu/clientb.xml [root@localhost images]# 注:由于都需要进配置文件,就不贴出来了,反正就是更改这四个地方。4.定义新虚拟机的配置文件
[root@localhost images]# virsh define /etc/libvirt/qemu/ghost.xml 定义域 dhcp(从 /etc/libvirt/qemu/ghost.xml) [root@localhost images]# virsh define /etc/libvirt/qemu/clienta.xml 定义域 clienta(从 /etc/libvirt/qemu/clienta.xml) [root@localhost images]# virsh define /etc/libvirt/qemu/clientb.xml 定义域 clientb(从 /etc/libvirt/qemu/clientb.xml)5.使用虚拟机
virsh list --all virsh start ghost virsh console ghost结束语:
本次实验适用于在没有图形化的条件下如何实现克隆虚拟机,做技术就是需要拥有一颗永不磨灭的好奇心。
相关文章推荐
- XP下使用虚拟机安装配置Solaris[多图]
- VirtualBox虚拟机XP与宿主机Ubuntu互访共享文件夹
- Linux下三大免费桌面虚拟机评测
- 当存储无可用空间时无法启动虚拟机
- 用 GNOME Boxes 下载一个操作系统镜像
- 让普通QQ号也能克隆QQ好友
- 浅析C#的复制和克隆
- JavaScript 克隆双重输入文字
- android 使用虚拟机安装apk(图文教程)
- javascript数组克隆简单实现方法
- 第五节 克隆 [5]
- Vmware虚拟机的安装及配置方法
- 一行代码实现纯数据json对象的深度克隆实现思路
- 深入JAVA对象深度克隆的详解
- 深入解析java虚拟机
- Java虚拟机JVM性能优化(二):编译器
- php实现对象克隆的方法
- apache虚拟机配置步骤和修改访问端口的方法(虚拟机端口映射)
- html的DOM中document对象images集合用法实例
- DOM节点深度克隆函数cloneNode()用法实例