2

SOLVED: My issue is solved. I used recovery mode to erase entire drive and create new APFS disk which was created with correct size. I then used my last Time Machine backup to restore the system. Thanks everyone.


So I got used Macbook Pro 2017 some days ago and it had its 128 GB SSD split into two disk containers each with its own disk. One disk is the main one and it has around 100 GB and the second one contained the remaining space.

I wanted to merge them. After trying unsuccessfuly with the Disk Utility app, I resorted to Terminal and found this answer to do it - https://apple.stackexchange.com/a/310665/256353 Of course I changed the disk identifiers...

However in the last step I got error:

Error: -69519: The target disk is too small for this operation, or a gap is required in your partition map which is missing or too small, which is often caused by an attempt to grow a partition beyond the beginning of another partition or beyond the end of partition map usable space

And now the 20 GB of space is just lost. I cannot see it anywhere. How do I get it back and merge to the main partition?

Below are Disk Utility screenshots

enter image description here

enter image description here

EDIT: I tried Disk Utility in Recovery Mode, but it did not help. I still cannot see the lost 20 GB. I also tried recreating second Container Disk to "undo" my previous changes but got error that there is no "disk" for it.

EDIT 2: Here is the screenshot when I want to partition my drive. 20 GBs is still missing.

enter image description here

EDIT 3: Added more diskutil output

diskutil list disk0

/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         121.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         98.9 GB    disk0s2

diskutil info disk0s1

   Device Identifier:         disk0s1
   Device Node:               /dev/disk0s1
   Whole:                     No
   Part of Whole:             disk0

   Volume Name:               Not applicable (no file system)
   Mounted:                   Not applicable (no file system)
   File System:               None

   Partition Type:            EFI
   OS Can Be Installed:       No
   Media Type:                Generic
   Protocol:                  PCI-Express
   SMART Status:              Not Supported
   Volume UUID:               E783267B-A4C3-3556-B751-DBED770EB996
   Disk / Partition UUID:     753A45C0-573F-458B-B5AE-EFEC09981DDF
   Partition Offset:          24576 Bytes (6 4096-Byte-Device-Blocks)

   Disk Size:                 314.6 MB (314572800 Bytes) (exactly 614400 512-Byte-Units)
   Device Block Size:         4096 Bytes

   Read-Only Media:           No
   Read-Only Volume:          Not applicable (no file system)

   Device Location:           Internal
   Removable Media:           Fixed

   Solid State:               Yes
   Hardware AES Support:      No

diskutil info disk0s2

Device Identifier:         disk0s2
   Device Node:               /dev/disk0s2
   Whole:                     No
   Part of Whole:             disk0

   Volume Name:               Not applicable (no file system)
   Mounted:                   Not applicable (no file system)
   File System:               None

   Partition Type:            Apple_APFS
   OS Can Be Installed:       No
   Media Type:                Generic
   Protocol:                  PCI-Express
   SMART Status:              Not Supported
   Disk / Partition UUID:     4BF4FEBA-0970-4F39-9177-0B3403D83921
   Partition Offset:          22403522560 Bytes (5469610 4096-Byte-Device-Blocks)

   Disk Size:                 98.9 GB (98929283072 Bytes) (exactly 193221256 512-Byte-Units)
   Device Block Size:         4096 Bytes

   Read-Only Media:           No
   Read-Only Volume:          Not applicable (no file system)

   Device Location:           Internal
   Removable Media:           Fixed

   Solid State:               Yes
   Hardware AES Support:      No

diskutil info disk0s3

