12

I have an old HP Athlon machine I use for testing software under the old processor. We have frequent brown outs, and after the last one the disk was a mess. It was so bad I could not run fsck and dispatch all the problems. I performed a fresh install of the OS, but I'm still getting fsck complaints.

I'd like to try one last time to reload Linux before condemning the hard drive or machine. After the filesystem is created but before the install occurs, I'd like an aggressive fsck performed to mark suspect blocks as bad.

The disk is large (about 500 GB) and a Debian 8 distro is relatively small (8-12 GB is usually more than enough), so I don't care if good blocks get marked as bad. I also like the GUI install, but I'm not married to it.

I have two questions:

  1. Does Debian 8 provide a choice to perform an fsck before installing the base system? If so, where is it? If not, then what is the process?

  2. Does fsck have a setting to control how aggressively blocks are marked as bad? If so, what is it? If not, then what can be used?


EDIT: the machine is an HP5850. Entering the BIOS, navigating to Storage and then Drive Protection System (DPS) Self-test resulted in DPS recommending replace the drive. DPS did not provide any statistics, so I'm not sure the extent of the damage.

Considering I can purchase an [old] new SATA II drive for $12 USD, I'm just going to replace it. There's no sense in wasting time or energy on it.


The related references are as follows. Neither question appears to be addressed.

3
  • Why not SpinRite? Commented Aug 8, 2016 at 20:41
  • If you have any bad blocks at all, the entire drive is physically failing and shouldn't be used. Commented Aug 8, 2016 at 21:32
  • 3
    "Aggressively fsck a disk" looks so dirty... Commented Aug 8, 2016 at 23:48

6 Answers 6

19
  1. "Does Debian 8 provide a choice to perform an fsck before installing the base system? If so, where is it? If not, then what is the process?"

    As an alternative, first download and burn a GPartEd CD (or write to a thumb drive). Before running the installer, boot GPartEd and partition the disk to your liking and run fsck or just run badblocks at length.

    When you run the Debian installer, just tell it how to use the partitions that are there. The installer does not need to create its own partitions. It is perfectly happy to use existing partitions.

  2. "Does fsck have a setting to control how aggressively blocks are marked as bad? If so, what is it? If not, then what can be used?"

    The -c option to e2fsck causes it to run the badblocks program to scan for bad blocks. You can run badblocks directly as well. By default, badblocks does a read-only test. To be more aggressive, you can specify -n for a non-destructive read-write test. You can also set the -p option to increase the number of passes that it makes.

    You may want to run badblocks before you partition. That way, you can specify the faster -w write-only test.

8
  • 1
    John, +1, just curious does badblocks has any method to mark on a hardware level, or just on the FS level?
    – heemayl
    Commented Aug 8, 2016 at 4:55
  • 3
    @heemayl My understanding is that, on modern hard disks, the hard disk's firmware attempts to do all of its own bad block management. The purpose of running badblocks is merely to force the hard disk to read/write all sectors. The hard disk does it own detection and remapping of bad sectors and, if all works as it should, the badblocks program is never informed that the hard disk is doing this.
    – John1024
    Commented Aug 8, 2016 at 5:25
  • hmmm..understandable. So in essence, fsck can mark blocks on FS but badblocks just help the disk firmware to to do the marking, does not do anything of its own?
    – heemayl
    Commented Aug 8, 2016 at 5:34
  • 3
    @heemayl In olden times, badblocks would spit out a list of bad sectors and the filesystem would make note of them. In modern times, badblocks and the FS still try to do that but, with a modern HD, the list is usually empty.
    – John1024
    Commented Aug 8, 2016 at 6:39
  • 1
    @heemayl, and if the list isn't empty, the disk is usually so badly broken that your best option is to replace it.
    – Mark
    Commented Aug 8, 2016 at 20:32
7

If you are getting fsck errors that often, the drive may as well be coughing up blood. Even if you mark every single bad block as bad, it won't be long before more blocks go bad. I would imagine you could change into another tty to do an fsck if you really need to (Ctrl + alt + F2 to switch to tty2), but I can't emphasize enough how much you need a new hard drive if what you are saying is accurate.

