How do I choose the right parameters when using badblocks?

Since your drive has a 4096 byte physical sector size, you want to use -b 4096. I don't think the -c argument makes much difference, so just leave it alone.

Also the drive's internal SMART test is better and faster than badblocks, so using smartmontools or the disk utility to run that instead is a better idea.


I have created a benchmark tool to test different settings. The test may take long time and remove your data, so please use with care.

badblocks_benchmark.sh:

#!/bin/bash

blocks=4194304      # 2^22, must be dividable by 2^8 (max i) = 256
block_size=512

result=""
for i in {1..8}
do
  block_count=1

  for j in {1..18}
  do
    echo -n "Benchmark with block count: $block_count, block size: $block_size: "
    execution_time=`/usr/bin/time 2>&1 -f "%Es" badblocks >/dev/null -w -b $block_size -c $block_count -t random $1 $blocks`
    status=$?
    if [ $status -eq 0 ]; then
      result=`echo -e "$result""\n""$execution_time: badblocks -b $block_size -c $block_count"`
      echo "$execution_time"
    fi

    block_count=$(( $block_count * 2 ))
  done

  block_size=$(( $block_size * 2 ))
  blocks=$(( $blocks / 2 ))
done

echo "Result:"
echo "$result" | sort --numeric-sort

You can use it as:

./badblocks_benchmark.sh /dev/sdX

If you want to benchmark with only 4k blocks then:

#!/bin/bash

blocks=4194304      # 2^22, you can use any 2^x number 
block_size=4096

result=""
block_count=1

for j in {1..18}
do
  echo -n "Benchmark with block count: $block_count, block size: $block_size: "
  execution_time=`/usr/bin/time 2>&1 -f "%Es" badblocks >/dev/null -w -b $block_size -c $block_count -t random $1 $blocks`
  status=$?
  if [ $status -eq 0 ]; then
    result=`echo -e "$result""\n""$execution_time: badblocks -b $block_size -c $block_count"`
    echo "$execution_time"
  fi

  block_count=$(( $block_count * 2 ))
done

echo "Result:"
echo "$result" | sort --numeric-sort

Based on my benchmarks the using only -b 4096 without -c (default 64) is pretty good.

My results (smaller is better): Execution time in seconds and arguments

