4

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 ?

Zatigem
  • 478
  • Did you happen to keep a copy of the old partition table? Even an image showing where the partition boundaries were? – terdon Aug 12 '23 at 18:03
  • 1
    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 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. – Raffa Aug 12 '23 at 18:36
  • 1
    Probably testdisk is able to recover your partitions. Take a look at the documentation first. – mook765 Aug 12 '23 at 18:53
  • 1
    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 – Raffa Aug 12 '23 at 18:59
  • 1
    @Raffa dd doesn’t even check if there is enough space on the destination. Should be totally avoided in 2023 :) – Zatigem Aug 13 '23 at 18:19
  • 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. – osirisgothra Aug 13 '23 at 21:26
  • @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. – Raffa Aug 14 '23 at 15:29

1 Answers1

3

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 !

Zatigem
  • 478