Sometimes we recycle a drive which has been used for some purposes like raid and storage of very important and critical data. Before we use them we always want to securely erase all the data. OK what about formatting? Unfortunately, formatting a disk drive can not help securing the permanent deletion either. Formatting a disk drive does not actually overwrite the data, and although it is way better than deleting the file from within Windows it is still very easy to retrieve data back from a formatted disk.
Using dd Command
By erasing the drive you can simply use the ‘dd’ command this is very helpful as its just destroying data but not the drive.
Wiping all Partition
This will overwrite all partitions, master boot records, and data.
1. Filling the disk with all zeros (This may take a while, as it is making every bit of data 0)
dd if=/dev/zero of=/dev/sda bs=1M
2. Filling the second partition on the /dev/sda disk with all zeros :
dd if=/dev/zero of=/dev/sda2 bs=1M
3. Filling the third partition with random data :
dd if=/dev/urandom of=/dev/sda3 bs=1M
Wiping the Master Boot Record (MBR)
If you are unable to fix your master boot record or if you did something wrong with it you can wipe it using this command :
dd if=/dev/zero of=/dev/hda bs=446 count=1
Wiping out and See the Progress
Sometimes we are very impatient with ‘dd’ result as once you have invoked the command, it will not show you any progress. There are an alternative way to do that. One is like the same process with added command:
-bash-4.1# dd if=/dev/zero of=/dev/sda bs=10MB & -bash-4.1# echo $! 1727 -bash-4.1# ps -ef | grep 1727 root 1727 1702 8 04:39 ttyS0 00:00:01 dd if=/dev/zero of=/dev/sda bs=10MB root 1729 1702 0 04:40 ttyS0 00:00:00 grep 1727 -bash-4.1# kill -USR1 1727 -bash-4.1# -bash-4.1# 2159+0 records in 2159+0 records out 21590000000 bytes (22 GB) copied, 157.469 s, 137 MB/
Another way is using a pv command. simply install pv once installed you can do the following:
dd if=/dev/zero | pv | dd of=/dev/sda2 bs=1M dd if=/dev/urandom | pv | dd of=/dev/null dd if=/dev/zero | pv | dd of=/dev/null Output 1,74MB 0:00:09 [ 198kB/s] [ <======> ]
Wiping out Disk Faster
I usually use these command to wipe out a disk faster.
dd if=/dev/zero of=/dev/sda bs=512 seek=$(( $(blockdev --getsz /dev/sda)- 1024)) count=1024 dd if=/dev/zero of=/dev/sdb bs=512 seek=$(( $(blockdev --getsz /dev/sdb)- 1024)) count=1024
var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-37138722-1']); _gaq.push(['_trackPageview']);