How do you delete all partitions on a device from the command line on Linux (specifically Ubuntu)? I tried looking at fdisk, but it presents an interactive prompt. I'm looking for a single command, which I can give a device path (e.g. /dev/sda) and it'll delete the ext4, linux-swap, and whatever other partitions it finds. Essentially, this would be the same thing as if I were to open GParted, and manually select and delete all partitions. This seems fairly simple, but unfortunately, I haven't been able to find anything through Google.

link|improve this question

80% accept rate
feedback

4 Answers

up vote 6 down vote accepted

Would this suffice?

dd if=/dev/zero of=/dev/sda bs=512 count=1 conv=notrunc
link|improve this answer
1  
This will not delete the partitions. By deleting the partitions he meant to preserve the MBR and just empty the partition table. – Mircea Vutcovici Mar 23 '11 at 19:22
No, this appears to do exactly what I need. I don't really care if the data is still there. GParted shows that the partitions are gone after running this, and that's what I wanted. – Cerin Mar 24 '11 at 11:53
Mircea Vutcovici wasn't talking about your data, but about the bootstrap code in your MBR. That's now gone, because you've erased it along with the 4 primary entries from the MBR-style partition table. – JdeBP May 17 '11 at 11:22
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.