Before I sell an old HDD I completely read and write the disk to verify that it has no bad sectors.

I always did writing like this:

dd if=/dev/zero of=/dev/sdb bs=100M status=progress

But my computer has 32GB RAM and a lot of the data might be in cache when dd exits.

Is there a way to see when the OS fails to write the cache to the disk (after dd terminated)?

What is the right option for dd to to flush the cache before exiting? sync, fsync or fdatasync?

Please don't suggest disk checking tools. dd is enough for me.

  • 2
    Is there a reason you don't want to use a tool designed for the task at hand. For instance, badblocks comes with every Linux distribution that I know of.
    – doneal24
    Jan 17, 2020 at 13:19
  • 1
    Maybe run sync after dd? Did you read man dd? It should explain the meaning of the parameters.
    – Bodo
    Jan 17, 2020 at 13:29
  • How about using a OS that supports a RAW device interface?
    – schily
    Jan 17, 2020 at 15:11

1 Answer 1


Although you specifically requested not to recommend disk checking tools, I will do so and hereby recommend: The disk itself. You can ask the drive to perform a thorough, internal self-test, eliminating all possible sources of problems regarding caches. The self-test can conveniently be accessed via gsmartcontrol:
gsmartcontrol self-tests tab

If you really do not want this, you still should consider using a tool like F3. It will not only check whether the data can be written but it can also check whether the written data can be read afterwards (which is, in my opinion, the more important function of a storage medium).

With dd's conv=fdatasync dd does not terminate before the last block was written.

  • 1
    On Linux, an other option to use is dd ... oflag=direct which does direct I/O (opening with O_DIRECT) without interaction with device's buffer cache. For applications unable to do so, the "raw" kernel module along the "raw" command can associate a dedicated char raw device to a block device. That's mainly for compatibility with other unixes using a raw device (it's translated into direct I/O internally)
    – A.B
    Jan 18, 2020 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.