* Re: Can i shrink the image file size?
2009-03-21 16:45 Can i shrink the image file size? John Wong
@ 2009-03-21 19:47 ` Piavlo
2009-03-21 20:25 ` Luca Tettamanti
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Piavlo @ 2009-03-21 19:47 UTC (permalink / raw)
To: John Wong; +Cc: kvm
You can create another smaller disk image and with help of
losetup,kpartx and ntfsclone
clone the ntfs data to the new image.
John Wong wrote:
> I create the 30G qcow2 image file, installed winxp, winxp show me the
> harddisk used 5G, but the image file size is 12G now.
> can i shrink the image file size? how?
> my kvm version is: "kvm-84", qemu version is: "0.9.1".
> please help, thank you.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Can i shrink the image file size?
2009-03-21 16:45 Can i shrink the image file size? John Wong
2009-03-21 19:47 ` Piavlo
@ 2009-03-21 20:25 ` Luca Tettamanti
2009-03-22 1:12 ` Ross McKay
2009-03-23 5:26 ` Alberto Treviño
3 siblings, 0 replies; 7+ messages in thread
From: Luca Tettamanti @ 2009-03-21 20:25 UTC (permalink / raw)
To: John Wong; +Cc: kvm
2009/3/21 John Wong <johnw@wonghome.net>:
> I create the 30G qcow2 image file, installed winxp, winxp show me the
> harddisk used 5G, but the image file size is 12G now.
> can i shrink the image file size? how?
It's not possible to directly reclaim the unused space (qemu is not
aware of what is used and what is not); a workaround is first filling
the unused space with zeros (using sdelete -c) and then compressing
the image with qemu-img convert -c; the side effect of sdelete is that
the image will grow to the limit of 30G, but then the empty space will
be highly compressible.
The alternative is dumping the FS and restoring it on a new image as
suggested by Piavlo.
Luca
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can i shrink the image file size?
2009-03-21 16:45 Can i shrink the image file size? John Wong
2009-03-21 19:47 ` Piavlo
2009-03-21 20:25 ` Luca Tettamanti
@ 2009-03-22 1:12 ` Ross McKay
2009-03-22 4:20 ` Matthew Palmer
2009-03-23 5:26 ` Alberto Treviño
3 siblings, 1 reply; 7+ messages in thread
From: Ross McKay @ 2009-03-22 1:12 UTC (permalink / raw)
To: John Wong; +Cc: kvm
John Wong wrote:
>I create the 30G qcow2 image file, installed winxp, winxp show me the
>harddisk used 5G, but the image file size is 12G now.
>can i shrink the image file size? how?
>my kvm version is: "kvm-84", qemu version is: "0.9.1".
>please help, thank you.
In addition to what the others said, you might be able to reclaim some
space by running qemu-img convert. If you tell it to compress, it will
certainly reduce the image file size, perhaps with a little loss in
performance.
qemu-img convert -c -O qcow2 source.img target.img
--
Ross McKay, Toronto, NSW Australia
"There is more to life than simply increasing its speed." - Gandhi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can i shrink the image file size?
2009-03-22 1:12 ` Ross McKay
@ 2009-03-22 4:20 ` Matthew Palmer
0 siblings, 0 replies; 7+ messages in thread
From: Matthew Palmer @ 2009-03-22 4:20 UTC (permalink / raw)
To: kvm
On Sun, Mar 22, 2009 at 12:12:13PM +1100, Ross McKay wrote:
> John Wong wrote:
>
> >I create the 30G qcow2 image file, installed winxp, winxp show me the
> >harddisk used 5G, but the image file size is 12G now.
> >can i shrink the image file size? how?
> >my kvm version is: "kvm-84", qemu version is: "0.9.1".
> >please help, thank you.
>
> In addition to what the others said, you might be able to reclaim some
> space by running qemu-img convert. If you tell it to compress, it will
> certainly reduce the image file size, perhaps with a little loss in
> performance.
The problem there is that qemu-img convert will only save space where the
blocks are zeroes, and most filesystems don't zero blocks when they're
freed, so not much space is actually saved.
I'm working on a tool at the moment that understands various filesystem
formats and doesn't copy the non-zero freed blocks either. It's only
working for swap partitions at the moment, but once I get up to speed on how
ext2/3 works I'll have that sorted. I guess I should announce it here once
I get ext2 support working now that there are people here who care...
- Matt
--
MacOS X ... [is] enough of a bother to luse it if you've progressed past the
"ooh, click on the shiny little picture!" stage, if you try to treat it as a
serious OS, then it really gets out the little tricycle wheels and the toy
horn that goes "onk! onk!" -- Dave Brown, ASR
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can i shrink the image file size?
2009-03-21 16:45 Can i shrink the image file size? John Wong
` (2 preceding siblings ...)
2009-03-22 1:12 ` Ross McKay
@ 2009-03-23 5:26 ` Alberto Treviño
2009-03-23 8:03 ` Ross McKay
3 siblings, 1 reply; 7+ messages in thread
From: Alberto Treviño @ 2009-03-23 5:26 UTC (permalink / raw)
To: kvm@vger.kernel.org
On Saturday 21 March 2009 10:45:58 am John Wong wrote:
> I create the 30G qcow2 image file, installed winxp, winxp show me the
> harddisk used 5G, but the image file size is 12G now.
> can i shrink the image file size? how?
I wrote a simple utility in .Net 2.0 that creates a file in Windows with all
0's until the drive is full, then deletes it. This allows qemu-img to
recreate the image and reclaim any sectors that are all 0's. This is what I
do:
1. Defragment the Windows drive(s). Run the defragmenter at least 3 times
to make sure you get good results.
2. Run my tool (http://mel.byu.edu/zerofill.exe). It will automatically
detect all drive letters, create a file filled with zero's and delete it whn
it's done. Make sure the VM is not under a lot of use or the continually
decreasing amount of disk space may interfere with whatever may be running.
3. Run qemu-img and recreate the virtual drive with the same format
parameters. For example, if your image is in qcow2 format you run:
qemu-img convert -O qcow2 win_xp.img win_xp.img.new
4. Rename win_xp.img to win_xp.img.old and win_xp.img.new to win_xp.img.
Run your VM and make sure everything works. If it does, remove
win_xp.img.old and go on with life.
I would recommend you back up your drive image before your start the first
couple of times, just to be sure. It's not fun when you screw up and can't
get back into your VM. I've done that a few times while developing this
technique. :-)
^ permalink raw reply [flat|nested] 7+ messages in thread