APFS partition inaccessible

Solution 1:

Well, nobody answered, but I was able to recover my APFS volume. It is important to mention that you have to have knowledge of your partition layout for successful restore. Hybrid MBR spans the entire volume and when I removed the incorrectly positioned volume the Hybrid MBR shrinked down to that point not leaving additional space and I got the error:

gpt add: /dev/disk3: error: no space available on device

I was able to fix it using:

sudo gdisk /dev/disk6
Password:
GPT fdisk (gdisk) version 1.0.5

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

Found valid GPT with hybrid MBR; using GPT.

Command (? for help): p
Disk /dev/disk6: 1000215216 sectors, 476.9 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): DF8BA5A4-2A3A-4A1B-9F1F-AA6A6332D9A5
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 1000215182
Partitions will be aligned on 8-sector boundaries
Total free space is 999805549 sectors (476.7 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       707245575   337.0 GiB   FFFF  CATALINA

Command (? for help): x

Expert command (? for help): n

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/disk6.
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.

That converted from Hybrid to Protective MBR (regular GPT). But still APFS did not have the correct code:

sudo gdisk /dev/disk6
GPT fdisk (gdisk) version 1.0.5

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

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/disk6: 1000215216 sectors, 476.9 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): DF8BA5A4-2A3A-4A1B-9F1F-AA6A6332D9A5
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 1000215182
Partitions will be aligned on 8-sector boundaries
Total free space is 999805549 sectors (476.7 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       707245575   337.0 GiB   FFFF  CATALINA

So then I was able to issue:

sudo gpt add -i 2 -b 409640 -s 707245575 -t apfs /dev/disk6
/dev/disk6s2 added

sudo gdisk /dev/disk6                                          
GPT fdisk (gdisk) version 1.0.5

Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/disk6: 1000215216 sectors, 476.9 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): DF8BA5A4-2A3A-4A1B-9F1F-AA6A6332D9A5
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 1000215182
Partitions will be aligned on 8-sector boundaries
Total free space is 292559974 sectors (139.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640       707655214   337.2 GiB   AF0A  CATALINA

Now the APFS restored the correct code AF0A and it reappeared in the disk utility and I could browse my files again.