Flash Drive Integrity Test (Burn-In)

sudo badblocks -v -w -s /dev/sdX

You can use a command-line utility in Linux/BSD to put a USB flash drive through a "torture test" just to be sure the drive can be trusted to hold your data. The test writes and reads/verifies every sector on the disk, leaving it completely written with zeros at the end of the process.

This procedure works for hard drives and SSDs as well.

The process is destructive. The drive will need to be formatted afterwards.

Procedure

There are two easy steps:

  1. Determine the device name of the drive.
  2. Run the command.

Determine the Device

Insert the drive into a USB port, then determine the device. There are many ways to do this. One way is to use the df command:

df -h

Another way is to use the lsblk command to list block devices.

lsblk

You can semi-automate the process using the "watch" command.

sudo watch df -h

or

sudo watch lsblk

Insert and remove the drive to see which device appears and disappears.

For the rest of this page, we'll assume the drive is /dev/sdX . Substitute your device's string.

#run the command

Run the command(s)

Make sure no partitions are mounted. Use lsblk to check for mounted partitions, then unmount any partitions that are.

umount /dev/sdXN

If the drive has multiple mounted partitions, unmount all of them.

Now you can run the badblocks command to verify the integrity of the drive's media.

sudo badblocks -v -w -s /dev/sdX
 -v: verbose mode
 -w: use write-mode test
 -s: show progress

What It Does

Four patterns are written to and read from the drive. These are the patterns, in order:

  1. 0xaa (10101010)
  2. 0x55 (01010101)
  3. 0xff (11111111)
  4. 0x00 (00000000)

All bits on the drive will have been "flipped" at least twice. After a successful test there will be no partitioning or formatting on the drive because all bits on it are left written with zeros.

More Information

There's informative documentation for the badblocks command on the Arch Linux Wiki.

There's an excellent answer on AskUbuntu.com about checking the integrity of a drive.

Category: Linux Gear

Page last modified on April 05, 2023
Powered by: PmWiki and Quick Wiki CMS