7

I'm attempting to resize a partition that's too small for my needs. Here's the output from diskutil list:

~> 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         400.0 GB   disk0s2
3:                 Apple_APFS Container disk2         100.0 GB   disk0s3

/dev/disk1 (synthesized):
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      APFS Container Scheme -                      +400.0 GB   disk1
                                Physical Store disk0s2
1:                APFS Volume Macintosh HD            234.4 GB   disk1s1
2:                APFS Volume Preboot                 23.6 MB    disk1s2
3:                APFS Volume Recovery                518.1 MB   disk1s3
4:                APFS Volume VM                      6.4 GB     disk1s4

/dev/disk2 (synthesized):
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      APFS Container Scheme -                      +100.0 GB   disk2
                                Physical Store disk0s3
1:                APFS Volume Mojave Beta             90.2 GB    disk2s1
2:                APFS Volume Preboot                 46.3 MB    disk2s2
3:                APFS Volume Recovery                512.3 MB   disk2s3
4:                APFS Volume VM                      3.2 GB     disk2s4

I looked at this MacObserver post and I tried this:

    sudo diskutil apfs resizeContainer disk0s3 150G

I also took a peek at this post, too re: diskutil documention.

Console output is as follows:

Started APFS operation Aligning grow delta to 49,999,994,880 bytes and targeting a new physical store size of 149,999,996,928 bytes Determined the maximum size for the targeted physical store of this APFS Container to be 100,000,002,048 bytes 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

I know I've got 50 gigs laying around on the other drive, but how do I reclaim from the Macintosh HD and give it to the Mojave Beta drive? Thank you for reading. I welcome your suggestions.

Update

Just for S's and G's, I tried making the big drive smaller and see what happens.

Current status:

Shrinking APFS Physical Store disk0s2 from 399,963,168,768 to 349,999,996,928 bytes
Shrinking APFS data structures
[ - 0%..10%..20%..30%..40%............................... ] 45.0%

Me right now

Update 2

I didn't blow up my hard drive, but it didn't work...well, it sorta worked...here's what diskutil list looks like right now after that attempt:

 ~> 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         350.0 GB   disk0s2
   3:                 Apple_APFS Container disk2         100.0 GB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +350.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            234.4 GB   disk1s1
   2:                APFS Volume Preboot                 23.6 MB    disk1s2
   3:                APFS Volume Recovery                518.1 MB   disk1s3
   4:                APFS Volume VM                      6.4 GB     disk1s4

/dev/disk2 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +100.0 GB   disk2
                                 Physical Store disk0s3
   1:                APFS Volume Mojave Beta             90.3 GB    disk2s1
   2:                APFS Volume Preboot                 46.3 MB    disk2s2
   3:                APFS Volume Recovery                512.3 MB   disk2s3
   4:                APFS Volume VM                      3.2 GB     disk2s4

So shrinking the big one and then attempting to make the little partition bigger. No ****ing idea where the other 50 gigs went, but it's in there somewhere. I looked at Disk Utility app and it shows a 350GB partition, a 100GB partition, and 50GB of free space.

If Apple monitors this, please make it simpler to resize partitions. This is a huge PITA and it shouldn't be.

6

Apple does not provide a way to do what you want to do. There are third party tools that can move a partition, but last time I checked, they will not work with APFS container partitions.

Partitions are stored on a drive contiguously. This means you can not just add any free space to a partition. The free space must exist directly below the partition. Let my show you an example similar to your situation.

First is the output from the command diskutil list disk1. The drive below is a a sparse disk image. I created the image to help illustrate my answer. The image is partitioned fairly close to your disk0.

Marlin:driveinfo davidanderson$ diskutil list disk1
/dev/disk1 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +500.3 GB   disk1
   1:                        EFI EFI                     314.6 MB   disk1s1
   2:                 Apple_APFS Container disk3         400.0 GB   disk1s2
   3:                 Apple_APFS Container disk4         100.0 GB   disk1s3

