Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a hard drive that went bad and before I send it for RMA I want to wipe as much as possible from it. I tried using windows utilities and also did dd of /dev/random. The problem is I can't wait for either of those solutions to finish as the reason for the RMA is that it writes at a max speed of 1 MB/Sec. It will take over 140 hours just to do a single pass of the 500GB hard drive.

I have been looking for a utility (or even a bash script on linux) that would pick sectors at random and write random data (or even zeros) to those sectors. I'm hoping that if I run this for 24 hours, that will wipe approximately 80 GB of data. Since it will be randomly chosen, all the bigger files will be impossible to recover and the smaller ones will either be wiped, will be missing chunks, or will possibly be recoverable. This is unfortunately the optimal solution for me at this point.


Thanks to "evildead" I was able to get a lot of the data on the drive to be randomly filled with junk from /dev/urandom. The bash script, in case someone ever needs it, is below:

while (true); do
    echo -e $number >> progress.txt
    dd if=/dev/urandom of=/dev/sdx1 skip=$number count=1

You will need to replace 976773168 with the number of blocks on your drive. I originally tried $RANDOM in bash, but it is only a 16-bit int and therefore is only 32k. As I needed a number that is over 900 Million I combined two $RANDOM values, so for instance if my random numbers are 22,861 and 11,111 I get 2,286,111,111 then fitting it to my block size I get a pretty random value in my range. It doesn't have perfect entropy but then again, what is really random on a computer? ;) The 10# is there in case the first random number is a 0, it forces bash to use base 10, not base 8, which is what it uses if it thinks the number is an octal (leading zero). I also write the random numbers to a file for analysis later to see what the spread was. If you don't need this you can just take out

echo -e $number >> progress.txt

and it will run fine. Also dont forget to replace sdx1 with the actual drive or partition you want to work on. I hope this is helpful for someone, I know it was really helpful for me.

share|improve this question
up vote 5 down vote accepted

you can use a shellscript in combination with dd.


 while (true); do
   number=$((($RANDOM * 32768 + $RANDOM)))
   dd if=/dev/urandom of=/dev/sdx1 skip=$number count=1

You only have to modify the number which is generatet from $RANDOM to fit to your Blocks.

share|improve this answer
Did you ever hear of software that does this? Cause I haven't and it seems like at least some people would find it useful. – Marcin Nov 21 '09 at 20:44
Worked great, I made some changes to the script for my situation, I added them to my question in case someone else had to use it in the future. Thanks for your help. – Marcin Nov 22 '09 at 10:58
Hi, I never had such a problem and so I never heard about any software to solves such a problen. I knew dd can skip blocks and supports limit wirtes with count. So the only problem was to get a random number and putting everything together. :) – evildead Nov 23 '09 at 0:13

My system isn't broken and writing from /dev/random is about 650Kb/s. Writing from /dev/urandom is 7Kb/s.

I've worked this issue for myself and for a purely bash solution you have to be realistic about what your goal is because unless your goal is to learn how to do it in bash because the point is doing it ALL in bash, the objective of wiping a disk securely is better accomplished in other ways though bash is useful in the solution.

evildead's bash algorythm to randomly select where dd will write to the drive works however, /dev/urandom is significantly slower than /dev/random and I think it is less secure to pepper the drive with chunks of random data and I think it will be harder to retrieve data from a wiped drive if you quickly do two passes writing one's then zeros to it.

For myself I wrote ones to the drive with:

tr '\0' '\377' < /dev/zero | pv > /dev/sdz

then I wrote zeros to the drive with:

pv < /dev/zero > /dev/sdz

Note the use of pv. It's a great program though you have to install it on most systems. Easy to find, doesn't seem to come with a man page but there is one on-line. It shows the progress of data passing through a pipe and with some programs you can even set it to stop after a certain amount of data is passed.

