When a GPT disk becomes unmountable after a forceful closure, the primary partition table is likely corrupted. Use gdisk or testdisk to verify and repair the header structure. On Windows, run chkdsk /f to fix file system errors, while Linux users should rely on fsck after ensuring the partition table integrity is restored.
Understanding GPT Corruption Causes
The GUID Partition Table (GPT) stores critical metadata at both the beginning and the end of a storage device. This redundancy is designed to protect against data loss if one header becomes damaged. However, when an operation such as formatting, resizing, or copying data is interrupted abruptly by a power failure or a forced shutdown, the synchronization between these two headers can break. The operating system may detect this inconsistency and refuse to mount the volume to prevent further damage.
This issue is distinct from physical hardware failure. If the drive spins up correctly and is detected in the BIOS or UEFI firmware, the problem is logical. The corruption typically manifests as the disk appearing as "unallocated" space, showing zero capacity, or throwing I/O errors when access is attempted. It is crucial to distinguish this from a completely failed drive, which would require professional data recovery services rather than software repair tools.
Verifying Partition Table Integrity on Linux
Before attempting any repairs, you must assess the extent of the damage. The tool gdisk is part of the gdisk package available in most Linux distributions. It provides a comprehensive suite of diagnostic commands that allow you to inspect the GPT structures without modifying them immediately. Open a terminal and execute sudo gdisk /dev/sdX, replacing /dev/sdX with your actual device identifier, such as sdb. Do not use the device letter with a partition number, like sdb1.
Once inside the gdisk interface, type v for the verify command. This scans the entire disk for inconsistencies. A healthy disk will report "The partition table looks OK." If there are errors, v will list specific issues, such as a mismatched backup header or invalid CRC checksums. Note that moving the backup header using the b command does not repair corruption; it merely relocates it. To actually fix structural errors, you must use the recovery menu.
Type r to enter the recovery and transformation menu. Here, you can select option e to load the backup GPT header from the end of the disk into memory. If the backup header is intact, this action often resolves the corruption by overwriting the damaged primary header with the valid backup. After loading the backup, return to the main menu with m and write the changes to disk using w. Always confirm the warning about overwriting existing data, as this step finalizes the repair.
Repairing File System Errors on Windows
If you are working within a Windows environment, the built-in utility chkdsk (Check Disk) is the standard approach for fixing logical file system errors. When a GPT partition is marked as dirty due to an abrupt shutdown, Windows will flag it as needing repair. Open the Command Prompt as an administrator and run chkdsk X: /f, where X is the drive letter of the affected partition.
The /f flag instructs chkdsk to fix errors found on the disk. If the file system is severely corrupted, you might need to add the /r flag, which locates bad sectors and recovers readable information. This process can take a significant amount of time depending on the size of the drive. During the scan, chkdsk will attempt to rebuild the Master File Table (MFT) and correct directory structure inconsistencies that arose from the forceful closure.
In cases where chkdsk fails to recognize the partition entirely, the issue may lie deeper in the partition table itself. In such scenarios, third-party recovery tools like TestDisk become necessary. TestDisk is a powerful open-source utility that can analyze the disk geometry and reconstruct the partition table based on known file system signatures. It is particularly effective when the primary GPT header is so damaged that Windows cannot even assign a drive letter to the volume.
Data Recovery Precautions
Any repair operation carries a risk of data loss, especially if the underlying file system structures are heavily fragmented. Before running any write operations like gdisk or chkdsk /f, it is highly advisable to create a sector-by-sector image of the drive using a tool like dd on Linux. This creates a bit-for-bit copy that can be used for testing repairs without touching the original data.
If the drive contains critical data that cannot be replaced, consider stopping all repair attempts and consulting a professional data recovery service. Physical media degradation combined with logical corruption can lead to permanent data loss if handled incorrectly. Software tools are effective for logical errors caused by improper shutdowns, but they cannot fix physical platter damage or controller failures. Always back up accessible files before initiating any deep-level partition table modifications.
Frequently Asked Questions
Can I use testdisk instead of gdisk?
Yes, TestDisk is often more user-friendly for automated partition table reconstruction. While gdisk requires manual verification steps, TestDisk can automatically search for lost partitions and write the new table in a single guided session, making it ideal for complex corruptions.
Why does my drive show as RAW format?
A RAW designation indicates that the operating system cannot read the file system signature because the GPT header or partition entry is corrupted. This usually happens after a crash, and the file system metadata is either missing or unreadable until the partition table is repaired.
Is chkdsk safe for NVMe drives?
Yes, chkdsk is safe for NVMe drives as long as you have a recent backup. Modern NVMe controllers handle wear leveling and error correction independently, so the software repair process works similarly to SATA drives without risking immediate hardware failure.
What if the backup GPT header is also corrupted?
If both headers are damaged, gdisk cannot simply swap them. You must use the 'r' menu to try rebuilding the header from scratch or use TestDisk to find the partition boundaries based on file system signatures, which effectively recreates the GPT entries.
How do I identify the correct device name in Linux?
Use the command lsblk or fdisk -l to list all block devices. Look for the disk size and model name to ensure you are targeting the correct physical drive, never the partition (which ends in numbers like 1 or 2).