I know that doing a dd if=/dev/hda of=/dev/hdb
does a deep hard drive copy. I've heard that people have been able to speed up the process by increasing the number of bytes that are read and written at a time (default: 512
) with the bs
option.
My question is:
- What determines the ideal byte size for copying from a hard drive?
and
- Why does that determine the ideal byte size?
As Chris S wrote in this answer the optimum block size is hardware dependent. In my experience it is always greater than the default 512 bytes. If your working with raw devices then the overlying file system geometry will have no effect. I've used the script below to help 'optimize' the block size of dd.
Unfortunately the perfect size will depend on your system bus, hard drive controller, the particular drive itself, and the drivers for each of those. The only way to find the perfect size is to keep trying different sizes. Fair warning that some devices only support one block size, though this is rare, and usually drivers make up the difference anyway.
I find that block size of 2^15 or 2^16 work best for my WDC (8mb cache) SATA drives connected to a Adaptec SAS RAID controller, 4x PCIe, 64-bit FreeBSD 8.0-STABLE. But for my cheap old thumb drive, sizes of 2^10 seem to be fastest.
The "perfect size" is almost always a power of two.
I can vouch in the merit of measuring the outcome of performing a test on the device being used prior to wasting any time. I stupidly didn't bother and after measuring, then adjusting my block size slashed my DD duration of a 590Gb transfer in half. The same BS value would have only reduced time by 20% using a different caddy / drive combo.