How do I choose the right parameters when using badblocks?

9,437

Solution 1

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.

Solution 2

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
Share:
9,437

Related videos on Youtube

htorque
Author by

htorque

Updated on September 18, 2022

Comments

  • htorque
    htorque over 1 year

    I'd like to use badblocks to check my new drive for bad blocks, but I'm not sure how to choose the values for block size and number of blocks to test in parallel. The man page just says:

    -b block-size Specify the size of blocks in bytes. The default is 1024.

    -c number of blocks is the number of blocks which are tested at a time. The default is 64.

    The drive to test is 2TB large, so I'd like to use values that don't make this process take days. :-)

    FWIW, smartmoontools reports:

    Sector Sizes: 512 bytes logical, 4096 bytes physical

    • Kris Harper
      Kris Harper over 12 years
      Just as an estimate, I've run a badblocks scan on my 2TB drive with default options and it took about 6 hours. Hopefully someone will help you cut that down.
    • htorque
      htorque over 12 years
      Thanks, that doesn't sound too bad (really :D).
    • psusi
      psusi over 12 years
      @root45 that's about as good as it gets. That's a sustained throughput of 92.6 MB/s, which is about the best such drives can do.
  • htorque
    htorque over 12 years
    Well, faster... the internal long S.M.A.R.T. test will finish in a couple of minutes - after running for four hours. Will use 4096 bytes as block size and experiment with the -c option.
  • htorque
    htorque over 12 years
    In the end the S.M.A.R.T. test took six hours. I then tested different values for the number of blocks to test in parallel and they didn't seem to influence the time at all. So I guess it's ok to just adjust the block size.
  • mmv-ru
    mmv-ru about 6 years
    I think, for benchmark purposes is better to use non-random template, like -t 0