MacOS – How to resolve messed up GPT (FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF) from Ubuntu without data loss

dual-bootefimacosrecoveryunix

I was having Ubuntu installed along with MacOS Catalina. I need windows for project work so I decided to create a partition and flash windows in it… Doing this I messed up and there was showing no option to boot into MacOS.
Right now I can log in into Ubuntu with no problem so is there any way, by which I can boot into MacOS located at disk0s2? Disk0s1 is EFI
I have access to /EFI/EFI from Ubuntu I can see 4 folders there… Apple, Boot, Microsoft, Ubuntu. What should I do?
P.s.: I have a blank partition of 50GB and in external hard disk I have a 5.5GB ISO file of old version of MacOS file.

Edit No.1

derek@derek-MacBookPro:~$ sudo gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 490234752 sectors, 233.8 GiB
Model: APPLE SSD SM0256
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): F3A656EC-6327-4E3B-B8D4-24D7C90F18DD
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 490234718
Partitions will be aligned on 8-sector boundaries
Total free space is 105470093 sectors (50.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       294970071   140.5 GiB   FFFF  MacOSX
   3       400439296       490233855   42.8 GiB    8300

Edit No. 2 result of sudo efibootmgr -v

derek@derek-MacBookPro:~$ sudo efibootmgr -v
BootCurrent: 0000
Timeout: 5 seconds
BootOrder: 0002,0001,0000,0080
Boot0000* ubuntu    HD(1,GPT,ba591477-7a5b-4314-95e2-3ea359d0b28c,0x28,0x64000)/File(\EFI\ubuntu\shimx64.efi)
Boot0001* Linux HD(1,GPT,ba591477-7a5b-4314-95e2-3ea359d0b28c,0x28,0x64000)/File(\EFI\ubuntu\grub.efi)FFFF.0000.0080...............
Boot0002* Linux HD(1,GPT,ba591477-7a5b-4314-95e2-3ea359d0b28c,0x28,0x64000)/File(\EFI\ubuntu\grub.efi)4.1.2.3............
Boot0080*   PciRoot(0x0)/Pci(0x1c,0x4)/Pci(0x0,0x0)/Sata(0,0,0)/HD(1,GPT,ba591477-7a5b-4314-95e2-3ea359d0b28c,0x28,0x64000)/File(\EFI\BOOT\BOOTX64.efi)
BootFFFF*   PciRoot(0x0)/Pci(0x1c,0x4)/Pci(0x0,0x0)/Sata(0,0,0)/HD(1,GPT,ba591477-7a5b-4314-95e2-3ea359d0b28c,0x28,0x64000)/File(\EFI\BOOT\BOOTX64.efi)

Edit No.3 : Output of sudo sgdisk -i 2 /dev/sda

derek@derek-MacBookPro:~$ sudo sgdisk -i 2 /dev/sda
Partition GUID code: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF (Unknown)
Partition unique GUID: 4D99D8DA-F7FF-451F-B9F2-074010EBF442
First sector: 409640 (at 200.0 MiB)
Last sector: 294970071 (at 140.7 GiB)
Partition size: 294560432 sectors (140.5 GiB)
Attribute flags: 0000000000000000
Partition name: 'MacOSX'

Edit No 4: sudo sgdisk -t 2:7C3457EF-0000-11AA-AA11-00306543ECAC /dev/sda

derek@derek-MacBookPro:~$ sudo sgdisk -t 2:7C3457EF-0000-11AA-AA11-00306543ECAC /dev/sda
[sudo] password for derek: 
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

Best Answer

Enter the following command. This will change the MacOS Catalina partition back to an APFS container.

sudo sgdisk -t 2:7C3457EF-0000-11AA-AA11-00306543ECAC /dev/sda

Next, you will need to reboot. Immediately after rebooting, hold down the option key until the Startup Manager appears. Hold down the control key before selecting macOS from the Startup Manager choices.