How to remove a partition with terminal?

So basically I partitioned my HDD on my MacBook Pro so that I could install Linux and dual boot. But I realized I don't really need Linux anymore but it doesn't appear on my regular disk utilities, only my one MacBook HDD does.

I type diskutil list in my terminal and this shows up

/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         121.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:          Apple_CoreStorage Macintosh HD            91.0 GB    disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:                        EFI                         29.3 GB    disk0s4

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           +90.6 GB    disk1
                                 Logical Volume on disk0s2
                                 B0DF20B2-B674-46B3-B337-57F6A89A500F
                                 Unlocked Encrypted

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *248.4 GB   disk2
   1:        Apple_partition_map                         32.3 KB    disk2s1
   2:                  Apple_HFS 256 GB                  248.3 GB   disk2s3

I'm basically trying to remove 4 under disk0. Any help would be appreciated.


Solution 1:

The command

sudo  diskutil  eraseVolume  jhfs+  MyVolume  disk0s4

should make the partition visible in the Disk Utility application. This command will erase the contents partition 4. You should probably quit the Disk Utility application before entering this command.

Once disk0s4 becomes visible in the Disk Utility application, you can remove the partition and reclaim the space.