MacOS – How to uninstall Linux from a MacBook properly

command linedisk-utilitymacospartitionunix

There are a lot of questions by those who have already bricked their macs trying to remove Linux so their questions usually stem from a position where one of the disk is labelled FFFF-FFFFFFFF-and more F's.
They come from the angle of having already done something wrong.

I'm not in that position, and I'd rather not start by bricking my mac.

Does you have any ideas on how to properly remove Linux from my mac (this includes the hidden FFFF partition)?

Any help explained in a very basic manner would be much appreciated.

diskutil list below

<code>diskutil list</code>

It may also be worth mentioning that in both
/dev/disk0 and /dev/disk1 there are gpt partitions when looked at via recovery mode.

to address the suspicious MBR sector I've used the command

sudo fdisk/dev/disk0

to give an inside look

enter image description here

Best Answer

Evidently, the tricky part is the removal of the Linux partitions (disk0s3 and disk0s4).

The last partition (disk0s4) is the Linux swap partition. The following command can be used to return this partition free space. This should also remove the hybrid partitioning in the Master Boot Record (MBR) Partition Table.

sudo diskutil eraseVolume free none disk0s4

The command below should return the remaining Linux partition (disk0s3) to free space. However, when tested under High Sierra (macOS 10.13.6), this command failed to work properly.

Note: When tested under Catalina (macOS 10.15.2), command below did work properly. However, after participating in discussions posted at this question, I can report the command may still fail under Catalina.

sudo diskutil eraseVolume free none disk0s3

The alternative way to remove this partition is to boot to macOS Recovery and use the command shown below. I would recommend using the command below over the above command. After entering the command below, you can boot back to macOS.

gpt -f remove -i 3 disk0 

The next command returns the free space back to the APFS container (disk0s2).

sudo diskutil apfs resizeContainer disk0s2 0

The next command mounts the EFI volume (disk0s1).

sudo diskutil mount disk0s1

The next command removes the linux boot files from the EFI volume. This will prevent Linux from appearing in the Startup Manager. With some versions of Linux, this folder may not exist.

rm -r /Volumes/EFI/EFI/BOOT

There will be other boot files remaining in the EFI volume. You do not have to remove these files if you do not wish to. The files will be in a folder named after the Linux that was installed. For example, with Ubuntu the command would be as follows.

rm -r /Volumes/EFI/EFI/Ubuntu

The next command unmounts the EFI volume (disk0s1).

sudo diskutil unmount disk0s1