I'm using KVM to live migrate VMs from one host to another. I have already written a web ui to do that. Now I want to implement a progress bar.

My idea is to compare the file size of the disk on the source and on the target while it's migrating.


ls -ls /data/file.raw
858963 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw


ls -ls /data/file.raw
698543 -rw------- 1 root root 21474836480 Dec 15 13:39 file.raw

Now, I took the allocated value and calculated it in percent.

100 / 858963 * 698543 = 81%

Fine. but there is one problem:

The disk is not sparse. The total size of the file is 1717926 blocks. Actually, there are only 858963 blocks allocated. So the live migration is still copying the empty parts of the file while my progress bar is already at 100%

I already tried around with du and stat.

How to get only the transferred file size of the disk?

  • The file, not the disk, is sparse. Try du -h /data/file.raw (real disk use) and du -h --apparent-size /data/file.raw. What do you use (with all args) to transfer the file? Commented Dec 19, 2016 at 15:42
  • I'm using libvirt to migrate the VM. virsh migrate --verbose --live --copy-storage-all $VM_NAME qemu+ssh://$TARGET/system According to the docs, it is using rsync. du -h returns 858M and du -h --apparent-size returns 6.0G
    – Vince
    Commented Dec 20, 2016 at 7:03
  • See bugzilla.redhat.com/show_bug.cgi?id=1219541 Commented Dec 22, 2016 at 10:27

1 Answer 1


Use virsh migrate as already suggested, or take advantage of rsync's sparse files support, from man rsync:

-S, --sparse Try to handle sparse files efficiently so they take up less space on the destination.

Try rsync -ahHS, add -P if you want to see progress and speed

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .