# Test of live blockcopy using a live VM with the backing chain: # base <- snap1 <- snap2 ---------- 1. Create a chain: base <-- snap1 <-- snap2 $ qemu-img create -f qcow2 base.qcow2 1G $ qemu-img create -f qcow2 -b base.qcow2 \ -o backing_fmt=qcow2 snap1.qcow2 $ qemu-img create -f qcow2 -b snap1.qcow2 \ -o backing_fmt=qcow2 snap2.qcow2 ---------- 1.1 Add some content (in each disk image): ---------- $ guestfish -a /path/disk.qcow2 > run > part-disk /dev/sda mbr > mkfs ext4 /dev/sda1 > list-filesystems > mount /dev/sda1 / > touch /foo > touch /bar > ls / bar foo lost+found >exit ---------- 2. Provide appropriate SELinux context to the disk images. $ chcon -t svirt_image_t base.qcow2 snap1.qcow2 snap2.qcow2 3. Enumerate the backing chain information $ qemu-img info --backing-chain /export/vmimages/snap2.qcow2 4. Create a persistent libvirt domain: ---------- $ cat < /etc/libvirt/qemu/vm1.xml vm1 512 1 hvm EOF ---------- 4.1 Define the above XML: $ virsh define /etc/libvirt/qemu/vm1.xml $ virsh start vm1 4.2 Take a backup of the guest XML, and make the domain transient: $ virsh dumpxml --inactive vm1 > /var/tmp/vm1.xml $ virsh undefine vm1 5. Create an existing destination file to which contents of snap2 can be copied: $ cp base.qcow2 snap1.qcow2 /export/backups/ $ mv /export/backups/snap1.qcow2 /export/backups/copy-vm1.qcow2 6. Abort any block operations on the current block device: $ virsh blockjob --abort vm1 vda 7. Perform blockcopy (which should get contents of snap2 into snap1, OVERWRITING contents of snap1): $ virsh blockcopy --domain vm1 vda \ /export/blockcopy-test/backups/copy-vm1.qcow2 --shallow \ --reuse-external --wait --verbose --finish Block Copy: [100 %] Now in mirroring phase $ echo $? 0 7.1 Make the domain persistent again: $ virsh define /var/tmp/vm1.xml 8. Enumerate the backing chain: $ qemu-img info --backing-chain ./backups/copy-vm1.qcow2 image: ./backups/copy-vm1.qcow2 file format: qcow2 virtual size: 193K (197120 bytes) disk size: 516K cluster_size: 65536 backing file: base.qcow2 (actual path: ./backups/base.qcow2) backing file format: raw Format specific information: compat: 1.1 lazy refcounts: false image: ./backups/base.qcow2 file format: raw virtual size: 193K (197120 bytes) disk size: 196K $ virsh blockjob --abort vm1 vda