9

The commands like:

sudo badblocks -sv /dev/sda1 > bads.txt
sudo e2fsck -l bads.tst /dev/sda1

or

sudo e2fsck -ckvt /dev/sda1

can scan disk /dev/sda1 for bad blocks and mark them as not-usable. But how to read the current bad blocks list for the /dev/sda1?

23W
  • 2,980

1 Answers1

15

To answer the question as asked: if /dev/sda1 is already formatted ext3/ext4 then

dumpe2fs -b /dev/sda1

will list the blocks which have been reserved as "bad" when the filesystem was created.

The disk itself does not reports bad blocks to the host unless it has exhaused its capacity to reallocate them.

Modern hard disks, i.e. those manufactured in the last two decades, will manage the list of bad blocks internally. When they come out of the factory they have a number of spare blocks; when a bad block is detected a spare block is used instead. The number of reallocated blocks is reported in the SMART parameters. If a modern hard disk reports bad blocks to the host this means that the available spare blocks have been exhausted and the hard disk is on its last legs.

AlexP
  • 10,197
  • 1
    I always believed "no bad blocks today" to be true but it's wrong. I've got two drives which have "pending reallocated sectors" which are BAD BLOCKS for the FS. These drives do not have any truly reallocated sectors. So they are not out of spare sectors. I found an explanation here: https://www.smartmontools.org/wiki/BadBlockHowto This also gives a way to make these sectors into GOOD or REALLOCATED again. Another explanation: https://www.smartmontools.org/wiki/FAQ#UnreadableuncorrectablependingsectorsorMediumerrorondisk.Whatsgoingon – JPT Oct 29 '19 at 15:19
  • @JPT: For completeness: "pending" sectors are sectors for which the firmware hasn't yet reached a decision whether to remap them or not. They shouldn't stay in the pending list for long -- the firmware will either decide that all is good, or will remap them -- unless the upper software layers decide to avoid using those sectors as matter of safety, in which case the firmware won't get a chance to retry them. If one notices that the number of sectors pending reallocation is non-zero and increasing then one should start planning to replace the disk as a matter of some priority. – AlexP Oct 29 '19 at 15:25
  • 1
    Yes, this is partially correct. If you read the links I provided, you will see that the drive waits for once successfully reading the data before it will replace the sectors. If this does not work, it won't ever reallocate the sectors, except you WRITE to them which signals: I don't need the data on these sectors any more. And this is the single case where bad blocks may be visible to the OS. all other cases which should make 90% are silently fixed without anyone noticing. – JPT Oct 30 '19 at 16:30