nova采用 libvirt blockcopy(python  API virDomainBlockRebase)来做live snapshot.

Create the base image:

 $ qemu-img create -f qcow2 base 1G
$ guestfish -a base.qcow2 
[. . .]
><fs> run
><fs> part-disk /dev/sda mbr
><fs> mkfs ext4 /dev/sda1
><fs> mount /dev/sda1 /
><fs> touch /foo
><fs> ls /
foo
><fs> exit

Create another QCOW2 overlay snapshot ‘snap1’, with backing file as ‘base’:

$ qemu-img create -f qcow2 -b base.qcow2 \
  -o backing_fmt=qcow2 snap1.qcow2

Add a file to snap1.qcow2:

$ guestfish -a snap1.qcow2
[. . .]
><fs> run
><fs> part-disk /dev/sda mbr
><fs> mkfs ext4 /dev/sda1
><fs> mount /dev/sda1 /
><fs> touch /bar
><fs> ls /
bar
baz
foo
lost+found
><fs> exit

Create another QCOW2 overlay snapshot ‘snap2’, with backing file as ‘snap1’:

$ qemu-img create -f qcow2 -b snap1.qcow2 \
  -o backing_fmt=qcow2 snap2.qcow2

Add another test file ‘baz’ into snap2.qcow2 using guestfish (refer to previous examples above) to distinguish contents of base, snap1 and snap2.

Create a simple libvirt XML file as below, with source file pointing to snap2.qcow2 — which will be the active block device (i.e. it tracks all new guest writes):

$ cat <<EOF > /etc/libvirt/qemu/testvm.xml
<domain type='kvm'>
<name>testvm</name>
<memory unit='MiB'>512</memory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64'>hvm</type>
</os>
<devices>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/export/vmimages/snap2.qcow2'/>
<target dev='vda' bus='virtio'/>
</disk>
</devices>
</domain>
EOF

Define the guest and start it:

$ virsh define etc/libvirt/qemu/testvm.xml
  Domain testvm defined from /etc/libvirt/qemu/testvm.xml
$ virsh start testvm
Domain testvm started

Perform live disk migration
Undefine the running libvirt guest to make it transient[*]:

$ virsh dumpxml --inactive testvm > /var/tmp/testvm.xml
$ virsh undefine testvm

Check what is the current block device before performing live disk migration:

$ virsh domblklist testvm
Target Source
------------------------------------------------
vda /export/vmimages/snap2.qcow2

Optionally, display the backing chain of snap2.qcow2:

$ qemu-img info --backing-chain /export/vmimages/snap2.qcow2
[. . .] # Output removed for brevity

Initiate blockcopy (live disk mirroring):

$ virsh blockcopy --domain testvm vda \
  /export/blockcopy-test/backups/copy.qcow2 \
  --wait --verbose --shallow \
  --pivot

Details of the above command: It creates copy.qcow2 file in the specified path; performs a --shallow blockcopy (i.e. the ‘copy’ shares the backing chain) of the current block device (vda); –pivot will pivot the live QEMU to the ‘copy’.

Confirm that QEMU has pivoted to the ‘copy’ by enumerating the current block device in use:

$ virsh domblklist testvm
Target Source
------------------------------------------------
vda /export/vmimages/copy.qcow2

Again, display the backing chain of ‘copy’, it should be the resultant chain as noted in the Scenario section above).

$ qemu-img info --backing-chain /export/vmimages/copy.qcow2

Enumerate the contents of copy.qcow2:

$ guestfish -a copy.qcow2 
[. . .]
><fs> run
><fs> mount /dev/sda1 /
><fs> ls /
bar
foo
baz
lost+found
><fs> quit

(You can notice above: all the content from base.qcow2, snap1.qcow2, and snap2.qcow2 mirrored into copy.qcow2.)

Edit the libvirt guest XML to use the copy.qcow2, and define it:

$ virsh edit testvm
# Replace the <source file='/export/vmimages/snap2.qcow2'/>
# with <source file='/export/vmimages/copy.qcow2'/>
[. . .] $ virsh define /var/tmp/testvm.xml

[*] Reason for the undefining and defining the guest again: As of writing this, QEMU has to support persistent dirty bitmap — this enables us to restart a QEMU process with disk mirroring intact. There are some in-progress patches upstream for a while. Until they are in main line QEMU, the current approach (as illustrated above) is: make a running libvirt guest transient temporarily, perform live blockcopy, and make the guest persistent again. (Thanks to Eric Blake, one of libvirt project’s principal developers, for this detail.)

http://kashyapc.com/2014/07/06/live-disk-migration-with-libvirt-blockcopy/

In QEMU, pre-copy storage migration has two phases:

  • add a streaming mirror to the existing image (not a snapshot+mirror);
  • reopen the image to the new mirror ("pivot" the mirror).

http://wiki.qemu.org/Features/SnapshotsMultipleDevices

