Can dd overwrite adjacent partitions

Would

dd if=/dev/zero of=somepartition bs=512

also wipe partitions after somepartition or stop at the end of somepartition?


Overwrite a partition with dd

dd is a very powerful but also dangerous tool. It does what you tell it to do without questions. So if you tell it to wipe the family pictures, ... and it is a minor typing error away.

But if you check and double-check, you can use it.

dd if=/dev/zero of=somepartition bs=512

or I would suggest

dd if=/dev/zero of=/dev/sdxn bs=4096

where x is the drive letter and n is the partition number and block size 4096 bytes makes the write process faster.

It is important that you write to a partition in this case. If you write to the whole drive (the drive head end) /dev/sdx the whole drive will be overwritten. But writing to the partition will be interrupted at the end of the partition and partitions behind it will be preserved. (I tested now on a USB pendrive in Lubuntu 16.04 LTS, so I know that it works like that.)

Exception for an extended partition

There is an exception for an extended partition (which is a container for logical partitions, in order to have more than four partitions in an MSDOS partition table). This is described in the following link,

Can I make image of 'extended' partition using dd?

But there is another problem too. I tested your command in a test environment, and dd read only one kibibyte (1024 bytes) when I wanted it to make an image of an extended partition.

I tested also this now on a USB pendrive in Lubuntu 16.04 LTS, and this applies to writing (as well as to reading). Only the first kibibyte is overwritten.

So to summarize, overwriting primary partitions and logical partitions work according to the main description in this answer. But do not use this method to overwrite an extended partition because only the first kibibyte will be overwritten. The extended partition's logical partitions will no longer be found via the partition table, but the data stored in them are still there.


I think your question is based on a fundamental misunderstanding about how dd (and in fact Unix-like operating systems in general) work:

dd cannot overwrite adjacent partitions, simply because dd cannot overwrite partitions, period.

dd simply writes to files. That's it.

Now, if you pass dd a file which represents multiple partitions, then dd will overwrite that file. But in that case, it's not dd writing past the end of the partition. dd will still write until the end of the file, and only until the end of the file.

But, if you pass dd a file which only represents one partition, then dd will not write past the end of this partition. Again, this has nothing to do with dd. dd simply writes to the file you tell it to write to. The fact that this file represents a single partition is (in this case) ensured by the block device driver in the kernel. dd has nothing to do with that.

So, in short: dd writes to files. What those files represent, is none of dd's concern. dd knows nothing about partitions.


Writes to a partition device won't write outside of that partition, with dd or anything else. You would need to use a wholedisk device to have any effect outside of a single partition.

(Caveat: unless your disk has a partition table with overlapping partitions, which should never happen.)


There is a dangerous, but rare special scenario in which this could happen even with non-buggy block device drivers:

  • Partition table on disk is changed in a way that partition x is resized to end on a lower boundary than before. Either the partition y behind it is resized top start on a lower boundary, or a new partition y is added into the space.
  • Partition y is filled with relevant data by means that are independent of the partition table, eg using dd with skip/count options on the whole-disk block device (eg /dev/sda)
  • The ioctl that tells the kernel to reread the partition table is not issued, or fails due to busy devices
  • Partition x is written to by any process that tries to write to it until it hits an error condition.