WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

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

To: Jonathan Ervine <JErvine@xxxxxxxxxx>
Subject: Re: [Xen-users] shrink or grow disk image?
From: John Haxby <john.haxby@xxxxxxxxxx>
Date: Wed, 30 Apr 2008 10:02:06 +0100
Cc: xen-users@xxxxxxxxxxxxxxxxxxx
Delivery-date: Wed, 30 Apr 2008 02:03:14 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <200804301025.23379.jervine@xxxxxxxxxx>
List-help: <mailto:xen-users-request@lists.xensource.com?subject=help>
List-id: Xen user discussion <xen-users.lists.xensource.com>
List-post: <mailto:xen-users@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=unsubscribe>
References: <1209496880.29921.59.camel@xxxxxxxxxxxxxxxxxxxxxxxx> <200804301025.23379.jervine@xxxxxxxxxx>
Sender: xen-users-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.12 (X11/20080226)
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

<Prev in Thread] Current Thread [Next in Thread>