THEN purely because I was irritated that no bash solution would write random numbers as fast as either of those writes above would do, I wrote a small C program called svrandom to generate random numbers QUICKLY which I called from bash as follows:

while :; do ./svrandom; done  | pv > /dev/sdz

On my system that fills drive /dev/sdz with random numbers as fast as writing /dev/zero does. Goal of wiping drive with random numbers achieved, and bash was used in the solution.

/* svrandom
a small program from September 2015 to generate strings of random numbers.
the default setting of 10000000 gives about 453 megs, adjust as 
needed */ 

#include <stdio.h>
#include <stdlib.h>
int main()
int r,a,b;
 /* adjust following number as needed to suit your string length */


In the source I mention that you can control the length of the random number string by adjusting a number. If you call it from a while loop you wont have to although there may be a carriage return at the end of each loop, but if you want one continuous string from just the program you will have to change the number.

snip! looking around I found this solution on

openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero |pv > /dev/sd{x}

and like the guy there said, I can't believe how fast this is. It's writing to the disk faster than I thought the disks maximum write speed was.

It looks to me that this command is using openssl to encrypt a string of zeros from /dev/zero using /dev/urandom as the seed but im not 100% sure. my solution with the C program to write random numbers writes to my system at 82mbps, this openssl solution is writing at 100mbps. wow!

share|improve this answer
I think your system is a bit broken if /dev/urandom can only supply data at 7kB/s. On my system it gives a nice, steady 4.8MB/s, according to pv. But +1 from me for a nice first answer - welcome to Server Fault! (And I hope you'll forgive me for marking it up a bit.) – MadHatter Sep 24 '15 at 14:19

If you have a powerful magnet, you can physically wipe it.

I take apart old, dead hard drives and get the voice coil magnets from the head positioning assembly. These are rare earth magnets, and from a typical 3.5" drive they're powerful enough to erase enough of the servo tracks on a hard drive so it'll be completely unusable.

One way or another, get the magnet, wipe it back and forth over the top cover of the drive and in less than a minute you'll have a dead drive. Since it's being RMA'd anyway, they shouldn't care.

share|improve this answer

The best software that will automate this process is Darik's Boot and Nuke (aka DBAN)

It's a boot CD with a comprehensive range of drive-wiping mechanisms, ranging in aggresiveness (And time taken to wipe the drive)

It is available from

share|improve this answer

Thanks for the solution on top!
Since I am not allowed to comment the answer with the script I have to add my tiny enhancement myself.
I just tuned it a little for more convenience so that one only has to define the device. fdisk will deliver the number of sectors:

# add device to mangle
# example: 
# disk=/dev/sde
# get number of sectors
sectors=$(fdisk $disk -l| head -1| awk '{print $7}')
# run
while (true); do
    echo -e $number >> progress.txt
    dd if=/dev/urandom of=$disk skip=$number count=1
share|improve this answer

The dban option is the correct answer to this problem.

Writing "random" data from /dev/random will run into problems on most systems because you'll exhaust the entropy on the system and wind up writing the data very slowly.

Almost as "random" as from /dev/random is to encrypt a string of zeros with a random passphrase. You can use dd and openssl to do this, and it allows you to nuke the disks as fast as the system is able to write to disk (instead of waiting on /dev/random). You'll be able to run this 3-5 times in the same time you'd run something that's just dding from /dev/random.

dd if=/dev/zero | openssl des > /dev/hda13
share|improve this answer
I don't understand how people constantly ignore part of the question on here. I am writing at 1 MB/Sec because the drive is broken. /dev/urandom provides data at a higher rate than that. dban is not the correct answer because it doesn't write to random sectors, it writes linearly sector by sector. It might write random DATA but it doesn't write it in a random ORDER. – Marcin Nov 22 '09 at 20:55
you can use /dev/urandom or /dev/zero, doesn´t really matter. Only thing not to use is definatly /dev/random, cause it blocks if entropy is exhausted. – evildead Nov 23 '09 at 0:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.