LinuxCommandLibrary

badblocks

Scan devices for bad disk blocks

TLDR

Check device for bad blocks (read-only)

$ badblocks -v [/dev/sdb]
copy
Destructive write test
$ badblocks -wsv [/dev/sdb]
copy
Non-destructive read-write test
$ badblocks -nsv [/dev/sdb]
copy
Save bad block list
$ badblocks -o [badblocks.txt] [/dev/sdb]
copy

SYNOPSIS

badblocks [options] device [last-block] [first-block]

DESCRIPTION

badblocks searches a device for bad blocks by performing read, write, or non-destructive read-write tests. It's used to verify disk integrity and create lists of bad blocks for filesystem tools.
The tool is particularly useful for testing new drives or diagnosing failing storage devices.

PARAMETERS

-v

Verbose mode
-w
Destructive write test (erases data)
-n
Non-destructive read-write test
-s
Show progress
-o file
Output bad blocks to file
-b size
Block size in bytes (default: 1024)
-c blocks
Number of blocks to test at once
-p passes
Number of test passes
-t pattern
Test pattern (random or specific value)

TEST MODES

Read-only (default)

Safe, detects existing bad blocks
Write (-w)
Destructive, thorough testing, erases all data
Non-destructive (-n)
Safe, reads then writes back original data

WORKFLOW

$ # Check for bad blocks (safe)
sudo badblocks -sv /dev/sdb

# Create bad block list for e2fsck
sudo badblocks -o badblocks.txt /dev/sdb
sudo e2fsck -l badblocks.txt /dev/sdb

# Thorough destructive test (WARNING: erases data)
sudo badblocks -wsv /dev/sdb
copy

CAVEATS

Write modes DESTROY all data on the device. Requires root privileges. Very slow on large drives (hours or days). Modern drives remap bad sectors automatically. Non-destructive mode still carries small risk of data loss. SMR drives may show poor performance during testing.

HISTORY

badblocks has been part of e2fsprogs since the early 1990s, created as a companion tool for ext2 filesystem management.

SEE ALSO

e2fsck(8), smartctl(8), dd(1)

> TERMINAL_GEAR

Curated for the Linux community

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

$169.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

$739.99
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95