Read the source code and the comments to understand what this does.
#!/bin/bash # --- # this will write 0s across a drive at random locations (using dd) # you specify the details in the variables location # --- # fill out these variables & copy paste script & it will not hurt (it will not do the writes) # For security purposes:L you will see the dd commands output (but they will not run) # To run them just select and copy the dd commands, and paste them back into the shell to run them # --- # You could also run the script and save it to a file # first edit ddestroy.sh to have the correct variables, then save and exit, and run the code like this: # $ ./ddestroy.sh > ddcommands # this will save all of the dd commands (and comments of the output) into the ddcommands file # now we just run the ddcommands file to execute those commands # since the output ddcommands, will not have +x bit, you can just run it with the bash "source" commands # $ source ddcommnds (##################### ### SET VARIABLES ### ### ALL IN MiBs ##### ### Megabytes ####### ##################### DISK=sda START_LOCATION=0 MAX_SIZE_OF_A_WRITE=1000 MIN_NUM_OF_WRITES_TO_DISK=24 ## example: ## DISK=sda ## START_LOCATION=0 ## MAX_SIZE_OF_A_WRITE=1000 ## MIN_NUM_OF_WRITES_TO_DISK=12 ## This will write to disk sda, from the beginning due to the 0 START_LOCATION ## 1 gig writes due to MAX_SIZE_OF_A_WRITE (max, but they will vary in size) ## at about 12 locations due to MIN_NUM_OF_WRITES_TO_DISK ## but since thats random too, it might be more locations) ###################### ### start of code #### ###################### SIZE=`cat /sys/block/$DISK/size` echo "# Size of disk '$DISK' is $SIZE sectors" SIZE_MB=`echo $SIZE | awk '{printf("%d",$1/2/1024)}'` echo "# Size of disk '$DISK' is $SIZE_MB megabytes" ### INPUT TO AWK: start location, write size max (but they all are random), max size of drive - all in MB, name of disk, min_number_of_writes_to_disk echo "$START_LOCATION $MAX_SIZE_OF_A_WRITE $SIZE_MB $DISK $MIN_NUM_OF_WRITES_TO_DISK" | awk '{ srand(); start=int($1); wrmax=int($2); ms=int($3); name_of_drive=$4; cu=start; range1=ms-start; min_number_of_writes=$5; random_division=min_number_of_writes/2; print "### WRITING AT RANDOM LOCATIONS (all units in MiB) ###" print "# - start_location: " cu; print "# - size_of_disk: " ms; print "# - max_random_size_write: " wrmax; print "# - min_number_of_total_writes: " min_number_of_writes; print "# - drive: " name_of_drive; i=1; while (cu<ms) { wr=int(wrmax*rand())+1; # random write amount printf("# write number : %d - current: %d", i, cu); ri=int(rand()*(range1/random_division)); printf(", skipping: %d, writing: %d\n", ri, wr); printf("dd if=/dev/zero of=/dev/%s bs=1M skip=%d count=%d\n", name_of_drive, cu, wr); cu=cu+ri+wr; i=i+1; }}')
Here is an example of the output of the above script (run with above variables, in your case you might need to change the variables at the top):
# Size of disk 'sda' is 7814037168 sectors # Size of disk 'sda' is 3815447 megabytes ### WRITING AT RANDOM LOCATIONS (all units in MiB) ### # - start_location: 0 # - size_of_disk: 3815447 # - max_random_size_write: 1000 # - min_number_of_total_writes: 24 # - drive: sda # write number : 1 - current: 0, skipping: 4078, writing: 574 dd if=/dev/zero of=/dev/sda bs=1M skip=0 count=574 # write number : 2 - current: 4652, skipping: 226970, writing: 953 dd if=/dev/zero of=/dev/sda bs=1M skip=4652 count=953 # write number : 3 - current: 232575, skipping: 196021, writing: 970 dd if=/dev/zero of=/dev/sda bs=1M skip=232575 count=970 # write number : 4 - current: 429566, skipping: 91782, writing: 582 dd if=/dev/zero of=/dev/sda bs=1M skip=429566 count=582 # write number : 5 - current: 521930, skipping: 77597, writing: 847 dd if=/dev/zero of=/dev/sda bs=1M skip=521930 count=847 # write number : 6 - current: 600374, skipping: 123842, writing: 727 dd if=/dev/zero of=/dev/sda bs=1M skip=600374 count=727 # write number : 7 - current: 724943, skipping: 280105, writing: 202 dd if=/dev/zero of=/dev/sda bs=1M skip=724943 count=202 # write number : 8 - current: 1005250, skipping: 120058, writing: 333 dd if=/dev/zero of=/dev/sda bs=1M skip=1005250 count=333 # write number : 9 - current: 1125641, skipping: 132812, writing: 806 dd if=/dev/zero of=/dev/sda bs=1M skip=1125641 count=806 # write number : 10 - current: 1259259, skipping: 200242, writing: 23 dd if=/dev/zero of=/dev/sda bs=1M skip=1259259 count=23 # write number : 11 - current: 1459524, skipping: 302782, writing: 599 dd if=/dev/zero of=/dev/sda bs=1M skip=1459524 count=599 # write number : 12 - current: 1762905, skipping: 156634, writing: 82 dd if=/dev/zero of=/dev/sda bs=1M skip=1762905 count=82 # write number : 13 - current: 1919621, skipping: 253624, writing: 234 dd if=/dev/zero of=/dev/sda bs=1M skip=1919621 count=234 # write number : 14 - current: 2173479, skipping: 263026, writing: 793 dd if=/dev/zero of=/dev/sda bs=1M skip=2173479 count=793 # write number : 15 - current: 2437298, skipping: 111068, writing: 439 dd if=/dev/zero of=/dev/sda bs=1M skip=2437298 count=439 # write number : 16 - current: 2548805, skipping: 3911, writing: 809 dd if=/dev/zero of=/dev/sda bs=1M skip=2548805 count=809 # write number : 17 - current: 2553525, skipping: 241985, writing: 363 dd if=/dev/zero of=/dev/sda bs=1M skip=2553525 count=363 # write number : 18 - current: 2795873, skipping: 105371, writing: 727 dd if=/dev/zero of=/dev/sda bs=1M skip=2795873 count=727 # write number : 19 - current: 2901971, skipping: 97775, writing: 378 dd if=/dev/zero of=/dev/sda bs=1M skip=2901971 count=378 # write number : 20 - current: 3000124, skipping: 71322, writing: 621 dd if=/dev/zero of=/dev/sda bs=1M skip=3000124 count=621 # write number : 21 - current: 3072067, skipping: 110192, writing: 552 dd if=/dev/zero of=/dev/sda bs=1M skip=3072067 count=552 # write number : 22 - current: 3182811, skipping: 239338, writing: 614 dd if=/dev/zero of=/dev/sda bs=1M skip=3182811 count=614 # write number : 23 - current: 3422763, skipping: 300794, writing: 228 dd if=/dev/zero of=/dev/sda bs=1M skip=3422763 count=228 # write number : 24 - current: 3723785, skipping: 10370, writing: 131 dd if=/dev/zero of=/dev/sda bs=1M skip=3723785 count=131 # write number : 25 - current: 3734286, skipping: 48606, writing: 364 dd if=/dev/zero of=/dev/sda bs=1M skip=3734286 count=364 # write number : 26 - current: 3783256, skipping: 305987, writing: 663 dd if=/dev/zero of=/dev/sda bs=1M skip=3783256 count=663
Notice how only the commands that need to be run dont have a # comment. All the descriptive text is commented out for a good purpose.