How to properly remove a Linux partition without messing up your drive? I know this seems like an beginner / dumb question, since an obvious answer would be:


Open Disk Utility
Remove Linux partition


However it seems that it might not be that easy, and that following those steps could actually lead to pretty messed up partition schemes:


Remove Linux partition on Mac. CoreStorage problems
OS volume shows as type &#39;FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF&#39;
Hardrive will not mount after deleting Linux partition. Can’t boot into Mac OS X
Remove Ubuntu and grow Mac partition


I am therefore asking this question in hope for a proper, safe way to remove a Linux partition after a dual boot Mac / Linux, without having to fear going to an hex editor to repair your drive or to use the internet recovery and losing all your data.

I'm running High Sierra 10.13.6 and Ubuntu 18.04, without REFind and no swap partition.

$ diskutil list

/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         180.8 GB   disk0s2
   3:       Microsoft Basic Data                         69.8 GB    disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +180.8 GB   disk1
                             Physical Store disk0s2
   1:                APFS Volume macOS                   69.9 GB    disk1s1
   2:                APFS Volume Preboot                 23.2 MB    disk1s2
   3:                APFS Volume Recovery                515.0 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4
I assume you have Linux installed in the Microsoft Basic Data partition. Although with Ubuntu 18, I would expect a Linux Filesystem partition type.

The command given below will remove the Microsoft Basic Data partition. The created free space will not appear in diskutil list.

sudo diskutil eraseVolume free none disk0s3


The command given below will add the free space to the APFS container partition. This added space will be available to macOS.

sudo diskutil apfs resizeContainer disk0s2 0


I suppose there will still be some Linux code in the hidden EFI partition. The commands below will remove any Linux code that would cause an icon to appear in the Startup Manager.

sudo diskutil mount disk0s1
rm -R /Volumes/EFI/EFI/Boot
sudo disktuil unmount disk0s1