Linux Administrator

How to Wipe Hard Drive Clean Using dd Command in Linux

If you want to wipe your hard drive to clean up partition error, bad installations, or for privacy. This tutorial will help you how to do this.

In this article I will show how to wipe hard drive clean using dd command in Linux.

Wipe Entire Disk

This will overwrite all partitions, master boot records, and data. Use the sudo command as well (sudo dd…).

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/sdX bs=1M 

Replace X with the target drive letter.

2. If you are wiping your hard drive for security, you should populate it with random data rather than zeros (This is going to take even longer than the first example.) :

dd if=/dev/urandom of=/dev/sdX bs=1M *replace X with the target drive letter.

Replace X with the target drive letter.

You need to replace sda with the device name you want to overwrite. sda is usually the first hard drive, the second drive would be sdb and so on. Use for example gparted to find the correct drive. If you replace the device name, you can also wipe USB sticks and other peripherals.

Wipe Master Boot Record (MBR)

If you messed up your master boot record (MBR) you can wipe it using this command :

dd if=/dev/zero of=/dev/hdX bs=446 count=1

Replace X with the target drive letter.

Wipe Partitions

You can wipe a partition using the same method than for the whole disk. Just replace the device identifier. If /dev/sda is the whole disk, then (on Linux, because the naming scheme vary from one Linux to another) /dev/sda3 is the third partition on the disk.

1. Filling the second partition on the /dev/sda disk with all zeros :

dd if=/dev/zero of=/dev/sdX2 bs=1M

Replace X with the target drive letter.

2. Filling the third partition with random data :

dd if=/dev/urandom of=/dev/sdX3 bs=1M

Replace X with the target drive letter.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.


  • Yes but before issuing dd to erase a disk using /dev/zero the volume has to be unmounted. Sorry if I missed that in your article.

  • This command will fill first disk partition with ones (and informing the beginning of the process):
    echo “Current time:” `date +”%Y-%m-%d %T”`
    tr ‘\0’ ‘\377’ /dev/sdX1 bs=1M

  • Thanks for the article! It was very informative.

    dd if=/dev/zero of=/dev/sdb3 bs=1M did not work for me. I am on Centos this is the error I got
    “Error: Could not stat device sdb3 – No such file or directory.”

  • I really didn’t know some of these things before which you have informed us through your helpful and informative article!! Thank you and keep sharing awesome stuff.

Leave a Comment