Installing Ubuntu on Mac with macOS Mojave

bootcampdisk-utilitymojavepartition

I tried to follow steps in the article Installing Ubuntu on Mac with macOS and Windows already installed.

But I have a different file system. And cannot resize with diskutil.

diskutil resizevolume disk0s2 200G 3 jhfs+ part1 4G jhfs+ part2 200M jhfs+ part3 200M
disk0s2 is an APFS Physical Store (use "diskutil apfs resizeContainer" instead to resize)

diskutil list disk0

/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         500.0 GB   disk0s2
sudo gpt -r show /dev/disk0 (disabled sip to get it works)
Password:
      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  122061322      2  GPT part - 7C3457EF-0000-11AA-AA11-00306543ECAC
  122138128          4         Sec GPT table
  122138132          1         Sec GPT header
sudo fdisk /dev/disk0
Password:
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    

diskutil apfs list

APFS Container (1 found)
|
+-- Container disk1 DF585E03-85EB-401C-8AAD-AFA0E08F6596
    ====================================================
    APFS Container Reference:     disk1
    Size (Capacity Ceiling):      499963174912 B (500.0 GB)
    Capacity In Use By Volumes:   189015490560 B (189.0 GB) (37.8% used)
    Capacity Not Allocated:       310947684352 B (310.9 GB) (62.2% free)
    |
    +-< Physical Store disk0s2 39E55C09-2343-4DC5-9AAE-8C0C004FE3F2
    |   -----------------------------------------------------------
    |   APFS Physical Store Disk:   disk0s2
    |   Size:                       499963174912 B (500.0 GB)
    |
    +-> Volume disk1s1 2769E4ED-BC35-43BA-8CC2-463B819B0CB4
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s1 (No specific role)
    |   Name:                      Macintosh HD (Case-insensitive)
    |   Mount Point:               /
    |   Capacity Consumed:         185070796800 B (185.1 GB)
    |   FileVault:                 No (Encrypted at rest)
    |
    +-> Volume disk1s2 78FAA400-3A62-412F-BF61-8EFF61614B50
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s2 (Preboot)
    |   Name:                      Preboot (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         44171264 B (44.2 MB)
    |   FileVault:                 No
    |
    +-> Volume disk1s3 30EB14BA-3B54-4B28-B6CA-566945971020
    |   ---------------------------------------------------
    |   APFS Volume Disk (Role):   disk1s3 (Recovery)
    |   Name:                      Recovery (Case-insensitive)
    |   Mount Point:               Not Mounted
    |   Capacity Consumed:         517799936 B (517.8 MB)
    |   FileVault:                 No
    |
    +-> Volume disk1s4 9392BB6E-1464-4687-BEDF-6E10BFC637ED
        ---------------------------------------------------
        APFS Volume Disk (Role):   disk1s4 (VM)
        Name:                      VM (Case-insensitive)
        Mount Point:               /private/var/vm
        Capacity Consumed:         3221245952 B (3.2 GB)
        FileVault:                 No (Encrypted at rest)

Best Answer

NOTE: for this guide I will be using an external USB disk as the target volume, and a copy of Debian 9.8 (as it is the only Linux installer I have on hand). Due to the fact that Ubuntu is based on Debian, the process should be similar enough to apply to both systems.

Due to the way APFS works, the entire capacity of the Container disk is able to be used as needed by any and all Virtual Volumes inside of it. While this comes with the downside that resizing the Container to be smaller will limit available free space for all of its child volumes, it also comes with the upside that fewer partitions have to be resized/moved in order to create a new standard partition.

For the sake of recreating your situation I have connected a 250 GB external disk to my machine, and formatted it with a single APFS Container, which holds a single Virtual Volume. The first step in this proccess is to find the disk identifier of the Container disk. It can be found in the output of the terminal command diskutil apfs list. In my case this was disk4, as can be seen in the screenshot below. According to the output you listed above, your Container disk is disk1.

Container Disk

To resize the Container, first decide how much space you want to dedicate to Linux, then subtract that from the total size of the Container disk as listed under Size (Capacity Ceiling). In this example I will be dedicating 1/3rd (84 GB) of my external disk to Debian. Once you have the new total size for your Container disk figured out, run the command diskutil apfs resizeContainer disk4 166G, substituting disk4 and 166G for your Container disk identifier and desired macOS partition size.

You will now have the difference in free space on your disk. It is important to note that this free space will not show up in Disk Utility (or diskutil), but it will still be available to the partition manager in the Debian installer, which is where we'll do the remainder of our partitioning from.

Free Space not visible

Now, either burn your installer image to a CD-R/CD-RW/DVD-R/DVD-RW (which I recommend), or write your installer to a USB disk by formatting it as GUID Partition Map and MS-DOS file system, then running the command sudo dd if=/path/to/installer.iso of=/dev/diskX bs=1M (where diskX is the disk number of your USB drive).

Reboot, and hold down the Option key at the chime/beep, and choose to boot from your Linux installer. Continue through the setup process until you reach the Partition Disks step, and choose the Manual option.

Select Manual Mode

As previously mentioned, you'll find that the free space created is available here, and is listed under a partition with no file system, or volume label, according to Linux (this is your APFS Container disk).

Free Space

Choose the Free Space partition and click Continue, select the option Create A New Partition in the following menu, and at the prompt set the size to its current value minus the amount of RAM you have installed in your machine. You will need that extra few gigabytes to create a swap partition in a moment. When it asks you where in the free space you want the partition to be created, choose Beginning.

Set the name to whatever you want, in this example I chose Main Disk.

Choose what filesystem you want the partition to use (viable options are EXT3, EXT4, BTRFS, JFS, and XFS. Personally I recommend EXT4).

Choose the mount point for the partition (default and recommended is /).

Choose mount options (recommended to leave as default).

Create a label for the partition (this is what will be displayed in partition editors like GParted).

Click Done setting up the partition.

Done with disk

Now select the free space following the partition you just created, which should be equal to the quantity of RAM in your machine. Once again choose Create a new partition, and this time use the default size. Change the name of the partition to SWAP, and set the filesystem to swap area. Click Done setting up the partition.

Swap done

Your partition list should now contain the following partitions after your unlabelled APFS Container (with names, sizes, and partition numbers adjusted of course).

partitions

After reviewing to make sure everything is correct, click Finish partitioning and write changes to disk. Allow the rest of the installer to proceed. If you get to a page that asks if you want to install the GRUB bootloader, choose No. The Startup Disk selector in System Preferences and the boot menu presented when holding down the Option key should be sufficient to boot into your new Linux installation.

Congrats! You now have a machine that is dual booted with macOS and Linux.