FFFFFFFF problem with hybrid partitioned drive, not able to fix with the guide in other topics

Like many other uses who reported the same problem, I tried to install and delete Ubuntu in my 13' mid-2014 MBP, messed up and got FFFFFFFF-FFFF-FFFF-FFFFFFFF partition, tried to follow the solutions in other topics, especially this one OS volume shows as type 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF' [duplicate]

EDIT1: I had macOS Mojave and APFS.

Unfortunately was not able to fix the issue. As I'm a new user and don't have enough reputation, was not able to add comment to that topic, this why I opened this new topic.

diskutil list result before and after I messed up with the partitions(diskutil list result before and after I messed up with the partitions)

I then booted from an external bootable macOS installation disk, follow the instructions in above topic (diskutil list, gpt -r show disk0, diskutil umountDisk disk0, gpt remove -i 2 disk0, but when I tried gpt add -i 2 -b 409600 -s 431203056 -t 7C3457EF-0000-11AA-AA11-00306543ECAC disk0 it showed Resource busyerror).

After rebooting to the macOS installation disk and tried to do everything all over again, got the following results:

-bash-3.2# diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:       Microsoft Basic Data BOOTCAMP                33.8 GB    disk0s3

/dev/disk1 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *16.0 GB    disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS Install macOS Mojave    15.7 GB    disk1s2

/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +2.1 GB     disk2
   1:                  Apple_HFS OS X Base System        2.0 GB     disk2s1

/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +5.2 MB     disk3

/dev/disk4 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk4

/dev/disk5 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk5

/dev/disk6 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk6

/dev/disk7 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk7

/dev/disk8 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk8

/dev/disk9 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk9

/dev/disk10 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +12.6 MB    disk10

/dev/disk11 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +4.2 MB     disk11

/dev/disk12 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +1.0 MB     disk12

/dev/disk13 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk13

/dev/disk14 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk14

/dev/disk15 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk15

/dev/disk16 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +1.0 MB     disk16

/dev/disk17 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +6.3 MB     disk17

/dev/disk18 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +6.3 MB     disk18

/dev/disk19 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk19

/dev/disk20 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk20

-bash-3.2# gpt -r show disk0
gpt show: disk0: Suspicious MBR at sector 0
      start       size  index  contents
          0          1         MBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6         
         40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409640  380859368      2  MBR part 218
  381269008   42970096         
  424239104   65994752      3  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  490233856        863         
  490234719         32         Sec GPT table
  490234751          1         Sec GPT header
-bash-3.2# diskutil umountDisk disk0
Unmount of all volumes on disk0 was successful
-bash-3.2# gpt remove -i 2 disk0
gpt remove: disk0: Suspicious MBR at sector 0
-bash-3.2# gpt add -i 2 -b 409600 -s 431203056 -t 7C3457EF-0000-11AA-AA11-00306543ECAC disk0
gpt add: unable to open device 'disk0': Resource busy
-bash-3.2# diskutil verifyDisk disk0
Started partition map verification on disk0
Checking prerequisites
Checking the partition list
Checking the partition map size
Checking for an EFI system partition
Checking the EFI system partition's size
Checking the EFI system partition's file system
Checking the EFI system partition's folder content
Checking all HFS data partition loader spaces
Checking booter partitions
Checking Core Storage Physical Volume partitions
The partition map appears to be OK
Finished partition map verification on disk0
-bash-3.2# diskutil verifyVolume disk0s2
Unable to find disk for disk0s2
-bash-3.2# dd if=/dev/disk0s2 count=3 | hexdump
-bash: hexdump: command not found
dd: /dev/disk0s2: No such file or directory

The FFFF partition is gone along with the disk0s2, don't know what to do now, please anyone help.

EDIT2: the output followed David Anderson's instruction:

-bash-3.2# gpt -r show /dev/disk0
gpt show: /dev/disk0: Suspicious MBR at sector 0
      start       size  index  contents
          0          1         MBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6         
         40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409640  380859368      2  MBR part 218
  381269008   42970096         
  424239104   65994752      3  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  490233856        863         
  490234719         32         Sec GPT table
  490234751          1         Sec GPT header
