We use a lot of sparse disk images. On one of them I setup a temporary swapfile of 4 gig and enabled it. I did not add it to fstab, etc. On reboot I wanted it to go away in this case. Anyway, upon rebooting and removing the 4gb file, I have not gained back the space in the sparse file. For example, if I do: du -s -B1 disk0 13056692224 disk0 That''s the same thing I got before removing the 4 gb file. Should I expect disk0 to "recover" the space automatically? VMware has a shrink disk option, does something similar need to be done in xen? Thanks, James _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Hi This is not a xen issue, this is a linux fs issue. In short: Xen does not know and neighter care about sparse files. It justs looks at the file like at a disk. The domUs writes are written into the file - while the file system allocates space it it was a sparse area. However, there is no such thing as removing blocks from a device. If you delete the file, you delete the filesystems pointer to that file. The data itself stays where it is. Even if it would be overwritten (by 0 or something), it would not get freed as sparse area again. The only thing you can do, is create a new file, copy all contents (backup/restore) and delete the old file. As the new file will only be allocated as much space as nessessary, it is a "shrink". Surely, the domU needs to be shut down completely. Regards, Steffen -----Ursprüngliche Nachricht----- Von: xen-users-bounces@lists.xensource.com [mailto:xen-users-bounces@lists.xensource.com] Im Auftrag von James Pifer Gesendet: Freitag, 12. September 2008 02:21 An: Xen List Betreff: [Xen-users] Recovering space or "shrink" disk img? We use a lot of sparse disk images. On one of them I setup a temporary swapfile of 4 gig and enabled it. I did not add it to fstab, etc. On reboot I wanted it to go away in this case. Anyway, upon rebooting and removing the 4gb file, I have not gained back the space in the sparse file. For example, if I do: du -s -B1 disk0 13056692224 disk0 That''s the same thing I got before removing the 4 gb file. Should I expect disk0 to "recover" the space automatically? VMware has a shrink disk option, does something similar need to be done in xen? Thanks, James _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
James Pifer wrote:> That''s the same thing I got before removing the 4 gb file. Should I > expect disk0 to "recover" the space automatically? VMware has a shrink > disk option, does something similar need to be done in xen? >As previously commented, Linux doesn''t recover "unused" space from a file. However, if you shut down the guest then you can use "cp --sparse=always" to "recover" sparse blocks. At the cost of temporarily allocating all the sparse blocks on the disk you can do "dd if=/dev/zero of=/tmp/hugefile; rm /tmp/hugefile" to make it possible to recover more disk space. Overwriting blocks that are not in use and contain non-null bytes is possible but I don''t know of an easy way to do it except in one or two special cases. jch _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
If the disk image is just for swap you could get a script which removes the file after shutdown and recreates it before the machine starts up. Just as long as you either recreate the swap outside the virtual machine or get a script on startup to recreate it inside the virtual machine you should be able to reclaim the lost disk space every boot. -- Alex Tomkins <tomkins@darkzone.net> _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users