Could not find disk: disk0s3
  • In you first screenshot, can you click APPLE SSD in the left sidebar, and then click "Partition" in the toolbar, and then take screenshot and post? I recently solved a similar issue, and might be able to help in your case, but I need to see that partition map first. – Gordon Gao Oct 4 '18 at 10:54
  • @GordonGao sure, see edited post. It looks bad to my eyes :-( – Filip Oct 4 '18 at 12:36
  • Enter these four commands and post the output to your question: diskutil list disk0, diskutil info disk0s1, diskutil info disk0s2 and diskutil info disk0s3. Post the output even if you get an error message. This information will tell me where the partitions are located on disk0. Basically, you will be posting the partition map @Gordon Gao asked for. – David Anderson Oct 8 '18 at 23:34
  • @DavidAnderson added the output to the bottom of my question. – Filip Oct 9 '18 at 7:00
  • Did you tried First Aid? – lowselfesteemsucks Oct 9 '18 at 14:42
3
+50

Based on that you are currently having a broken disk, I would strongly recommend stopping trying to mess more around and instead bite the bullet and reinstall MacOS completely. After booting the installation media/recovery partition, start Disk Utility and use it to erase the drive completely, possibly even write a new partition layout and then install telling MacOS to use the whole drive.

If you have anything on it you want to keep, create a backup first (note 1). Time Machine is an obvious candidate as you can either get your home directory back, or you can tell the installer to restore your computer as it was. I did this a lot on my previous Mac after upgrading the harddrive. If you encrypt your backup, you get your passwords back too.

Note 1: I have been burned enough to never fiddle with disk partitions and file systems on machines without proper backup. You can literally lose everything in seconds. Messing with terminal commands is tempting fate :)

  • Looks like I will have to go down this path, however I am scared of erasing the drive completely and then hoping I will manage to restore it to full size. I have external disk connected with Time Machine backups which runs at least a few times a day. Can I somehow "check" if backup is truly working to get back all my files and apps? – Filip Oct 9 '18 at 12:44
  • How can you be scared given what you've done already? – Thorbjørn Ravn Andersen Oct 9 '18 at 13:36
  • You can check your backup by starting Time Machine (from the icon) and restoring an old file to e.g. the desktop. There may also be a validation option but I have not used it. – Thorbjørn Ravn Andersen Oct 9 '18 at 13:37
2

The news is not good. Based on the information posted in your question, I have compiled the following table. All values are in bytes.

     Start             End               Size        Identifier      Type
--------------   ---------------   ---------------   ----------   ----------
        24,576       314,597,375       314,572,800    disk0s1     EFI
   314,597,376    22,403,522,559    22,088,925,184                Free Space
22,403,522,560   121,332,805,631    98,929,283,072    disk0s2     Apple_APFS

This table shows the free space is above the APFS container partition. Currently, there is no way to add this space back to the APFS container partition.

The new Golden Rule: Each drive should at most one APFS container.

The whole point of creating APFS was so users would not have the problem you created. If you need to add a new volume for macOS use, you should add the new volume to the existing APFS container. This rule also applies when you what to install any additional macOS operating systems.

One solution to your problem would be to find some third party software that could move the APFS partition. Unfortunately, these types of utilities will only move partitions that they can identify. So far, I have not found a utility that recognizes APFS container partitions.

Example of How to Add a "Mac OS Extended (Journaled)" Volume

This example differ from your situation in the following ways.

  • I used a disk image file for this example, so I could execute the commands while booted to macOS. You will have to boot to Internet Recovery, a macOS installation flash drive or macOS installed on an external drive.
  • I am working with disk1 and you would be working with disk0. My APFS container is disk2 and your APFS container is disk1.
  • My block size is 512 bytes. Your block size is 4096 bytes.

Below is the example.

Marlin:~ davidanderson$ diskutil list disk1
/dev/disk1 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +122.0 GB   disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                 Apple_APFS Container disk2         99.8 GB    disk1s2
Marlin:~ davidanderson$ gpt -r show /dev/disk1
      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   42968752         
   43378392  194902864      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  238281256          1         
  238281257         32         Sec GPT table
  238281289          1         Sec GPT header
