MacOS – Missing HDD space after running diskutil commands

apfshigh sierramacospartition

I was trying to resize my bootcamp partition and add a new partition as exFat to share between the two… I formatted my bootcamp partition, was unable to figure out how to merge it with my main macOS partition… After some searching, I came across : https://www.macobserver.com/tips/deep-dive/resize-your-apfs-container/

I followed the steps I thought I needed… using the command

sudo diskutil eraseVolume "Free Space" %noformat% /dev/disk0s4

for the appropriate disks… So far so good, or so I thought.

I entered the command

diskutil apfs resizeContainer disk0s2 0

But recieved the following:

Started APFS operation Error: -69771: The target disk is too small for
this operation

After running the diskutil list command, I realized that I can't even find the space I erased earlier anywhere… Can someone help me figure out how to reclaim that space? I do have a backup of data on time machine; however, someone else is experiencing a similar issue, and they did a clean install and their space is still missing as well. https://discussions.apple.com/thread/8291525

I'm not one to usually post or ask for help, I tend to search and find solutions out there, but I'm not having any luck. Any help would be greatly appreciated. Any info needed, I'll be happy to provide.

Below is the results of disktil list

/dev/disk0 (internal):
    #:                       TYPE NAME           SIZE       IDENTIFIER
    0:      GUID_partition_scheme                500.3 GB   disk0
    1:                        EFI EFI            314.6 MB   disk0s1   
    2:                 Apple_APFS Container disk1  423.0 GB   disk0s2
    3:                  Apple_HFS XPlatform      15.9 GB    disk0s3
    4:                 Apple_Boot                134.2 MB   disk0s4
    5:       Apple_KernelCoreDump                655.4 MB   disk0s5

/dev/disk1 (synthesized):
    #:                       TYPE NAME       SIZE       IDENTIFIER
    0:      APFS Container Scheme -         +423.0 GB   disk1                                 Physical Store disk0s2
    1:                APFS Volume Macintosh HD  319.3 GB   disk1s1
    2:                APFS Volume Preboot    22.4 MB    disk1s2
    3:               APFS Volume Recovery    509.8 MB   disk1s3
    4:          APFS Volume VM               1.1 GB     disk1s4

 /dev/disk2 (disk image):
    #:                       TYPE NAME        SIZE       IDENTIFIER
    0:                CCCOMA_X64FRE_EN-US... +4.7 GB     disk2

As you can see, I'm missing about 60 gb, which is the amount of space I was attempting to free up.

EDIT:

Results for the fdisk /dev/disk0 command:

Disk: /dev/disk0    geometry: 7602/255/63 [122138133 sectors]
Sector size: 4096 bytes       
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -  122138132] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused 
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused

Results for the gpt -r show /dev/disk0 command:

    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  103270257      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
103347063    3873482      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
107220545      32768      4  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
107253313    2441407 
109694720     160000      5  GPT part - 5361644D-6163-11AA-AA11-00306543ECAC 
109854720   12283408           
122138128          4         Sec GPT table
122138132          1         Sec GPT header

EDIT 2: Ran the commands from macOS Recovery and the results were a bit different, so I thought I'd share that as well.

-bash-3.2# csrutil disable
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
-bash-3.2# fdisk /dev/disk0
Disk: /dev/disk0    geometry: 520/128/63 [4194024 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -    4194023] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
-bash-3.2# gpt -r show /dev/disk0
    start     size  index  contents
        0        1         PMBR
        1        1         Pri GPT header
        2       32         Pri GPT table
       34        6         
       40  3931800      1  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  3931840   262151         
  4193991       32         Sec GPT table
  4194023        1         Sec GPT header

EDIT 3: Original results recreated.

sudo fdisk  /dev/disk0
Disk: /dev/disk0    geometry: 7602/255/63 [122138133 sectors]
Sector size: 4096 bytes
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -  122138132] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      

sudo gpt  -r  show  /dev/disk0
      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  103270257      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  103347063    3873482      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  107220545      32768      4  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  107253313    2441407         
  109694720     160000      5  GPT part - 5361644D-6163-11AA-AA11-00306543ECAC
  109854720   12283408         
  122138128          4         Sec GPT table
  122138132          1         Sec GPT header

