First command
sudo dd if=/dev/zero of=/dev/sda
second command
sudo dd if=/dev/zero of=/dev/sda bs=1M
I am formatting my pc for 4 hours with first code but it didn't finish.
Is the first code wrong?
What is the difference?
First command
sudo dd if=/dev/zero of=/dev/sda
second command
sudo dd if=/dev/zero of=/dev/sda bs=1M
I am formatting my pc for 4 hours with first code but it didn't finish.
Is the first code wrong?
What is the difference?
The default block size for dd
is 512 Bytes, with the second command you tell dd
to use 1MB block size.
What's block size?
A block is a unit measuring the number of bytes that are read, written, or converted at one time. Command line options can specify a different block size for input/reading (ibs) compared to output/writing (obs), though the block size (bs) option will override both ibs and obs. The default value for both input and output block sizes is 512 bytes (the block size of Unix block devices). The count option for copying is measured in blocks, as are both the skip count for reading and seek count for writing. Conversion operations are also affected by the "conversion block size" (cbs).
For some uses of the dd command, block size may have an effect on performance. For example, when recovering data from a hard disk, a small block size will generally cause the most bytes to be recovered. For greater speed during copy operations, a larger block size may be used. When dd is used for network transfers, the block size may have an impact on packet size, depending on the network protocol used.
First command uses 512 byte blocks, whereas the second uses 1MB blocks. Actually a 4kB blocksize will do the trick in most cases as the disk uses 4kB blocksize on hardware level.
What happens in the first case is the following (simplified):
... replacing a 4kB block requires 8 reads from disk and 8 writes to disk.
I guess you get the image for what happens when you increase block size to 4kB or larger (preferably multiple of 4kB) and how that increases speed. It doesn't have to read the disk any more, because entire blocks are written.
On top of that speed up, it is quite likely that the PC is now delivering data fast enough to the disk, that it can probably write consecutive block one after the other, without having to wait for the rotating platter to do a full revolution until the right block appears under the heads.
Argument bs=1M
in second command means number of bytes read and then written. So, when you run dd
with this argument, 1 MB will be read from /dev/zero
, and then 1 MB will be written to /dev/sda
. When you don't have the argument, default value for byte number is used, I think it is 512 bytes. This number of bytes is much smaller, so more reading and writing is needed to complete requested operation and it will be slower.