On Aug 8, 2014, at 4:29 AM, Robert Moskowitz <rgm(a)htt-consult.com> wrote:
Unfortuately there is no such command to delete all partitions,
though you kind of can do it by changing the table type, say from msdos to gpt.
I forgot to address this specifically. First, you really should delete the filesystem
signature before deleting partitions. This makes the filesystem invalid, and thus things
like libblkid and libparted aren't going to recognize latent (stale) filesystems. The
tool for this is wipefs part of util-linux. Use it like this for example:
wipefs -a /dev/sdb[123]
That will delete the fs signatures on all file systems found on partitions 1 through 3 on
disk sdb. The partition table still contains entries of course, but the filesystems in
them are invalidated.
Next, if you want to get rid of all partitions, you can also use wipefs on a whole disk.
This removes the signature for the partition table. Most any tool will consider it
invalid, rather than broken, so it's not going to offer to fix it, it'll offer to
repartition it: so in the GPT case, it gets a whole new disk identifier GUID rather than
just restoring the signature. It is possible, btw to restore the signature and thus
restore the partition table and all of its partitions (since those sectors aren't
actually erased).
You could also blow away 34 sectors from the start and end of the drive using dd
if=/dev/zero. That's a hammer.
Oh and I mentioned cgdisk (member of the gdisk family) that was wrong, it's
curse-based. You want to look at sgdisk which is for use in scripts and accepts all
commands from the CLI. It has a way to delete partitions individually. Note that this does
not employ wipefs, so the actual filesystem contained within the partition you've
deleted is still intact; and this also leaves the partition header intact, all it's
doing is removing a partition table entry. sgdisk also has two zap options: one overwrites
everything (sectors containing both MBR and GPT structures), the other option overwrites
only the sectors containing GPT structures.
So it really depends what you want to achieve, and how arbitrary the source drives are
going to be.
If you're writing a program or script you might look at python-blivet which has done a
ton of work abstracting all of this stuff, if you can do what you need to do in python,
then you can use sane pthyon code to do things like wipe all fs's, delete all
partitions, create new GPT, add new partitions, format them. And you don't need to
know the prose for the 5 different utilities to make that happen. python-blivet is
actually at the core of the Fedora installer, specifically for manipulating storage (it
does everything you can imagine in including create, modify, destroy LVM objects; btrfs
subvolumes; bunch of md raid stuff, etc.)
http://pkgs.fedoraproject.org/cgit/python-blivet.git/
Chris Murphy