Leroy Tennison
2017-Jul-11 05:34 UTC
[libvirt-users] Is there still no easier way to shrink a VM image?
I have numerous qcow2 images which need to be reduced in size and have their maximum size (virtual size) reduced. Physical disk space became so low that VMs "auto-paused" themselves, I moved enough images to solve the immediate problem but need to rectify the underlying issue. It seems that qcow[2] files are grown in size such that the data inside of them takes about 50-60% of the space (does anyone know the actual algorithm or how to control it?). Given the total physical disk space on the hypervisors, I need something more restrictive. Our hypervisors are a mix of Ubuntu 14 or 16 LTS (qemu-img 2.2 or 2.5). After doing all the preparation (defragment, reduce OS partition size) "qemu-img resize" reports that shrinking isn't supported yet. My web research indicates that, to accomplish this, I have to: convert to raw shrink the image convert back to qcow[2] increase the image size to provide for some growth I'm hoping I've missed something in my research and that someone knows an easier way. I don't feel constrained to qemu-img but this is a production environment precluding consideration of experimental software. Virt-resize, guestfish or any other reasonable option is fine with me. Solutions or ideas? Thanks.
Martin Kletzander
2017-Jul-11 07:50 UTC
Re: [libvirt-users] Is there still no easier way to shrink a VM image?
On Tue, Jul 11, 2017 at 12:34:31AM -0500, Leroy Tennison wrote:>I have numerous qcow2 images which need to be reduced in size and have >their maximum size (virtual size) reduced. Physical disk space became >so low that VMs "auto-paused" themselves, I moved enough images to solve >the immediate problem but need to rectify the underlying issue. It >seems that qcow[2] files are grown in size such that the data inside of >them takes about 50-60% of the space (does anyone know the actual >algorithm or how to control it?). Given the total physical disk space >on the hypervisors, I need something more restrictive. >I don't get it. You have virtual size greater than the free space on the physical storage and instead of the VM finding out you want the guest OS to see it has no space at all?>Our hypervisors are a mix of Ubuntu 14 or 16 LTS (qemu-img 2.2 or 2.5). >After doing all the preparation (defragment, reduce OS partition size) >"qemu-img resize" reports that shrinking isn't supported yet. My web >research indicates that, to accomplish this, I have to: > > convert to raw > > shrink the image > > convert back to qcow[2] > > increase the image size to provide for some growth > >I'm hoping I've missed something in my research and that someone knows >an easier way. I don't feel constrained to qemu-img but this is a >production environment precluding consideration of experimental >software. Virt-resize, guestfish or any other reasonable option is fine >with me. Solutions or ideas? Thanks. >>_______________________________________________ >libvirt-users mailing list >libvirt-users@redhat.com >https://www.redhat.com/mailman/listinfo/libvirt-users
Michal Privoznik
2017-Jul-11 09:23 UTC
Re: [libvirt-users] Is there still no easier way to shrink a VM image?
On 07/11/2017 07:34 AM, Leroy Tennison wrote:> I have numerous qcow2 images which need to be reduced in size and have > their maximum size (virtual size) reduced. Physical disk space became > so low that VMs "auto-paused" themselves, I moved enough images to solve > the immediate problem but need to rectify the underlying issue. It > seems that qcow[2] files are grown in size such that the data inside of > them takes about 50-60% of the space (does anyone know the actual > algorithm or how to control it?). Given the total physical disk space > on the hypervisors, I need something more restrictive. > > Our hypervisors are a mix of Ubuntu 14 or 16 LTS (qemu-img 2.2 or 2.5). > After doing all the preparation (defragment, reduce OS partition size) > "qemu-img resize" reports that shrinking isn't supported yet. My web > research indicates that, to accomplish this, I have to: > > convert to raw > > shrink the image > > convert back to qcow[2] > > increase the image size to provide for some growth > > I'm hoping I've missed something in my research and that someone knows > an easier way. I don't feel constrained to qemu-img but this is a > production environment precluding consideration of experimental > software. Virt-resize, guestfish or any other reasonable option is fine > with me. Solutions or ideas? Thanks.In addition to what Martin replied (I don't quite understand your goal either), I often use 'virsh domfstrim $domain' to free up some unused blocks in a qcow2 image. However, this doesn't change the virtual size of the disk. Just the physical footprint. Michal