diskutil is a Mac OS native utility that can be used to modify, verify and repair local disks by manipulating their structure.

Terminologies

A partition is a logical storage unit located on a hard disk. A hard disk can contain a single partition, using all the space it contains, or it can be split into multiple partitions.

To store data on a partition, it needs a filesystem. Once a partition has been formatted, this combination of partition and filesystem is known as a volume.

There are three Partition Schemes you can use:

  • GPT: GUID Partition Table
  • APM: Apple Partition Map
  • MBR: Master Boot Records

Unless you intend to boot a PowerPC-based Mac or Windows PC before Windows 7 32-bit with your hard disk, there’s no reason to select anything other than GPT. Intel Macs only boot from GUID partitions. Linux supports both MBR and GPT.

diskutil - The Tool

The diskutil command provides many of the features of Mac OS X Disk Utility, from verifying and repairing volumes to changing partition information.

diskutil list

Should you have a number of disks and only want to view information about a specific one, you can append the disk identifier to the command:

diskutil list disk2

The first number represents the physical disk identifier. The number following the letter β€œs” represents the partition number. If a disk has three partitions, it would follow this convention:

  • disk2s1
  • disk2s2
  • disk2s3

diskutil info

In addition to list, you can also use info with the corresponding identifier to display even further information, like so:

diskutil info disk2s1

Verifying and repairing volumes

You can verify and repaire the file system data structures of a volume

diskutil verifyVolume /Volumes/{volume name}
diskutil repairVolume /Volumes/{volume name}

Erasing disks

You can either erase a whole disk which will remove any partitions stored upon it, or individual volumes without affecting others.

To erase an entire disk, you’ll need the disk identifier, enter the following, adjusting the disk identifier to suit:

# diskutil eraseDisk {filesystem} {Name to use} /dev/{disk identifier}
diskutil eraseDisk ExFAT TFL /dev/disk2

Utilities

# Display all file system personalities that can be used for
# erasing and partitioning in diskutil.
diskutil listFilesystems

Back up SD Card or USB Storage

diskutil list
 
# Assume the SD card is `/dev/disk2`
sudo dd if=/dev/disk2 of=~/Downloads/R4-revolution-v2.img

Restore Backup Images (NDF/ISO) to SD Card or USB Drive

diskutil list
 
# Assume the device matching the device is `/dev/disk2`
diskutil unmountDisk /dev/disk2
 
# Be careful to make sure you have the right device name, 
# as the below commands are capable of writing over your hard disk.
 
# NDF
sudo dd bs=1m if=~/Downloads/retropie.img of=/dev/rdisk2 conv=sync
 
# ISO
sudo dd bs=4m if=~/Downloads/debian-live-9.2.0-amd64-gnome.iso of=/dev/rdisk2 conv=sync
 
# You can check the progress by sending a SIGINFO signal (press Ctrl+T).
 

Reference - Respberry Pi documentation

Create Bootable Linux USB Stick

  1. Convert ISO

    hdiutil convert /path/to/downloaded.iso -format UDRW -o /path/to/newimage
  2. Unmount USB stick

    diskutil unmountDisk /dev/diskX
  3. Write image to USB stick

    sudo dd if=/path/to/newimage.dmg of=/dev/diskN bs=1m
  4. Check progress with Ctrl + t{.verbatim}