From: Pete Verdon on
Hi,

I'm putting together a test system that will need to store (though not
run simultaneously) many Xen images. I intend to make new images by
copying a "template" image, which I'm currently creating, and then
installing the specific software needed for that particular image's
purpose (they will differ). Therefore I need the space occupied by an
image to be initially small, but with the potential to grow - some
images will end up with little more than the basic OS, while others will
have a full-blown IBM app server on them. I don't want to make all the
images big enough to hold the largest system.

At present, my template system lives in a file whose size is reported by
straight du -h as 4.5G and by du --apparent-size -h as 6.1G. The actual
space productively used (df on the virtual machine) is under 1GB. I
assume that this means I have a 6.1GB sparse file, of which 4.5GB is
solidly filled by a filesystem, of which <1GB is used.

Is it possible to reliably shrink and expand an ext3 filesystem inside a
sparse file? How about causing it to happen automatically? Presumably if
I have to expand and contract the filesystem manually there's no point
in having a sparse file - the space used would always be the size of
filesystem. Is there such a thing as a sparse filesystem, so that I can
say "you can grow up to xGB, but only if you're actually using the space
to store files"? Is there a better way to do this in the first place?

Thanks,

Pete