How to remove Bad Sectors from HD

Questions about the project and the distribution - obviously no support questions here please
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
Locked
madonawills

How to remove Bad Sectors from HD

Post by madonawills »

I want to remove Bad Sectors from my Hard Disk, How I can ?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
itsme4401

Re: How to remove Bad Sectors from HD

Post by itsme4401 »

Simply stated: You can't.
Even worse: Your HDD is stating to you that its decease is immiment.
Smartcontrol

Code: Select all

sudo smartctl -a /dev/sda
should give you the answer how bad it is.
Back up your data now(!) i.e. even before you run smartcontrol.
homerscousin

Re: How to remove Bad Sectors from HD

Post by homerscousin »

It depends. A power outage can cause bad sectors. They can probably be fixed. A deteriorating disk surface or read/write head you may fix some errors now, but they will be back. Noone here could even guess without you posting your SMART numbers. There are lots of disk scanning programs out there from HDD manufacturers, Windows and Linux. You can easily Google search this. Just be aware that these programs are very HDD intensive. They scan the entire disk. If you have a fragile disk to begin with, it may only make it worse. Be prepared with a new drive and save all your important files before you try to fix.
User avatar
heavy metal
Level 3
Level 3
Posts: 148
Joined: Mon Jan 25, 2010 11:00 pm
Location: Puerto Rico

Re: How to remove Bad Sectors from HD

Post by heavy metal »

Install "GSmartControl" and/or "Gnome-Disk-Utility (Palimpsest)", Both programs are IMHO the best out there and they work very good in telling you the condition of your disk, been using these programs since Lucid Linx and now on LM Maya!
Debian 12 Gnome on a MSI H61M-P25 (B3) PC & on a Dell Latitude E6410 & HP EliteBook 8540p Laptops.
LMDE 6 on a Panasonic ToughBook CF-C1 Laptop.
Bodhi Linux 7 on a HP Compaq DC5750 Small Form Factor PC.
Windows 11 on a Intel DH55TC PC.
User avatar
heavy metal
Level 3
Level 3
Posts: 148
Joined: Mon Jan 25, 2010 11:00 pm
Location: Puerto Rico

Re: How to remove Bad Sectors from HD

Post by heavy metal »

FYI, I have succeeded in removing bad sectors from my brother's 160GB Western Digital Hard Drive, I just used an Windows XP install cd I had around, just use the "Full Format" option, not the "Quick Format" option, the Windows Full Format option will check and try to repair any errors like bad sectors on your hard disk, at least it worked for my brother's hard disk!
Debian 12 Gnome on a MSI H61M-P25 (B3) PC & on a Dell Latitude E6410 & HP EliteBook 8540p Laptops.
LMDE 6 on a Panasonic ToughBook CF-C1 Laptop.
Bodhi Linux 7 on a HP Compaq DC5750 Small Form Factor PC.
Windows 11 on a Intel DH55TC PC.
woodsman

Re: How to remove Bad Sectors from HD

Post by woodsman »

Can you clone the drive to free up that drive?

Theoretically you then can perform a full write and read to require the firmware to mark the bad blocks. Something like this:

dd if=/dev/zero of=/dev/sdX
dd if=/dev/sdX of=/dev/null

Some might argue that only the latter command is needed to have the firmware mark bad blocks. In that case you do not need to clone the drive or even backup. You do need to boot with a live disk, however, in order to have the drive not in use anywhere.

Of course, performing the first command will destroy all data, which is why I asked whether you can clone the drive. Please do not execute that first command on any drive that you still need the data. :)

There is a how-to often cited but following the instructions is a challenge for many people because of the expertise required:

http://smartmontools.sourceforge.net/badblockhowto.html

That all said, I have had drives that once they started developing bad blocks never could be repaired. Bad blocks kept returning. Sometimes best to replace the drive and then use the suspect drive for spare projects where data retention is not mission critical.

I use smartd to monitor my drives in all systems and have the configuration files set to send me emails of any errors.
User avatar
coffee412
Level 8
Level 8
Posts: 2183
Joined: Mon Nov 12, 2012 7:38 pm
Location: I dont know
Contact:

Re: How to remove Bad Sectors from HD

Post by coffee412 »

There is good advice in the replies about hard drives and bad sectors. What I would like to do is go thru a typical repair problem with the OP question.

