Deleting All Partitions From the Command Line

Solution 1:

Would this suffice?

dd if=/dev/zero of=/dev/sda bs=512 count=1 conv=notrunc

Solution 2:

The wipefs program lets you easily delete the partition-table signature:

wipefs -a /dev/sda

From man wipefs

wipefs can erase filesystem, raid or partition-table signatures (magic strings) from the specified device to make the signatures invisible for libblkid.

wipefs does not erase the filesystem itself nor any other data from the device. When used without any options, wipefs lists all visible filesystems and the offsets of their basic signatures.

wipefs calls the BLKRRPART ioctl when it has erased a partition-table signature to inform the kernel about the change.


Solution 3:

Quick and Dirty: use gparted to delete the partitions, or if you’re in a hurry:

dd if=/dev/zero of=/dev/[disk device] bs=512 count=1

This will zap the MBR of the drive (Data is still intact).

Alternatively:

dd if=/dev/zero of=/dev/[disk device]

to wipe the whole drive (write a single pass of zeros over everything. Not "secure" but usually good enough), or use a "disk shredder" tool for a secure wipe.


Solution 4:

See man sfdisk, which is a non-interactive variant of fdisk. Other than that, you can delete the whole partition table with dd, as pk wrote.


Solution 5:

You should be able to use parted for this aswell, although that may involve some scripting to loop through the partitions.