badblocks scans a device for unreadable blocks.
# Non-destructive read-only scan (default, safe)
sudo badblocks -sv /dev/sdX
# Non-destructive read-write scan (backs up and restores each block; slow, still risky on a failing disk)
sudo badblocks -nsv /dev/sdX
# DESTRUCTIVE write test: overwrites the entire device with a random pattern
sudo badblocks -c 10240 -wsvt random /dev/sdX
The
-wwrite-mode test destroys all data on the device. Use it only on empty or new disks.-sshows progress,-vis verbose,-csets blocks tested at once,-t randomselects the pattern.
Modern disks remap bad sectors internally, so badblocks finding errors means the spare pool is nearly exhausted. Check health first with smartmontools (smartctl -a): reallocated and pending sector counts are the better early warning. For large disks add -b 4096 to match the sector size.