-= BAD SECTORS =-

Bad sectors on a hard drive are caused by different problems. Basically what happens is that the drive read/write heads are either damaged in some way or for some reason damage a sector(s) on the hard drive. Perhaps the read/write heads of the drive are just wearing out and not able to read some sectors correctly. Either way you are going to be ahead of the game by replacing the drive in question. You can never remove a bad sector. What you can do is have the sector marked out so that it is not used in the future. Most current drives firmware, when it detects a bad sector, will do this and has spare sectors available to remap the bad sector to a good sector. However, These are limited. Running smartcontrol and checking the readout from your drive is a good way of seeing if you have bad sectors and how many have been remapped. In my shop if I detect a bad sector I recommend a replacement drive as soon as possible. The reason for this is because even though the bad sector has been remapped you will eventually be finding more bad sectors as the drive is used more.

-= BACKING UP =-

Before you do anything with the drive you want to at the very least backup your data. This can be as simple as installing an other drive and making a copy of your home directory to the backup drive. In this senario you will be reinstalling your operating system on the new replacement drive and then moving your important documents over to the new drive from your backup drive. A better way to make a backup is to clone your bad drive (if you can) to the backup drive using DD. DD is a command line program that is very easy to work with but will take a while to perform the cloning. DD does a sector by sector copy of the drive including unused space. Therefore it is common for it to take a long time to perform this. However, Using DD will duplicate everything on the disk so that you only need to swap out the bad disk for the good cloned replacement. Keep in mind that should the bad sectors contain important files you might have to do some new repairs after replacement. Anyways, To perform a clone of a bad drive (we will call it /dev/sda) to a new drive (we will call /dev/sdb) you will need to boot from (in this case) your mint dvd and open up a term window , issue the following command as root:

Code: Select all

sudo DD if=/dev/sda of=/dev/sdb conv=sync,noerror
DD will perform a clone of the bad drive to the new drive and should it encounter bad sectors it will not error out.

You can also use clonezilla, A bootable cd. Be sure to go into expert mode and select skip bad sectors.

When complete replace your old drive with the new clone. Be sure to mark your bad drive with a black marker pen as bad. No sense in keeping it around either as some tend to do.

-= SOME OTHER THOUGHTS =-

Its very important that whenever you are going to work on a drive that you get a backup of some sort before you do. What normally happens when a drive is suspected of being bad is that in the testing phase you are stressing the drive and it could fail or develop other problems.

Its also important to understand that should you be in a situation where you are recovering files from a drive you should clone the drive or perhaps just the partition and work on that instead of the bad drive. The reason for this is that during a recovery a drive is stressed pretty hard and can fail during the recovery.

DD is always performed on unmounted drives.

I cannot stress enough that you backup. Even if your drives are good you should have some backup plan. If your just interested in backing up important files you can use a program like rsync and backup to a secondary drive in the computer. Operating systems can always be reinstalled but data is the important stuff.

On my surfing box I have a 1TB system drive and a spare 1TB that I use rsync to back up my home directory. Making a bash script to backup the home directory and creating a cron job to do this at 2am in the morning. Should I ever need to recover a file it becomes quite easy then. I also run a 3 disk raid5 setup on my backup server for all important files and image files. This is more advanced but provides an extra layer of safety.

One other point - Clonezilla is a fine program but I have ran into situations where the drive discriptions can get swapped around. Be very sure which drive is which!

In linux you would see this:
/dev/sda (bad drive)
/dev/sdb (replacement drive)

Booting from a clonezilla disk you might see this instead:
/dev/sda (GOOD DRIVE)
/dev/sdb (BAD DRIVE)

Therefore, Do not assume that the discription of your drives will be the same when booting from a clonezilla disk other wise you will have 2 blank disks!!


coffee :D
Ryzen x1800 Asus Prime x370-Pro 32 gigs Ram RX480 graphics
Dell PE T610, Dell PE T710
- List your hardware Profile: inxi -Fxpmrz
MeshCentral * Virtualbox * Debian * InvoiceNinja * NextCloud * Linux since kernel 2.0.36
srs5694
Level 6
Level 6
Posts: 1386
Joined: Mon Feb 27, 2012 1:42 pm

Re: How to remove Bad Sectors from HD

Post by srs5694 »

