Partitioning a USB drive on the cli in macOS

Partitioning a USB drive on the cli in macOS

I found myself having difficulty using macOS Disk Utility to accomplish creating 2 partitions on a USB drive. For some reason my Partition button is greyed out.

WARNING: If you follow these instructions you will lose all of the data on the device you specify in the command. Proceed with caution!!!

If you still find the option grayed out remove all partitions through the “Erase” option. This might resolve your issue and allow you to setup partitions.

If this still doesn’t work, you can use the command line executable for disk utility to partition the disk.

First, find the USB device name assigned by macOS:

MacBook-Pro: user$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         500.1 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +500.1 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            447.1 GB   disk1s1
   2:                APFS Volume Preboot                 21.6 MB    disk1s2
   3:                APFS Volume Recovery                509.9 MB   disk1s3
   4:                APFS Volume VM                      7.5 GB     disk1s4

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *15.5 GB    disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:       Microsoft Basic Data PART1                   15.3 GB    disk2s2

You can see here my USB device is showing up as /dev/disk2

Next, open Terminal and key in the following command:

diskutil partitionDisk disk2 2 GPT MS-DOS PART1 4G MS-DOS PERSISTENCE R

Here is what each part of this command means:

  • diskutil is the command
  • partitionDisk means I want to partition a disk
  • partition disk2
  • create 2 partitions, partition type is GPT for (GUID Partition Table)
  • 1st partition is MS-DOS, named PART1, and 4G in size
  • 2nd partition is MS-DOS, named PERSISTENCE, and uses Remaining space

This will create 2 FAT partitions on the disk. The first partition will be 4GB in size and be named PART1. The second partition will also be FAT and will use the remaining free space on the device. After doing this I was able to make adjustments to the device using the Disk Utility user interface. Let me know in the comments if this worked for you too.