Will dd if=/dev/zero of=/dev/sda wipe out a pre-existing partition table?

Will dd if=/dev/zero of=/dev/sda wipe out a pre-existing partition table?

Yes, the partition table is in the first part of the drive, so writing over it will destroy it. That dd will write over the whole drive if you let it run (so it will take quite some time).

Something like dd bs=512 count=50 if=/dev/zero of=/dev/sda would be enough to overwrite the first 50 sectors, including the MBR partition table and the primary GPT. Though at least according to Wikipedia, GPT has a secondary copy of the partition table at the end of the drive, so overwriting just the part in the head of the drive might not be enough.

(You don't have to use dd, though. head -c10000 /dev/zero > /dev/sda or cat /bin/ls > /dev/sda would have the same effect.)

does fdisk /dev/sda g (for GPT) wipe out the zeros written by /dev/zero?

Also yes (provided you save the changes).

(However, the phrasing in the title is just confusing, /dev/zero in itself does not do anything any more than any regular storage does.)


The partition table is stored near the beginning1 of the (logical2) disk device.

Overwriting that area with anything (zeroes from /dev/zero or any other data) will replace the partition table with gibberish, so it will no longer be obvious where the partitions on the device begin.
One can still scan the whole disk and try to identify the "magic bytes" that mark the beginnings of file systems, though.

Conversely, if you use fdisk (or any other partitioning tool) to create a new partition table, the tool will overwrite the first few bytes of the disk to store that new table.

There's only one beginning to the disk, so whatever you do last will "stick" there.

Note, however, that some partition table formats (like GPT) will keep backup copies in different places (e.g. at the end of the disk for GPT), from which some of the partition information can be recovered.

1: e.g. in the first 512 bytes for an MBR or the first and last 17408 bytes for a GPT
2: The drive can internally remap the logical blocks to different parts of the physical medium, but that mapping is invisible to (and unimportant for) the operating system.

Tags:

Linux

Dd

Gpt

Fdisk