A normal “format” of a drive will only erase the file and partition table of the drive, thus allowing the data to be recovered with easily available software such as testdisk and scalpel. This will show you how to securely erase a drive by writing random data “bits” over the entire drive.
This also shows how to get an “interactive” display of dd’s progress.
1. You need to have “dd” and “pv” installed on CentOS/RedHat this is done by running (You may need to add the EPEL or RPMForge repo).
[user@client ~]$ sudo yum install dd pv
On Debian/Ubuntu you can do this by running:
[user@client ~]$ sudo apt-get install dd pv
2. Become root before running the commands (as pv will take over the password input for sudo)
[user@client ~]$ sudo su
3. First we will write random data over the entire drive to destroy anything that is on it. Run the command where [TOTAL] is the size of your drive in Bytes and [DRIVE] is the target disk you want to erase.
Warning! This will destroy any data on the drive!
[user@client ~]$ sudo dd if=/dev/urandom |pv -s[TOTAL]| sudo dd of=/dev/[DRIVE] bs=6M
It took about 8 minutes to fully erase a 4GB USB drive I was testing.
4. To be really secure, you can now write 0′s over the whole drive so the drive is completely blank. This should be a lot quicker than the random data command.
[user@client ~]$ sudo dd if=/dev/zero |pv -s[TOTAL]| sudo dd of=/dev/[DRIVE] bs=6M
Now you can use a format utility to reformat the drive for other use.