[clue-tech] How does bytesize affect dd?

Nate Duehr nate at natetech.com
Wed Dec 21 23:22:22 MST 2005


Hani Duwaik wrote:
> I was wondering if anyone could shed some light on the 'bs' option of 
> the 'dd' command...
> 
> Specifically, I know that in the following command:
> 
> dd if=xxx of=yyy bs=zzz
> 
> will copy the contents of 'xxx' to 'yyy' block-by-block with a block 
> size of 'zzz' ... however, my question is what affect increasing 'bs' 
> would have aside from possibly speeding things up.
> 
> In addition, how do the conv flags "noerror, notrunc, sync" come into play.
> 
> I'm particularly interested in how this applies to reading/writing CDs/DVDs.
> 
> TIA,
> 
> -Hani

The bs directive to dd is a compound command that overrides ibs= and 
obs= (input block size,  and output block size).

It may also be a little clearer if you read up in the manpage or info 
page on the "notrunc" option.

dd is a bit-for-bit copy, but if your input source is shorter than your 
ibs=size, it will truncate the output.

Different versions of dd can react differently to being fed by pipes... 
short reads mean the input buffer is holding a small copy of something 
and it'll get written out as a much larger truncated block on the output 
if that's happening.  dd can be a pain that way on different Unixes.

Thus, tools like cpio and tar were born.  ;-)

Most of the time, the default bs of 512k is fine for almost anything. 
However there may be some speed benefit from using 1024 or 4096 as long 
as your filesystem you're coming from/to uses those sizes.

A commonly used example is floppy disks... 1024k works "better" with 
those as dd doesn't have to spin up/down the floppy disk as much.  Same 
type of thing used to happen with old slow tape drives.

My hda1 on one of my systems has a natural blocksize of 1024, so going 
bigger that that isn't going to help any and could yield messy stuff.

durango:~# blockdev --report /dev/hda1
RO    RA   SSZ   BSZ   StartSec     Size    Device
rw    16   512  1024         63     273042  /dev/hda1

(This is /boot by the way, and small block sizes tend to be found on 
these...)

However a different partition on a different disk in the machine is 
formatted with a bigger block size.

durango:~# blockdev --report /dev/hdb1
RO    RA   SSZ   BSZ   StartSec     Size    Device
rw   256   512  4096         63  156360582  /dev/hdb1

dd bs commands mixed with other dd directives also come in handy for 
slicing and dicing disks into chunks in a binary way, if you have a need 
for that.  Forensic analysts obviously like that feature.  I rarely find 
a use for it.

The Jargon file also has some entertaining bits on why dd's syntax is so 
horrid.  It was a joke, supposedly.  I can't confirm or deny that, but 
it's entertaining.

Nate
_______________________________________________
CLUE-tech mailing list
CLUE-tech at cluedenver.org
http://cluedenver.org/mailman/listinfo/clue-tech



More information about the clue-tech mailing list