2

I have seen examples of using the dd and ddrescue command, and I see that instead of asking the user for the size of the block on their device, they recommend using bs=1M and I do not understand why.

What happens if the disk sector size is 512 bytes and 1MB is assigned to bs?

Can any value be used independently of the size of the disk sector?

In the case of discs of advanced format and with a capacity of 1TB, what do you recommend to use?

3

What is bs option and why it's used ?

It has been explained in dd is producing a 32 MB random file instead of 1 GB ( which I recommend reading, btw ) that bs option refers to how much single read() syscall would read and store in memory ( if size of memory and the device you're reading from allow for such size ). This is also referenced in the manual:

bs=BYTES read and write up to BYTES bytes at a time (default: 512);

Thus, it has nothing to do with number of blocks/sectors on the disk, but with dd's performance - storing more things in memory for faster processing. To quote one ServerFault answer:

I know when I'm copying hard disks I get a faster rate by specifying bs=1M than by using bs=4k or the default. I'm talking speed improvements of 30 to 300 percent. There's no need to tune it for absolute best unless it's all you do every day. but picking something better than the default can cut hours off the execution time.

The choice of bs value has also been discussed on another stackoverflow post:

The optimal block size depends on various factors, including the operating system (and its version), and the various hardware buses and disks involved. Several Unix-like systems (including Linux and at least some flavors of BSD) define the st_blksize member in the struct stat that gives what the kernel thinks is the optimal block size

As for why 1M it's potentially because people found this to be an optimal value. Remember that RAM size used to be 512M. So using 1M would be small enough to keep RAM usage low, but have decent dd speed.


Concerning your question:

What happens if the disk sector size is 512 bytes and 1MB is assigned to bs?

Nothing. dd will read data in chunks of 1MB. It doesn't change the data in any way. It may improve dd speed as compared to smaller block size, but has no effect on the data itself.

Different story would happen if you read in chunks smaller than the sector size of the drive: drives have to serve full sector size and the kernel caches that information. See Matthew Ife's answer on the same Serverfault post. But again, no effect on data itself.

In the case of discs of advanced format and with a capacity of 1TB, what do you recommend to use?

Advanced format such as what ? As far as dd itself goes, it should not care about any disk format - all it knows is to read and write from and to block devices; it doesn't matter if you write to USB stick or SCSI drive - the syntax is the same, it's the kernel that handles the minute details and has drivers for those devices to properly pass the data.

And again, capacity also doesn't matter. 1TB SATA drive is still an SATA drive.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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