9

I may be misunderstanding some concepts here, but as far as I know, each disk has a partition table and actual partitions.

I'm looking to test a hard drive for bad sectors and errors, but the tools I found to do this are meant for partitions -- not disks. badblocks takes a partition /dev/sda1 not /dev/sda. Same story with e2fsck.

As far as I understand, those tools only test space assigned to partitions, not a whole disk. Is there any way to test an entire disk?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Gacek
  • 207
  • 1
  • 2
  • 7

1 Answers1

16

Is there any way to test whole disk?

Yes, using badblocks:

badblocks /dev/sda

The manpage refers to partitions because badblocks can tell mkfs.ext2 about the bad blocks it finds, and that only works when checking partitions. But badblocks itself works fine on full disks.

However badblocks is really a relic of a bygone era when hard drives didn’t manage their bad blocks themselves. Nowadays drives track errors themselves and are capable of remapping bad sectors as circumstances allow (typically, when a bad sector is rewritten). You’re probably better off running SMART tests and checking the results:

smartctl -t long /dev/sda
smartctl -t offline /dev/sda
smartctl -x /dev/sda

(make sure each test completes before running the next one).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • 1
    I get `badblocks invalid starting block (0)` error on this. Found on internet its due I did not supply partition. – Gacek Jan 19 '20 at 15:23
  • @Gacek Just omit the `first_block` argument. `badblocks` will start from the beginning of the disk by default. –  Jan 19 '20 at 15:26
  • 3
    @Gacek It's not mentioned anywhere in the `badblocks` manpage that it only works with partitions, but not full disks. With that being said, I would not rely on `badblocks`: I just run it on an old broken disk both in its read-only and in its read/write mode and it was NOT able to find any bad blocks; but running an actual OS on it failed almost immediately -- it probably has to do with the real-life access pattern which `badblocks` doesn't try to emulate. –  Jan 19 '20 at 15:32
  • my badblocks was being blocked by other test, thats why i had that error. I will try smartctl and return :) – Gacek Jan 19 '20 at 17:30
  • 1
    Modern drives hide badblocks. I thought you need to ask SMART, to tell you the health of the device. Does badblocks talk to SMART? – ctrl-alt-delor Jan 19 '20 at 18:15
  • 1
    @ctrl-alt-delor they hide them up to a point — a failed block will still cause read errors. `badblocks` doesn’t talk to SMART. – Stephen Kitt Jan 19 '20 at 19:04
  • It looks like `smartctl` does not have a progress functionality. But we can accompany its progress with a command like: `while true; do clear; sudo smartctl -l selftest /dev/sda; sudo smartctl -c /dev/sda | head -11 | tail -3; sleep 5; done` – GarouDan Apr 12 '21 at 01:39
  • or, if you only want to check the current test progress and not do a selftest, try this: `while true; do clear; sudo smartctl -c /dev/sda | head -11 | tail -3; sleep 5; done` – Henrique de Sousa Jan 28 '23 at 00:10