Live disk migration with libvirt blockcopy的更多相关文章

  1. [译] libvirt 虚机的生命周期 (Libvirt Virtual Machine Lifecycle)

    翻译自:http://wiki.libvirt.org/page/VM_lifecycle   这篇文章描述虚机生命周期的基本概念.其目的在于在一篇文章中提供完整的关于虚机创建.运行.停止.迁移和删除 ...

  2. 虚拟机Q&A

    Q1:虚拟机运行一段时间后,各个版本的第一台虚拟机容量变大,增大容量可以接受 原因:不详 解决方法:用备份镜像替换当前镜像 1.1G Jun 24 17:07 win7_sp1_32_0.qcow2 ...

  3. kvm虚拟化管理

    虚拟化 KVM (kernel-based virtual machine) 常见的一些虚拟化的软件xen kvm vmware esx openVZ Oracle VM VirtualBox vsp ...

  4. kvm常用操作

    安装一些虚拟化的组件 yum -y install kvm python-virtinst libvirt bridge-utils virt-manager qemu-kvm-tools virt- ...

  5. openstack虚拟机迁移的操作记录

    需求说明:计算节点linux-node1.openstack:192.168.1.8  计算节点linux-node2.openstack:192.168.1.17 这两个计算节点在同一个控制节点下( ...

  6. Redhat6.x下如何进行远程安装虚拟机

    远程主机IP:192.168.122.1 远程主机名:server1.example.com 本地主机IP:192.168.122.2 本地主机名:server2.example.com 1.登录到远 ...

  7. 【制作镜像Win*】特殊配置

    下载disk.config: wget http://10.254.3.75/images/configdrive/disk.config 修改libvirt.xml,更换cdrom为disk.con ...

  8. Linux-KVM虚拟化

    kvm安装 1.在宿主机上准备好yum(只需要本地镜像yum就可以) 2.查看CPU是否支持inter或AMD的虚拟技术 # cat /proc/cpuinfo |grep -E "vmx| ...

  9. openstack项目【day24】:KVM部署

    本节内容 虚拟化支持 软件准备 检查CPU虚拟化支持 安装软件包 激活并启动libvirtd服务 网络模式 配置桥接网络 验证网络 尝试连接Hypervisor 创建虚拟机 虚拟机操作 一.虚拟化支持 ...

随机推荐

  1. EasyNVR摄像机无插件直播流媒体服务器前端构建之输入框样式的调整

    EasyNVR授权方式分为软件的授权和硬件授权两种方式,软件授权需要在软件输入永久邀请码可以激化永久授权 起初我们的界面设计是为了满足功能的需求就是 ,用户可以输入激活码提交,完成永久授权. 在实际的 ...

  2. 解决EasyNVR现场无固定公网IP的问题,万千企业期待的EasyNVS管理平台是什么?

    前言 EasyNVS云管理平台已经研发上线,今天就来给大家讲解一下EasyNVS到底是个啥,有什么特殊的功能呢? 首先,我们先从EasyNVR智能云终端(以前我们常称之为EasyNVR无插件直播服务器 ...

  3. IDEA : Git Pull Failed 解决(IDEA中使用stash功能)

    一.问题: 本地要commit代码,commit之前需pull代码,但pull提示冲突.如下 Git Pull Failed Your local changes would be overwritt ...

  4. CAS 源码编译

    准备 :gradle   idea 第一次用Idea 还是有点不熟悉呀,还是eclipse 顺手! 哈哈 下载源码  :我的是4.2.7 解压 导入idea 重点: 调试时候在写 .没时间

  5. coursera 《现代操作系统》 -- 第十三周 期末考试

    一些概念在书上不好找,可以通过谷歌搜索,比如搜索中断向量, site:coursera.org 中断向量   3  下列关于中断和异常的叙述中,哪一个是错误的? x86系列处理器提供的4个处理器特权级 ...

  6. 小程序html 显示 图片处理

    let arr = [] for (const v of r.data.data ){ // v.content = v.content.replace(/<img/g ,' <image ...

  7. 解决httpclient抛出URISyntaxException异常

    这两天在使用httpclient发送http请求的时候,发现url中一旦包含某些特殊字符就会报错.抛出URISyntaxException异常,比如struts漏洞的利用url:(大括号就不行) re ...

  8. Python3.6全栈开发实例[015]

    15.电影投票:程序先给出几个目前正在上映的电影列表. 由用户给每个电影投票.最终将该用户投票信息公布出来 lst = ['北京遇上西雅图', '解救吴先生', '美国往事', '西西里的美丽传说'] ...

  9. kettle连接sqlserver

    1.Sql Server的 数据库链接 Sql server链接有两类,MS SQL SERVER 和 MS SQL SERVER(NATIVE),这两个有什么区别呢,且看下面. 第一类,MS SQL ...

  10. android学习一---搭建开发环境

    android基于Java并运行Linux内核上的轻量级操作系统.由于是基于java的,学习起来也不是太难,对java有一定了解并知道一些基本的图形用户界面,入门就很简单了. 一.了解JDK ,SDK ...