Marlin:~ davidanderson$ diskutil unmountdisk disk1
Unmount of all volumes on disk1 was successful
Marlin:~ davidanderson$ dd if=/dev/zero seek=409640 count=32 bs=512 of=/dev/disk1 
32+0 records in
32+0 records out
16384 bytes transferred in 0.018801 secs (871444 bytes/sec)
Marlin:~ davidanderson$ diskutil unmountdisk disk1
Unmount of all volumes on disk1 was successful
Marlin:~ davidanderson$ gpt remove -i 2 /dev/disk1
/dev/disk1s2 removed
Marlin:~ davidanderson$ gpt add -i 2 -b 409640 -s 42968752 -t hfs /dev/disk1
/dev/disk1s2 added
Marlin:~ davidanderson$ gpt add -i 3 -b 43378392 -s 194902864 -t apfs /dev/disk1 
/dev/disk1s3 added
Marlin:~ davidanderson$ newfs_hfs -J -v "New JHFS+" /dev/disk1s2
Initialized /dev/rdisk1s2 as a 20 GB case-insensitive HFS Plus volume with a 8192k journal
Marlin:~ davidanderson$ diskutil mount disk1s2
Volume New JHFS+ on disk1s2 mounted
Marlin:~ davidanderson$ diskutil mount disk2s1
Volume Disk 1 on disk2s1 mounted
Marlin:~ davidanderson$ diskutil list disk1
/dev/disk1 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +122.0 GB   disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS New JHFS+               22.0 GB    disk1s2
   3:                 Apple_APFS Container disk2         99.8 GB    disk1s3
Marlin:~ davidanderson$ gpt -r show /dev/disk1
      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   42968752      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
   43378392  194902864      3  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  238281256          1         
  238281257         32         Sec GPT table
  238281289          1         Sec GPT header

Basically, I did the following.

  1. Used the diskutil list disk1 and gpt -r show /dev/disk1 commands to get the disk identifiers and partition information. Based on order and size, a mapping between the disk identifiers and the partitions can be determined.
  2. Used the dd if=/dev/zero seek=409640 count=32 bs=512 of=/dev/disk1 command to zero out the beginning of the free space. This is to insure the new partition will not mount until formatted. The value of 32 was chosen arbitrarily.

    Note: The diskutil unmountdisk disk1 command is entered frequently. The command is required before entering many of the commands.

  3. Used the gpt remove -i 2 /dev/disk1 command to remove the second partition. This command removed the APFS partition from the table. The APFS data stored in the partition is unchanged.

  4. Used the gpt add -i 2 -b 409640 -s 42968752 -t hfs /dev/disk1 command to add the new unformatted "Mac OS Extended (Journaled)" partition. This consumed the free space.

  5. Used the gpt add -i 3 -b 43378392 -s 194902864 -t apfs /dev/disk1 /dev/disk1s3 command to restore the partition removed in step 3. The APFS data on this partition is unaltered.

  6. Used the newfs_hfs -J -v "New JHFS+" /dev/disk1s2 command to format the new partition. The new volume was given the arbitrarily picked label of "New JHFS+".

  7. Used the diskutil mount disk1s2 and diskutil mount disk2s1 commands to mount the volumes.

  8. Used the diskutil list disk1 and gpt -r show /dev/disk1 commands to show the results.

  • Damn, that is really not good. It is also impossible to create back the second Disk Container which I had and deleted? At this point I would at least love to have any access to this space, even as a separate drive... – Filip Oct 9 '18 at 12:25
  • @Filip: I did not state that the free space could not be used for a separate drive. I only stated that the free space could not be merged into the existing APFS container. You can use this free space to create a separate "Mac OS Extended (Journaled)", "ExFAT" or "MSDOS (FAT)" volume. If this is an acceptable solution, then you should change your question to reflect this. – David Anderson Oct 9 '18 at 17:24
  • I think I'll bite the bullet and reinstall macOS. Just curious, how would I go about allocating this free space into new volume? Since I also tried it before I posted this question and I couldnt do it. – Filip Oct 10 '18 at 8:53
  • @Filip: I updated my answer with an example. – David Anderson Oct 10 '18 at 10:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .