All partitions are missing because GPT table was erased

Ubuntu Version

Ubuntu 24.04 LTS Flavors

Desktop Environment (if applicable)

Other

Problem Description

HELP ! All partitions are missing because GPT table was erased.

Thanks for reading my topic.
Please HELP ME !
Here is machine mainboard A960D SB710 SATA2 AMD FX 6300 and HDD WD WD20PURX-89G3VY0 2,5 TB SATA 3.
Others details about that HDD are :
Disk /dev/sda: 2.28 TiB, 2501392932864 bytes, 4885533072 sectors

OS Linux Lubuntu 24.04.3 kernel 6.14.
I had used the software HDAT2 to run “detect repair bad cluster” only to see if the begin of disk had some problem and only was tested below of 4 MB begin of HDD and not was tested the end of disk. Test had erased the GPT table.
The HDD is new and the partitions were created only once in the following order:

sda1 8 MB unformated bios_grub
sda2 600 MB ext2 /boot
sda3 12 GB BTRFS / ( OS partition )
sda4 1 GB BTRFS /home
sda5 21 GB BTRFS /opt
sda6 1,2 TB BTRFS Data
sda7 1,2 TB BTRFS Data

HDAT2 has a command to scan for file system in the disk only for list information and running that command is showed in begin of disk

GPT header 1
GPT table 0
FAT 12
DIR 1

in the end of disk
GPT header 1
GPT table 0

It’s strange not having GPT table backup in the end of HDD. Not was done any test in that area and HDAT2 not has command to erase MBR or GPT tables.
I had tried run “parted” and when trying the “rescue” option is showed a message “no partition table” so not is possible run that test.

Using “parted print”
Disk /dev/sda: 2.28 TiB, 2501392932864 bytes, 4885533072 sectors
Disk model: WDC WD20PURX-89G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

I’m very concerned about trying to perform any action that would modify or write to that disk.
I had done a test in other disk doing the same actions above … create some partitions and then HDAT2 erasing the fist sectors for erase the GPT table .. then had created an GPT table and “parted” allow to run the “rescue” option needing input values for START and END, but I had used for START 0 and END total number of sectors and the command run for only 20 seconds not listing any partition to recover. It’s strange because the HDD is 1 TB and obvioulsy 20 seconds not was totally scanned. I had used others values, but always run in 20 seconds.

Please help me if you known any way to fix it using a command or software for recover all my partitions.
Have a nice week. Thanks very much for replying. God protect your life.

Given that HDAT2 is a DOS program normally starting from its own supplied DOS disk, I suspect there isn’t a lot we can help with here, if the behavior was unexpected you should surely contact the author and ask there for help.

Since you know all the sizes your partitions used to have I guess your best move forward is to re-create and re-format the partitions as you had them before and restore the backups you have surely taken before running such a low-level hardware managing disk utility …

1 Like

Thanks for your reply. I remember you.. All good in your path ?

Unhappily has a partition with my data and not has backup.

I need recover the partitions.

Question also asked (albiet not identical) at https://askubuntu.com/questions/1569246/all-partitions-are-missing-because-gpt-table-was-erased

2 Likes

despair or some other word… I have little time left :frowning:

The only tool I can think of that might help is Testdisk:

https://www.cgsecurity.org/wiki/testDisk

But the chances are not high considering what has already happened.

2 Likes

gdisk can repair the GPT table in certain circumstances - worth investigation?

I removed “Help” from the topic title because you have posted in Support and Help

3 Likes

If you know the exact starting sector and size for each partition, you can just recreate the partition table, it will not affect the partition content. parted only scans at most 16MB at the beginning of the range, you will need to scan for each partition separately choosing the suitable start range. parted only scans for known filesystems, so e.g. it will not find the BIOS GRUB anyway (this partition contains the GRUB executable image).

It is possible to use Linux device-mapper to setup read-only base image and writable overlay which allows experimenting with partition tables without risk to destroy data.

1 Like

gdisk scan the disk and then create a new GPT table.

Further information here
I can’t help you with exact instructions because I cannot reproduce and test a fix.
In this instance, I can only make a suggestion for you to investigate a possible solution

2 Likes

@tea-for-one

THANKS VERY MUCH !

Can you post a link that describes it? It is the first time I hear about this possibility and gdisk manual does not mention it.

I want a software scanning totally the HD and then creating a GPT table for all partitions.

If the information is important to you, I would be tempted to say don’t try to do this yourself. Take it to a specialist company. The data are all still on the drive, and will be recoverable with the right tools.

In future, you know that you need to take daily backups.

2 Likes

I will use a disk clone and to do a test in other HD for recover the partitions.

And probably not use any tools that talk directly to the hardware on such a low level that it can actually damage it to a point where it is not recoverable and usable at all anymore (HDAT2 is apparently known that it can hard-brick disks if you use it wrongly)

5 Likes

Take plenty of care to clone the correct way, and not accidentally overwrite the original!

Thanks for saying it.

I will clone using a software not changing the source partition and then trying some commands.

BTRFS is much fragile.

Gdisk repairs primarily require either primary or backup gpt partition table, so it can resync them.
https://www.rodsbooks.com/gdisk/repairing.html

If you know exact start & end of partitions, you can manually recreate partition table. But usually you have to have backed up partition table info first to know details for sector start & end.

Both bios_grub & Windows’s reserved are un-formatted partitions. Those often cause partition tools issues as they often cannot see them when looking for formats.

It looks like HDAT2 does not support bios_grub and/or BTRFS partitions. Best to use Linux tools for Linux.

As suggested above testdisk may be best choice. It does not look like Photorec works on BTRFS file systems.
There seem to be several tools like photorec that may work with BTRFS. But have never used them so will not directly suggest any. Not sure I trust Google’s AI. :slight_smile:

2 Likes

@rubi1200

Thanks for your reply abou TestDisk.

@paddylandau

Thanks very much for your reply. I remember yours replies in a topic created by me in 2020.
I’m glad seeing you are alive.

Thanks for all replies.
I has recovered all files.
I have used BTRFS since 2020 and lost count of how many times errors occurred on the partitions when using writeback.
Is correct if not is done a writeback flush losing files, but happen the terrible parent transid error with 2 numbers. If both number are close in 20 digits is possible clean the tree log and mount for fix, but if the both numbers are more high than 20 numbers is a fatal error.
I have used for years NTFS , FAT32 , exfat and ext2 and ext4 was rarely used. You don’t run into that many problems with them.
If the disk was damaged with bad blocks exactly in area of MFT is possible use a software to recover all files in a damaged NTFS. In BTRFS you need pray.
Why did I still use BTRFS?
Because it’s very efficient at allocating files and does compression.
A 1 TB partition formatted using ext4 will reserve 18 GB.
If you format for BTRFS in a partition only for read only files using the command below will be reserved only 48 KB instead several GBs for metadata.

mkfs.btrfs -d single -M --csum xxhash -n 4096 -s 4096 -L BTRFS -o mixed-bg -o skinny-metadata -o no-holes -o block-group-tree /dev/sdXX

option “-M” mix data and metada in same disk area thus not creating reserved area for metadata and doing file compression gain nearly 40 GB of space compared to ext4.
BTRFS is much more faster to access the directories than ext4.
Unhappily that file system is much fragile. The partition was damaged not doing any file operation.
I also use RapidDisk being writeback for “/” and “/home” , but not for the partition used for user data. That software is very good and avoid repeated written in same partition.

I had tried the command below to fix the partition , but not any fixes.

“btrfs rescue super-recover”
show the message below
All supers are valid, no need to recover

sudo btrfs rescue zero-log /dev/sda7
sudo btrfs rescue clear-space-cache v2 /dev/sda7 ( I remember before 2022 testing that command was damaged the file system losing all files ).
sudo btrfs rescue clear-uuid-tree /dev/sda7

sudo btrfs rescue chunk-recover -v /dev/sda7
More than 3 horus to complete task and was possible fix several chunks, but not one chunk not was possible fix so not completing the fix.

“btrfs rescue clear-ino-cache”

“btrfs check --init-extent-tree” ( create a new extent tree ).
Not work.

“btrfs-find-root /dev/sda7”
had showed a “well block” 7146754048
Thus I had done the command below, but not any fix.

sudo btrfs check --repair --tree-root 7146754048 --super 0 /dev/sda7
using SB copy 0, bytenr 65536
Opening filesystem to check…
parent transid verify failed on 6342438912 wanted 773 found 775
parent transid verify failed on 6342438912 wanted 773 found 775
Ignoring transid failure
ERROR: child eb corrupted: parent bytenr=7146754048 item=0 parent level=1 child bytenr=6342438912 child level=1
ERROR: could not find extent tree
ERROR: cannot open file system

Also had used another value 6342438912, not fix.
sudo btrfs check --repair --tree-root 6342438912 --super 0 /dev/sda7
using SB copy 0, bytenr 65536
Opening filesystem to check…
parent transid verify failed on 6342438912 wanted 774 found 775
parent transid verify failed on 6342438912 wanted 774 found 775
Ignoring transid failure
WARNING: could not setup extent tree, skipping it
WARNING: could not setup csum tree, skipping it
WARNING: could not setup free space tree, skipping it
ERROR: couldn’t load block group tree
ERROR: cannot open file system

Maybe I’m not using the correct command for btrfs-find-root.
If has a problem not allowing mount perhaps the solution is a software reading the files not needing mount ? Exactly it.

Photorec can recover all files, but has a problem. All files will be recovered without original naming and the way as show the configuration types of files to recover does doubt if will be recovered all files because not show a option for all files. All recovered files will be numbered. Not exactly a simple solution.

The solution was

A simple bash script of 14,9 KB. Internally use btrfs-find-root and btrfs rescue for scan totally the partition and then make an list of all files for recover needing configure an output path.
In a HDD WD Purple partition 1.2.
It took more than 4 hours to recover all the files. It not recover symbolic links.
After I tested everything, and there was no damage. All files used the correct original filenames.

I didn’t delete the damaged partition because I’m going to compile the software below for testing and learning purposes. If I can fix it, that would be good to know.

https://www.system-rescue.org/

I backed up everything that was recovered =)
Whatever it is, there’s something strange about it… If the extended tree and CSUM tree were damaged, preventing them from being mounted, but all the files are intact, it would be very simple if the BTRFS developers created a solution where the BTRFS repair tool analyzes all the files and then completely recreates the extended tree, CSUM tree, and any other damaged parts… but it’s very difficult to fix resulting the user to have a terrible experience.
Have a great week, and thank you very much for all replies!

2 Likes