Friday, September 18, 2015

LowLevelFormat with Linux


I needed a script that was able to destroy the data on multiple storage devices and create a new NTFS partition.
The script needed to be plain simple, for me and eventually colleges. 

doing a quick search on the Internet I found the command shred. this program allowed me to create a simple script:

#!/bin/sh

HDD=$1

if [ -z "$HDD" ]; then
   echo "please give a drive to destroy"
else
   clear
   echo "Low Level Format of /dev/$HDD"
   shred -v -z -n 3 /dev/$HDD

   echo "Create a new NTFS FS on /dev/$HDD"
   mkfs.ntfs -f -F -S 4096 /dev/$HDD
fi

Script breakdown:
1: start a bash script
3: put the argument in var HDD
5,6: check if HDD is filled and give an error if it's not
8: clear the screen
9: print what drive will be formated
10: do the actual shred
      -v = verbose
      -z = do a zeroing at the end
      -n 3 = fill the disk with random data, 3 times
because of the verbose you will get a lot of output, giving you an idea of much longer you have to wait.

12: print the second action, creating a new partition
13: the actual command to create a new partition.

ToDo:
1. create a list of available disks, allowing the user to select the disk he/she wants to LLF
2. allow the user to change the number of random data fill
3. allow the user to change the final partition type.