Wipe free space


Opawesome
Go to solution Solved by Opawesome,

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 comment
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 comment
  • Solution

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 having 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
typo
  • Thanks 3
Link to comment
  • 1 year later...
On 4/12/2023 at 4:14 AM, shiftylilbastrd said:

Does it just write zeros to all the free space or does it randomize the written data?

Yes, zeros. You could replace "/dev/zero" with "/dev/random" to have randomised data (subject to the warning bellow). This link can help you decide which one to pick: https://stackoverflow.com/questions/11499409/dev-zero-or-dev-random-what-is-more-secure-and-why

 

On 4/12/2023 at 4:14 AM, shiftylilbastrd said:

Is there a way to add a run "X" number of times to be able to get a more secure wipe of the disk?

I guess the safer way for you might just be run the script "X" number of times. Playing with the "dd" command while not being comfortable with the CLI can result in loosing all your data (I am not kidding).

Link to comment
  • 2 months later...
On 6/27/2023 at 9:45 AM, jasonjulius1122 said:

While using the command "dd if=/dev/random >/dev/disk??/big_file" can be an effective way to wipe the free space on your array, there are newer and potentially better methods available. One alternative approach is to use tools specifically designed for secure file deletion, such as "shred" or "sfill," which provide more control and options for securely wiping free space. These tools offer enhanced security and reduce the risk of encountering cascading failures associated with the full-disk error condition caused by the mentioned command.

 

Are those unraid tools though? I don't wanna pull disks from my server and all that. Will that script be fine to use? (how do you actually use it heh) thanks.

Link to comment

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.