Fun with GPT

Jason wanted to borrow my server for his work, so this meant I had to re-build my desktop machine so that I could rsync my data across. As the computer only boots Linux, I thought I’d use GPT (GUID Partition Table) instead of the MSDOS partition table. There are 4 hard drives in my desktop, which I want to run in RAID 5.

As the new Ubuntu release Intrepid is almost out, I thought I’d try this too. I set my drives to use GPT, but then realised that I wanted to offset the partition to align the RAID array. Because fdisk does not support GPT partition tables I had to use parted. As time was short (and I am not as familiar with parted) I just thought I would switch back to a MSDOS partition table and get on with it, using fdisk.

I did my usual trick of wiping the first 512 bytes to clear the master boot record and the partition table.
dd if=/dev/zero of=/dev/sda bs=1 count=512

But fdisk still warned that there was a GPT on the disk.. hmm.. This just didn’t feel clean, so I wanted to solve it.

Wiping the front of the disk didn’t solve the issue, so I figured that it must be stored somewhere else.

I ran strace on the fdisk command to see where on the disk it was looking in order to detect the GPT and therefore print the error. The result told me that it was seeking the 300069051904th byte – at the end of the disk. (Note: I didn’t save the inital result, so this one below is me running it again on a drive where I had not wiped the first 512 bytes.)

open("/dev/sda", O_RDONLY) = 3
uname({sys="Linux", node="localhost.localdomain", ...}) = 0
ioctl(3, BLKSSZGET, 0x7fff931b96cc) = 0
lseek(3, 512, SEEK_SET) = 512
read(3, "EFI PART\0\0\1\0\\\0\0\0002\317\362*\0\0\0\0\1\0\0\0\0\0\0\0/"..., 512) = 512
close(3)

The trace showed me that fdisk was reading at the end of the disk, from byte 300069051904. If you read up on GPT you will discover that there is a secondary header on the end of the disk. I didn’t know this at the time :)

Using dd I could offset the starting point (in blocks) to start writing my zeros. Thanks to strace I knew the location, so I simply needed to convert the bytes into blocks.

300069051904 / 512 (512 bytes in a block)

Then I passed this information to dd
sudo dd seek=586072367 if=/dev/zero of=/dev/sda

Next I just had to check whether it worked
sudo fdisk -l /dev/sda

Disk /dev/sda: 300.0 GB, 300069052416 bytes
255 heads, 63 sectors/track, 36481 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sda doesn't contain a valid partition table

No more error.. now I was free to re-partition the drive and continue the install.

So there you go! I’ll know for next time (although I really should just learn to use parted).

2 Responses to “Fun with GPT”


  • Hi there,

    Just a short note; I had a similar GPT signature problem, though the solution for me ended up being to zero out the first five megabytes (or so) of the drive. The first 512 didn’t hold the signature, neither did the last 200 megabytes. I appreciate the pointer that the signature doesn’t (necessarily) rest in the boot record.

    -Stephan

  • No worries. I’ve since just learned to use parted, which is very different to fdisk but actually is quite good. Knew I’d have to do that sooner or later :-)

    -c

Leave a Reply