How to clear bad sectors in hard disk using ubuntu

My hard disk has developed more than 1200 bad sectors and it is failing to install any operating system. I am using ubuntu 12.04 through my pen drive. I need to zero fill my hard disk. Please advice.


Solution 1:

Well you have a lot of bad sectors. My advise is to replace the drive. But if you still want to mark those bad sectors, then you can use fsck. fsck is used to check and optionally repair one or more Linux file systems. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo fsck /dev/sd*  (replace * with your device ID)

Note: When dealing with any hard drive issue please make sure that you have a current backup of all you information.

The "fsck" command stands for "file system check"; it scans the disk for bad sectors and labels the ones that aren't working.

If you want to zero out the drive, just follow Piskvor's answer.

Solution 2:

To answer your specific question: sudo dd if=/dev/zero of=/dev/sdX will overwrite disk /dev/sdX with zeroes. Use with caution; there is no "undo" for this.

To address the underlying problem: if your hard disk has this many errors, it will fail catastrophically in the very near future, and you will lose anything that's written on it; replace it with a working one ASAP. Overwriting it with zeroes will not eliminate the bad sectors, and only postpones the problem.