Ask Your Question
2

Why does virt-clone make qcow2 images smaller

asked 2016-06-25 14:48:55 -0500

wigust gravatar image

According to virt-clone man page, cloned image must be the same size as original with ---nonsparse option.

Create machine:

sudo virt-install --connect qemu:///system --name centos --memory 1024 --disk size=10,format=qcow2,sparse=no --cdrom /mnt/zalman-data/Downloads/ISO/CentOS/CentOS-7-x86_64-Minimal-1511.iso --vcpus=1,maxvcpus=4 --cpu host --network bridge=br0 --virt-type kvm --graphics vnc --os-variant centos7.0 --autostart

Check the size of installed machine:

sudo qemu-img info /mnt/zalman-data/Documents/Development/libvirt/centos.qcow2
[sudo] password for opykhalov: 
image: /mnt/zalman-data/Documents/Development/libvirt/centos.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Clone machine:

sudo virt-clone -o centos -n test --file /mnt/zalman-data/Documents/Development/test.qcow2

Check the size of cloned image:

sudo qemu-img info /mnt/zalman-data/Documents/Development/libvirt/test.qcow2
image: /mnt/zalman-data/Documents/Development/libvirt/test.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

Clone another one with --nonsparse:

sudo virt-clone -o centos -n test2 --file /mnt/zalman-data/Documents/Development/test.qcow2 --nonsparse

Check the size of the second cloned image:

sudo qemu-img info /mnt/zalman-data/Documents/Development/libvirt/test2.qcow2
image: /mnt/zalman-data/Documents/Development/libvirt/test2.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

It's look good. But if i try to check with ls command, sizes doesn't match:

ls -lh /mnt/zalman-data/Documents/Development/libvirt/
-rw-------. 1 qemu qemu  11G Jun 25 17:46 centos.qcow2
-rw-------. 1 root root 1.1G Jun 25 18:15 test.qcow2
-rw-------. 1 root root 1.1G Jun 25 18:20 test2.qcow2
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-06-25 16:31:34 -0500

wigust gravatar image

updated 2016-06-29 19:56:17 -0500

However, if i clone with below command, the size of cloned volume is match with original.

sudo virsh vol-clone --prealloc-metadata --pool default centos.qcow2 test3.qcow2

So currently, I use this approach to make a full copy of VM:

sudo virsh suspend centos
sudo virsh vol-clone --prealloc-metadata --pool default centos.qcow2 test.qcow2
sudo virt-clone --preserve-data -o centos -n test --file /mnt/zalman-data/Documents/Development/libvirt/test.qcow2 
sudo virt-sysprep -d test
sudo virsh start test

After boot change ip and hostname. Ready to go

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-06-25 14:42:01 -0500

Seen: 1,518 times

Last updated: Jun 29 '16