Hide Forgot
Description of problem: qemu-img can't parse negative value of qemu-img resize command. I tested same issue in Fedora 16. It fixed. But in RHEL6.1, It occured. How reproducible: # qemu-img create -f raw test.img 10G Formatting 'test.img', fmt=raw size=10737418240 # qemu-img resize test.img 9G <- It success. Image resized. # qemu-img resize test.img -1G <- It failed. resize: invalid option -- '1' Actual results: # qemu-img resize test.img -1G resize: invalid option -- '1' Expected results: # qemu-img resize test.img -1G Image resized. # ls -l test.img -rw-r--r--. 1 root root 9663676416 Sep 2 13:53 test.img Additional info: This issue fixed by following patch in upstream. http://lists.gnu.org/archive/html/qemu-devel/2011-04/msg02551.html
Fixed in upstream commit e80fec7f. Will backport to RHEL.
Additional information. please see manpage of qemu-img in Fedora 15 or Upstream. QEMU-IMG(1) QEMU-IMG(1) NAME qemu-img - QEMU disk image utility SYNOPSIS usage: qemu-img command [command options] OPTIONS The following commands are supported: (snip) resize filename [+ | -]size Change the disk image as if it had been created with size. Before using this command to shrink a disk image, you MUST use file system and partitioning tools inside the VM to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss! After using this command to grow a disk image, you must use file system and partitioning tools inside the VM to actually begin using the new space on the device.
Reproduced this issue with qemu-kvm-0.12.1.2-2.209.el6.x86_64. Got following output by: # qemu-img --help qemu-img version 0.12.1, Copyright (c) 2004-2008 Fabrice Bellard usage: qemu-img command [command options] QEMU disk image utility (snip) resize filename [+ | -]size Steps: 1. create a raw format image file: # qemu-img create -f raw test.raw 10G Formatting 'test.raw', fmt=raw size=10737418240 # qemu-img info test.raw image: test.raw file format: raw virtual size: 10G (10737418240 bytes) disk size: 0 2. resize this image file to 6G: # qemu-img resize test.raw 6G Image resized. # qemu-img info test.raw image: test.raw file format: raw virtual size: 6.0G (6442450944 bytes) disk size: 0 3. resize to 20G # qemu-img resize test.raw 20G Image resized. # qemu-img info test.raw image: test.raw file format: raw virtual size: 20G (21474836480 bytes) disk size: 0 4. increase it by +2G # qemu-img resize test.raw +2G Image resized. # qemu-img info test.raw image: test.raw file format: raw virtual size: 22G (23622320128 bytes) disk size: 0 5. decrease it by 2G # qemu-img resize test.raw -2G resize: invalid option -- '2' Marking qa_ack+ according to above info.
Interestingly, you can work around this by specifying the negative value as an addition eg: to remove 2gb from image # qemu-img resize image.img "+-2G"
Deferring to RHEL 6.5 because this is low priority and we're over capacity. This kind of behavior is quite common in getopt(3) applications. The workaround is to use -- before the option (or +-2G, as suggested by Jamie).
Why discuss this about 1 year? I propose new sub-commands "qemu-img extend" and "qemu-img reduce" eg. To extend 2GB from image # qemu-img extend 2GB image.img eg. Do not give negative size parameter for "qemu-img resize", To reduce 2GB from image # qemu-img reduce 2GB image.img
Still broken in RHEL 6.3
Still broken in RHEL 6.4