Scrubbing your HDD/SSD data to mitigate bitrot (without 3rd party software)

Note: Excuse me if this post appears mirrored. I could not fix it, but you can try pressing Ctrl+Shift+X or Ctrl+Alt+X and hope that your browser switches the page’s reading-direction.

Bitrot is a real threat, regardless of what storage media is being used. And while some file systems (e.g. ReFS, ZFS) implement automatic measures to protect against bitrot, they might not be readily available, or implementing them could mean too much technical knowledge or work than one can afford.

Besides, self-healing or resilient file systems aren’t practical for certain types of storage media, such as USB drives (containing flash banks or HDDs).

For the unprotected file systems, one can only cross their fingers and hope that the data will keep its integrity. However, there are applications out there that do a raw data read to help the drive detect and correct any potential or partial read errors before they become permanent. The work principle is pretty simple, the program just asks for the contents of the file. The drive contains the error-correction mechanisms in case some data block has correctable errors.

I personally prefer to do this kind of check on my portable drives without using any exotic tools. On Windows (while the performance is not great this is a quick and easy way), I just open a command prompt with administrator privileges, and issue the following instructions (for scrubbing drive D:), which cause the system to read all files in the current directory and its sub-directories recursively, sending the output from this read operation to the NUL special device, effectively not outputting anything to the screen other than the file name:

CD \
FOR /r %i IN (*) DO TYPE "%i" > NUL
Drive read activity

On Linux I use the dd command to read the whole drive or partition.
Assuming the partition is /dev/sdb2 (you can use lsblk to list all block devices and their partitions), this is the command:

dd if=/dev/sdb2 of=/dev/null status=progress bs=16K conv=noerror

There must be a better way on Linux to check only the files, not the whole partition, but I really didn’t get to need to do it that much, so I’m leaving it here.