Qemu-img resizes vm but disk storage space does not change

I’m trying to enlarge a qemu/libvirt vm installed through virtual manager. For a test I am using enlarge.qcow2.

I increase the size by:

sudo qemu-img resize ~/VMimages/enlarge.qcow2 +40G

qemu-img responds saying image size successfully increased.

virt-filesystems verifies that it was enlarged.

(base) tom@mydesktop: ~/VMimages $ sudo virt-filesystems -a enlarge.qcow2 --all --long -h
Name       Type        VFS      Label  MBR  Size  Parent
/dev/sda1  filesystem  unknown  -      -    1.0M  -
/dev/sda2  filesystem  vfat     -      -    512M  -
/dev/sda3  filesystem  ext4     -      -    39G   -
/dev/sda1  partition   -        -      -    1.0M  /dev/sda
/dev/sda2  partition   -        -      -    513M  /dev/sda
/dev/sda3  partition   -        -      -    39G   /dev/sda
/dev/sda   device      -        -      -    80G   -

But I look at the directory where the file is located and the size on disk has not changed.

(base) tom@mydesktop: ~/VMimages $ dir enlarge.qcow2
-rw------- 1 root root 23G May  6 08:56 enlarge.qcow2

I do realize that I need to expand the partitions to fill the enlarged disk space.

I don’t understand how the disk size can be increased and the new size not show up in file storage directory.

Need some more knowledge input.
thanks, tom kosvic

I assume that this is not different from having unpartitioned space at the end of a physical disk. You have to decide what you want to enlarge, and then make a plan because the unpartitioned space might not be direct at the end of the to be enlarged partition. And after you succeeded in enlarging one or more partitions, you have look at what is on them. Mostly file sytems, but not all file system types can be enlarged.

yes, I understand that I need to adjust the partition sizes. I use gparted to do that. I did enlarge the partitions to include full size (no unallocated space).

My question is still, why did the file size of enlarge.qcow2 not increase on disk when image was increased by 40G apparently successfully. It is still 23G when image size is 80G.

thanks, tom kosvic

@tckosvic because it’s not used and you never specified/allocated the full space to be used on install…

We only use VirtualBox … but no doubt qemu / libvirt operates in a similar fashion.

In VBox, we can specify how large we anticipate the space the image will use … the default is VBox only allocates what’s required initially, then dynamically grows as needed. So you might anticipate needing 80gb, but VBox will initially allocate 10gb.

There is an option in VBox (as you are creating the VM specs) to initially allocate the full desired size as you create the VM. So, in this scenario, VBox will initially allocate the VM size to 80gb.

There is an option in virt-manager to allocate vm img to full size of storage during install. I don’t recall if that was selected.

But, I increased the size of the image though qemu-img by 40G. I then expanded the partitions to fill the new space. Disk size did not increase.

Is it the consensus that if I fill the entire img disk with data that the size on disk will automatically increase to provide storage upon shutdown?

I will fill the image with dummy data to see if that happens.

thanks for input. tom kosvic

I saw in enlarge.qcow2 vm details that the size of the virtio disk is now 80G. That is the enlarged size.
Again, the size reported by ls on harddrive is still 23G.

I have not yet filled the vm disk with data.

tom kosvic

You guys were right. I filled the vm with zeros in a 70G file that was created
using dd. I put the zeros file in my /home in the enlarge.qcow2.

Upon completion of dd, the size on host hard drive of my test “enlarge.qcow2” increased to 77G as measured by ls -ahl.

I think I understand this better. I guess qemu has permissions to just take disk space from user as it needs it. I thought this would all have to be allocated ahead of full space usage.

thanks, tom kosvic

I did a search for “qemu/libvirt preallocate disk size” in my Brave browser to see what its AI response is (personally, I don’t always trust AI responses). Here’s what it came back with (and as I suspected it has same functionality as VBox):

To preallocate disk space for a VM using QEMU/Libvirt, you can use the
“qemu-img create” command with the “–preallocation=full”
or “-o preallocation=full” option when creating the image. This will allocate the entire disk space upfront, which can potentially improve write performance but also increases the initial disk usage on the host.

Here’s a breakdown of the process and considerations:

  1. Creating a Preallocated Disk Image:
  • “qemu-img create -f qcow2 -o preallocation=full mydisk.qcow2 10G”: This command creates a QCOW2 (qcow2) image file named “mydisk.qcow2” with a size of 10 GB, and the “preallocation=full” option ensures the entire 10GB is allocated immediately.
  • “qemu-img create -f raw -o preallocation=full mydisk.raw 10G”: Similar to the above, but this creates a raw image file.