macOS – How to Format External HFS Disk Without ESP

disk-utilitydiskutilmacos

When formatting an external disk larger than 2GB, OS X automatically creates an EFI System Partition (ESP). For compatibility with other devices, I want to format a large disk with only one partition, and no ESP. How can I do this in OS X Yosemite?

diskutil eraseDisk HFS+ 002 disk2

I found this Technical Note describing Apple's partitioning policy, but it doesn't say how to avoid creating the ESP.

Edit: Forgot to mention I need to use GUID partition map for compatibility, not MBR.

Best Answer

You can repartition the disk with gpt and format the partition with newfs_hfs:

Open Terminal.app and to get an overview enter:

diskutil list

Get the partition table of the disk in question (below I assume the disk to partition is disk2):

sudo gpt -r show disk2

Destroy the GUID partition table and create a new one:

diskutil umountDisk disk2
sudo gpt destroy disk2
sudo gpt create disk2

If the disk previously was formatted as a FAT volume, a new GUID partition table can't be created because the PMBR turns into an MBR (which blocks the GPT creation) and you have to overwrite it first:

diskutil umountDisk disk2
sudo gpt destroy disk2
diskutil umountDisk disk2
sudo dd if=/dev/zero of=/dev/disk2 count=1
sudo gpt create disk2

Get the new partition table:

sudo gpt -r show disk2

Now create a new partition with gpt. Depending on the block size of your disk you may have to align the partition. Disks with a block size of 512 Bytes have to be aligned. On disks with a block size of 4096 Bytes you can use the first free block (block nr. 6) and the size of the free space.

Example (a 2.2 TB disk with a block size of 512 Bytes):

       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34  4292870077         
  4292870111          32         Sec GPT table
  4292870143           1         Sec GPT header

Do the math and align your volume to 4k blocks. This means: the start block and the size is divisible through 8 (and has to fit in 4292870071 blocks in my example because the lowest recommended start block is 40). Create a new partition:

sudo gpt add -i 1 -b 40 -s 4292870064 -t 48465300-0000-11AA-AA11-00306543ECAC disk2

with i: index position (usually 1 for the first partition); b: start block; s: size in blocks and t: type of partition (here HFS+ = 48465300-0000-11AA-AA11-00306543ECAC).

Example (a 6.0 TB disk with a block size of 4096 Bytes):

      start       size  index  contents
          0          1         PMBR
          1          1         Pri GPT header
          2          4         Pri GPT table
          6  976746229       
  976746235          4         Sec GPT table
  976746239          1         Sec GPT header

sudo gpt add -i 1 -b 6 -s 976746229 -t 48465300-0000-11AA-AA11-00306543ECAC disk2

Format the partition with newfs_hfs (-v name: name the volume; -J: journaled):

 sudo newfs_hfs -v test -J /dev/rdisk2s1

The volume will be mounted automatically. Else enter diskutil mount disk2s1.


Be warned: checking the disk with Disk Utility will yield:

Problems were found with the partition map which might prevent booting...

and with diskutil verifyDisk disk2

Started partition map verification on disk2
Checking prerequisites
Checking the partition list
Problems were found with the partition map which might prevent booting
Error: -69770: Partition map check failed because no slices were found