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.
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.
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.
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.
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:
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.