Home Maintenance of NAND disk in GNU/Linux
Post
Cancel

Maintenance of NAND disk in GNU/Linux

NAND disk ranges from USB flash drives (thumb drive, memory stick, pendrive, call it what you prefer) to SDD disks. Both are based on NAND flash cells.

As hard disk drives (HDDs), NAND disks can suffer several types of failures: logical failures, firmware failures, and bit rot. Since we cannot avoid firmware failures, we will try to avoid (or minimize) bit rot and logical failures.

Bit rot

Transistors in the flash storage device hold charge which represents data. This charge gradually leaks over time, leading to accumulation of logical errors (also known as “bit rot” or “bit fading”). The only thing we can do to avoid this is plug in periodically our disk or flash drives. The paper, from 2015, “Data Retention in MLC NAND Flash Memory: Characterization, Optimization, and Recovery” from Carnegie Mellon University states “today’s flash devices, which do not require flash refresh, have a typical retention age of 1 year at room temperature”.

Logical failures

Flash memory has a finite number of P/E (program/erase) cycles. Although many use a wear leveling strategy to work around these limitations, others don’t. Before a total disk death from usage occurs, some transistors can die from use causing data access errors.

Maintenance

The maintenance process for a SSD disk is the same as in “Maintenance of HDD in GNU/Linux”. But, the maintenance process differs a bit for an USB flash drive. In an USB flash drive we won’t have S.M.A.R.T. capabilities, so we can skip this step. Besides, as a flash drive is not a disk, a flash drive lacks of a reallocator that marks bad sectors and reallocates its data to spare sectors. So, the best we can do is rely on badblocks. And, as we will use fsck, we will use badblocks through the fsck -cc option.

Let’s say our partition is still /dev/sdb1:

1
$ sudo fsck -fccky /dev/sdb1

Combining -k with -cc option, any existing bad blocks in the bad blocks list are preserved, and any new bad blocks found by running badblocks will be added to the existing bad blocks list. Besides, with -cc option the bad block scan will be done using a non-destructive read-write test.

Print badblock results

To see the blocks marked as bad in a ext2/ext3/ext4 filesystem we have to use dumpe2fs:

1
$ sudo dumpe2fs -b /dev/sdb1

Enjoy! ;)

This post is licensed under CC BY 4.0 by the author.