Why is this dd command with a count and bs param running past its count?

I have a dd command with bs=1M and count=40960M (40GB) and it’s consistently running past its count every time I try to run it. This is the exact command, and the output captured before I stop it:

dd if=/dev/zero of=/swap/swapfile bs=1M count=40960M status=progress
50383028224 bytes (50 GB, 47 GiB) copied, 458 s, 110 MB/s

Based on the progress output, it seems like it’s just running indefinitely and probably would keep going until the of destination is completely filled. What am I misunderstanding about dd that’s causing this to keep running forever?

Asked By: Dan Herbert

||

You have to multiply the bs and count parameters to get the siez fo the data it will actually write. You’re asking it to write 40 billion (40960 million) blocks, each block being 1 MB large. That’s… quite a large amount of data.

If you want to write 40 GB, you can use bs=1 count=40960M, bs=1M count=40960, or some similar combination.

Answered By: John

The count parameter in the dd specifies the number of blocks to be copied, and the bs parameter determines the block size.

dd interprets the M suffix represent "million" as a binary multiplier.

count=40960M in the count parameter means 40,960 million blocks, not megabytes.

Which results in a much larger size than you intended.

Remove the M suffix to calculate the correct value for count.

This is the correct command:

dd if=/dev/zero of=/swap/swapfile bs=1M count=40960 status=progress

Answered By: Blockchain Office
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.