--- title: "Resize A QEMU Disk Image" blurb: "Our hosting provider allows us to upload a custom image when provisioning a new server. We will have to resize the image if it does not match the size of the server's disk space." ... ## 1. Install `guestfs-tools` $ apt-get update $ apt-get install guestfs-tools ## 2. Download an image Download an image from [https://cdimage.debian.org/images/cloud/](https://cdimage.debian.org/images/cloud/). ## 3. List partitions Check the image disk partitions to see which partition needs resizing. $ virt-filesystems --long -h --all -a debian-12-nocloud-amd64.qcow2 ## 4. Create output container $ qemu-img create -f qcow2 \ -o preallocation=metadata debian-12-nocloud-amd64-resized.qcow2 20G ## 5. Generate resized image $ virt-resize --expand /dev/sda1 \ debian-12-nocloud-amd64.qcow2 debian-12-nocloud-amd64-resized.qcow2 ## Conclusion You can now open `debian-12-nocloud-amd64-resized.qcow2` with a virtual machine program and the disk size will be 20G. ## References `virt-resize` manpage $ man virt-resize