I know of three ways to do what you want, given your current situation:
Method 1: Easy but Risky and Slow
The first method is to use TestDisk, which can scan a disk for filesystem data and generate new partition table entries to match what it finds. This approach is relatively automated, and hence easy; but the tools must scan much of the disk, which can take a while. Worse, TestDisk may be thrown by stray data from old partitions you've deleted, thus producing bad results. Thus, there's a chance that TestDisk will generate a completely wrong partition table; or it might give you a number of choices about what to recover, and you may not be able to decide which is correct.
Although TestDisk can recover partition start and end points, and is likely to set the partition type code correctly, it will not be able to restore the partition's original GUID. This can be important for booting, as noted in the next section.
Note that TestDisk (or some similar tool; it's not the only one in this category) will become your only choice once you shut down or reboot the computer.
Method 2: Harder but Safer and Faster
Because your kernel is still using the old partition table, the data on your partitions can still be retrieved from memory. The question is how to do so, and the answer is to look in the
/sys/block/sda directory tree. That directory should have subdirectories for each partition (
sda2, and so on), and each of these directories has a
start and a
size file with the starting location and size of the partition, in sectors. For instance:
$ cat /sys/block/sda/sda2/start
$ cat /sys/block/sda/sda2/size
This indicates that, on my system,
/dev/sda2 starts at sector 1126440 and is 1536000 sectors in size. You can extract this information and, using
gdisk, re-create the partition table -- or at least, create partitions with the correct sizes. You'll need to use your knowledge of what's in each partition to set their type codes. AFAIK, there's no way to recover GUID values (the same is true of the previous approach). The GUID value of the ESP may be important, since it's likely to be used by the EFI as part of its boot process. You should be able to extract this from the
sudo efibootmgr -v output -- it will be embedded in the string that's part of the
ubuntu line. You can use
gdisk to change this value after you've re-created the ESP -- use the
c option on the experts' menu.
Method 3: Best and Easiest But You Probably Can't Do It
The best and easiest way to do what you want is to restore the partition table from a backup. The
gdisk tool offers a
b option on the main menu to create such a backup. If you'd done so, you could restore the backup with the
l (lowercase "L") option on the recovery & transformation menu.
Restoring a backup in this way will restore all the partition table data to the way it had been when the backup was made. This includes GUID values, partition names, and of course partition sizes. It's conceivable that you've made such a backup but have forgotten it. If so, use it. If not, though, this won't do you any good, except insofar as you now know about this option, and may be motivated to make a backup for use in the future.