-bash-3.2# fdisk /dev/disk0
Disk: /dev/disk0    geometry: 30515/255/63 [490234752 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -     409639] <Unknown ID>
*2: DA 1023 254  63 - 1023 254  63 [    409640 -  380859368] <Unknown ID>
 3: 0C 1023 254  63 - 1023 254  63 [ 424239104 -   65994752] Win95 FAT32L
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
-bash-3.2# fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> setpid 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
*2: DA 1023 254  63 - 1023 254  63 [    409640 -  380859368] <Unknown ID>
Partition id ('0' to disable)  [0 - FF]: [DA] (? for help) 0
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
-bash-3.2# gpt -f add -i 2 -b 409640 -s 380859368 -t apfs disk0
gpt add: disk0: Suspicious MBR at sector 0
disk0s2 added
-bash-3.2# fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> edit 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
Partition id ('0' to disable)  [0 - FF]: [0] (? for help) DA
Do you wish to edit in CHS mode? [n] n
Partition offset [0 - 490234752]: [409640] 409640
Partition size [1 - 489825112]: [489825112] 380859368
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
-bash-3.2# gpt -r show /dev/disk0
gpt show: /dev/disk0: Suspicious MBR at sector 0
      start       size  index  contents
          0          1         MBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6         
         40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409640  380859368      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  381269008   42970096         
  424239104   65994752      3  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  490233856        863         
  490234719         32         Sec GPT table
  490234751          1         Sec GPT header
-bash-3.2# fdisk /dev/disk0
Disk: /dev/disk0    geometry: 30515/255/63 [490234752 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -     409639] <Unknown ID>
 2: DA 1023 254  63 - 1023 254  63 [    409640 -  380859368] <Unknown ID>
 3: 0C 1023 254  63 - 1023 254  63 [ 424239104 -   65994752] Win95 FAT32L
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
-bash-3.2# 

EDIT3: problem solved, was able to boot into macOS, but when I deleted the free space using Disk Utility (it got attached the the main volume, worked as expected), and then did a reboot, got FFFFFFFF again, the output:

-bash-3.2# diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF               217.0 GB   disk0s2
   3:       Microsoft Basic Data BOOTCAMP                33.8 GB    disk0s3

/dev/disk1 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *16.0 GB    disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS Install macOS Mojave    15.7 GB    disk1s2

/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +2.1 GB     disk2
   1:                  Apple_HFS OS X Base System        2.0 GB     disk2s1

/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +5.2 MB     disk3

/dev/disk4 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk4

/dev/disk5 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk5

/dev/disk6 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk6

/dev/disk7 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk7

/dev/disk8 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk8

/dev/disk9 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk9

/dev/disk10 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +12.6 MB    disk10

/dev/disk11 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +4.2 MB     disk11

/dev/disk12 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +1.0 MB     disk12

/dev/disk13 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk13

/dev/disk14 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk14

/dev/disk15 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk15

/dev/disk16 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +1.0 MB     disk16

/dev/disk17 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +6.3 MB     disk17

/dev/disk18 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +6.3 MB     disk18

/dev/disk19 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +524.3 KB   disk19

/dev/disk20 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            untitled               +2.1 MB     disk20

-bash-3.2# gpt -r show disk0
gpt show: disk0: Suspicious MBR at sector 0
      start       size  index  contents
          0          1         MBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6         
         40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409640  423829464      2  GPT part - FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
  424239104   65994752      3  GPT part - EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  490233856        863         
  490234719         32         Sec GPT table
  490234751          1         Sec GPT header
-bash-3.2# 


Below is the procedure to fix the partition containing Mojave.

Reboot to the macOS installation disk. I assume this is a Mojava installation USB flash drive. Next, you need to preform the following steps.

  1. Remove partition 2 from the MBR partition table.
  2. Add partition 2 to the GPT.
  3. Restore partition 2 to the MBR partition table. (This is an undo of step 1.)

