Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to minimize the amount of space my virtual disk is using, by zero'ing out the data on any deleted files. The virtual disk is a VDMK running ubuntu with a single Ext4 partition on VirtualBox.

What is the best way to find any deleted files, and zero them out, so that when I export the appliance the disk size is only existing files on the disk?

share|improve this question
wait wha? if they are deleted why would they take up space? – xenoterracide Apr 21 '10 at 5:12
@xenoterracide, When you are compressing or exporting a VM it does not look at the filesystem withing the guest. It has no way to determine if a block is used, or not. If you fill up all unused blocks with zeros within a guest then a VM will compress well. – Zoredache Apr 21 '10 at 6:37
After reading some answers and some comments. Your biggest problem appears to be how do you find said deleted files... I don't think the tools exist... esp not for ext4. I'd suggest rsync-ing the files you have to a new partition or image or something that won't have this problem... – xenoterracide Apr 22 '10 at 9:00
up vote 3 down vote accepted

If you are using a filesystem that supports it then you can use zerofree.

If you are not then you basically need to just use dd to write zero to a file on each partition until there is no space left. Then delete the file you filled with zeros.

share|improve this answer

For each file system, do like

sudo dd if=/dev/zero of=/zero
# ...wait until the filesystem is full...
sudo rm /zero

That will create a file over all free space on the filesystem, filled with zeros. When you delete it, there will be only zeros left on partition. However, I guess you need to gzip the virtual disk anyway, as zeros take up space anyway. I am not sure how smart virtualbox disk management is.

share|improve this answer

Dump and restore would work.

share|improve this answer
Dump and restore what exactly? – Bozojoe Apr 21 '10 at 15:30
The dump(1) and restore(1) UNIX commands. – Bill Weiss Apr 21 '10 at 15:33

If you haven't deleted the files yet, you could do something like this:

shred --iterations=0 --exact --zero --remove file
share|improve this answer
The files have been deleted. How could I find large deleted files to do shred against them? – Bozojoe Apr 21 '10 at 15:31

For this to work, you have to use thin provisioning. Or am i wrong there?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.