Hacker News new | past | comments | ask | show | jobs | submit login

Or instead of files just write to the block device with one big random file with the supposed byte-accurate size of the device, then read it back and compare. Something like:

  dd bs="$(blockdev --getsize64 "$device")" count=1 if=/dev/urandom of=random-file
  dd if=random-file of="$device"
  cmp random-file "$device"
Using cmp instead of something like md5sum is better since it would stop on the first differing byte, instead of reading the whole thing for both.

EDIT: I'm not sure if my use of dd's bs and count is a good idea, though. It might be better to do:

  head -c "$(blockdev --getsize64 "$device")" /dev/urandom > random-file
to get more reasonable buffer sizes. Documentation on head says -c works on bytes, not characters, so that's good.

For that second line, I often prefer to do:

  pv random-file > "$device"
to get a neat progress bar.

EDIT 2: As discussed in other threads, one should make sure to invalidate the kernel's cache of the device between steps 2 and 3. My safest bet on how to do that is to reboot the computer.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact