4

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

6

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.

2
2

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).

2
  • 1
    Thanks but I'm using the NTFS filesystem in my external hard drive. Does this command apply to this situation, too? – user19920 Dec 2 '09 at 14:27
  • To my knowledge there is no standard Linux command/utility to check/repair NTFS volumes, with or without a surface scan. You'll need to try from a Windows machine. – David Spillett Dec 2 '09 at 18:01
2
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

0

Not sure if NTFS-related:

Bad block HOWTO for smartmontools

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Tamara Wijsman Aug 11 '12 at 14:46
0
# ntfsresize -i /dev/sdb3

Device name        : /dev/sdb3
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 287967052288 bytes (287968 MB)
Current device size: 287967052800 bytes (287968 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 178645 MB (62.0%)
Collecting resizing constraints ...
You might resize at 178644316160 bytes or 178645 MB (freeing 109323 MB).
Please make a test run using both the -n and -s options before real resizing!

# ntfsresize -ns  /dev/sdb3

Non-destructive resize

# ntfsresize -s  /dev/sdb3

Real resize! careful...
1
  • 1
    It would probably be useful to give a little context to the code block you've posted. Those that know will I'm sure, have no trouble understanding. But if your answer is to be useful for others as well, you should describe here what the commands actually do. – JoshP Sep 27 '12 at 12:57
0

If you hope to retain the data on that external partition, you do not want to write to that drive ever again, which some of these answers propose. Instead, use a forensic recovery tool to image the drive. ddrescue is my favorite tool for such work.

Here's my "notes to self", which are mac specific, but cover the main points: Identifying the hardware /dev mount names of source and target, unmounting them, then sweeping the source onto the target, with read-retry disabled, logging read errors, but skipping the failing blocks for last.

Forensic imaging of disks and/or rescuing failing disks: Gnu ddrescue (not the same as dd_rescue, though similar) All needs to be done as root.
First confirm your device mounts:
diskutil list
Unmount source (eg disk1) (and destination if sending to a physical partition, instead of a raw image file):
diskutil unmount disk1
Do a block-by-block image copy, from disk1 to a mountable disk image file, creating a log and first focusing on the readable parts:
ddrescue -v /dev/disk1 myrescueddisk.dmg rescue.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy