How To Wipe Hard Drives With DD Command In Linux

In this guide I will be showing you how to wipe your hard drives using the Linux dd command with dd examples. You have a few options when it comes to wiping your hard drives, you can wipe the MBR (master boot record) or you can wipe the entire drive. If you are looking for a guide on wiping specific files only, then please read about the shred command.

How To Wipe Entire Hard Drive With DD

Lets begin with a dd example for wiping the entire drive. If you want to make sure the data is not going to be recovered then you should probably use random data and not just 1 repeating bit. The following command will wipe /dev/sda by overwriting the entire drive with random bits. You can change the target drive by changing /dev/sda to whichever drive you wish to wipe. The OS is usually going to be on /dev/sda.

dd if=/dev/urandom of=/dev/sda

If you would like to really make sure the data will not be recoverable, then you can over-write multiple times using a bash loop and the Linux dd command. The one liner below will overwrite the entire hard drive 3 times.

for i in {1..3}; do; echo "Phase: $i"; dd if=/dev/urandom of=/dev/sda; done

How To Wipe The MBR (Master Boot Record) Only

If you are not worried about whether the data can be recovered and just need to do a quick format (for example during re-provisioning of servers that boot to disk before PXE), then you can simply zap the MBR and the drive will no longer be bootable. This will force your server to skip booting from the hard drive and continue through the boot order.

dd if=/dev/urandom of=/dev/sda bs=512 count=2

How To Wipe Old IDE Hard Drives

One thing to note is that the above Linux dd commands are for SATA drives only, if you still have an old IDE hard drive then you will need to replace sd* with hd*. Here is an example of wiping an old IDE hard drive using the dd command.

dd if=/dev/urandom of=/dev/hda

I hope this post on using the dd command has helped you, please don’t forget to like, comment, or share. Thanks for the support!

Leave a Reply

Protected with IP Blacklist CloudIP Blacklist Cloud