25

What's the difference between two dd commands that have different bs and count values, as long as they multiply to the same? For example:

  1. dd if=/dev/random of=aa bs=1G count=2
  2. dd if=/dev/random of=aa bs=2G count=1
Rocky
  • 1,599
  • 2
  • 15
  • 10
  • 5
    Both commands will take ages. Use urandom if you need random numbers. Use zero if you just need fast input of something. – Nils Dec 13 '11 at 20:01
  • 5
    Use /dev/urandom, not /dev/random. See http://security.stackexchange.com/questions/3936/is-a-rand-from-dev-urandom-secure-for-a-login-key/3939#3939, http://security.stackexchange.com/questions/3259/howto-seed-the-prng-in-openssl-properly/3262#3262, – Gilles 'SO- stop being evil' Dec 14 '11 at 11:40

4 Answers4

27

As far as the end result is concerned, they will do the same. The difference is in how dd would process data. And actually, both your examples are quite extreme in that regard: the bs parameter tells dd how much data it should buffer into the memory before outputting it.

So, essentially, the first command would try to read 2GB in two chunks of 1GB, and the latter would try to read whole 2GB at one go and then output it to the aa file.

19

The result will be the same but in the first case dd will write two 1GB blocks while in the second one 2GB block. The difference is that dd keeps the copied block in memory. You will need 1GB of RAM in the first case and 2GB in the second.

In my opinion there is no need to use such large blocks. You can do a couple of tests but in my case I achieve a greater speed with much smaller blocks (< 1MB)

Matteo
  • 9,796
  • 4
  • 51
  • 66
9

The first one will take up 1G of memory, fill it with data from the input file and output it, two times.

The second one will take up 2G of memory, fill it with data from the input file and output it.

golimar
  • 417
2

The used block-size should match the best speed settings for source and target device.

You can best see the difference if you try to copy an LV device. The usage of very small BS-size will interrupt the read-process unnecessary. The usage of a very big BS-size will lead to long waits during write.

Since standard LVs consist normally of 4 MB chunks, wich is also a good size for physical disk access I use bs=4M for these.

Try to experiment with 16K or 256M - you will note the difference - and watch the disk indicator during copy...

Nils
  • 18,492