Yet another corrupted partition table on macOS Mojave

If you suspect disk0s2 is is actually a APFS container, then you change the partition type in the GUID Partition Table (GPT) to APFS. Normally one would first hex dump the beginning of disk0s2 to see if the content matches what is expected for a APFS container. Apparently, the is difficult from Recovery mode. A last resort would be to see if the APFS magic number would be the characters NXSB. This can done by entering the commands given below.

dd if=/dev/disk0s2 count=4 skip=32 bs=1 2>/dev/null; echo

If the partition is a APFS container, then the following be output.

NXSB

Note: Any error messages produced by dd command will not be shown. To display these messages omit 2>/dev/null. Doing so on a APFS container partition would produce an output similar to what is shown below.

NXSB4+0 records in
4+0 records out
4 bytes transferred in 0.020234 secs (198 bytes/sec) 

However, if you look at the dd output already posted to your question, you can see the NXSB characters.

If you can boot Ubuntu, then you could hex dump the first sector of the APFS container partition by entering the command given below.

sudo hexdump -Cv -n 512 /dev/sda2

Changing the partition type from Core Storage to APFS

The easiest way to change a partition type is to use the third party gdisk command. This command can be run from Ubuntu already installed on your Mac.

You can make the partition type change form Ubuntu by using the gdisk command. You will need version 1.0.4 of gdisk. If you have an older version then download and install the updated version from the SourceForge GPT fdisk website. The command to enter is given below.

sudo gdisk /dev/sda

Below is an example of the proper interaction with gdisk.

GPT fdisk (gdisk) version 1.0.4

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

Found valid GPT with protective MBR; using GPT.

Command (? for help): t
Partition number (1-8): 2
Current type is 'Apple Core Storage'
Hex code or GUID (L to show codes, Enter = 8300): af0a
Changed type of partition to 'Apple APFS'

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/sda.
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.

You can also change the partition type from macOS. The different ways to boot are as follows.

  • Boot from an external drive with macOS already installed. Open a Terminal application window to enter the necessary commands.
  • Boot to macOS Recovery over the Internet. Once booted over the Internet, you can open a Terminal window to enter the necessary commands.
  • Use another Mac to create a USB bootable installer for macOS. Once booted to the installer, you can open a Terminal window to enter the necessary commands.
  • Boot the Mac in Target Disk mode and connect to another Mac. In this case, the drive will not be disk0. You will need to run diskutil list to determine the correct identifier.

The commands to enter are shown below.

sudo diskutil unmountdisk disk0
sudo gpt remove -i 2
sudo diskutil unmountdisk disk0
sudo gpt add -i 2 -b 409640 -s 725609832 -t 7C3457EF-0000-11AA-AA11-00306543ECAC /dev/disk0

Note: Most of gpt commands require the drive to be unmounted. Since macOS likes to auto mount partitions, you may need to enter the command diskutil unmountdisk disk0 before entering each gpt command.