The Disk Utility application provides a nice graphical user interface for completing common management functions for internal and external hard drives. It has its shortfalls, however, and is not the most efficient tool on MacOS for carrying out HDD and SSD operations. For the most powerful and streamlined software to process these operations, look no further than Terminal.app. This article will discuss a few basic functions to get you on your way to more effective disk management.
The command “man diskutil” will provide you with an excellent segue into utilizing these functions, as it will cause Terminal to display the manual related to the functionality of diskutil. Remember, if you are interested in learning about other command line tools, “man” is always a great place to start. Once you have acclimated yourself with some of the available flags shown in the manual, press “Q” to return to the CLI.
In order to work on a drive, you’ll first want to identify the disk and/or volume you intend to modify. For the purposes of this post, we will leave out volumes and just focus on the disk. Typing “diskutil” followed by the flag “list” will bring up all drives detected by your system. You will note in the output below that a synthesized disk is recognized because the drive is formatted with the APFS format.
Adding a drive will cause the output below. Note the USB drive present, indicated by the /dev/disk2 identifier, is formatted to FAT32 with the drive called “EMPTY”
This brings us to the “eraseDisk” flag. eraseDisk is used to, you guessed it, erase a disk. In order to complete this function, you must first indicate that you wish to operate within diskutil, then enter eraseDisk, followed by the desired format, what the disk should be called, and finally the identifier. Let’s say we want to format the disk to Mac OS Extended Journaled, which is notated by “JHFS+” and “CTCI” is what we’ll call it. REMEMBER, you should always run “diskutil list” to ensure you are completing the desired operation on the desired disk as this is virtually irreversible.
Completed, your disk is now ready to use:
As you can see from the screenshots above, this USB drive has only 1GB of storage, so the time saved is negligible. Where the real time savings and power come in with larger drives, stubborn drives that will not mount or unmount, or testing drive health. Here are some additional commands to help in some of these situations:
diskutil unmountDisk <diskID>
diskutil mountDisk <diskID>
diskutil eject <diskID>
sudo diskutil unmount force <diskID> Note: “sudo” requires an administrator password
diskutil verifyDisk <diskID>
diskutil verifyVolume <VolumeID> Note: in the example above “CTCI” is the VolumeID
Be sure you only type commands into Terminal that you fully understand to ensure you do not achieve undesired results and, as a rule of thumb, always type “exit” to properly end your session prior to closing Terminal.app. If you need some help, or need to perform different diskutil functions in the command line, CTCI is here and happy to help.