MacOS – Unable to boot Mac OS and disk utility unable to repair disk after bootcamp delete win10

bootbootcampdata-recoverydisk-utilitymacos

simillary to the someone else problem described here: Unable to boot Mac OS and disk utility unable to repair disk after bootcamp delete windows partition
The laptop is: MacBook Pro 15” i9 2019
Last used system: macOS Big Sur
Problem: I’m not able to repair and run Mac OS. On startup there is a folder icon with the question mark. I was able to enter the recovery mode but there is no startup disk that can be found.
Here are the steps that I executed:

  1. In the Recovery mode (Don’t know why but was shown the recovery mode for macOS Mojave but I’ve updated it to macOS Big Sur more than 1 month ago) I’ve ran the repairVolume commnad for disk1 in terminal but waited for 16h to complete but didn’t so I’ve started to look for different solutions. The error says allways: and didn’t stop, just running over and over.
 Checking the container superblock,
error: nx_block_count is 122061322, while device block count is 103759765
  1. I decided to go step by step in this problem:
    But the commands and responses looked like this
[-bash-3.2# gpt remove -i 2 disk0
disk0s2 removed
[-bash-3.2# gpt -f add -i 2 -b 409640 -s 976695384 -t apfs disk0
gpt add: /dev/disk0: error: no space available on device

  1. As the previous error says that device block count is 103759765 and I cound’t use 976696384 so I’ve replaced it to 103759765 and ran again
gpt -f add -i 2 -b 409640 -s 103759765 -t apfs disk0

This time it works and response was that disk0 added

  1. Restarted the mac but still the same error (folder icon with question mark). But from this time when I’m opening Recovery panel (command + option + R) It’s shown as macOS Big Sur.

  2. In disk utility I don’t have First Aid option anymore and the disk0s2 is displayed as Not Mounted. When I click to Mount icon the error is shown:
    enter image description here

  3. output of diskutil list:
    enter image description here

  4. output of diskutil list /dev/disk0:
    enter image description here

  5. output of gpt -v -r show /dev/disk0:
    enter image description here

  6. output of fdisk /dev/disk0:
    enter image description here

  7. output of diskutil apfs list:
    enter image description here
    It seems that here might be the problem, but I don’t know how to fix it. *Previously before step 2 it shows simillary to this:

|
+-- 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 F31C2BCB-9CEA-4449-9CAD-4893BBF532A5
|   |   -----------------------------------------------------------
|   |   APFS Physical Store Disk:   disk0s2
|   |   Size:                       372000141312 B (372.0 GB)
|   |
|   +-> No Volumes
  1. output of diskutil info /dev/disk0:
    enter image description here

  2. output of fsck_apfs -y /dev/disk0s2
    enter image description here

I will be obligated if anyone can help with adding APFS container and running the system again!

Best Answer

You were close. The correct commands are given below.

gpt remove -i 2 disk0
gpt -f add -i 2 -b 76806 -s 122061322 -t apfs disk0

The question you gave as a link had a drive with a 512 byte sector size. Your drive has a 4096 byte sector size. The means your APFS container partition starts at sector 76806 instead of the value you choose of 409640. You can see this in the image you posted in step 8. Here you posted the output from the command gpt -v -r show /dev/disk0. In a typical macOS installation, there would be no free space between the two partitions.

Generally, running any application or command from a older version of macOS to repair a drive containing a newer version of macOS is not a good idea. On my 2018 Mac mini, I have Mojave and Big Sur installed in the same APFS container. When I run diskutil verifyVolume disk0s2 using Mojave and again using Big Sur, I get different results. Mojave incorrectly finds errors and Big Sur does not. Using Mojave to try repairing an APFS container with Big Sur installed could more damage than good. In your case, I do not know if any of your attempts at repair damaged the contents of the drive.