Here is the output from sudo gpt -r show /dev/disk1. This command shows the values store in the GUID Partition Table (GPT). In this case, the units are blocks of 512 bytes.

Marlin:driveinfo 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     614448      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     614488  781250000      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  781864488  195283952      3  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  977148440          5         
  977148445         32         Sec GPT table
  977148477          1         Sec GPT header

Since disk0 is your boot drive, you can not use the gpt command without a sudo and System Integrity Protection (SIP) disabled. An alternative to the gpt command is a third party tool called driveinfo. If you use this tool, you will not need to disable SIP or use a sudo. Below is the output from this command. Here, the units are in bytes.

Marlin:driveinfo davidanderson$ ./driveinfo -rd disk1
  Code       Size             Type       Identifier  Mounted  Name
  ----  ---------------  --------------  ----------  -------  ----
                    512  PMBR                                     
                    512  Pri GPT header                           
                 16,384  Pri GPT table                            
                  3,072  Free Space                               
            314,597,376  EFI              disk1s1      No     EFI 
        400,000,000,000  Apple_APFS       disk1s2      No         
         99,985,383,424  Apple_APFS       disk1s3      No         
                  2,560  Free Space                               
                 16,384  Sec GPT table                            
                    512  Sec GPT header                           

Next, I will enter the command below to create 50 GB of free space. This is similar to what you did.

sudo diskutil apfs resizeContainer disk0s2 350G

The results are shown below.

Marlin:driveinfo davidanderson$ diskutil list disk1
/dev/disk1 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +500.3 GB   disk1
   1:                        EFI EFI                     314.6 MB   disk1s1
   2:                 Apple_APFS Container disk3         350.0 GB   disk1s2
   3:                 Apple_APFS Container disk4         100.0 GB   disk1s3

Marlin:driveinfo davidanderson$ sudo gpt -r show disk1
      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2         32         Pri GPT table
         34          6         
         40     614448      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
     614488  683593744      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  684208232   97656256         
  781864488  195283952      3  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  977148440          5         
  977148445         32         Sec GPT table
  977148477          1         Sec GPT header

Marlin:driveinfo davidanderson$ ./driveinfo -rd disk1
  Code       Size             Type       Identifier  Mounted  Name
  ----  ---------------  --------------  ----------  -------  ----
                    512  PMBR                                     
                    512  Pri GPT header                           
                 16,384  Pri GPT table                            
                  3,072  Free Space                               
            314,597,376  EFI              disk1s1      No     EFI 
        349,999,996,928  Apple_APFS       disk1s2      No         
         50,000,003,072  Free Space                               
         99,985,383,424  Apple_APFS       disk1s3      No         
                  2,560  Free Space                               
                 16,384  Sec GPT table                            
                    512  Sec GPT header                

The 50 GB of free space was created immediately after disk1s2. In order to add this free space to disk1s3, the space would have to occur immediately after disk1s3.

So, to add the 50 GB of free space to disk0s3 you would have to first move this partition up by 50 GB. I do not believe there currently exists software which can move a APFS container. Therefore, you can not move space from one APFS container to another APFS container.

Alternative solutions could include:

  • Clone the contents disk0s3 to disk0s2. See Geoff Nixon's answer for one such way to clone the contents.
  • Install a fresh copy of Mojave in disk0s2, then use the Migration Assistant application to copy important data from disk0s3. I should warn you that I have no knowledge if the Migration Assistant will work with two APFS container partitions on the same drive.
  • Backup disk0s3 to another drive by using Time Machine or some other means. You could then try restoring to disk0s2

Implementing any of the above solutions would allow you to remove disk0s3 and resize disk0s2 to contain the space originally occupied by both partitions.

Appendix

Often a user needs to know the partitioning of a drive. In particular, were the free space is. The diskutil list disk0 command shows the partitions in ascending order and the size of each partition. However, this command does not show free space. The Disk Utility application does occasionally show free space but the value is often incorrect and does not show where the free space is with respect to the other partitions

So, where is the free space shown? Here are a few ways to determine where the free space is.

  1. The sudo gpt -r show /dev/disk0 command will show the logical sector blocks used by each partition. The command will also show the free space between each partition in logical sector block units. In the days of OS X, you could run this command on the boot drives. Starting with macOS, System Integrity Protection (SIP) has to be disabled to do this.
  2. Use the diskutil info -plist disk0s# command to retrieve partition number # start and size byte values. You need to repeat the command for each partition on a drive. Next, you can compile a table similar to the output from the gpt -r show /dev/disk0 command. Basically, free space is any space not allocated to a partition, the Protected Master Boot Record (PMBR) and the GUID Partition Tables (GPT).
  3. Write a BASH script that would automate way number 2. A free script can be downloaded from this site. Assuming your downloads goto to the default Downloads folder, you can get the free space by entering the command shown below. Note: You do not need to enter sudo or disable SIP.

    ~/Downloads/driveinfo-1.0.1/driveinfo -r disk0
    

A Note about using APFS container partitions

It is not normal to have two APFS container partitions on the same drive. Doing so, defeats one of the principle reasons for the creation of the APFS. If you need two different APFS volumes, the you should create each volume in the same APFS container partition. This is also true, if you want to have two or more different versions of High Sierra and/or Mojave installed.

When you want remove a APFS volume, then the free space is automatically returned to the APFS container. You should not need to enter a sudo diskutil apfs resizeContainer disk0s# 0 command. If you delete a volume containing a version of macOS, then there is some additional clean up that needs to be preformed. The necessary clean up steps are outlined in the accepted answer to the question: Remove macOS from a APFS container?

  • Thank you for such a detailed explanation. I was hoping to take my small drive from 100G to 150G by utilizing 50G that are now free. The command you gave resizes the 350G disk to 400G. I tried sudo diskutil apfs resizeContainer disk0s3 0, but it says not enough space. I think I'm going to nuke the whole drive and start over if I can't figure out this evening :) – Adrian Dec 15 '18 at 1:07
  • @Adrian: I edited my question in an effort to better explain why your approach is not working. – David Anderson Dec 15 '18 at 20:24
5
+50

I'm not following much of the prior discussion. It looks like you have plenty enough space to consolidate.

  1. Get back your 50G on the first physical partition.
    diskutil ap resizeContainer disk0s2 0

  2. Restore the logical partition you want to keep from the second APFS container to an additional logical partition on the first container.
    asr restore --source /dev/disk2s1 --target /dev/disk1.

    This may take some time if it needs to defragment. (If this gives you some trouble (during inversion), you may need to nuke (diskutil ap deleteVolume) the Preboot, VM, and Recovery partitions on the second container. I assume that's ok by you, and I haven't actually seen that be an issue for some time.)

  3. Mount your new "Mojave Beta" logical partition, the one now on the first container. Make sure it looks right.

  4. Get rid of the second APFS container:
    diskutil ap deleteContainer disk0s3; then remove the physical partition entirely: diskutil eraseVolume free free disk0s3.

  5. And finally, reclaim the remainder of the disk on the first (only) APFS Container once more:
    diskutil ap resizeContainer disk0s2 0.

No? Am I missing something?

  • Would Mojave Beta still be bootable? – David Anderson Dec 21 '18 at 10:56
  • 1
    It should be, though you may need to use systemsetup -setstartupdisk to switch volume "roles" (It might be hit-and-miss with changing the startup disk via System Preferences). See eclecticlight.co/2018/08/30/… – Geoff Nixon Dec 21 '18 at 12:54
0

FYI, you have to specify the container (in your case "disk2", so command should be:

For example to increase the size of the Mojave Beta disk (disk2):

sudo diskutil apfs resizeContainer disk2 150G

Not sure if you have to shrink another volume or not.

Also your Time Capsule settings should be validated to insure you don't have too much history (to limit space).

You must log in to answer this question.

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