Lost space after removing bootcamp

This is a very common question. Once again, the answer is given below.

sudo diskutil apfs resizeContainer disk0s2 0

Unbelievably complex problem solved quite easily by some "magic"

How was the problem created in the first place:

  • My disk whole space 1TB
  • i created 150 GB boot camp windows 10 partition via boot camp assistant
  • i deleted the boot camp partition via the boot camp assistant
  • my disk didnt got back the 150 GB space - LOST??

Solution:

  1. Allocate / Have some free space on the problematic partition where you lost the capacity
  2. create new partition on the problematic partition by disk utility... select problematic disc / partition, "partition" button, "+" button, select a capacity (i have selected 40GB, if you were wondering) and apply or confirm it.
  3. after completion the new partition the system creates the new partition AND (here comes the magic part) the original partition gets the lost space back
  4. simply remove the newly created partition, and you have the old good partition at capacity with the "lost" capacity.

All was done in normally booted macOs, no recovery mode etc was needed, no data lost.

Don't ask me why or how it works, it just did work in my case.