heavy metal wrote:FYI, I have succeeded in removing bad sectors from my brother's 160GB Western Digital Hard Drive, I just used an Windows XP install cd I had around, just use the "Full Format" option, not the "Quick Format" option, the Windows Full Format option will check and try to repair any errors like bad sectors on your hard disk, at least it worked for my brother's hard disk!
Chances are you simply wrote data around the bad sectors, by reorganizing which sectors are used. The bad sectors are still there. The filesystem might map them out, but bad sectors often spread, so the problem is very likely to recur. There are analogous tools for some Linux filesystems, but they're basically historical relics, from the days before SMART hard disks. I wouldn't recommend using them.

It's also possible that you triggered the drive to automatically swap the bad sectors with spares, as coffee412 described. This would have happened sooner or later in any event -- but in my experience, if the disk was showing symptoms of having bad sectors, the odds of a rapid increase in problems are very high, even if the disk maps out the first of the bad sectors.

The most optimistic interpretation of what happened to you is that it wasn't bad sectors at all, but some sort of filesystem damage. In that case, a complete reformat of the disk would certainly fix the problem.

This is just entropy in action. Disks fall apart, just like everything else. Unfortunately, we lack the technology to do the microscopic repairs that would be necessary to save a disk once it starts to physically fail. Sector re-mapping and mapping bad sectors out of use by the filesystem are just ways to delay the inevitable. I agree with coffee412 and others who've said that you should replace a drive the moment you start seeing bad sectors. Trying to squeeze a little more life out of the disk is flirting with disaster.
User avatar
coffee412
Level 8
Level 8
Posts: 2183
Joined: Mon Nov 12, 2012 7:38 pm
Location: I dont know
Contact:

Re: How to remove Bad Sectors from HD

Post by coffee412 »

It just doesnt make any sense to map out a bad sector and proclaim "My hard drive is fixed!". Its still broke and its going to eventually get worse. So then, Your going to have more issues and have to fix them again (rinse / repeat...).

Just replace the failing drive.

Besides, How valuable is your data?

coffee
Ryzen x1800 Asus Prime x370-Pro 32 gigs Ram RX480 graphics
Dell PE T610, Dell PE T710
- List your hardware Profile: inxi -Fxpmrz
MeshCentral * Virtualbox * Debian * InvoiceNinja * NextCloud * Linux since kernel 2.0.36
Edward M. Grant

Re: How to remove Bad Sectors from HD

Post by Edward M. Grant »

coffee412 wrote:It just doesnt make any sense to map out a bad sector and proclaim "My hard drive is fixed!". Its still broke and its going to eventually get worse. So then, Your going to have more issues and have to fix them again (rinse / repeat...).
That depends. My CentOS telecommuting machine reported 1 bad block on its boot disk soon after I installed the OS in 2008 and is still reporting 1 bad block today. My old Toshiba laptop started reporting bad blocks one day, and was increasing the number of bad blocks by about a hundred a day by the time I replaced the drive.

So I wouldn't worry much about a single bad block, but if the number keeps increasing, it's time to replace the disk.
srs5694
Level 6
Level 6
Posts: 1386
Joined: Mon Feb 27, 2012 1:42 pm

Re: How to remove Bad Sectors from HD

Post by srs5694 »

Modern disks use SMART, which is supposed to map out a small number of bad blocks. Thus, if a single bad block becomes visible to the OS, that means that the number of bad blocks on the disk is actually much higher than that -- enough to exceed the manufacturer-defined safety margin for the disk. It's like spotting a termite in your house -- the one you spotted is not the only one there!
kukamuumuka

Re: How to remove Bad Sectors from HD

Post by kukamuumuka »

1. backup your data and OS from the partition and re-format the partition via another partition or live-DVD/USB

Code: Select all

sudo mkfs.ext4 -c /dev/sdxy  ## where x=drive and y=partition
PatH57

Re: How to remove Bad Sectors from HD

Post by PatH57 »

Hi,

agree with all of your comments, if the good drive tells you he is seek then he is...
That said play with it as a spare, will teach alot about how it works (time consuming but linux users like to know :D )
Get a USB to disk converter for a few $ and install or try to install different OSs (got winxp, win7 and win8 one one faulty) and when it goes belly up you didn't loose anything but you learned a lot.
Just for fun...
Locked

Return to “Non-technical Questions”