1

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?

3
  • wait wha? if they are deleted why would they take up space? Apr 21, 2010 at 5:12
  • 1
    @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, 2010 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... Apr 22, 2010 at 9:00

5 Answers 5

3

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.

1

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.

1

Dump and restore would work.

2
  • Dump and restore what exactly?
    – Bozojoe
    Apr 21, 2010 at 15:30
  • 1
    The dump(1) and restore(1) UNIX commands.
    – Bill Weiss
    Apr 21, 2010 at 15:33
0

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

shred --iterations=0 --exact --zero --remove file
1
  • The files have been deleted. How could I find large deleted files to do shred against them?
    – Bozojoe
    Apr 21, 2010 at 15:31
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .