Discussion:
"Hot" resizing QCow2 image using a simple python script
Laurent Coustet
2009-12-29 13:07:52 UTC
Permalink
Hi,

I just wrote a small python script that helps resizing a QCow2 image
without rewriting it.

I'm sure that's not the correct way to do it, but it seems to work well.

Beware this script DO NOT SUPPORT SHRINKING !! It do not check any error
case, so; use at your own risks !
--
Laurent Coustet
http://ed.zehome.com/
Laurent Coustet
2009-12-29 15:32:23 UTC
Permalink
Post by Laurent Coustet
Hi,
I just wrote a small python script that helps resizing a QCow2 image
without rewriting it.
I'm sure that's not the correct way to do it, but it seems to work well.
Beware this script DO NOT SUPPORT SHRINKING !! It do not check any error
case, so; use at your own risks !
***@bingo:/home/kvm$ qemu-img check etch_stable_20091223.qcow2
ERROR: invalid cluster offset=0x657261746f720000
ERROR: invalid cluster offset=0x657261746f730000
ERROR l2_offset=657261746f722026: Table is not cluster aligned; L1 entry
corrupted
ERROR: I/O error in check_refcounts_l1
ERROR: I/O error in check_refcounts_l1
qemu-img: An error occurred during the check


Hahahaha not so easy :-) Trying to find what's going on :)
--
Laurent Coustet
Laurent Coustet
2009-12-29 15:47:27 UTC
Permalink
Post by Laurent Coustet
use at your own risks !
Don't use it, I just forgot to move all datas if l1 needs more blocks..
Kevin Wolf
2009-12-29 20:49:30 UTC
Permalink
Post by Laurent Coustet
Hi,
I just wrote a small python script that helps resizing a QCow2 image
without rewriting it.
I'm sure that's not the correct way to do it, but it seems to work well.
Beware this script DO NOT SUPPORT SHRINKING !! It do not check any error
case, so; use at your own risks !
You need to really resize the L1 table and not just extend the l1_size in the
qcow2 header. And don't use the script with snapshots. VM state is saved
after the end of the virtual disk, so if you extend the disk it might overlap
the VM state (you would need to move the VM state to make it safe with
snapshots).

The right way would be a patch to qemu rather than an external python script
anyway. Doing it correctly would probably even be easier this way because
things like a function for growing the L1 table already exist.

Kevin
Laurent Coustet
2009-12-30 08:28:04 UTC
Permalink
Post by Kevin Wolf
You need to really resize the L1 table and not just extend the
l1_size in the
Post by Kevin Wolf
qcow2 header. And don't use the script with snapshots. VM state is saved
after the end of the virtual disk, so if you extend the disk it might overlap
the VM state (you would need to move the VM state to make it safe with
snapshots).
Ok.
Post by Kevin Wolf
The right way would be a patch to qemu rather than an external python script
anyway. Doing it correctly would probably even be easier this way because
things like a function for growing the L1 table already exist.
Yeah, I was just experimenting with this script.

The second version I tried of the script I wrote was copying old L1 then
padding to l1_table_size, and shifting all others offsets. Are there
other things to care about, like L2 table, and refcount table ?

Thanks,
--
Laurent Coustet
Laurent Coustet
2009-12-30 08:39:43 UTC
Permalink
Post by Kevin Wolf
The right way would be a patch to qemu rather than an external python script
anyway.
I've seen the code on git a little bit, seems rather simple to me, but
what do you think is the better way to integrate such a fonctionality ?
New command ?

The best approch for me I think is to extend "convert".

Example:
qemu-img -f qcow2 -O qcow2 original5G.qcow2 output10G.qcow2 +5G

Thanks,
--
Laurent coustet
Stefan Weil
2009-12-30 12:18:55 UTC
Permalink
Post by Laurent Coustet
I've seen the code on git a little bit, seems rather simple to me, but
what do you think is the better way to integrate such a fonctionality
? New command ?
The best approch for me I think is to extend "convert".
qemu-img -f qcow2 -O qcow2 original5G.qcow2 output10G.qcow2 +5G
Thanks,
Extending convert would be good if you want to create a new image.
This syntax might be better (no new parameter, final size instead of delta):

qemu-img convert -f qcow2 -O qcow2 -o size=10G original5G.qcow2
output10G.qcow2

For resizing an existing image, a new command is needed:

qemu-img resize -f qcow2 -o size=10G original5G.qcow2

Although there is no urgent need for either variant...

Regards
Stefan
Kevin Wolf
2009-12-31 14:16:07 UTC
Permalink
Post by Stefan Weil
Post by Laurent Coustet
I've seen the code on git a little bit, seems rather simple to me, but
what do you think is the better way to integrate such a fonctionality
? New command ?
The best approch for me I think is to extend "convert".
qemu-img -f qcow2 -O qcow2 original5G.qcow2 output10G.qcow2 +5G
Thanks,
Extending convert would be good if you want to create a new image.
qemu-img convert -f qcow2 -O qcow2 -o size=10G original5G.qcow2
output10G.qcow2
qemu-img resize -f qcow2 -o size=10G original5G.qcow2
Although there is no urgent need for either variant...
I agree that convert is the wrong command if you don't copy. And copying an
image while resizing is probably not a very common task. If you really need
to do it you could copy first and resize afterwards. So I'm all for the
qemu-img resize version.

Kevin

Loading...