Fix bad blocks on Mac hard disk

24

18

I have a hard disk that I scanned with TechTool and it reports one bad block. As far as I can tell, TechTool only scans and reports a failure. It doesn't fix anything.

Back in the day, Norton Disk Doctor did the job of scanning and flagging (remapping) bad blocks on the Mac. Today we have various tools for fixing up HFS+ directory errors (Disk Utility, fsck, DiskWarrior, TechTool), but I don't know of any tool that will do a surface scan and fix the bad blocks too.

What software is available for this?

If I know the address of the bad block, is there a low-level terminal utility for marking it?

Andrew Vit

Posted 2010-06-02T21:52:05.997

Reputation: 990

Question was closed 2019-09-08T08:08:58.597

3Modern HDDs remap bad blocks automatically upon failed read operations. The only problem is losing data in that block, which may render a file unreadable/broken, or maybe introduce an error into FS - for that, use your system's checkdisk/fsck (I'm not that familiar with Macs). [Sometimes bad blocks are the result of power loss, and not the hardware problem; this is fixable, but a different topic.] – chronos – 2010-06-02T22:45:06.400

5@chronos There are plenty of modern HDDs that only remap bad blocks automatically upon failed WRITE operations, not read. I've worked with plenty of recent hard drives that will keep failing to read the same bad block again and again and again, but as soon as you write to it, the problem is fixed. – Spiff – 2010-06-04T00:23:46.877

2@Spiff - you are correct, I made an error trying to avoid lengthy explanation of how block's data and CRC fields work together to ensure data integrity, and thus requiring a write operation to check if its a physical block problem or just corrupted CRC (which is fixable). Actually, I am not aware of any modern HDDs performing remap on read... – chronos – 2010-06-04T05:33:42.707

1

There is a thing to consider: my experience of 'fixing' Pending sector on a NTFS partition consisted of 1) identifying the exact data sector, 2) writing to it, and 3) resetting internal NTFS bad sectors counter (which was the only step I documented at http://bogdan.org.ua/2010/03/01/ntfstruncate-binary-for-debian-resetting-ntfs-bad-clusters-counter.html). I am not sure if HFS+ also maintains such a counter of bad blocks - if it does, that may be an additional problem, if you want to recover that single sector.

– chronos – 2010-06-04T05:46:17.417

1Fixing bad sectors on Apple Snow Leopard (2009-10-30) – Graham Perrin – 2013-04-01T18:38:30.927

Answers

9

I don't know of any tool that will do a surface scan and fix the bad blocks too.

What type of a Mac and what type of hard drive are you having problems with?

I doubt you will find any software tools to "fix" bad blocks, at least for recent hardware. I don't know when it started but some time back the ability to remap a bad sector was merged into the firmware of the hard drive.

If you look at the S.M.A.R.T. registers for your drive with a tool like SMARTReporter, you should see an entry with ID number 05 and title "Reallocated Sectors Count". This is the number of bad sector's which the drive has remapped.

Perhaps Disk Warrior's "Bad Block" is referring to something else? (I couldn't guess what that might be though).


Update in reply to comment (below):

SMARTReporter appears to be a rather "quirky" utility. You can in fact query & display the contents of a drive's S.M.A.R.T. registers, you just have to jump through unexpected hoops to do it.

In the SMARTReporter FAQ you can find this tidbit:
Can SMARTReporter tell me exactly which S.M.A.R.T. test is failing?
Yes, starting with version 2.4.5! Right-click the drive in the drive-list in the preferences window and select "Check S.M.A.R.T. attributes".

Another SMARTReporter quirk is that cut'n paste apparently only works in these display windows when you use the menu bar entries. The keyboard shortcuts & mouse "right-click" context window won't do it. On the other hand, SMARTReporter IS free. ;-)

But I digress ...

Curiously, SMART Utility calls the drive "Failing" when all other utilities show it as "Verified". It shows 1 Pending Bad Sectors. So, how do you change a "pending" bad sector to a "removed" or "reallocated" one?

My understanding is that you would not do it. The drive's firmware is supposed to do it automagically on its own. Note what it says in the table in the Wikipedia S.M.A.R.T. article.

  • 05 Reallocated Sectors Count
    Count of reallocated sectors. When the hard drive finds a read/write/verification error, it marks this sector as "reallocated" and transfers data to special reserved area (spare area). This process is also known as remapping, and "reallocated" sectors are called remaps.
    This is why, on modern hard disks, "bad blocks" cannot be found while testing the surface – all bad blocks are hidden in reallocated sectors. However, as the number of reallocated sectors increases, the read/write speed tends to decrease.
    The raw value normally represents a count of the number of bad sectors that have been found and remapped. Thus, the higher the attribute value, the more sectors the drive has had to reallocate.

  • C5 Current Pending Sector Count
    Number of "unstable" sectors (waiting to be remapped, because of read errors). If an unstable sector is subsequently written or read successfully, this value is decreased and the sector is not remapped. Read errors on a sector will not remap the sector (since it might be readable later); instead, the drive firmware remembers that the sector needs to be remapped, and remaps it the next time it's written.

So if the above is true then apparently the Pending Sector Count needs to be interpreted cautiously. The sector read error most likely occured during the disk scan you did earlier with TechTool. (BTW, do you mean TechTool Deluxe 3.1.3?) Since TechTool probably didn't try to write the sector, it was not (yet) reallocated.

Can that be done without a reformat?

I think a "reformat" would only accomplish something if the format wrote to every sector on the drive. I do not know whether a standard (non-secure) erase with Disk Utility ... which is what I believe you mean by a reformat in the context of a MAC ... would accomplish this.

If you did this it would be a very time consuming task. I recently did something like this with a 500GB laptop drive and it took a tad under 2 1/2 hours to complete. Of course, you'd have to add in the time to (hopefully) restore your system from your (hopefully trustworthy) backup.

It is not clear to me that there is a need for you to attempt to actively force this to be "corrected". Supposedly the drive's firmware should handle this on it's own the next time there is an attempt to write to bad sector. Also, it seems likely to me that the offending sector is not currently being used as part of any file. TechTool just "stumbled across" it while scanning all sectors of your drive.

But if you wanted to attempt to force a correction then I guess you'd have to do something which would force a write to that sector. It doesn't seem worth the effort though. I would just continue to back up your files and keep an eye on your drive in case it starts to degrade further.

irrational John

Posted 2010-06-02T21:52:05.997

Reputation: 3 243

1This is for my iMac internal SATA HD.

SMARTReporter doesn't say much beyond "Verified" but another tool called SMART Utility has all the info. Curiously, SMART Utility calls the drive "Failing" when all other utilities show it as "Verified".

It shows 1 Pending Bad Sectors.

So, how do you change a "pending" bad sector to a "removed" or "reallocated" one? Can that be done without a reformat? (Yes I'm backed up, but in the interest of saving time.) – Andrew Vit – 2010-06-02T23:11:32.890

1In addition to what I said in my update above, my personal preference is to run the drive manufacturer's diagnostics. Perhaps it's more than is really needed, but I figure "Why not?" But it beats the heck out of me how to do this for an iMac. Typically, the diagnostics are distributed as a bootable CD image, but I don't believe any of them will boot on an Intel Mac. To get around this I usually remove the drive and mount it in a Windows PC. However, I believe removing the drive from an iMac can be a real PITA which I would not recommend to most. <sigh> – irrational John – 2010-06-03T20:51:27.433

@Andrew Vit - it might be the case that writing to that Pending Bad Sector will fix it (remove the sector from the list of Pending without adding to the list of Reallocated). – chronos – 2010-06-04T05:49:38.080

3For the record, ended up doing exactly that: reformatted with the "write zeros" option which took some time, then cloned back from my backup. My "pending" bad block that was being reported in SMART Utility went away: it just disappeared and the drive shows no bad blocks now... /shrug/ – Andrew Vit – 2010-06-06T08:43:34.290

1@Andrew Vit: Thanks for updating with your status. I always appreciate finding out how the story ends. If it makes you happy, then no doubt it was worth the trouble. But IMO the "write zeros" reformat was overkill. The sector probably wasn't being actively used and would (probably) have been remapped if/when you did use it. Out of curiousity, could you check your SMART values again and see if the sector was in fact remapped? (Reallocation count changed from 0 to 1?) Or whether it was "just a corrupted CRC", a possibility that chronos mentioned in an earlier comment? – irrational John – 2010-06-06T12:35:56.557

12

If you're seeing bad blocks when you run a filesystem integrity check, the hard drive has most likely already exceeded the number of blocks it can remap, and has exhausted its "spare" sectors. You should backup your data immediately (if you haven't already) and replace the drive before the problem gets worse and you lose your data.

I'd suggest downloading smartmontools and GSmartControl to view the SMART diagnostics as another check, if you aren't sure which SMART diagnostics to trust.

If the SMART diagnostics are reporting no reallocated sectors (or if the VALUE column for "Reallocated Sector Count" is still well below THRESHOLD), there is an easy way to perform a surface scan and remap the bad blocks at the same time. (Note: make sure to backup your data first!)

The easiest way to force the drive to do its own bad block remapping is to boot from an Ubuntu Live CD, then open a terminal and run this command:

sudo badblocks -nvs /dev/sda

This will do a non-destructive random read-write test on the first drive, remapping bad sectors along the way.

If you have more than one hard drive, you can replace /dev/sda with /dev/sdX, where X is lowercase letter. You can get a list of all hard disks (/dev/sdX devices) by typing this command:

sudo fdisk -l

Since you're using Mac OS X, which is based on BSD, you might also want to read up on badsect and bad144, which are the built-in BSD command-line utilities for dealing with bad blocks.

rob

Posted 2010-06-02T21:52:05.997

Reputation: 13 188

This is going to take a while: Testing with random pattern: 0.15% done, 27:02 elapsed. (0/0/0 errors) – neu242 – 2013-08-12T09:27:40.220

Alternatively, if you have unix tools installed on a different startup disk, you can download and build http://e2fsprogs.sourceforge.net/ which contains badblocks. Then just unmount the disk you want to check and run badblocks on it.

– user8128167 – 2014-02-24T04:08:16.363

6

The OS X builtin command fsck_hfs has an option -S that apparently will scan and rectify bad blocks on a hard disk on OS X.

From the documentation:

-S Cause fsck_hfs to scan the entire device looking for I/O errors. It will attempt to map the blocks with errors to names, similar to the -B option.

Example:

fsck_hfs -fy -S /dev/disk3s11

It seems to be doing that when run on a a disk without bad blocks but I've yet to check/document what it does when there are bad blocks.

Matthew Elvey

Posted 2010-06-02T21:52:05.997

Reputation: 419

I don't believe that this does a per-block read and rewrite like badblocks -n, which is frequently necessary to get the disk firmware to actually spare out the block. – Taryn – 2018-11-07T00:36:08.577

6

My experience with SpinRite from grc.com has been very positive. I've managed to recover at least 4 disks that have failed every other attempt to repair them. The only downside is that it requires a BIOS-based machine, meaning it won't work on modern EFI-based Macs. The good thing is that just about any other p.o.c. PC will run it, from floppy, CD, or flash drive. I've not found anything else that comes close in terms of actually inspecting the contents of individual sectors and recovering the data in what every other utility discards as a bad block.

Alphaman

Posted 2010-06-02T21:52:05.997

Reputation: 61

3

It's bit of an old question, but still valid. What worked for me is the following:

  • If possible start up from a partition or drive other than your main one. Make sure it's not the Mac's Recovery option if you want to use a 3rd party application to identify the corrupt files
  • Identify all the files on your harddive that are corrupted due to bad blocks. I happen to use Carbon Copy Cloner to create a mirror of my drive as a backup (it gives you a list of corrupt files). There are probably other tools around that can do this.
  • Locate these files on your drive, and delete them (empty the trash as well!)
  • Open Disk Utility and erase empty disk space by writing '0's. (you only have to write once, so pick the fastest option). Please mind, this can still take some time, especially if you have a lot of free space.

This identifies the bad blocks and marks them as such so the won't be used again. As mentioned earlier, errors will only show up when trying to WRITE to it. By writing 0's, you do just that.

  • if you have a backup of these files somewhere, manually replace them from your backup (if you want to replace them in the first place).

I can imagine this can be very time-consuming, especially if there are many errors and thus many files to replace. If that's the case, consider replacing the drive, it'll get worse...

Gerbie

Posted 2010-06-02T21:52:05.997

Reputation: 31

0

I've heard good things about SpinRite from GRC, but never tried it myself.

fredden

Posted 2010-06-02T21:52:05.997

Reputation: 286

Sadly, SpinRite would likely do more harm than good on an already-failing drive. :( – rob – 2010-06-03T22:45:58.280

the controversial guy that made spinrite has been caught saying a lot of bullshit back in the early 2000s; I remember him writing about 'weak bits' which is something that just does not exist for example. – Thomas – 2017-05-24T15:55:30.443

@rob harm in what way? SpinRite seems to combine a number of approaches, with an emphasis on extraordinarily good care … – Graham Perrin – 2013-04-01T15:08:00.800

2@GrahamPerrin for one, it doesn't make sense to attempt to recover your data and write it back to the same known defective media. But ignoring that, as soon as SpinRite encounters an unreadable block, it tries and retries repeatedly before continuing. In the meantime, the drive can continue to degrade to the point of total failure (either "naturally" or possibly as a result of extra wear & tear caused by SpinRite's constant retries). I've run SpinRite on a failing 250 GB hard drive in the past, and it ran for more than a month without completing. In short: try ddrescue and other tools first. – rob – 2013-04-01T22:10:26.283

2@rob thanks, I didn't realise that. GRC Tech Support confirmed to me that recovery to something other than the disk from which recovery is attempted is not supported in the current version of SpinRite. – Graham Perrin – 2013-04-19T19:50:23.337

0

It sounds like most drives will only reallocate a bad block on a write, so that's how all processes 'fix' bad blocks. If you're willing to reformat, lots of people talk about doing a low-level format that writes zeros (Disk Utility will do this).

The only tool on the Mac that I found that will do this is "Speed Tools". When it finds a bad block it will write a zero to the block (even if it's in a file... the thinking is that it's already bad).

http://www.intechusa.com/

aerickson

Posted 2010-06-02T21:52:05.997

Reputation: 24

That’s not what a low level format does, or even any kind of format, as format doesn’t mean to erase, it means to put the drive in a format that allows using it. A low level format decides where to put the tracks and sectors on the disk, and is only needed once when the drive is manufactured.

– Chai T. Rex – 2019-05-29T23:08:54.397

If you read a bit further, you'll see that the article you linked mentions that "low level formatting" has now come to mean writing the same value to all blocks. https://en.wikipedia.org/wiki/Disk_formatting#Disk_reinitialization

– aerickson – 2019-05-31T01:16:41.010

If you read a bit further, you'll see that that's still incorrect. – Chai T. Rex – 2019-06-01T01:56:32.380

0

Attention first to the comment by @chronos … think: dataloss. In an edge case, a fix may make recovery of data impossible.


Amongst the utilities that I have used on Macs, one is outstanding for unmistakable alerts such as this:

enter image description here

Warning

The operation you are about to perform may cause data loss.

To spare a bad block … write data to the drive. This will most likely result in volume or data corruption if a bad block is found and spared.

You can learn about such things before purchasing the product – refreshingly honest.

(To appreciate the risk of dataloss, see for example the SpinRite documentation linked from the Why care? part of my answer under How to check whether there is bad sector on a USB harddisk on OS X?)

For its unmistakable warnings, for pre-purchase satisfaction and more, this answer is my vote of confidence in:

Drive Genius 3

Graham Perrin

Posted 2010-06-02T21:52:05.997

Reputation: 1 147

In Ask Different there's a comment from @BSDGuy – Graham Perrin – 2013-04-19T19:40:32.170

-1

Horrible, Horrible advise above. I mean WOW-horrible advise. :shakes head:

  1. I don't know of any modern utilities for Mac OS X that actually fix (mark) bad blocks and let you get on with your day. That being said, you need to find an older version of Norton Utilities for Mac OS to fix the bad blocks on the HD in question. Such as Version 7.0 or 8.0.

  2. Since I'm assuming you are using a PC in Mac's clothing(Post PPC computer using an intel CPU and running Unix[Mac OS X]), you will need to find yourself a good PPC Macintosh (or maybe it will run in emulation on an intel PC?) that can still boot OS 9. Get a (I'm assuming you have a SATA HD?) SATA PCI card that works with OS 9. Then boot off the Norton CD, run Disk Doctor, and scan/repair the HD in question.

  3. This just sounds hard to do, but it's not. Being a "REAL" Mac technician and fan boy for the last 20 some years, I have machines from the 128k up to a Dual G5, so the hardware is just lying around for me. In other words, it's super easy for me.

  4. Why do I sound rude? Because I am. I'm very crossed with the current Apple, and I especially hate Steve Jobs for destroying Apple Computer for us 1980's and 90's Macintosh Users, and turning the Mac into nothing more than a PC that runs a bland version of Unix. He, and the people that think like him, are the reason that Mac's no longer have the utilities you need to repair your HD "properly".

  5. Anyone that tells you to look at SMART data, or relies on SMART data in any way, you should not listen to them. SMART is extremely flawed.

  6. HD's have almost always remapped bad blocks automatically, at least since I can remember and I'm old for a technician. BUT! They do a crappy job at it and if you are seeing bad blocks, that's because the HD has run out of the tiny amount of space that is reserved for re-mapping bad blocks automatically. IE, you need to run a utility that does a better job at it.

NotAnMSFan

Posted 2010-06-02T21:52:05.997

Reputation: 17