I created 20 GiB .qcow2 image for my virtual machine. Next I installed Ubuntu 20.04 on it. The system uses ~8 GiB, so I decided to shrink the image to 10 GiB using the following command:

# qemu-img resize --shrink ubuntu20.04.qcow2 10241M

The value of 10241M was calculated using the last sector of the partition that was shrinked in gparted (using the Ubuntu live system inside the virtual machine). The last sector was 20973567 so ((20973567+1)×512)/1024/1024 = 10241 MiB.

As a result of the qemu-img resize --shrink command I got the following image:

# ls -al ubuntu20.04.qcow2
    -rw------- 1 root root 10740432896 2020-08-04 20:26:46 ubuntu20.04.qcow2

The size here (10740432896) is 10242.875 MiB and it's larger (+1920000 bytes) compared to the virtual size, which can be checked via:

# qemu-img info ubuntu20.04.qcow2

image: ubuntu20.04.qcow2
file format: qcow2
virtual size: 10 GiB (10738466816 bytes)
disk size: 9.19 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

So here 10738466816 bytes is exacty 10241 MiB.

So where the 1920000 bytes come from?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.