MacOS – How to fix the corrupted APFS container

apfsdisk-utilityhigh sierramacosssd

I'm using MBP late 11 running 10.13.2 on Samsung Evo 850 250GB internally.

Everything was fine for months but few days ago something horrible occurred. I'm so shocked and urgently need your help.

Finder wasn't responding and I had to restart it by force. But it didn't boot again and just showed a black screen. Tried several times without success which finally I had to install another High Sierra on my 2nd drive (a healthy HDD)

Here's few shots which convince me that the APFS container is damaged (SSD=disk0):

Disk0s2 – part1

Disk0s2 – part2

Container

Weird thing called Synthesized

Diskutil list

Diskutil apfs list

Diskutil repairDisk/repairVloume

Here's few notes which probably help you know where the error lies:

Note1: Used a third party app and it found 4 partitions including VM , Recovery , macSSD , Preboot. Tried to recover data from macSSD partition and fortunately almost all important data was intact and almost all files were healthy and readable/playable. That's why I think it may just be a corruption of the APFS container.

4 lost partitions found by a recovery app

Note2: diskutil verifyVolume disk2

MacBook-Pro:~ rainyhighsierra$ diskutil verifyVolume disk2
Started file system verification on disk2
Verifying storage system
Performing fsck_apfs -n -x /dev/disk0s2
Checking volume
Checking the container superblock
error: object (oid 0x1): o_cksum (0x7f23daf6f220955d) is invalid for object
warning: checkpoint 247 fsck_obj_phys failed
error: object (oid 0x107): o_cksum (0xe096dd51deca9041) is invalid for object
warning: checkpoint 262 fsck_obj_phys failed
error: object (oid 0x10b): o_cksum (0x661d289dd9202cbd) is invalid for object
warning: checkpoint 266 fsck_obj_phys failed
Checking the EFI jumpstart record
error: (oid 0x2aac6) nrl: invalid o_cksum (0x8eaa1aec711175bb)
error: verification/reading of the nx_reaper object failed
The volume /dev/disk0s2 could not be verified completely
Storage system check exit code is 0
Finished file system verification on disk2

Note3: Trying to add an empty volume SAM to synthesized container (disk2) to see what may happen

MacBook-Pro:~ rainyhighsierra$ diskutil ap addVolume disk2 apfs SAM
Exporting new APFS Volume "SAM" from APFS Container Reference disk2
Started APFS operation on disk2
Preparing to add APFS Volume to APFS Container disk2
Error: -69620: Unable to get capacity info for an APFS Container or APFS Volume
MacBook-Pro:~ rainyhighsierra$

Note4: GPT strucure of disk0

MacBook-Pro:~ rainyhighsierra$ sudo gpt show /dev/disk0
Password:
      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6      
         40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     409640  487987488      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  488397128          7      
  488397135         32         Sec GPT table
  488397167          1         Sec GPT header
MacBook-Pro:~ rainyhighsierra$

Note5: I had ~3-5 GB free space on the SSD at the time of crashing


Please help me repair the disk and take back the OS. The drive looks like healthy and repairable.

Best Answer

Your GPT Structure looks ok but just to be sure, there are a few things you can do. However, before proceeding, back up all of your data (time machine works well). Then proceed to

  1. Download Gdisk for mac
  2. Install the package
  3. Open up your terminal application
  4. enter the command sudo gdisk /dev/disk0
  5. Enter your administrator password
  6. A message will appear. If something is broken it should auto-repair itself and look something like this

    GPT fdisk (gdisk) version 1.0.3

    Warning: Devices opened with shared
    lock will not have their partition table automatically reloaded! The
    protective MBR's 0xEE partition is oversized! Auto-repairing.
    
  7. Press x, hit enter

  8. Press p, hit enter

  9. Press o, hit enter

  10. Press q

  11. Copy and paste the results in your answer.

  12. Close terminal

  13. Go to the App store

  14. Download Mac OS High Sierra

  15. Get a USB stick

  16. Go to https://support.apple.com/en-us/HT201372 and follow the instructions on the site.

  17. Restart your mac with your newly created bootable USB of High Sierra (or corresponding OS)plugged in, while holding down the 'Alt' key.

  18. A boot screen will appear.

  19. Select the option "Install Mac OS High Sierra"

  20. Once in your installation screen, go to the "Utilities" menu and select "Disk Utility"

  21. Click on your hard drive and hit the "First Aid" button. Then use the first aid button/tool on each of it's partitions/containters.

  22. Exit Disk Utility. Reboot. Check if things are fixed. If not, continue with instructions....

  23. Reboot with USB inserted again, and go back to "Install Mac OS High Sierra".

  24. Once in the install screen, click the "Install Mac OS"

  25. !IMPORTANT! - DO NOT FORMAT THE HARD DRIVE OR ITS PARTITIONS.

  26. At the "Select the disk in which to install" screen, select your disk, but DO NOT FORMAT. Then hit the "Install" button.

  27. Wait for the installer to finish.

  28. Reboot.

  29. Check and see if things are working. They should be. Done.