How to Completely Wipe Hard Disk Contents

If you are planning to discard your old hard disk, make sure that they do not contain any valuable information when they head out of your door. The last thing on your mind is the potential of having your identity stolen from sensitive information stored in that hard disk.

When you delete a file, the file is removed from the filesystem. But the contents of the file can still be retrieved, as the areas of the disk used to store the contents are never wiped but simply marked as “free” for use by other data. The contents will be available till those areas of the disk are overwritten by new data. Formatting of the hard disk will not wipe the data either.

Normally, hard disk manufacturers provide tools that can be used to wipe the hard disks. But a computer running Linux can be used to wipe the data as well. Here’s how…

  1. Connect the hard disk to the computer running Linux using a spare SATA or IDE cable and boot the computer.
  2. Check for the device /dev/urandom.
  3. ibrahim@anfield-vm:~$ ls -l /dev/urandom
    crw-rw-rw- 1 root root 1, 9 2011-08-31 18:21 /dev/urandom
    
  4. If the device is not found, create it using mknod command as root user.
  5. ibrahim@anfield-vm:~$ sudo mknod /dev/urandom c 1 9
    [sudo] password for ibrahim:
    ibrahim@anfield-vm:~$ ls -l /dev/urandom
    crw-r--r-- 1 root root 1, 9 2011-08-31 19:17 /dev/urandom
    
  6. Determine the block device for the hard disk you want to wipe. Use the output of dmesg or lshw commands to determine the correct block device, you wouldn’t want to wipe off the wrong hard disk!
  7. Use the Linux dd command to write random data and wipe the disk. This will take some time, depending on the size of the hard disk. I am wiping the disk /dev/sde in the example below.
  8. ibrahim@anfield-vm:~$ sudo dd if=/dev/urandom of=/dev/sde
    [sudo] password for ibrahim:
    dd: writing to `/dev/sde': No space left on device
    262145+0 records in
    262144+0 records out
    134217728 bytes (134 MB) copied, 30.5276 s, 4.4 MB/s
    

Although the dd command only needs to be run once, you can increase the level of security by running the dd command a number of times to wipe the hard disk. If you are unable to use the /dev/urandom device, you can try your luck by substituting it with devices such as /dev/random or /dev/zero. Once the dd command has completed, shutdown the computer and remove the hard disk.

Note that with sensitive and sophisticated equipment, it is theoretically possible to recover data even after it has been over written. Hard disks with extremely sensitive information need to be sent for degaussing. A hard drive that is degaussed is rendered useless.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }