Ubuntu: how to fix the hard-drive Bad Sector



Question:

I tried to fix my hard drive using Ubuntu but I found that message and didn't know what to do with.... I need to fix my bad sectors

fsck /dev/sdb    fsck from util-linux 2.20.1    e2fsck 1.42.5 (29-Jul-2012)    fsck.ext2: Permission denied while trying to open /dev/sdb    You must have r/w access to the filesystem or be root    


Solution:1

A bad sector on a drive is a sign of permanent damage to the drive. Unless you have reason to believe that your drive marked these sectors as bad incorrectly, you cannot "fix" them.

It means that a part of your drive is damaged to the extent that it can no longer reliably be read from and/or written to.

Your system can continue to use the drive by marking that sector as unusable, but I'd generally recommend a drive replacement anyway, as often a bad sector can be a sign that more sectors, or the whole drive, may fail soon.

In fact, you can often force the drive to un-mark a sector as bad, and that sector will be usable again. However, it may stay like this, or it may become bad again, which is why this is not a good idea.

Now, as for the error message you've pasted in your question (as of my writing this), that error has nothing to do with bad sectors. It means that you don't have access to the drive. Being sudo can give you access, so:

sudo fsck /dev/sdb  

However, this is still probably not what you want, because /dev/sdb refers to the entire drive, whereas fsck is designed to work on filesystems, which are usually (but not always, and you may have an exception here) placed in partitions. If the above didn't work, you may instead have wanted to do this to the 1st partition on that drive:

sudo fsck /dev/sdb1  

You can get a list of partitions per drive with:

sudo fdisk -l  


Solution:2

I have answered the same question already.

In short: Boot a rescue system and use

badblocks -svn /dev/sda  

to have the hard disk controller replace bad blocks by spare blocks.

Read more details here: https://askubuntu.com/a/490549/299014


Solution:3

In the olden days you used to have to take a note of the badblocks that were written on the drive and enter those in the defect list before formatting the drive, because hard disk surfaces were never "perfect", manufacturer's got wise to this because people buying disks would look at the defect table printed on the disk and buy the ones with the least amount of defects...

Now scroll forward 20 or so years and hard disk manufacturers hide the fact a brand new disk has bad blocks with the firmware, when you buy a brand new disk it will have in all probability bad blocks already, the firmware will detect newly grown badblocks and maps them out from a set of spare cylinders it has, but this only happens when a write operation occurs on that sector and the ECC algorithm detects bit failure, only then will it map the block out. So getting back to the point you can force a drive to map out the badblocks by simply using DD, ie/

dd if=/dev/zero of=/dev/sd?? bs=1M   

obviously alter the of=target to reflect the drive you want to zero this is the quickest way to re-map a drives defects, its also the quickest way to totally trash your linux setup by getting the target drive wrong, so check, double check then check again, before you press the enter key, you can increase the size of the blocksize in the dd command to make things go quicker but there are diminishing returns after a point, I find anything between 1M and 8M works best for me

You can get DD to just write one sector, the bad one... to get it remapped, so you don't have to backup your drive, but that's a whole different kettle of fish and Russian roulette if you don't know exactly what you're doing .....

This command WILL destroy everything on your hard drive including any partitions. But it will force the drive to map out any bad sectors it may have.

It is perfectly ok for a disk to have bad sectors as long as they aren't on the boot sector, if they are then the drive is useless, if you notice a few months later that your drive has developed more bad sectors then it's time to start shopping for a replacement.

I've revived hundreds of drives like this and they've lived on for many years afterwards, a bad sector isn't necessarily the death knell for the drive.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »