24

How can I check whether there are any bad sectors on an externally connected USB hard disk drive?

1

6 Answers 6

6

Related questions

  1. Fix bad blocks on Mac hard disk – includes some non-free and closed source software
  2. What free or open source software can I use with Mac hardware to verify integrity of every block of a disk …?

It's sometimes inappropriate to use the automatic sector relocation capabilities of a drive, so the question raised by ohho becomes distinctive:

  • it's about discovery.

Essentially

If there's a defective sector, then you'll either:

  • care about data within that sector; or
  • not care

– consider this before performing any action that may cause relocation (or remapping or sparing, or whatever you call it).

Why care?

Whilst SpinRite 6 is not for Macs, a 2003 page for version 5 is enlightening:

Note the section about auto-relocation and the associated risk of dataloss.

SpinRite aside, fast forward a decade from 2003 to 2013:


To the question here …

How to check whether there is bad sector on a USB harddisk on OS X?

For Mac – for OS X – I don't know of anything as capable and careful as SpinRite (nothing to disable auto-relocation).

So, as things stand: to verify the sectors of a disk on USB with OS X, we're probably limited to using utilities that may cause relocation. I can't estimate the degree of risk of associated dataloss, but if that risk is acceptable then I should steer first towards:

  • the utilities that are up-voted or recommended in related questions (1) and (2) above.

Hint: what's under related question (1) is more immediately user-friendly.

S.M.A.R.T.

The OS alone can not use S.M.A.R.T. technologies on drives that are external on buses such as USB 2.0 and FireWire.

Elsewhere there's a wealth of information ( and misunderstanding ;) so I'll focus this part of the answer on just one point:

  • getting Apple's OS to work with S.M.A.R.T. technology with external USB and FireWire drives.

OS X SAT SMART Driver

kasbert / OS-X-SAT-SMART-Driver on GitHub:

… a kernel driver for Mac OS X external USB or FireWire drives. It extends the standard driver behaviour by providing access to drive SMART data. The interface to SMART data is same as with ATA family driver, so most existing applications should work. The driver requires a SAT (SCSI ATA Translation) capable external drive enclosure. …

If you try this KEXT with Lion then – as with any third party kernel extension – proceed with caution.

28

The OS X built in command fsck_hfs has an option -S that apparently will check whether there is bad block on a USB hard disk on OS X.

From the official man page(Update: Bloody hell! Apple has removed the manpages from its site.):

-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 partitions without bad blocks but I've yet to check/document what it does when there are bad blocks.

Update: Warning: fsck_apfs cannot do this; while it also has a -S option, it does NOT cause a scan; it does something else entirely.

5
4

Open the Terminal.app in Applications/Utilities.

Cut and paste this inside to install Brew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install e2fsprogs with brew: brew install e2fsprogs

Type diskutil list to find your device (/dev/diskX)

Run badblocks on your device: (replace the X with your device number)

/usr/local/Cellar/e2fsprogs/1.44.3/sbin/badblocks -v /dev/diskX

3
  • You might want to adjust with your version number (1.44.3 here) in the line: '/usr/local/Cellar/e2fsprogs/1.44.3/sbin/badblocks -v /dev/diskX'
    – brunobhr
    Jun 28, 2019 at 12:57
  • On macOS High Sierra 10.13.6: Operation not permitted while trying to determine device size (with/without sudo)
    – bonh
    Jul 1, 2019 at 3:06
  • Could it be linked to the SIP protection? osxdaily.com/2015/10/05/…
    – brunobhr
    Jul 1, 2019 at 12:05
0

Depending on the filesystem on the drive you could run

fsck_msdos /dev/disk1s1

This would check an FAT FS. Maybe that's what you want? Possible commands are:

fsck_cs
fsck_exfat
fsck_hfs
fsck_msdos
fsck_udf
2
  • 3
    These commands check (and optionally repair) the volume data structures, they don't scan the disk for readability/writability of the disk surface. Feb 27, 2012 at 15:48
  • 1
    fsck_hfs -S scans the entire filesystem contents and maps blocks with I/O errors to names.
    – siefca
    Dec 26, 2017 at 16:30
0

Only way to really know is to write to each sector and read it back to see if you get the same thing back, checking for errors on the way.

badblocks under Linux does this. badblocks has a nondestructive read/write test mode.

Under Windows, I believe if you invoke chkdsk with the /F, /B, and /R options it will test each sector for bad sectors. It is also non-destructive but I'm not sure if it actually writes to each sector to test.

This Superuser answer suggests that SpinRite 6 may also do the same thing but I haven't tested.

0

Let me advise you in what order you should proceed if you suspect/know you have bad sectors:

1) Make a copy of your entire partition to another device using dd (look up your partition name using df). This might take a while, maybe more than a day on a USB2 disk for 400Gb. bs= speeds it up (factor 5 or more), sync fills input blocks with zeroes if there were any read errors.

dd if=/dev/disk3s8 of=/dev/disk4s9 bs=1024k conv=noerror,sync

2) Then check if it actually worked, not only the folder structure but also open the content.

3) If it didn't, try to copy the content of your partition on a file level.

cp -Rp /Volumes/<source>/ /Volumes/<destination>/

4) Only now, that you have tried to save as much as you can without touching the filesystem, run a check on the partition. -f option will force even if it appears ok, -S scans for bad blocks. This operation is not guaranteed to be non-destrictive, but it might save your disk.

fsck_hfs -fS /dev/disk3s8

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .