William Hargrove
2006-Jul-24 13:35 UTC
[Xen-users] Clearout (defrag) of sparse file used for Xen VM
Hi, I''ve got a Xen VM sitting inside a sparse file, as shown below, with the VM and it''s swap file, each at 69gb ls -lh: -rw-r--r-- 1 root root 69G Jun 5 12:42 hamdev02 -rw-r--r-- 1 root root 2.0G Jun 5 14:53 hamdev02-swap -rw-r--r-- 1 root root 69G Jun 5 12:38 hamdev01 -rw-r--r-- 1 root root 2.0G Jun 5 14:34 hamdev01-swap One of the sparse files has now grown quite large, compared with another VM: du -sh: 44G hamdev02 2.0G hamdev02-swap 2.0G hamdev01 9.8M hamdev01-swap Has anyone got any suggestions on how I could non-destructively reduce the size of the file? We are starting to run out of space on the partition these VMs sit on. I''ve been looking at various ext3 based tools to try and defragment the file, copy it to a new file, dump and restore the file etc, but none of those seem to work. Short of completely removing the file (and the VM) which I don''t want to do.. I''m a bit short of options. Any ideas? Thx, Will H. _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Javier Guerra
2006-Jul-24 13:55 UTC
Re: [Xen-users] Clearout (defrag) of sparse file used for Xen VM
Quoting William Hargrove <William.Hargrove@betfair.com>:> I''ve got a Xen VM sitting inside a sparse file, as shown below, with the > VM and it''s swap file, each at 69gb> Has anyone got any suggestions on how I could non-destructively reduce > the size of the file? We are starting to run out of space on the > partition these VMs sit on. > > I''ve been looking at various ext3 based tools to try and defragment the > file, copy it to a new file, dump and restore the file etc, but none of > those seem to work.i think you''re approaching the problem from the wrong side: that of the underlying filesystem. on the underlying filesystem, a sparse file that has grown is that big because it''s holding data. no sane tool would reduce its size, because that would mean throwing out data. OTOH, since those files are holding virtual block devices, some (most?) of that data might be currently unused blocks, that''s where you could recover some storage. first, the swapfiles: there''s nothing there that must be preserved between reboots of the VM, apart from a little formatting header. just do swapoff on the VM, delete the swapfile, create a new one, attach it to the VM, do mkswap and swapon. the new swapfile should be smaller (at least for a while) now, the filesystem itself. first do a "df -h" on the VM, to make sure you''re actually using less storage than the current size of the sparse file. if the VM has 40GB used, you won''t be able to recover much; but if you''re currently using just 10GB, it''s worth a try. the easiest way would be to poweroff the VM, then mount the imagefile with a loop device; create a new sparse file, mkfs and mount the new file, and copy from one to the other. use cp -a or tar to preserve owner and privileges. umount all and restart the VM with the new image. don''t try to suspend and resume with the new image, because it won''t be a block-identical copy; just equal at the filesystem level. if you want to reduce downtime, you could do the copying from within the VM, but at the end you have to restart it with the new image. good luck! ------ Javier _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users