stackhpc / ansible-role-libvirt-vm

This role configures and creates VMs on a KVM hypervisor.
128 stars 67 forks source link

Fails resizing qcow from 15G to 50G #55

Closed goetzk closed 4 years ago

goetzk commented 4 years ago

Hi, This feels like a variation of #23 , but I'm reporting in case. I'm trying to build instances copying an existing qcow image; the process fails due to a resizing error.

rvar/lib/libvirt/images# virsh vol-create-as --pool default --name tv --capacity 50GB --format qcow2
Vol tv created

/var/lib/libvirt/images# virsh vol-upload --pool default --vol tv --file /var/lib/libvirt/staging/W10-V1.vdi.qcow 

/var/lib/libvirt/images# virsh vol-resize --pool default --vol tv --capacity 50GB
error: Failed to change size of volume 'tv' to 50GB
error: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified

/var/lib/libvirt/images# ls -lh /var/lib/libvirt/staging/W10-V1.vdi.qcow
-rwxr-xr-x 1 root root 16G May 14 20:20 /var/lib/libvirt/staging/W10-V1.vdi.qcow

I haven't investigated beyond this yet but I will try and update if I find a cause for the issue.

goetzk commented 4 years ago

I forgot to include the actual task output. sorry if its a bit munted, i tried to remove the identifying information.

TASK [ansible-role-libvirt-vm : Ensure the VM disk volumes exist] ********************************************************************************************
failed: [.au] (item={u'capacity': u'50GB', u'name': u'windows-desktop-00.qcow', u'format': u'qcow', u'device': u'disk', u'image': u'W10-V1.vdi.qcow', u'type': u'file', u'pool': u'default'}) => {"ansible_loop_var": "item", "changed": false, "item": {"capacity": "50GB", "device": "disk", "format": "qcow", "image": "W10-V1.vdi.qcow", "name": "windows-desktop-00.qcow", "pool": "default", "type": "file"}, "msg": "non-zero return code", "rc": 1, "stderr": "Shared connection to au closed.\r\n", "stderr_lines": ["Shared connection to au closed."], "stdout": "Failed to resize volume  to 50GB\r\nerror: Failed to change size of volume 'windows-desktop-00.qcow' to 50GB\r\nerror: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified\r\nVol windows-desktop-00.qcow deleted\r\n\r\n", "stdout_lines": ["Failed to resize volume  to 50GB", "error: Failed to change size of volume 'windows-desktop-00.qcow' to 50GB", "error: invalid argument: Can't shrink capacity below current capacity unless shrink flag explicitly specified", "Vol windows-desktop-00.qcow deleted", ""]}
goetzk commented 4 years ago

The light of day and contemplation reveals the cause:

ls -lh *
-rwxr-xr-x 1 1000 1002 8.8G May 13 08:08 serp-2019.vdi.qcow
-rwxr-xr-x 1 1000 1002 9.1G May 13 08:19 serp-w10.qcow
file *
serp-2019.vdi.qcow: QEMU QCOW Image (v1), 53687091200 bytes
serp-w10.qcow:      QEMU QCOW Image (v1), 53687091200 bytes

They're preallocated to 50 GiB (Base 2) / 53GB (Base 10) so resizing them to 50GB (base 10) causes them to shrink.