6
  • "If you are getting fsck errors that often..." - what I am not sure about is, are the handful of fsck problems after the reinstall the extent of the problem, or is it the tip of the iceberg. The system boots, encounters a few filesystem errors (4 or 6), recovers by remounting as read-only, and then boots.
    – user56041
    Commented Aug 8, 2016 at 1:06
  • @jww can you please post some exact examples of said filesystem errors? Commented Aug 8, 2016 at 1:40
  • Why switch to another tty? What advantage does doing so provide?
    – fpmurphy
    Commented Aug 8, 2016 at 3:54
  • @fpmurphy1 it sounded like he couldn't open a terminal window, so switching to another tty would be the next best way to get into a shell. Commented Aug 8, 2016 at 6:55
  • @jww: Are the same blocks reported every time, or are a new set reported on each boot?
    – TMN
    Commented Aug 8, 2016 at 19:03
5
  1. No, and I don't think it's worth it. Fsck (as implemented by most filesystems) does not check your drives. It validates the filesystem metadata and makes sure the view is consistent when you mount them. It doesn't make much sense to do it before installation, because by definition, you'll only have empty space.

  2. Use badblocks instead. If you want to make sure your data doesn't rot, use a filesystem which supports scrubbing. Lvm itself can do it too.

3

To check a modern disk for reliability, consider using the built in tests; you can trigger them with the smartctl utility, eg:

smartctl -t long /dev/sdx
#wait an hour or two
smartctl -a /dev/sdx
#should have recorded a result in the self-test log

If you want to make sure beforehand that everything has recently been written to, in order to discover sectors that will not write properly, you could overwrite the whole medium with something like a dd from /dev/urandom, or shred with one of the randomizing options.

4
  • 3
    Note that a dd from /dev/random will take many days to complete on a 500GB drive. Commented Aug 8, 2016 at 13:47
  • 1
    fixed typo, thx :) Didn't want to spell out the exact dd syntax since I wanted to avoid having command lines around that, if accidentally pasted into a shell, will cause truly irrecoverable data loss. Commented Aug 8, 2016 at 16:27
  • Unfortunately, Debian does not appear to provide smartctl: E: Unable to locate package smartctl. Is it a Red Hat/Fedora utility?
    – user56041
    Commented Aug 9, 2016 at 18:59
  • debian/ubuntu package is smartmontools. BTW, use apt-cache search to search for which package has something. Commented Aug 10, 2016 at 8:33
2

I would recommend getting the manufacturer's low-level format software (if any exists) which may only run on Windows (or if you're lucky, from a bootable CD/DVD/USB for which you'd download an image from their website). If you have sufficient control over the operation to reduce the reported capacity of the drive in exchange for a much larger spare sector pool, you should do so, in anticipation of many of those spares being substituted as you test the drive as @rackandboneman has suggested. Far better to have a 400- or 450-GB drive with all bad sectors swapped for spares and more left for future defects, than to exhaust the spare pool and have future bad sectors that can't be transparently remapped.

3
  • I was able to run SeaTools for DOS. SeaTools reported SMART did not trigger, which seemed unusual. The long test and short test failed immediately. I resized the disk down to 32 GB; and then ran the long test again. SeaTools found 4 bad LBAs around the 1190000 mark and repaired them. A fresh OS install went perfectly; and subsequent reboots had no trouble. Since I purchased the replacement SATA II drive, I'll keep it as a hot spare if the existing drive misbehaves.
    – user56041
    Commented Aug 9, 2016 at 19:05
  • @jww pity that you've already accepted a different answer. Commented Aug 10, 2016 at 15:04
  • Yeah, its the Q&A trap... I have to ask specific questions to get a precise answer. If I would have asked, "how do I install Linux on a failing hard drive", then the question probably would have been closed.
    – user56041
    Commented Aug 10, 2016 at 16:24
0

Some basic things if you don't have fancier tools available (eg it's a USB disc and SMART doesn't work):

dd if=/dev/sdX of=/dev/null bs=1M

will read all of the disc. You'll see in the dmesg log if there are sectors which couldn't be read. Though it won't tell you if it managed to read them after retries. It's not as good as badblocks but I mention it for its ubiquity.

If you have bad sectors and you don't want anything on the disc:

dd if=/dev/zero of=/dev/sdX bs=1M

will cause all the blocks to be rewritten. If there are sectors which are unreadable, this should cause them to be swapped with sectors in the reallocated pool and become usable again.

If you have a disc where reallocation is happening then the disc is on the way out. I wouldn't use it for anything important, but sometimes you have data you don't care that much about and it might be OK for that.

If it's an SSD then things are different and these don't apply.

You must log in to answer this question.