Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on an embedded system with the busybox version of dd. I'm trying to test an erase to the drive from some outside utility, however dd does not read from the disc again after the erase, but shows me the cached data.

I've narrowed it down to dd as when I do an initial dd, see the data, restart my system to flush the cache, did the erase, and then ran dd again it came up with all zeros.

However, if I do dd on factory settings, erase the drive, and do dd again without restarting it won't show me all zeros until a restart.

I've read in the GNU manpage that dd supports the iflag opt, with a nocache flag, but busybox does not support that option so that's out of the question.

My question is how can I force dd to read from the disk again rather than from cache?

share|improve this question
Potential nitpicking, but... dd does not cache it. The kernel/disk system does. This is why Frostschutz's command (which does not get send to dd) works. – Hennes Jul 12 '13 at 22:26
up vote 8 down vote accepted

You could try

echo 3 > /proc/sys/vm/drop_caches

which drops all sorts of caches.

For details see /usr/src/linux/Documentation/sysctl/vm.txt on drop_caches.

share|improve this answer
Just a note: that only works with Linux. Also, the /proc filesystem is disabled in some embedded configurations of Linux. – Evan Teitelman Jul 12 '13 at 20:28
@EvanTeitelman Right, It seems to work here though, so I'm going to upvote and accept this answer. – ardentsonata Jul 12 '13 at 20:40

You can accomplish what you want by turning on synchronous IO for dd by adding conv=fsync. This basically tells dd to perform a fsync call after every write (fsync is an OS call to flush data to disk. See man 2 fsync). When doing this, you will want to use large block sizes as the default is 512b, which is horribly inefficient for hard drives.

For example:

dd if=/dev/zero of=/dev/sda bs=1M conv=fsync

(the conv=fsync option is supported by busybox's dd).

Frostschutz's solution does work, but calling sync flushes all IO, not just the dd stuff. Trivial non-issue most likely, but I think conv=fsync is the "proper" solution.

share|improve this answer
Will try this when I get back to work! Thanks for the suggestion. – ardentsonata Jul 14 '13 at 10:02
So while fsync is supported by busybox, it isn't supported on the (much older) version of busybox that's on the embedded system, and as a result @frostschutz's is more correct for me. But your solution is definitely the more general correct way to do it, so have an upvote. – ardentsonata Jul 16 '13 at 21:35
The question says "how can I force dd to read from the disk again", but the fsync option takes effect with writes, not reads...? – Josip Rodin Oct 21 '15 at 13:19

Direct I/O (open mode O_DIRECT) should work, but your kernel and/or dd may not support it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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