0:28.50s: badblocks -b 1024 -c 512
0:28.50s: badblocks -b 4096 -c 1024
0:28.50s: badblocks -b 512 -c 1024
0:28.50s: badblocks -b 65536 -c 8
0:28.51s: badblocks -b 2048 -c 1024
0:28.51s: badblocks -b 32768 -c 16
0:28.51s: badblocks -b 65536 -c 128
0:28.51s: badblocks -b 65536 -c 64
0:28.52s: badblocks -b 32768 -c 128
0:28.52s: badblocks -b 65536 -c 4
0:28.52s: badblocks -b 8192 -c 64
0:28.53s: badblocks -b 16384 -c 512
0:28.53s: badblocks -b 16384 -c 8
0:28.53s: badblocks -b 32768 -c 32
0:28.53s: badblocks -b 32768 -c 4
0:28.53s: badblocks -b 32768 -c 64
0:28.53s: badblocks -b 65536 -c 16
0:28.53s: badblocks -b 8192 -c 512
0:28.54s: badblocks -b 4096 -c 256
0:28.54s: badblocks -b 4096 -c 32
0:28.54s: badblocks -b 4096 -c 64
0:28.54s: badblocks -b 8192 -c 128
0:28.55s: badblocks -b 1024 -c 1024
0:28.55s: badblocks -b 1024 -c 256
0:28.55s: badblocks -b 16384 -c 256
0:28.55s: badblocks -b 2048 -c 128
0:28.55s: badblocks -b 2048 -c 64
0:28.55s: badblocks -b 32768 -c 8
0:28.55s: badblocks -b 4096 -c 16
0:28.55s: badblocks -b 512 -c 2048
0:28.55s: badblocks -b 512 -c 256
0:28.55s: badblocks -b 65536 -c 1
0:28.55s: badblocks -b 8192 -c 1024
0:28.55s: badblocks -b 8192 -c 16
0:28.55s: badblocks -b 8192 -c 256
0:28.55s: badblocks -b 8192 -c 32
0:28.56s: badblocks -b 2048 -c 2048
0:28.56s: badblocks -b 512 -c 512
0:28.57s: badblocks -b 1024 -c 64
0:28.57s: badblocks -b 16384 -c 128
0:28.57s: badblocks -b 16384 -c 4
0:28.57s: badblocks -b 16384 -c 64
0:28.57s: badblocks -b 2048 -c 512
0:28.57s: badblocks -b 2048 -c 8192
0:28.57s: badblocks -b 32768 -c 256
0:28.57s: badblocks -b 4096 -c 128
0:28.57s: badblocks -b 4096 -c 2048
0:28.57s: badblocks -b 512 -c 16384
0:28.57s: badblocks -b 65536 -c 32
0:28.57s: badblocks -b 65536 -c 65536
0:28.57s: badblocks -b 8192 -c 8
0:28.58s: badblocks -b 1024 -c 2048
0:28.58s: badblocks -b 1024 -c 4096
0:28.58s: badblocks -b 16384 -c 16
0:28.58s: badblocks -b 2048 -c 4096
0:28.58s: badblocks -b 4096 -c 512
0:28.58s: badblocks -b 65536 -c 131072
0:28.59s: badblocks -b 1024 -c 8192
0:28.59s: badblocks -b 2048 -c 256
0:28.59s: badblocks -b 2048 -c 32
0:28.59s: badblocks -b 32768 -c 2
0:28.60s: badblocks -b 1024 -c 128
0:28.60s: badblocks -b 1024 -c 16384
0:28.60s: badblocks -b 512 -c 4096
0:28.60s: badblocks -b 65536 -c 2
0:28.62s: badblocks -b 16384 -c 32
0:28.62s: badblocks -b 512 -c 128
0:28.62s: badblocks -b 512 -c 32768
0:28.63s: badblocks -b 512 -c 8192
0:28.65s: badblocks -b 4096 -c 4096
0:28.67s: badblocks -b 16384 -c 1024
0:28.79s: badblocks -b 8192 -c 2048
0:28.80s: badblocks -b 8192 -c 4
0:28.81s: badblocks -b 16384 -c 2048
0:28.83s: badblocks -b 32768 -c 512
0:28.86s: badblocks -b 65536 -c 512
0:28.89s: badblocks -b 2048 -c 16384
0:28.98s: badblocks -b 65536 -c 256
0:29.09s: badblocks -b 8192 -c 4096
0:29.10s: badblocks -b 4096 -c 8192
0:29.10s: badblocks -b 512 -c 65536
0:29.15s: badblocks -b 1024 -c 32768
0:29.15s: badblocks -b 32768 -c 1024
0:29.34s: badblocks -b 4096 -c 8
0:29.35s: badblocks -b 1024 -c 32
0:29.40s: badblocks -b 16384 -c 2
0:29.41s: badblocks -b 32768 -c 1
0:29.41s: badblocks -b 512 -c 64
0:29.45s: badblocks -b 32768 -c 131072
0:29.46s: badblocks -b 2048 -c 16
0:30.10s: badblocks -b 2048 -c 32768
0:30.13s: badblocks -b 1024 -c 65536
0:30.14s: badblocks -b 16384 -c 4096
0:30.16s: badblocks -b 4096 -c 16384
0:30.16s: badblocks -b 512 -c 131072
0:30.22s: badblocks -b 8192 -c 8192
0:30.23s: badblocks -b 65536 -c 1024
0:30.26s: badblocks -b 32768 -c 2048
0:30.38s: badblocks -b 1024 -c 131072
0:30.38s: badblocks -b 2048 -c 65536
0:30.49s: badblocks -b 4096 -c 32768
0:30.50s: badblocks -b 65536 -c 2048
0:30.50s: badblocks -b 8192 -c 16384
0:30.53s: badblocks -b 32768 -c 4096
0:30.64s: badblocks -b 16384 -c 8192
0:31.01s: badblocks -b 2048 -c 131072
0:31.13s: badblocks -b 32768 -c 8192
0:31.14s: badblocks -b 65536 -c 4096
0:31.17s: badblocks -b 16384 -c 16384
0:31.17s: badblocks -b 4096 -c 65536
0:31.17s: badblocks -b 8192 -c 32768
0:32.20s: badblocks -b 4096 -c 131072
0:32.20s: badblocks -b 65536 -c 8192
0:32.21s: badblocks -b 8192 -c 65536
0:32.24s: badblocks -b 32768 -c 16384
0:32.25s: badblocks -b 16384 -c 32768
0:34.42s: badblocks -b 8192 -c 131072
0:34.57s: badblocks -b 16384 -c 65536
0:34.61s: badblocks -b 32768 -c 32768
0:34.71s: badblocks -b 65536 -c 16384
0:39.08s: badblocks -b 4096 -c 4
0:39.23s: badblocks -b 1024 -c 16
0:39.39s: badblocks -b 8192 -c 2
0:39.56s: badblocks -b 16384 -c 1
0:39.60s: badblocks -b 2048 -c 8
0:39.69s: badblocks -b 512 -c 32
1:02.34s: badblocks -b 1024 -c 8
1:02.45s: badblocks -b 4096 -c 2
1:02.50s: badblocks -b 512 -c 16
1:02.57s: badblocks -b 2048 -c 4
1:03.64s: badblocks -b 8192 -c 1
1:10.68s: badblocks -b 512 -c 4
1:10.69s: badblocks -b 1024 -c 2
1:11.07s: badblocks -b 2048 -c 1
1:14.60s: badblocks -b 512 -c 2
1:15.02s: badblocks -b 1024 -c 1
1:22.85s: badblocks -b 512 -c 1
1:47.08s: badblocks -b 1024 -c 4
1:47.21s: badblocks -b 4096 -c 1
1:47.49s: badblocks -b 2048 -c 2
1:47.96s: badblocks -b 512 -c 8