4

I want to do a quick "wipe" of some disks so they look like they're ready to be newly partitioned. Currently there is a GPT partition type on disk, which seems to write some data both at the beginning and end of the disk. In this case, it doesn't matter if the data on the disk is wiped, so no need to wait for the whole disk to dd from /dev/zero. So what's a simple way to clear just the beginning and end GPT headers?

In this case, I'm using Linux (CentOS 7) with standard SATA disks (/dev/sda, etc.)

3 Answers 3

4

This should do it pretty efficiently, based on the information about GPT on this site.

Clear the first block (two 512-byte sectors for MBR and header, and 16KiB for partition entries):

dd if=/dev/zero of=/dev/sdwhatever bs=512 count=34

The last part is trickier. I'm borrowing from this question to assist, although if you have ddrescue handy, it can go in reverse.

dd if=/dev/zero of=/dev/sdwhatever bs=512 count=34 seek=$((`blockdev --getsz /dev/sda` - 34))
1
  • 1
    The reason this is so helpful is that all the commands (dd, blockdev ... uh that's it) are available in RHEL's initrd.img which means they're guaranteed to be available in the Anaconda/kickstart %pre environment. Thank you!
    – Rich
    Apr 29 at 1:55
7

gdisk has an option for it. Open extended options, choose 'zap':

gdisk /dev/sda
> x
> z
> w (maybe?)
2
  • TIL, the gdisk Zap option! This will be my preferred method when only doing one or two disks.
    – Paul
    Jun 30, 2016 at 22:35
  • This looks a simpler option than what I posted, assuming you have gdisk available. Jul 5, 2016 at 20:35
1

FreeBSD utility gpart can do it in this pretty straightforward way:

gpart destroy -F /dev/sdX
2
  • Should this be gparted instead of gpart? I didn't find a gpart command installed by default, and there's no RPM in the regular CentOS repos.
    – Paul
    Jun 30, 2016 at 22:38
  • Sorry, gpart is a FreeBSD tool for managing GPT. I was sure linux have it too.
    – Kondybas
    Jul 1, 2016 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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