Bug 952974

Summary: qemu-img resize of a qcow2 image file does not work for reducing the size
Product: Red Hat Enterprise Linux 6 Reporter: nigil <nigil>
Component: qemu-kvmAssignee: Virtualization Maintenance <virt-maint>
Status: CLOSED WONTFIX QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.4CC: acathrow, bsarathy, dyasny, juzhang, mkenneth, nigil, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-04-17 20:01:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description nigil 2013-04-17 05:32:10 UTC
Description of problem:
Reducing the size of a qcow2 image does not work with qemu-img resize command.

Version-Release number of selected component (if applicable):
# rpm -qa | grep qemu
qemu-img-0.12.1.2-2.355.el6.x86_64
gpxe-roms-qemu-0.9.7-6.9.el6.noarch
qemu-kvm-tools-0.12.1.2-2.355.el6.x86_64
qemu-guest-agent-0.12.1.2-2.355.el6.x86_64
qemu-kvm-0.12.1.2-2.355.el6.x86_64

# lsb_release -r
Release:        6.4

How reproducible:
100%

Steps to Reproduce:
1. Create a qcow2 image in an NFS mounted volume.
2. Increase the size using qemu-img resize. See the size changed.
3. Reduce the size of the image using qemu-img resize. This operation Failed with error message "qemu-img: This image format does not support resize". 


  
Actual results:
Could not Reduce the size of the image using qemu-img resize

Expected results:
Should reduce the size of the image using qemu-img resize.

Additional info:
# qemu-img create -f qcow2 qcow2file1.img 10G
Formatting 'qcow2file1.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536

# qemu-img info qcow2file1.img
image: qcow2file1.img
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 140K
cluster_size: 65536

# ls -l qcow2file1.img
-rw-r--r--. 1 root root 262144 Apr 17 10:31 qcow2file1.img

# qemu-img resize qcow2file1.img +10G
Image resized.

# qemu-img info qcow2file1.img
image: qcow2file1.img
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 144K
cluster_size: 65536

# qemu-img resize qcow2file1.img -10G
resize: invalid option -- '1'
qemu-img version 0.12.1, Copyright (c) 2004-2008 Fabrice Bellard
......
Supported formats: raw cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 qed parallels nbd blkdebug host_cdrom host_floppy host_device file

# qemu-img resize qcow2file1.img 10G
qemu-img: This image format does not support resize

# qemu-img resize qcow2file1.img +-10G
qemu-img: This image format does not support resize

# qemu-img resize qcow2file1.img +10G^C

# qemu-img resize qcow2file1.img +10G
Image resized.

# qemu-img info qcow2file1.img
image: qcow2file1.img
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 144K
cluster_size: 65536

# qemu-img resize qcow2file1.img -5G
resize: invalid option -- '5'
qemu-img version 0.12.1, Copyright (c) 2004-2008 Fabrice Bellard
Supported formats: raw cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 qed parallels nbd blkdebug host_cdrom host_floppy host_device file

Comment 1 juzhang 2013-04-17 05:39:27 UTC
Currently,  Seems qcow2 can not support shrink. Raw format support.

Comment 2 nigil 2013-04-17 05:46:32 UTC
Thanks. The same has been said in 
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Using_qemu_img.html
But I think we should have this feature for qcow2 format also as mainly qcow2 images are used for thin-provisioning. Please update the inclusion plan for this and close the bug.

Comment 4 Ademar Reis 2013-04-17 20:01:53 UTC
(In reply to comment #2)
> Thanks. The same has been said in 
> https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/
> 6/html/Virtualization_Administration_Guide/sect-Virtualization-
> Tips_and_tricks-Using_qemu_img.html
> But I think we should have this feature for qcow2 format also as mainly
> qcow2 images are used for thin-provisioning. Please update the inclusion
> plan for this and close the bug.

Unfortunately qcow2 doesn't support resize and in this case you should either use raw or convert the image to a new one (the effective way to resize a qcow2 image).

Indeed, it's a nice feature to have. Note taken, but closing the bug as WONTFIX because we don't have any plans to support it yet.