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? I created the img files using virt manager to setup sles with para-virtualized settings. I''ve done some searching and I came across qcow, but it looks like that''s not supported. Are others doing this? Any help or suggestions is appreciated. James _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
>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?Have you used lvm in the install? Never used sles... Only thing I can think of is to mount the image, and dump/rsync it into another mounted image. jlc _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
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... Jon _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
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@lists.xensource.com http://lists.xensource.com/xen-users
John Haxby wrote:> 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?On Fedora 8, at least, cp handles sparse files quite nicely and "cp --sparse=always" seems to do a good job of turning blocks of zeros into holes. You learn something new every day. jch _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
On Wed, 2008-04-30 at 12:06 +0100, John Haxby wrote:> John Haxby wrote: > > 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? > > On Fedora 8, at least, cp handles sparse files quite nicely and "cp > --sparse=always" seems to do a good job of turning blocks of zeros into > holes. > > You learn something new every day.I''m playing around with the suggestions. Thanks everyone! James _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
> 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?The suggestions by other folks basically cover most of the sensible ways of doing this. You can change the size of the file in place, or you can copy the relevant data to a different sized file. As others have mentioned, it''s sensible to make a backup copy to try changes on, then abandon the original if it works OK. If you''re shrinking then you need to shrink the guest filesystem *first* and adjust the guest partition table. Then shrink the disk image itself. If you''re growing then you need to grow the disk image first, then adjust the guest partition table, then grow the guest filesystem. You could either do the adjustment of the partition table and filesystem from within the guest, or by stopping the guest and doing the operations from dom0. The parted partition editor can, in principle, resize partitions and the filesystems within them, so it might be worth trying that out. Resizing an image file won''t be picked up by a running guest automatically. Using xm block-remove followed by xm block-add might do the trick but obviously you can''t do that for devices the guest is using (e.g. the guest''s root device). This is only really an issue if you''re trying to make the size changes "on line". If the guest is shut down, then it''ll see the new sizes at next power on.> I created the img files using virt manager to setup sles with > para-virtualized settings. > > I''ve done some searching and I came across qcow, but it looks like > that''s not supported.The qcow format is now supported by Xen, I believe, although it may not be supported by your version. I don''t think it solves your immediate problem although it could cut down on the space required for machines based on this image. Cheers, mark -- Push Me Pull You - Distributed SCM tool (http://www.cl.cam.ac.uk/~maw48/pmpu/) _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users