Oops, you just accidentally deleted a whole partition on your Linux or Windows server! What do you do?
Well, the very first thing you should do is take down as much information as you can about the partitions very quickly as a reference and shut the server down immediately. The likelihood of success in recovering the partition is directly linked to reducing the amount of data written to the disk where the partition was.
While many guides use old and trusty tools like test disk, these are very manual. Assume you know your GPT from your BIOS mode and your MBR from your disk geometry. Many people do not know this and will struggle to understand many of the terms used when using the command line alone to make a recovery.
Luckily there is a well-established tool available built right into the GParted suite, which will scan your entire physical disk for lost/deleted partitions and recover them in place and put them right back where they were when used together with the test disk. You can download the latest GParted ISO from here: https://gparted.org
Step 1
Boot your server using the GParted iso via the IPMI (raise a support ticket for IPMI access if you do not have it).
Step 2
Select the correct physical hard disk in the top right-hand corner e.g. /dev/sda or /dev/nvme0n1
Step 3
You will see that the partition is missing. Launch a terminal from the GParted desktop and run the command ‘testdisk’.
Step 4
You will be offered a list of disks, select the same disk as was selected in the GParted GUI interface, then pick the option ‘Analyze’ and then ‘Quick Search’ your partition take should be found then choose the ‘Write’ option.
Step 5
Go back to the GParted UI, and from the GParted menu on the top left, click ‘Refresh Devices’. You should now be able to see your old partition back where it was.
Step 6
Suppose this process fails from the ‘Device’ menu in GParted. In that case, you will find the option to ‘Attempt Data Rescue’. This will scan the entire disk for deleted or lost data, you will be able to recover it as long as it has not been overwritten and it was not encrypted.