EDIT 4:

Results after running sudo diskutil erasevolume free n disk0s5

diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         423.0 GB   disk0s2
   3:                  Apple_HFS XPlatform               15.9 GB    disk0s3
   4:                 Apple_Boot                         134.2 MB   disk0s4

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +423.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            307.6 GB   disk1s1
   2:                APFS Volume Preboot                 22.4 MB    disk1s2
   3:                APFS Volume Recovery                509.8 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4

sudo fdisk  /dev/disk0
Disk: /dev/disk0    geometry: 7602/255/63 [122138133 sectors]
Sector size: 4096 bytes
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -  122138132] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused   

sudo gpt  -r  show  /dev/disk0
      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  103270257      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  103347063    3873482      3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
  107220545      32768      4  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  107253313   14884815         
  122138128          4         Sec GPT table
  122138132          1         Sec GPT header

EDIT 5: Command results once again.

diskutil list
/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         438.9 GB   disk0s2
   3:                 Apple_Boot                         134.2 MB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +438.9 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            307.6 GB   disk1s1
   2:                APFS Volume Preboot                 22.4 MB    disk1s2
   3:                APFS Volume Recovery                509.8 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4

sudo fdisk  /dev/disk0
Disk: /dev/disk0    geometry: 7602/255/63 [122138133 sectors]
Sector size: 4096 bytes
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 -  122138132] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      

sudo gpt  -r  show  /dev/disk0
      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  107143739      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  107220545      32768      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  107253313   14884815         
  122138128          4         Sec GPT table
  122138132          1         Sec GPT header

EDIT 6: Someome kindly pointed out that I had not shared my end goal. Am now looking to have one drive with the full 500gb available and then go from there to establishing a bootcamp partition and then an additional exFat partition that can be shared between the two OS!

EDIT 7: All issues have been resolved!

Best Answer

The folks at Apple seem to be operating under a paradigm where no drive space is ever unallocated. Therefore, when System Integrity Protection (SIP) is enabled, the macOS operating system prevents execution of any utilities or commands which could report the location of lost space on system drives. Your Mac uses a single physical system drive named /dev/disk0.

System drives generally contains two types of partition tables. The first is the Master Boot Record (MBR) table and the second is the GUID Partition Table (GPT). The command fdisk dumps the contents of the MBR table, while the command gpt partially dumps the contents of the GPT. To used these command on a system drive, you need to either disable SIP or execute the commands while booted to macOS Recovery. The commands you need to enter are given below

fdisk  /dev/disk0
gpt  -r  show  /dev/disk0

The gpt commands prints a table of the space occupied by each partition. The table also prints unallocated space. Generally, you need to know which partitions are located before the lost (unallocated) space you wish to recover. Usually, the diskutil command can then used to recovery this space. Although, other commands such as fdisk, gpt and gdisk can also be used.

Note: Generally the identifier produced by disktuil output contains the index for a given partition. This is not alway true. You may need to consider other output from both the diskutil and gpt commands before matching a partition index with an identifier.

If you could post the output from the above commands, then someone (or I) could help with the correct commands to repair your Mac.

Update 1

You can erase the Apple_KernelCoreDump` partition by executing the command given below. The result will a block of free space the the end of your drive. The size of this block will be about 61 GB.

sudo  diskutil  erasevolume  free  n  disk0s5

Beyond this change, I am not sure what to post. I need to know how you want the drive partitioned. So far, you have mentioned partitions for ExFat and Windows. Currently you have Apple_HFS and Apple_Boot partitions. You can not merge the free space back to the APFS container until these partitions are erased. Also, if you are going to reinstall Windows, you probably should state the model/year of your Mac and the version of Windows.

Update 2

The following command will return all free space back to the APFS partition.

sudo  diskutil  erasevolume  free  n  disk0s3
sudo  diskutil  apfs  resizecontainer  disk0s2  0

If the above commands work, are you then going to attempt to install Windows 10 through the use of the Boot Camp Assistant? Other users have reported problems using the Boot Camp Assistant when the internal physical drive has an APFS partition.