#!/usr/bin/env python import os, sys ''' Nuke GPT on any given block device. Based on original work by lestercheung@gmail.com http://blog.gnub.net/2009/03/die-gpt-die.html ''' def clear_gpt(target): ''' According to http://en.wikipedia.org/wiki/GUID_Partition_Table - GPT stores partition data in the first and last 34 LBA blocks. A LBA sector is normally 512 bytes. ''' sys.stdout.write("%s nuked: " %target) fd = open(target, "w+") fd.seek(0) fd.write('\0' * 34 * 512) sys.stdout.write("[%s] " %"GPT1") fd.seek(0, 2) # SEEK_END is 2 disk_size = fd.tell() fd.seek(disk_size - 34*512) fd.write('\0' * 34 * 512) sys.stdout.write("[%s] " %"GPT2") sys.stdout.write("\n") if __name__ == '__main__': args = sys.argv if len(args) < 2: sys.stderr.write("Use: %s device1-to-nuke-gpt-table [ ... device2-3-4-to-nuke-gpt-table ... ]\n" %args[0]) sys.exit(1) for x in sys.argv[1:]: if os.path.exists(x): clear_gpt(x) else: sys.stderr.write("%s: not found\n" %x)