From: "Alberto Treviño" <alberto@byu.edu>
To: "kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: Can i shrink the image file size?
Date: Sun, 22 Mar 2009 23:26:21 -0600 [thread overview]
Message-ID: <200903222326.21791.alberto@byu.edu> (raw)
In-Reply-To: <49C519C6.2020908@wonghome.net>
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. :-)
next prev parent reply other threads:[~2009-03-23 7:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-03-23 8:03 ` Ross McKay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200903222326.21791.alberto@byu.edu \
--to=alberto@byu.edu \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox