Search code examples
qemukvmlibvirt

Does libvirt support clone qcow2 with copy on write


The format qcow2 support copy-on-write.detail about qcow2 is here. Does libvirt suport clone qcow2 VM Image with copy-on-write. I find none options about:

virt-clone


Solution

  • virt-clone will clone your disk image to the same file format as the original.

    If your original disk is an LVM partition then you have to clone to a disk raw format image cause the lvm partition is a raw device

    eg:

    # virt-clone -d -o winxp -n winxpclone -f winxpclone.img
    
    # qemu-img info winxpclone.img 
    image: winxpclone.img
    file format: raw
    virtual size: 5.0G (5368709120 bytes)
    disk size: 3.1G
    

    You can convert the cloned disk image to qcow2:

    # qemu-img convert -f raw winxpclone.img -O qcow2 winxpclone.qcow2
    
    # qemu-img info !$ 
    qemu-img info winxpclone.qcow2 
    image: winxpclone.qcow2
    file format: qcow2
    virtual size: 5.0G (5368709120 bytes)
    disk size: 3.1G
    cluster_size: 65536
    

    If your VM has a qcow2 file format disk image then virt-clone will clone your disk image to a qcow2 file format

    # virt-clone -d -o winxpclone -n winxpcloneclone -f winxpcloneclone.img
    
    # qemu-img info winxpcloneclone.img 
    image: winxpcloneclone.img
    file format: qcow2
    virtual size: 5.0G (5368709120 bytes)
    disk size: 3.1G
    cluster_size: 65536
    

    to resume:

    virt-clone will keep the same file format to the cloned disk as the original.

    An good solution is to use virt-sparsify

    http://libguestfs.org/virt-sparsify.1.html

    to reduce the exported disk image size