Partition Table Repair: GPT, MBR, and What Not to Touch

A disk that suddenly shows as unallocated, or as a single partition of the wrong size, usually has an intact filesystem and a damaged partition table. The table is a small index at the start of the disk, and when it is wrong the operating system has no way to find the data that is still sitting there.

The short version: image the disk first, then inspect, then write. Any tool that offers to “fix” the table automatically before you have a copy is a tool that can turn a recoverable disk into a formatted one.

MBR and GPT are different failure modes

The older MBR scheme keeps its partition entries in the first sector plus a copy of the boot code, and it is vulnerable to a single overwritten sector. GPT keeps a primary header and a backup header at the end of the disk, with a CRC checksum on both. A GPT disk with a damaged primary header is often repaired by restoring from the backup, which is why GPT failures are usually more recoverable.

Knowing which scheme the disk uses matters before running anything: the repair of one is not the repair of the other, and tools that guess can write the wrong structure. Read the first sector and the last sector and compare what you find before deciding.

The first command is an image, not a repair

Write a full disk image to a separate drive of equal or greater size, and work only against the image. A partition table repair that goes wrong on the original can destroy the backup header and the filesystem superblock in one operation, and the image is what makes that survivable.

For very large disks, imaging the first and last few hundred megabytes is enough to work on the table itself in many cases, and it is far faster. But for any repair you intend to apply to the original afterwards, a full image is the safer artefact.

Reading what is actually there

Tools that parse the table and list candidate partitions are diagnostic, not corrective. Their job is to show you where the filesystems begin and end, and whether the entries are consistent with the sizes reported. Compare the sizes against what you remember, against the filesystem’s own metadata, and against the backup header.

When the primary header is damaged, restoring the backup header is often a single command provided by the partitioning tool, and it recalculates the checksums. When both are damaged, a partition-scanning tool can rebuild entries from the filesystem signatures, but that reconstruction is a hypothesis rather than a recovery, and it must be verified before anything is written.

Common causes worth recognising

A disk cloned from a larger drive to a smaller one often ends with a table that describes the old size, and the last partition extends past the end of the new disk. An interrupted write during a resize leaves an entry that points into unallocated space. A disk used in a RAID set and then attached directly can show a table that belongs to the array rather than to the disk.

Each of these has a specific repair, and each is much easier to identify than to guess at. Writing down what changed before the failure usually identifies the cause in a minute, which is why a change log on anything holding data is worth keeping.

After the repair, verify before you trust

Mount read-only first and check that the filesystem reports the expected size and that a few known files are present. Then run a filesystem check on the image, not on the original. Only after the image behaves correctly should the same repair be applied to the original disk, and only with a fresh image taken beforehand.

If the filesystem itself is damaged, the partition repair is only the first step. Mixing the two, by running a filesystem check against a wrong-sized partition, is how a readable disk becomes an unreadable one.

Why the backup copy exists

GPT stores its primary header and entry array at the start of the disk and a backup copy at the very end. The two copies exist precisely so that a damaged primary can be replaced from the backup, and the repair is usually a matter of telling a tool to use the backup rather than rebuilding anything by hand.

This is why the first action after a GPT complaint is to image the whole disk, not the partitions. Imaging the whole disk preserves both copies, including the backup that may be the only intact metadata left, and it makes every subsequent attempt reversible. Working on the original before imaging is the mistake that turns a repairable table into a lost disk.

Reading the errors correctly

Messages about a missing or corrupt GPT header, about overlapping partitions, or about CRC mismatches point at different problems. A CRC mismatch on the header suggests a torn write or a failing sector at the start of the disk; overlapping partitions suggest a tool wrote entries without checking; a header that reads as all zeroes suggests the first sectors were overwritten by something with block-level access.

Each of those has a different next step, and the sector that failed is diagnostic: a single bad sector at the start can be worked around by writing the backup header there, while a pattern of unreadable sectors means the drive itself is failing and the repair is secondary to getting the data off.

After the repair, verify from the operating system

A repaired table that a partition tool accepts is not necessarily a table the operating system interprets correctly. Mount read-only, compare the file listing against a known inventory, and check the free space map. A filesystem that mounts but reports the wrong size is a table that was rebuilt with plausible but incorrect geometry, and continuing to write to it will produce corruption that looks like a filesystem bug.

What to check before you commit

  • Identify MBR or GPT from the first and last sectors before touching anything.
  • Image the disk, or at minimum the ends, before writing anything.
  • Use parsers to read, not to fix, until the structure is understood.
  • Try restoring the GPT backup header before reconstructing entries.
  • Record what changed on the disk before the failure.
  • Mount read-only and verify on the image before applying the repair to the original.

Partition repair is mostly restraint. The table is small, the data is usually fine, and the difference between a recovered disk and a formatted one is whether a copy existed before the first write.

Leave a Comment