LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-24-2014, 01:28 PM   #1
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Rep: Reputation: 70
Zeroing-out unused space


Hi all,

Is there a command that enables one to zero-out all the unused space on a drive or partition?

cheers,
cc.
 
Old 10-24-2014, 01:38 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Code:
dd if=/dev/zero of=$HOME/zerofile.bin bs=1M
Let it run until the disk runs out of space, and then delete $HOME/zerofile.bin.
 
1 members found this post helpful.
Old 10-24-2014, 02:24 PM   #3
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
Quote:
Originally Posted by suicidaleggroll View Post
Code:
dd if=/dev/zero of=$HOME/zerofile.bin bs=1M
Let it run until the disk runs out of space, and then delete $HOME/zerofile.bin.
This sounds fiendishly clever and too good to be true. There must be a catch somewhere but I can't see it. Possibly a brilliant solution. I'll bet someone now comes along with a snag that makes the idea totally unworkable. You wait and see.
 
Old 10-24-2014, 03:28 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
i was just going to suggest the same.
yes, it's the magic of unix.
 
Old 10-24-2014, 05:24 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Completely Clueless View Post
There must be a catch somewhere but I can't see it.
Well, if you don't do it as "root" the reserved space on the filesystem won't get cleared, and of course if this is some exotic filesystem or device that compresses its data, it might take a long time to run out of space for all those compressed zeros. Also, for SSDs and Flash drives, you will zero the visible free space, but you won't know what happens on the free space that the controller manages. (That space will get cleared when the controller gets the proverbial "round tuit," but you can't control when that happens.)
 
Old 10-24-2014, 05:25 PM   #6
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
Quote:
Originally Posted by ondoho View Post
i was just going to suggest the same.
yes, it's the magic of unix.
Wow. I'm resigned to using dd for backups and this will save a huge amount of otherwise wasted disk space when compressed. Unwiped disk space is too much like random data and IIRC, random data doesn't compress. A huge bunch of zeroes, OTOH, will compress wonderously.
 
Old 10-24-2014, 05:28 PM   #7
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
Quote:
Originally Posted by rknichols View Post
Well, if you don't do it as "root" the reserved space on the filesystem won't get cleared, and of course if this is some exotic filesystem or device that compresses its data, it might take a long time to run out of space for all those compressed zeros. Also, for SSDs and Flash drives, you will zero the visible free space, but you won't know what happens on the free space that the controller manages. (That space will get cleared when the controller gets the proverbial "round tuit," but you can't control when that happens.)
Well fortunately I'm not doing this for security purposes, so if that's all I have to worry about, I'm not worried.
 
Old 10-24-2014, 05:37 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Completely Clueless View Post
Well fortunately I'm not doing this for security purposes, so if that's all I have to worry about, I'm not worried.
In that case, if this is a filesystem that has reserved space (like ext2/3/4 and others -- not FAT), you'll need to do it as the UID or GID that has rights to the reserved space. Otherwise, any UID or GID with write permission in some directory will do.
 
Old 10-25-2014, 05:22 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Completely Clueless View Post
Wow. I'm resigned to using dd for backups and this will save a huge amount of otherwise wasted disk space when compressed. Unwiped disk space is too much like random data and IIRC, random data doesn't compress. A huge bunch of zeroes, OTOH, will compress wonderously.
???
i don't think that dd compresses anything.
it will faithfully copy every single zero.
 
Old 10-25-2014, 06:10 AM   #10
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by ondoho View Post
???
i don't think that dd compresses anything.
it will faithfully copy every single zero.
Indeed, but the gzip (or such), that the image is piped to, compresses consecutive zero's nicely.
 
Old 10-25-2014, 10:55 AM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
bzip2 compresses them even better. Can take about halfway to forever to do it, though.
 
Old 10-25-2014, 01:54 PM   #12
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
but if you really want to "install" something like in the windows world
there is "bleach bit"

i would also recommend this , it is a good thing to have around
and has it's uses

basically it is a gui for cleaning up files
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shrink image size by zeroing unused blocks rjvencken Linux - General 4 08-28-2012 07:41 PM
Recovering unused hd space: Server vshell Linux - Newbie 4 05-16-2006 03:53 PM
Deleting unused space from a partition Tsukasa7 Linux - Newbie 2 08-31-2005 02:05 PM
Zeroing out ununsed space in a ext3 partition saravkrish Linux - General 2 11-19-2004 03:10 PM
Zeroing free space? RyanBarnard Linux - Software 2 09-23-2004 06:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration