There is unfortunately no current (stable/reasonable) way to make an
existing filesystem image sparse without jumping through some hoops. Pretty
much any of the variants I've seen will require you to have as much (or
more) free disk space as there is data on the disk image. A twist on Mark's
idea to tar it and create a new virtual machine is this.
This chunk'o'code will create and format a new sparse filesystem, and use
tar (or two tar's actually) to duplicate the old filesystem to the new. You
could easily break this into two scripts as well and actually store the tar
for backup purposes if you wanted.
cd /location/of/filesytem/image
dd if=/dev/zero of=sparse_filesytem_image bs=1 count=0 seek=4GB
mkfs.ext3 -F sparse_filesytem_image
mkdir /mnt/dest
mkdir /mnt/source
mount sparse_filesystem_image /mnt/dest -o loop
mount old_filesystem_image /mnt/source -o loop
cd /mnt/source
tar -cpVSO * | tar -xC /mnt/dest
umount /mnt/dest
umount /mnt/source
That should produce a perfect copy of the filesystem, in a new sparse
filesystem, while maintaining the sparseness of the actual files on that
filesystem. Plugin your actual directory and file names, disk image size,
and filesytem type and voila. I typed a lot of that from memory, so you'll
want to test the new filesystem before deleting the old one.
Another method might be a variant of the above with rsh, or cp, although cp
duplicates files on hard links and could potentially make the image huge.
-----Original Message-----
From: xen-users-bounces@xxxxxxxxxxxxxxxxxxx
[mailto:xen-users-bounces@xxxxxxxxxxxxxxxxxxx] On Behalf Of Mark Williamson
Sent: June 18, 2008 4:42 PM
To: xen-users@xxxxxxxxxxxxxxxxxxx
Cc: Luciano Mazaira / Costas Galicia
Subject: Re: [Xen-users] Recover disk space after deletion files in
CitrixXenserver
Hi there,
> I have a Citrix Xenserver host with a CentOS5.1 virtual guest.
>
> The original vm's disk space is 40 Gigabytes and the filesystem is ext3.
>
> When I delete 35 G, the CentOS operating system see 5 G, but the host
> still see 40 G. When I try export the virtual machine, it takes too much
> time and the image has 40 G, not 5 G.
>
> Can anyone help me to recover the disk space?
The amount of storage in the guest is not visible to the host, so it's not
generally straightforward to get the host to recognise when space has been
freed in a guest and take action accordingly.
With sparse files, it is possible to create a virtual disk which starts off
small and then gradually grows as the guest allocates more space, however
the
reverse operation is harder. Sparse files also have the downside that if
you
run out of space for VBDs and they cannot grow, it will cause crashes and /
or corruption for the virtual machine(s) affected.
I'm not an expert on XenServer so I'm not sure what to suggest. If you can
access the VBD file itself there are things you could try to save space
(creating a proper sparse copy of the file), however this would only work if
the empty space in the guest is already set to zero. If you've used the
space and then freed it, this will not generally be the case, making it
harder to free up the space.
A strategy which ought to work but which is more invasive would be to tar up
the contents of your VBD and then create a new virtual machine from those
contents.
The best strategy will depend on what you're trying to do. Whatever
strategy
you try, you should back up your original VM first in case you damage it and
keep that backup until you're sure that what you've done has worked.
I'll also note that you can get more specific help on the Citrix software at
http://forums.xensource.com. This xen-users mailing list is mainly aimed at
users of the open source Xen project and we're not all that familiar with
the
commercial products!
Cheers,
Mark
--
Push Me Pull You - Distributed SCM tool
(http://www.cl.cam.ac.uk/~maw48/pmpu/)
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|