Badblocks tests block devices such as hard drives and USB memory sticks for bad blocks. It is one of the first diagnostic tools I use when facing a problem of unknown origin.
First step is to boot the box with a live distribution. Open a terminal, become root (everything in this article must be done as root) and see if your live distro automatically mounted the hard disk. In one case, I saw:
# df -T Filesystem Type Size Used Avail Use% Mounted on none unionfs 2.9G 266M 2.7G 9% / /dev/sdb1 xfs 7.8G 4.5G 3.4G 57% /media/hd6 /dev/sdb6 xfs 142G 103G 40G 73% /media/hd7
If you need more information — perhaps something looks suspicious — gparted (run as root) is a fuller featured tool.
In the above example we see that the root partition on the hard disk, /dev/sdb1, is mounted as /media/hd6. So we unmount it, using the mount point, not the device name: umount /media/hd6.
Once identified and unmounted, run badblocks as root:
# badblocks -sn /dev/sdb
Naturally, replace sdb1 with your device name. Bad blocks identified, if any, will be shown on standard output.
The -n option specifies nondestructive testing, which is slow. If there’s nothing on the device worth saving, substituting -w for -n will perform a faster destructive test.
If you want to test a mounted device that can be unmounted — say, a USB stick — you can do that without having to use a live CD. Just unmount the device first, as root:
# umount /dev/sdb
Again, substitute your device name for “sdb”.