Zombie Partitions and the GPT Undead

I’ve just had a hard drive that I tried to join to a ZFS pool. The drive had been used before when testing ZFS on Linux. However, when trying to add the drive it would complain about not finding the first partition:

cannot resolve path '/dev/disk/by-id/ata-ST3160215ACE_9RX5F4K9-part1'

fdisk showed the drive as being empty but having a GPT table.

fdisk -l /dev/disk/by-id/ata-ST3160812A_5LSBGY5S

WARNING: GPT (GUID Partition Table) detected on ‘/dev/disk/by-id/ata-ST3160812A_5LSBGY5S’! The util fdisk doesn’t support GPT. Use GNU Parted.

Fdisk can’t do GPT so I fired up parted.

root@vhost:/home/administrator# parted /dev/disk/by-id/ata-ST3160812A_5LSBGY5S
GNU Parted 2.3
Using /dev/sdg
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Warning: /dev/sdg contains GPT signatures, indicating that it has a GPT table. However, it does not have a valid fake msdos partition table, as it should. Perhaps
it was corrupted -- possibly by a program that doesn't understand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partition
table. Is this a GPT partition table?
Yes/No? Yes
Model: ATA ST3160812A (scsi)
Disk /dev/sdg: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number Start End Size File system Name Flags
1 1049kB 160GB 160GB zfs
9 160GB 160GB 8389kB

It reported that the GPT signature was damaged and appeared to fix it for me as I could now see two partitions on the drive. I removed them and set the partition table to a simple msdos one:

(parted) rm 1
(parted) rm 9
(parted) mktable msdos
Warning: The existing disk label on /dev/sdg will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
Warning: /dev/sdg contains GPT signatures, indicating that it has a GPT table. However, it does not have a valid fake msdos partition table, as it should. Perhaps
it was corrupted -- possibly by a program that doesn't understand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partition
table. Is this a GPT partition table?
Yes/No? yes

Now let’s see if it’s all gone….

(parted) p
Model: ATA ST3160812A (scsi)
Disk /dev/sdg: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags

(parted) q
Information: You may need to update /etc/fstab.

After reboot I tried to create the pool again but was met with the same error I had at the start!
I then tried the following:

  • zeroing the drive with dd.
  • Checking (and wiping) the drive with badblocks.
  • Using Seagate’s own HD utility software to check for errors (Pass!)
  • Sticking the drive into another computer and adding it to an existing RAID set in the hope that it would obliterate any remaining partition info
  • Using Seagate’s own HD partitioning utility to configure the drive
  • Using Seagate’s own HD utility software to low-level format the disk
  • Draping goat entrails across the platters in an attempt to appease any gods who might know about this sort of thing
  • Watching England Ladies lose to France in the Women’s World Cup (not really affecting the HD issue but I needed to do something whilst waiting for the various scans & wipes to happen!

After each of these the GPT partitions kept coming back!

Plugging the drive into Windows didn’t help as the Disk Management utility wouldn’t let me change the GPT table either. I then remembered the Windows command line tool diskpart but had forgotten which commands I needed:

C:\Documents and Settings\Me>diskpart

Microsoft DiskPart version 5.1.3565

Copyright (C) 1999-2003 Microsoft Corporation.
On computer: PC1

DISKPART> help

Microsoft DiskPart version 5.1.3565

ADD – Add a mirror to a simple volume.
ACTIVE – Marks the current basic partition as an active boot partition.
ASSIGN – Assign a drive letter or mount point to the selected volume.
BREAK – Break a mirror set.
CLEAN – Clear the configuration information, or all information, off th
disk.
CONVERT – Converts between different disk formats.
CREATE – Create a volume or partition.
DELETE – Delete an object.
DETAIL – Provide details about an object.
EXIT – Exit DiskPart
EXTEND – Extend a volume.
HELP – Prints a list of commands.
IMPORT – Imports a disk group.
LIST – Prints out a list of objects.
INACTIVE – Marks the current basic partition as an inactive partition.
ONLINE – Online a disk that is currently marked as offline.
REM – Does nothing. Used to comment scripts.
REMOVE – Remove a drive letter or mount point assignment.
REPAIR – Repair a RAID-5 volume.
RESCAN – Rescan the computer looking for disks and volumes.
RETAIN – Place a retainer partition under a simple volume.
SELECT – Move the focus to an object.

DISKPART> list disk

Disk ### Status Size Free Dyn Gpt
——– ———- ——- ——- — —
Disk 0 Online 233 GB 0 B
Disk 1 Online 149 GB 0 B
Disk 6 Online 149 GB 0 B

DISKPART> select disk 6

Disk 6 is now the selected disk.

DISKPART> clean

DiskPart succeeded in cleaning the disk.

DISKPART> exit

Leaving DiskPart…

I then removed the drive, put it back into my Linux computer and successfully added the drive to the ZFS pool. YAY!
I’m surprised that it took my Windows machine to do something that seems so simple. It’s odd that Seagate’s own utilities couldn’t wipe the disk either and the fairly comprehensive Linux utilities dd, parted and fdisk, which normally do so well, couldn’t wipe this disk.

As with everything to do with computers it shows that there are multiple tools for the same job and some work better in some situations that others.