APFS Partitions corrupted

apfsbootcampdisk-utilityhard drivepartition

I recently ran Boot Camp Assistant to remove the Windows partition from my 2017 MacBook Pro, but during the partitioning step I quit Boot Camp Assistant. After restarting the computer the next time, I got a flashing drive icon and macOS was no longer booting.

My only option at this point was Internet recovery. I tried running Disk Utility, unfortunately First Aid seems to be unable to fix the problem:

Disk Utility Screenshot

Looks like the APFS Container got corrupted.

diskutil apfs list

|
+-- Container ERROR -69808
|   ======================
|   APFS Container Reference:     disk1
|   Size (Capacity Ceiling):      ERROR -69620
|   Capacity In Use By Volumes:   ERROR -69620
|   Capacity Not Allocated:       ERROR -69620
|   |
|   +-< Physical Store disk0s2 2881B334-866B-4DC7-98F9-2DB0B583B353
|   |   -----------------------------------------------------------
|   |   APFS Physical Store Disk:   disk0s2
|   |   Size:                       451000901632 B (451.0 GB)
|   |
|   +-> No Volumes

Next, I tried diskutil repairVolume on the APFS Volume, but again, no luck:

diskutil repairVolume disk0s2
Started file system repair on disk0s2
Repairing storage system
Performing fsck_apfs -y -x /dev/disk0s2
warning: nx_block_count is 122061322, while device block count is 110107642
error: object (oid 0x1): o_cksum (0x50eca9de0b97f54e) is invalid for object
Checking the container superblock
Storage system check exit code is 8
Error: -69716: Storage system verify or repair failed
Underlying error: 8

GPT partitions:

Password:
     start       size  index  contents
         0          1         PMBR
         1          1         Pri GPT header
         2          4         Pri GPT table
         6      76800      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     76806  110107642      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
 110184448   11953680         
 122138128          4         Sec GPT table
 122138132          1         Sec GPT header

Also, recovery tools like iBoysoft do see the APFS volumes and all the files after I provide the encryption password, so the volumes seems to be OK:

iBoysoft sees the APFS volumes

Is there any way I can re-build the partitions/APFS container so the disk will boot again? Any help would be much appreciated. Thanks!

Note: currently I am running a fresh install of Catalina on an external HDD.

Best Answer

Your best option is to use any recovery tools possible to mount the Volumes and get the files off the disk. If macOS Recovery can access it, then go to Disk Utility and simply make a disk image or something so that you have all your files. Then, remove the APFS Container Disk, and erase Apple SSD AP0512J... making sure that there is nothing left. Then, reinstall macOS from the reinstall macOS option in Recovery. This will allow your Mac to boot normally and you can later restore the files that you were able to previously recover.