Wipe free space


6 posts in this topic Last Reply

Recommended Posts

Hi all,

 

I would like to wipe the free space on my array (not the actual files).

 

Is the command is this post (dd if=/dev/random >/dev/disk??/big_file) still the best way to do so or is there a newer/better way?

 

I understand that running this command creates a full-disk error condition and therefore a risk of cascading failures.

 

Best,

OP 

Link to post
7 minutes ago, TangoEchoAlpha said:

I don't know if either will be viewed as a 'full disk' but how about nwipe (kinda replacement for the old Darik's Boot And Nuke DBAN) or shred?

Can any of those be used to wipe free space and not files or entire disk?

Link to post
7 minutes ago, Opawesome said:

Can any of those be used to wipe free space and not files or entire disk?

Ah, sorry. Yes, I think they will wipe the entire disk. The only tool I have ever used to wipe free space is on Windows, a free tool called file shredder - https://www.fileshredder.org/

 

Actually, shred can delete individual files. Check out the -u option:

 

Quote

Delete FILE(s) if --remove (-u) is specified. The default is not to remove the files because it is common to operate on device files like /dev/hda, and those files usually should not be removed. When operating on regular files, most people use the --remove option.

 

Edited by TangoEchoAlpha
Link to post
Posted (edited)

It turns out this little script seems to do the job:

 

#!/bin/bash

DISKNUMBER="1" # Set the disk number which free space should be wiped

dd if=/dev/zero of=/mnt/disk"$DISKNUMBER"/zero.small.file bs=1024 count=102400
cat /dev/zero > /mnt/disk"$DISKNUMBER"/zero.large.file
sync ; sleep 5 ; sync
rm /mnt/disk"$DISKNUMBER"/zero.small.file
rm /mnt/disk"$DISKNUMBER"/zero.large.file
unset DISKNUMBER

 

I have just tested it in a screen session. The disk filled up as expected and then the "zero.small.file" and "zero.large.file" were deleted to free up the space back.

 

The point of have a small file is to avoid keeping the disk completely filled too long, as it can take time to delete the large file.

 

I hope this helps.

 

Any improvement or remark is obviously more than welcome.

 

OP

Edited by Opawesome
Link to post
2 hours ago, TangoEchoAlpha said:

Actually, shred can delete individual files. Check out the -u option:

 

Well, as stated, I don't want to delete any file, I want to wipe the free space. So shred is not a solution.

 

But thank you anyway.

Op

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.