brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: badblocks -sv reads a whole disk to find bad blocks without writing to it

Disk
~/tips/tip-disk-badblocks-read-only-scan

sudo badblocks -sv /dev/sdX

Reads every block of a disk and lists the ones that cannot be read, without writing.

A used disk from Marktplaats, or an old drive you want to give a second life in a backup box: before trusting it, I’d want to know whether every block can still be read. badblocks reads the disk from start to end and lists the blocks that fail.

lsblk -o NAME,SIZE,MODEL
sudo badblocks -sv /dev/sdX

Without options, badblocks does a non-destructive read-only test. -s shows the progress as a rough percentage, and -v reports the number of read, write and corruption errors at the end. The bad block numbers go to standard output, so an empty list and zero errors is what you want to see. Replace sdX with the disk from the lsblk list and check the size and model twice. A full read of a large hard disk takes hours, so I’d run it inside tmux or screen.

Now the part you really need to read. The flag -w does a write-mode test: it writes patterns over every block of the disk and reads them back. That’s a thorough test for a brand-new disk, and it destroys everything on it. The -n mode is a non-destructive read-write test, but it still wants a disk that isn’t mounted. On a disk with data you care about, stick to the plain read-only scan.

One more thing from the manual. If you want to feed the list of bad blocks to a filesystem, don’t pass the output to mke2fs or e2fsck yourself, because the block numbers depend on the block size. Use their -c option, which runs badblocks with the right settings for you. And a read scan is a different view than SMART: a disk can pass badblocks today and still show worrying SMART values, so I’d look at both.

Further reading: badblocks(8) manual page

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link