You are not logged in.

#1 2009-06-10 11:29:42

Andy Mack
Member
Registered: 2008-06-16
Posts: 133

Zero Free HD Space

I found this on my travels and thought it would be better to ask here if it is safe to use

dd if=/dev/zero of=DELETEME; sync; rm -f DELETEME    (/dev/random can be used if you're paranoid)

I'd rather ask here as I trust people here rather than some random fella who posted it.

Will this just zero free space on my / and /home partitions or do I need to specify this?

Thanks

Offline

#2 2009-06-10 12:31:44

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: Zero Free HD Space

What that command does depends on what DELETEME is. If DELETEME is a hard drive partition (/dev/sda1), it will write zeroes to the entire partition, destroying everything on it. In that case, the rm -f DELETEME part doesn't make much sense.

If DELETEME is a regular file (Document.pdf), it would zero the contents of the file and then delete it. A bit more secure than simply deleting the file, I suppose.

In both cases, I'm not sure if 'sync' is required/useful or not.

Just be careful with dd. It does exactly what you tell it to, no questions asked.

Edit: As far as I know, there's no way to zero only the free space on your hard drive unless the free space you refer to is an empty partition. I can't think of a reason to do this anyway.

Last edited by dmartins (2009-06-10 12:34:04)

Offline

#3 2009-06-10 12:45:08

keenerd
Package Maintainer (PM)
Registered: 2007-02-22
Posts: 647
Website

Re: Zero Free HD Space

If you typed in that line as is, it would create a file called DELETEME in the present working directory.  This file would grow until the mount point of the pwd is filled.  I am pretty sure that dd will handle running-out-of-space gracefully.  Sync makes sure the stuff is actually written, and then it deletes the file, freeing up everything.

It should work as expected, unless DELETEME already exists and is a link pointing to /dev/sda :-)

DON'T use /dev/random.  That is your high quality random number generator, it can only produce a few bytes a second.  For generating gigs of random, use /dev/urandom, the pseudo random generator.  Whether random numbers are better than zeros is for another discussion.

You should be able to safely try this on a flash drive.  cd into it and make sure your pwd is /mnt/flash/ (or whatever) and it will not touch your hard drive.

Note that many filing systems get very upset when you fill the last few bytes.  Some handle it more gracefully than others, but Linux filesystems seem to handle it the best.

Offline

Board footer

Powered by FluxBB