Can `btrfs scrub` remember the bad blocks/sectors

btrfs

I have a USB thumb drive formatted in btrfs format. But I found if I copy a 1 GB file onto this disk, the file is corrupted. And btrfs scrub reports there're many uncorrectable errors. But if I keep copying more files on the disk, those files seems to be fine. So I think only a small consecutive blocks on disk is corrupted.

I wonder if btrfs scrub can scrub my entire drive and remember the corrupted blocks and do not use them in the future.

Best Answer

It probably can, but that won't help you due to how flash media work.

In contrast to a hard disk which can write or erase individual bits, while a flash medium can write individual bits it can only erase them a whole erase block at a time. The size of an erase block can differ, but it's often something like 128k. Since that's a lot to erase and rewrite if we only want to change one 'sector' (the size unit with which hard disks and operating systems deal), the thumb drive will split the erase block up into sector-sized units. When you change something it will mark the sector on which you've just changed something as "no longer in use", and then write the modified version somewhere else. After a while, it will see that the erase block has no active sectors anymore, and erase the block.

What this means is that if one sector is broken, the next time you write to that sector it will not be broken anymore, since it will now be a different sector.

In addition, flash tends to wear out after a number of write cycles, at which point it will fail (the exact number differs based on the quality of the flash chips, but is rarely less than something like 100000). For this purpose as well as for the extra space needed for the erase block stuff, a thumb drive has some extra capacity that is not announced; e.g., a 4g thumbdrive might expose 4000M but have 4096M internally, or 4200M, or some such. When a particular erase block starts to fail after too many write/erase cycles, your thumbdrive will mark it as such and no longer use it. It can do this for a while, but eventually the extra space will have been used up; at this point, when it tries to copy a sector to make a requested change, it will not find an empty sector anymore and can only produce a write error.

When your thumb drive reaches that point, as yours seems to have, it's time to replace it; it won't be long now before you'll start losing data (if that hasn't already happened)

Related Question