External Hard Drive bad sectors recover/mark utility in linux

I've just installed the new version of Ubuntu, Karmic Koala, in my laptop. Everything is fine, except for the fact the system identified about 300 bad sectors in my 1TB external hard drive. I'd like to recover or just mark then. Is there any free utility, that I can run on Linux, to accomplish this?

Update:

The partition is formatted in NTFS.

Thanks in advance


If the OS itself is showing bad sectors, then your drive is going downhill. The hardware should be removing bad sectors from service transparently, and it may have run out of spare sectors to remap to. If this is the case, your data is very much at risk.

I'd take David's suggestion to heart and migrate your data ASAP. You may want to install "smartmontools" and run smartctl to see what the device itself reports.

You can try using the "badblocks" utility on the raw device which houses your NTFS drive, since it works on the device and is not filesystem dependent. Make sure you read the man pages CAREFULLY and use the non-destructive mode. It should be able to read each sector, then re-write each sector. Doing this should force the drive itself to remap any problematic sectors. Test this procedure on a USB stick or some other media first.

I recommend you tell badblocks to process a large number of sectors at a time, since a 1TB drive will take a very long time to scan.

Again... make sure you know what you are doing. One slip and your data is toast.

If the data is valuable to you and you're not confident in your abilities, you may wish to use a commercial solution such as SpinRite (though, it's pricey and will require a Windows machinie). Note, I've never used SpinRite, but I've heard good things about it online.


It depends on the filesystem you are using. If you are using ext2, etx3 or ext4 (IIRC Ubuntu 9.10 defaults to ext4 for new installs, earlier versions default to ext3) then you can run

e2fsck -c -c -k -C 0 /dev/device

i.e.

e2fsck -c -c -k -C 0 /dev/sdc1

for the filesystem on the first partition of drive sdc. The filesystem should not be mounted while this takes place, so if it is needed for your normal running system you will need to run e2fsck while booted from a "live CD" or similar.

The -c option is what causes the surface scan to be added to what the checker does, then second -c makes it do a non-destructive write+read test, -k tells it to keep any existing list of badblocks instead of retesting them and -C 0 just makes e2fsck output more progress information as it does its work. See man e2fsck for more detail.

The above will mark the bad blocks so that are not used in future. You will need to rerun it if you ever reformat the drive or that individual partition. You should also rerun it occasionally anyway, in case there are any "almost bad" sectors that degrade further. There is no way of "recovering" bad sectors.

I recommend you consider migrating your data onto another drive instead though, unless there is nothing of any real importance on there (i.e. it wouldn't inconvenience you overly if the drive suddenly got much worse and the data became practically unreadable or corrupt). If you don't replace the drive, make sure you have good backups in place for anything you do care about (though you should have a good backup regime in place anyway).


fsck.ext4 -cDfty -C 0 /dev/sdxx

source: http://www.commandlinefu.com/commands/view/8474/run-a-ext4-file-system-check-and-badblocks-scan-with-progress-info