Score:4

Recover data on a hard-drive that changed partition table

mr flag

From Ubuntu running from CD I formatted the C: drive using GParted and I changed the partition table on one HDD from MBR/MSDOS to GPT but I realized (too late) that it affected all partitions on the same HDD. Basically I lost data on the secondary partition which I wanted to keep.

I used GParted to perform the change of partition type. I did not do anything else since and the entire HDD is unallocated now.

How can I recover partitions with files please ?

terdon avatar
cn flag
Did you happen to keep a copy of the old partition table? Even an image showing where the partition boundaries were?
Raffa avatar
jp flag
If that is all you did, then there is a fair enough chance that your data is recoverable … But, **FIRST**, [creat an image of the whole disk to file](https://askubuntu.com/a/1422748) and secure an intact copy of it before attempting any fix … Do your fixing attempts on a copy of the image file and not on the physical disk which you shouldn’t try to mount either … You should be able to extract all your data from the image file and even repair its partitions and mount them safely.
mook765 avatar
cn flag
Probably [testdisk](https://www.cgsecurity.org/wiki/TestDisk_Download) is able to recover your partitions. Take a look at the [documentation](https://www.cgsecurity.org/testdisk_doc/) first.
Raffa avatar
jp flag
Note that a partition table of a certain disk is loaded into the kermel and changing the partition table on the disk might not be reflected until next reboot or you have to refresh it manually .,, So, keep this in mind as well before attempting any fix … Refreshing the kernels copy of that disks partition table might be all you need, so try this first
Zatigem avatar
ru flag
@Raffa `dd` doesn’t even check if there is enough space on the destination. Should be totally avoided in 2023 :)
osirisgothra avatar
mx flag
If you stopped soon enough, the changes might not have taken effect. Did you turn off the PC at this point or just stop and keep it running at that point? If you do try to recover the partition, it will be helpful if you have ANOTHER (larger) drive to run from while doing diagnostics. If you don't it may be tricky. If the data is really super-important I would consult a professional data recovery firm, as that is what they do day in and day out, and would know best how to proceed. Though this route could be more expensive than just doing it yourself.
Raffa avatar
jp flag
@Zatigem In case of a non-existent/non-functional partition table/data structure, it would be much safer imaging a disk with a low level tool like `dd` overlooking partitions, volumes, data structures and data while truly writing an exact disk image to file … Other tools have their "optimized" ways of copying disks/partitions that are not necessarily useful in such cases of data recovery … See for example https://askubuntu.com/a/1479247 … I haven’t looked into the source code of the Gnome disks utility’s disk imaging tool though to know for sure, but the odds it does some optimizations too.
Score:3
ru flag

1) Get the path of your drive

First, open GParted or Disks and fetch the device path of your HDD (see the screenshot below): dev sda

Here the HDD is at /dev/sda.

2) Backup your data if possible

It is highly recommanded to create an image of your HDD before attempting any rescue.

To create an image, use Disks. Select your HDD at /dev/sda then click on the 3 vertical dots (disk options) and "Create a disk image…".

3) Use Test Disk to recover your lost partitions

Install Test Disk with:

sudo apt install testdisk

Then run it for your drive with /dev/sda, the path you fetched on the first step:

sudo testdisk /dev/sda
  1. You’ll have to confirm the media, press ENTER on [Proceed] for /dev/sda,
  2. Then choose the right partition table type. In your case it’s [EFI GPT]. and ENTER,
  3. Choose [ Analyse ] and ENTER.
  4. ENTER on [Quick Search].
  5. Now Test Disk is showing your lost partitions. Press ENTER to continue
  6. If you have found all your lost partitions, and ENTER on [ Write ]. If you haven’t found them, try a [Deeper Search].
  7. Confirm with Y and ENTER on [Ok]
  8. Reboot or unplug and plug your drive A

Hurray, all your partitions are back !

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.