Enter the following commands in a Terminal application window.

fdisk -e /dev/disk0
setpid 2
0
quit
y
gpt -f add -i 2 -b 409640 -s 380859368 -t apfs disk0
fdisk -e /dev/disk0
edit 2
DA
n
409640
380859368
quit
y

Below is an example.

$ fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> setpid 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 2: DA   25 127  15 - 1023 254  63 [    409640 -  380859368] <Unknown ID>
Partition id ('0' to disable)  [0 - FF]: [DA] (? for help) 0
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
$ gpt -f add -i 2 -b 409640 -s 380859368 -t apfs disk0
gpt add: disk0: Suspicious MBR at sector 0
disk0s2 added
$ fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> edit 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
Partition id ('0' to disable)  [0 - FF]: [0] (? for help) DA
Do you wish to edit in CHS mode? [n] n
Partition offset [0 - 492187540]: [409640] 409640
Partition size [1 - 491777900]: [491777900] 380859368
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
$ 

Note: Your output will sightly differ from what is shown above.

The command to reclaim the free space is given below.

Note: Since you use the Disk Utility application to resize, you do not need to enter this command.

diskutil apfs resizecontainer disk0s2 0

An example output is shown below.

$ diskutil apfs resizecontainer disk0s2 0
Started APFS operation
Aligning grow delta to 22,000,689,152 bytes and targeting a new physical store size of 217,000,685,568 bytes
Determined the maximum size for the targeted physical store of this APFS Container to be 217,000,685,568 bytes
Resizing APFS Container designated by APFS Container Reference disk3
The specific APFS Physical Store being resized is disk0s2
Verifying storage system
Performing fsck_apfs -n -x /dev/disk0s2
Checking volume
Checking the container superblock
Checking the space manager
Checking the object map
Checking the APFS volume superblock
Checking the object map
Checking the fsroot tree
Checking the snapshot metadata tree
Checking the extent ref tree
Checking the snapshots
Verifying allocated space
The volume /dev/disk0s2 appears to be OK
Storage system check exit code is 0
Growing APFS Physical Store disk0s2 from 194,999,996,416 to 217,000,685,568 bytes
Modifying partition map
Growing APFS data structures
Finished APFS operation
$ 

This command reclaimed the space, but created a error in the GPT. The output from diskutil list disk0 is shown below.

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *252.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF               217.0 GB   disk0s2
   3:       Microsoft Basic Data BOOTCAMP                33.8 GB    disk0s3

To once again fix this problem, enter the following commands.

gpt -f remove -i 2 disk0
fdisk -e /dev/disk0
setpid 2
0
quit
y
gpt -f add -i 2 -b 409640 -s 423829464 -t apfs disk0
fdisk -e /dev/disk0
edit 2
DA
n
409640
423829464
quit
y

Below is an example

$ gpt -f remove -i 2 disk0
gpt remove: disk0: Suspicious MBR at sector 0
disk0s2 removed
$ fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> setpid 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 2: DA 1023 254  63 - 1023 254  63 [    409640 -  423829464] <Unknown ID>
Partition id ('0' to disable)  [0 - FF]: [DA] (? for help) 0
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
$ gpt -f add -i 2 -b 409640 -s 423829464 -t apfs disk0
gpt add: disk0: Suspicious MBR at sector 0
disk0s2 added
$ fdisk -e /dev/disk0
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> edit 2
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
Partition id ('0' to disable)  [0 - FF]: [0] (? for help) DA
Do you wish to edit in CHS mode? [n] n
Partition offset [0 - 492187540]: [409640] 409640
Partition size [1 - 491777900]: [491777900] 423829464
fdisk:*1> quit
Writing current MBR to disk.
Device could not be accessed exclusively.
A reboot will be needed for changes to take effect. OK? [n] y
$ 

Which is the same as before, except for the removal of partition 2 from the GPT and the size change to 423829464 sectors.