Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 8 down vote accepted

Would this suffice?

dd if=/dev/zero of=/dev/sda bs=512 count=1 conv=notrunc
share|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
    
Don't forget to unmount the driver, otherwise it won't work. –  OrangeTux Dec 6 '13 at 14:47

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

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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