Live disk migration with Libvirt blockcopy

Source: Internet
Author: User

Nova uses libvirt blockcopy (python APIvirDomainBlockRebase)来做live snapshot.

Create the base image:

Qemu-img create-f Qcow2 Base 1G
Run PART-DISK/DEV/SDA MBR mkfs ext4/dev/sda1 mount/dev/sda1/ Touch/foo LS/ Exit

Create Another QCOW2 overlay snapshot ' Snap1 ' with backing file as ' base ':

Base.qcow2-o Backing_fmt=qcow2 Snap1.qcow2

Add a file to Snap1.qcow2:

Run PART-DISK/DEV/SDA MBR mkfs ext4/dev/sda1 mount/dev/sda1/ Touch/bar LS/ 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 BAS E, Snap1 and SNAP2.

Create a simple libvirt XML file as below, with source file pointing to Snap2.qcow2-which would be the active block Devic E (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/virsh start TESTVMDomain 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's 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'll pivot the live QEMU to the ' copy '.

Confirm that QEMU have pivoted to the ' copy ' by enumerating of the current block device on use:

Virsh domblklist TESTVM Target     Source------------------------------------------------vda        /export/vmimages/copy.qcow2 

Again, display the backing chain of ' copy ', it should is 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:

Run mount/dev/sda1/ LS/ 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 <source file=‘/export/vmimages/snap2.qcow2‘/> <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 have to support persistent dirty bitmap- This enables us to restart a QEMU process with disk mirroring intact. There is some in-progress patches upstream for a while. Until They is in Main line QEMU, the current approach (as illustrated above) Is:make a running Libvirt guest transient T Emporarily, perform live blockcopy , and make the guest persistent again. (Thanks to Eric Blake, one of the Libvirt project ' s principal developers, for this detail.)

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

Live disk migration with Libvirt blockcopy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.