[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-users] shrink or grow disk image?



Jonathan Ervine wrote:
On Wednesday 30 April 2008 03:21:20 James Pifer wrote:
I have installations of sles for 64 and 32 bit in img files. I can
copy the img file, create a new domU, adjust the networking as
needed, and I have a new server up and ready to be configured.

Problem is my img file is a lot bigger than needed for some uses. Is
there a way to shrink an img file? Or, if I create a new "template"
server that is smaller, can the img file be grown when needed?

Growing image files is easy enough - you simply create another blank one and then cat it to the original one. I've done this a few times - although I'd still recommend that you do this on a backup of the original image file :-) using image files isn't the best for performance- you should look at using LVM and setting up individual volumes for your VMs.

Shrinking I'm not so sure about... I don't think you can shrink an image file - however you could create a (smaller) new one, and copy the contents of the larger used one to the new one. Combinations of dd and lomount are probably useful for this...
truncate(2) and ftruncate(2) can both grow and shrink files. Growing just extends the file size without allocating disk space (a sparse file); shrinking just frees up disk space. Of course, lopping the end off an image file could do unspeakable things to the enclosed file system, but you've already thought of that.

Of course, if your original file is sparse then shrinking isn't going to actually free disk space but as you've just copied it (using, presumably, cp) then you've filled all the holes with zeroes. If you copy the file with tar and the --sparse options then the holes won't get filled in and you won't be using space that you don't need. I suspect, though I haven't tried it, that copying a file with lots of zero-filled blocks using tar --sparse will convert those blocks into holes. Does that help?

jch

_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.