How to Resize Your APFS Container on macOS High Sierra

2 minute read
| Deep Dive

If you’re running one of the macOS High Sierra betas and have tried to resize your APFS container without success, I’ve got the answer for you. You can’t currently do this from Disk Utility, so it requires some Terminal geekery. Of course, if you haven’t already migrated over to APFS, you might want to look into that first, with the help of John Martellaro.

resize your apfs partition

You’ve moved over to APFS under the High Sierra beta, and want to resize that partition, so here’s what you need to do (Image Credit: Pagefact)

Finding Where Your APFS Partition Lives

I’m confident that by the time High Sierra ships in the fall, this will be possible within the graphical Disk Utility. It’s a pretty common requirement, so Cupertino is bound to incorporate it more easily into the final version of macOS 10.13 High Sierra. For now, though, the Terminal is our friend.

To do this, you’ll need to open Terminal from Applications -> Utilities. Once there, issue this command to find out where your APFS container lives:

diskutil list

My output looks like the image below. Note that my APFS container is named /dev/disk1, and resides at /dev/disk0s2.

Locate, then resize your APFS container

Locating your APFS container prior to resizing it

Resizd Your APFS Container (the Hard Way)

Let’s talk about shrinking the APFS partition, or container, first. You use the same command for both processes, but you might be likely to want to reduce the size of your APFS partition first, perhaps to install another operating system on your Mac. To shrink my 1TB APFS container to 750GB, I’d issue the following command in Terminal:

sudo diskutil apfs resizeContainer disk0s2 750g jhfs+ Extra 250g

That command would resize the APFS container from 1TB to 750GB, also creating a 250GB journaled HFS+ partition with the freed space. We need to use sudo here, to take administrative privileges over the Terminal session.

I could have also issued the command like this, and diskutil would automatically determine the size for my new partition:

sudo diskutil apfs resizeContainer disk0s2 750g jhfs+ Media 0b

The output of the command will look something like this:

Resize your APFS container from Terminal

Resize you APFS container from Terminal

I could also create multiple partitions, using a command like this:

sudo diskutil apfs resizeContainer disk0s2 750g jhfs+ Media 200g FAT32 Windows 50g

Note that in my case, I could replace disk0s2 with disk1 for either command, since my APFS container is located at disk1. The diskutil command automatically locates the physical store for my APFS container, and resizes things accordingly.

Shrinking Your APFS Partition to Reclaim Space

If you decide you want to reclaim that space into your APFS container, you can do that using diskutil as well. First, though, you have to delete the JHFS+ or other partition and set it as free space on your hard drive. This command will do the trick, assuming your volume is named disk0s3.

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

Next, resize your APFS container:

diskutil apfs resizeContainer disk0s2 0

In this case, diskutil automatically claims all available free space on the physical storage device, but you can also replace 0 with a size value.

Yes, You Can Resize Your APFS Container on a Live Filesystem

Before you ask, yes, I’ve verified this process works even when you’re booted into High Sierra on that APFS volume. You will notice that your Mac becomes unresponsive for a time, as it verifies the filesystem, checks everything out, and then carries out the resize operation. For the best file integrity, though, I’d probably recommend doing this from Recovery Mode. I live on the bleeding edge, though, and did this from the live filesystem without any data corruption.

17 Comments Add a comment

  1. Travis Jacob

    When I do the final step to claim free space, I get an error saying the target disk is too small for this operation

    please help

    • Jeff Butts

      Travis,

      Sorry it’s taken me a while to get back to you. This is crucial: in the next to final step, did you try this command:

      sudo diskutil eraseVolume “Free Space” %noformat% /dev/disk0s3

      with curley quotes? If so, try it again, making sure you copy it from this comment, not from above. I just noticed that curly quotes snuck into my code snippet above.

      • polr

        Hi Jeff,

        I’m having the same issue as Travis, using your latest edit wit the non-curly quotes.

        Any idea what might be the issue?

        Thanks!
        Paul

    • Jeff Butts

      polr, I’m not sure what might be causing that, and the fact that the file system is so new means not many folks are posting yet about their exploits with APFS. Shoot me an email at jeffb (at) macobserver (dot) com, and include the output of diskutil list for me. I’ll see what I can make of it.

  2. sebastianginter

    Hi,
    I have a q.
    How to delete partition with APFS.? When i try delete from DiskUtility from Sierra Recovery Partition system tell me “cant umnount a disk” (this is the same disk – I have only one 128gb ssd with 3 partitions – Sierra, APFS High sierra and recovery sierra”. Can’t do this!
    And can’t resize partition APFS. I have only 25gb and can’t resize to 35GB!.
    It’s SAFE ?
    Regards
    Sebastian

  3. Jeff Butts

    Sebastian,

    As I explained in the above article, you can’t yet resize or delete APFS containers from Disk Utility. You have to use diskutil from the Terminal. Check this article and see if it helps. If not, shoot me a message and I’ll see if we can’t sort it out.

  4. Tyler Rheaume

    I am getting the error “Error: -69771: The target disk is too small for this operation” when running the last command. I am positive that I have the command correct and I have the APFS container selected.

  5. Jeff Butts

    To anyone running into the “the target disk is too small” issue, here’s what I believe is happening. APFS is only able to resize itself to space on the disk that exists beyond the last sector of the existing APFS container. If you have deleted a partition that was placed before the beginning of the APFS container, it won’t be accessible to resizing your existing APFS container.

    In such an instance, my recommendation is to make a clone of your APFS drive, using either Carbon Copy Cloner or Super Duper, and then repartitioning the entire drive the way you want it. Start fresh, basically. Then you can copy your clone back onto your drive.

    It’s a pain, but it’s a pain that exists with HFS+ volumes, too. You aren’t supposed to be able to delete the first partition on a drive, and you can’t grow a volume “backwards.” I.e., you can expand from the end of your existing partition towards the last sector on your drive, but you can’t expand from the beginning towards the first sector.

    • Yao Lu

      Hi Jeff,

      Thank you so much for your analysis. And I believe it’s correct. I had this knowledge for HD but the fact that it also applies to SSD didn’t hit me until I read your comment.

      My problem in short: disk0 (non-APFS logical partition) and disk1 (APFS system drive). disk1 ran out of space. No matter how I re-format/erase disk0, I cannot extend disk1 to use that space. Because disk1 is the last partition, and a partition can only extend “forward”.

      Here’s what I did to solve the issue:
      0. Backup data on your logical partition. (In my case it’s non-APFS disk0).
      1. Re-format disk0 to APFS container (using “erase” in Disk Utility app).
      2. Use Carbon Copy Cloner to copy ALL files from disk1 to disk0.
      3. Go to “System Preferences” -> “Startup Disk”. You should be able to see both disk0 and disk1 are selectable startup drives. Previously it’s only disk1. (basically what happened here is we “cloned” the entire OS from disk1 to disk0.
      4. Select disk0 (the cloned OS) as startup drive and restart. Now the entire system runs on disk0.
      5. In Disk Utility app -> Partition, use “-” symbol to delete disk1, and disk0 will automatically expand to eat up the space freed from disk1.

      Thanks again for your advice!

      Note: The above steps are a bit more than simply “extend disk1” since it combined two disks as a result. What we want to achieve is “shift” the last non-expandable APFS partition ahead so that we can get more space “afterwards”. Plus, you can always create new partitions later.

  6. WonderBrad

    Hi Jeff,

    When I try to resize the APFS container and create a new volume, using your first example, I get the error:

    APFS Container Resize error code is 49153
    Error: -69606: A problem occurred while resizing APFS Container structures

    Have you come across this before?

    Thanks,
    Brad

  7. iaboeyad

    Hi Jeff.

    Thank you for the explanation, it is really helpful

    Can I remove disk0s2 and merge it with disk0s4 ?
    disk0s2 was my old OS, now I installs OSX on disk0s4 I want to merge disk0s2 into disk0s4 ? is that possible or it should be in order ?

    Thanks

  8. Akshat

    Hi Jeff,

    I have encountered a peculiar problem. I tried enable writing on my NTFS formatted external drive using Terminal. This is the code I used –
    sudo nano /etc/fstab
    LABEL=NAME none ntfs rw,auto,nobrowse
    Then Ctrl+O, enter and Ctrl+X

    I didn’t succeed in that, contrary my Mac would hang every time I’d click on Finder after a reboot.

    So I decided to follow the article and delete the entry I made in fstab and saving and exiting it.

    After that, I see my disk utility is not listing any disks at all. I can boot the Mac and use all the apps but cannot access any of my files. I checked disk utility on terminal and found this –

    /dev/disk0 (internal, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *251.0 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_APFS Container disk1 170.7 GB disk0s2
    3: Microsoft Basic Data 80.1 GB disk0s3

    /dev/disk1 (synthesized):
    #: TYPE NAME SIZE IDENTIFIER
    0: APFS Container Scheme – +170.7 GB disk1
    Physical Store disk0s2
    1: APFS Volume 110.5 GB disk1s1
    2: APFS Volume 32.3 MB disk1s2
    3: APFS Volume 519.9 MB disk1s3
    4: APFS Volume 2.1 GB disk1s4
    5: APFS Volume 20.5 KB disk1s5

    So you see, the container disk (170 GB) which was earlier Macintosh HD is now just container scheme. Any idea how I can mount it back? I’m hoping all my data will be safely tucked in it somewhere considering both my users and all settings etc are intact.

    I’m using a MacBook Pro Late 2013 running on High Sierra (obv). Please help!

  9. thombamford

    Was getting quite frustrated before I found this article. Thank you for posting! Worked like a charm.

  10. jonny_satts

    Hi Jeff,

    I have been having huge problems even when trying to follow the instructions here and in other APFS related posts. What is unusual for me is that the rogue partition doesn’t appear as an external disk. After erasing it following instructions you gave it converted from APFS and resides now (in disk utility) as: “PCI-Express Internal Physical Volume • Mac OS Extended (Journaled)”. It can be mounted and unmounted but not much else. Here is what I am looking at from the terminal:

    Jons-MacBook-Pro-2:~ jonsatterley$ 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 379.0 GB disk0s2
    3: Apple_HFS Untitled 120.8 GB disk0s3

    /dev/disk1 (synthesized):
    #: TYPE NAME SIZE IDENTIFIER
    0: APFS Container Scheme – +379.0 GB disk1
    Physical Store disk0s2
    1: APFS Volume Macintosh HD 242.1 GB disk1s1
    2: APFS Volume Preboot 21.5 MB disk1s2
    3: APFS Volume Recovery 506.6 MB disk1s3
    4: APFS Volume VM 2.1 GB disk1s4

    I want to kill the 120GB disk0s3 partition (which was originally reserved for a failed boot camp) but every time I try to use the terminal or disk utility I don’t get the result as you explained. I also tried to do a full erase/restore using Time Machine, but the outcome still ended in the 120GB partition surviving. I’d readily start again completely and erase everything, but I don’t know how to get my Mac back to factory conditions as this 120GB partition just won’t go away!

Add a Comment

Log in to comment (TMO, Twitter, Facebook) or Register for a TMO Account