Dual Booting Ubuntu on Mac - UTRA-ART/Caffeine GitHub Wiki

Written by: Erick Mejia Uzeda

Overview

I installed Ubuntu (16, then 18) on my MacBrookPro 2015 twice, first on Mojave and second on Catalina

What follows is a high level overview of what you are trying to accomplish when dual booting Ubuntu on your computer.

Make a Live Ubuntu USB stick

Download an Ubuntu image (.iso) and flash it onto a USB. The USB should be at least 2 GB and will need to be formatted.

Partition your Hard Disk

To allocate memory on your hard disk to install and run Ubuntu, one must partition their hard disk. The risk in this step is rather low, provided you do not go formatting the whole disk or the wrong partition. In general you will be creating 2 partitions, one for the Linux Filesystem (houses the OS and all your data) and the other as SWAP (basically extra RAM but in system memory).

Installing rEFInd

In order to boot into both Ubuntu and Mac once dual booted, we need to install the rEFInd boot manager. This step requires you to boot into Recovery Mode and disable System Integrity Protection (SIP).

You can enable SIP back after, so do not worry too much about disabling it

Installing Ubuntu on the Hard Drive

Here is where you need to be careful not to overwrite your whole disk with the Ubuntu OS and likewise you don't want to overwrite your MacOSX partition with Ubuntu.

If you only overwrite the MacOSX partition, you can retrieve the Mac OS through recovery mode, but your previous data will be lost. At this point it is advisable to have a backup of your computer

In general, when installing Ubuntu (given that you have created a separate partition) you want to select the Something Else option, which then allows you to select which partition you want to install Ubuntu on and as well which partition to use as SWAP. Be careful of which partition you select, there is no undo button!

Generally, the MacOSX partition is the second partition whereas the EFI occupies the first partition. If you created partitions of different sizes, make sure they agree with what you expect before overwriting them!

Post Ubuntu Installation

By default you will directly boot into Ubuntu when you boot your computer and have no option to boot into Mac. Use the efibootmgr command to list then re-order the boot order, so that the rEFInd boot manager is loaded first.

rEFInd will provide you options to boot into all the OS you have installed on your computer

At this point, your Ubuntu installation should be complete. To see the specifics of how to accomplish the above, read through the guides provided below.

Guides

Removing Volumes (Linux from Mac)

To install Ubuntu 18 given that I had Ubuntu 16, I decided to re-install Ubuntu by deleting then creating a new, bigger partition. What follows is the process I had to go through to create this partition

Say we made a new partition and installed Linux on it, hence we have a new Volume (in general 2 volumes, one for Linux swap and the other for the Linux Filesystem). Now we want to remove Linux and give all that space back to our main operating system. On MacOSX we use diskutil:

# These commands were found [here](https://apple.stackexchange.com/questions/334497/cant-delete-linux-partition-with-disk-utility)
$ diskutil eraseVolume free none diskXsY	# erases Volume specified by diskXsY which additionally removes the partition (bc we use “free”)
$ diskutil apfs resizeContainer diskXsY 0	# resizes the container specified by diskXsY via a group-to-fit operation (because of “0” limit)

NOTE: when you erase the Linux volume, it may happen that your Mac Volume’s type changes from Apple_APFS to FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF. Do NOT reboot your Mac (otherwise you won’t be able to boot into MacOSX and would have to use Internet Recovery Mode to fix your problem) and HOPEFULLY you have disabled SIP prior to this. We now fix our partition in our current session by following this answer: https://apple.stackexchange.com/questions/349252/macos-partition-shows-up-as-ffffffff-ffff-ffff-ffff-ffffffffffff-mojave.

# ASSUME: you have disabled SIP in recovery mode prior to this error
# Download gdisk (min required version is 1.0.4)
# Before installing, remove it’s quarantine attribute:
xattr -d com.apple.quarantine ~/Downloads/gdisk-1.0.4.pkg

# Once gdisk is installed, run the following commands
sudo gdisk /dev/disk0	# Assume disk0 is where your MacOSX partition lives 
t
2
w
y

# To then reclaim the freed up space, run:
sudo diskutil apfs disk0s2 0 # Assume disk0s2 is your MacOSX partition

# To re-enable csrutil on your next restart, run:
sudo csrutil clear

NOTE: if you reboot while your MacOSX volume is FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF, then I would refer you to the following resources: