How to resize a qcow2 disk image on Linux - Linux Tutorials - Learn Linux Configuration

Qcow2 is the default virtual disk storage format used by Qemu (qcow stands for qemu copy-on-write). This image format makes use of thin provisioning, so, after we initially set the maximum virtual size of a disk, space is actually allocated only when used, but not made available back to the host when freed.In this article we see how to “sparsify” a qcow2 disk image to reclaim available space, how to expand it or shrink it, and how to manage the partitions layout on it from the host system, connecting it by using the NBD protocol.


This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-resize-a-qcow2-disk-image-on-linux

Package which provides virt-sparsify is libguestfs-tools. ( please change libguests-tools to libguestfs-tools)

To resize a qcow2 disk image on Linux, you can use the “qemu-img” command. The following steps outline the process of increasing the size of a qcow2 disk image:

Determine the current size of the image:

qemu-img info .qcow2
Increase the size of the image:

qemu-img resize .qcow2 +G
For example, to increase the size of the image “disk.qcow2” by 10GB, you would run:

qemu-img resize disk.qcow2 +10G
Expand the partition within the guest operating system to utilize the newly added space:
This requires booting into the guest operating system and using its built-in tools to resize the partition.

Note: You may need to shut down the virtual machine using the qcow2 disk image before resizing it.

Siddharth_Verma: Yours works well when you have a full GUI with gparted installed. I had a CLI image from Turnkey Linux.

The method described here was perfect. I expanded the image as needed for me to install additional tooling.

A technical correction, it’s necessary to disconnect the disk after an expansion also:

$ sudo qemu-nbd -d /dev/nbd0

and for completeness:

$ sudo modprobe -r nbd