1

I am using this command to overwrite the data of a hdd:

sudo dd if=/dev/zero of=/dev/sdc bs=10M status=progress conv=fsync

If the size of my hdd is not divisible by 10M, will dd abort or will it overwrite the end?

For example if the size is 10001M. Will it overwrite the last 1M? Even if it's smaller than bs?

zomega
  • 972

1 Answers1

4

It will try to read 10 MB blocks, but if it gets a short read, it'll just write a similarly short block and continue. It will copy everything though, unless you use count=N to restrict the number of blocks it'll read and write.

E.g. here, the output 0+2 means no complete blocks were read or written, but 2 partial blocks were, for a total of 8 bytes as in the input.

$ (echo foo; sleep .3; echo bar) | dd bs=512 | wc -c
0+2 records in
0+2 records out
8 bytes copied, 0.301053 s, 0.0 kB/s
8

The block size of reads and writes doesn't really matter on disk partition devices on Linux, so except for the progress display, you could just run cat < /dev/zero > /dev/sdc instead. If you have pv, you could use pv < /dev/zero > /dev/sdc.

There are a number of posts here about how dd actually behaves, see e.g.

ilkkachu
  • 138,973
  • Or pv -Ss "$(blockdev --getsize64 /dev/sdc)" /dev/zero > /dev/sdc if you want a nice progress bar. See also things like nwipe / wipe / shred... which are designed for that. – Stéphane Chazelas May 07 '22 at 14:14
  • @StéphaneChazelas, hmm, I thought pv autosenses the size, but yeah, -S seems necessary to avoid the eventual error message. – ilkkachu May 07 '22 at 14:23
  • You're right. I had assumed it would only autosenses the size of the input (with /dev/zero here having infinite size), but it seems that if the output goes to a block device, it gets its size as well. – Stéphane Chazelas May 07 '22 at 15:42