You are not logged in.
I was checking an SD card which gave me some problems, and I tried to write some random data to it using dd.
First, I wanted to write a 64 Mb to the card:
$ dd if=/dev/urandom of=/media/54E2-7939/test.bin bs=64M count=1
0+1 registros leídos
0+1 registros escritos
33554431 bytes (34 MB) copiados, 4.39998 s, 7.6 MB/sAccording to the output, it only wrote 34 MB data. I checked, and the written file does indeed have that size. I thought that the card was faulty, but when I tried on a different card that I know is all right, I got the same output and results.
But later on, I tried the same, but instead of using /dev/urandom, I used /dev/zero, and this time I got the expected file size:
$ dd if=/dev/zero of=/media/54E2-7939/test.bin bs=64M count=1
1+0 registros leídos
1+0 registros escritos
67108864 bytes (67 MB) copiados, 7.15289 s, 9.4 MB/sDoes anyone have any idea what is happening here?
Last edited by ricrogz (2016-02-07 14:10:04)
Offline
Your blocksize is too large, and dd is happy to accept short reads.
Short reads are always a possibility so if you want to guarantee a result of blocksize*count, you should always use iflag=fullblock to make dd keep reading until the block is actually full.
In terms of performance there is no point in going beyond bs=1M - with one exception, if you're reading from / writing to the same HDD, a larger blocksize will reduce the number of seeks. So when copying from one partition to another partition of the same disk you could use bs=1G iflag=fullblock, if you have 1G of RAM to spare.
Offline
pv -Ss 64M </dev/urandom >test.binI barely use dd anymore. And you get a progress bar for free.
BTW, using dd arguments the way you did is a bad idea. Basically you told it to allocate 64MB of memory, fill it with data from if and then write to of. If you tried to transfer 10G this way it would run out of RAM, possibly after 10 minutes of filling all available swap and bringing the system to crawl.
Offline
Thanks for your great tips.
It's good to know that it is not a problem, and even better to know how to properly use dd and pv.
Offline