I have found over the years that the Disk Utility app in macOS has become less and less useful to me over the years. My guess has been the dev teams at Apple have trying to cut back on the ability of less informed to do unpleasant things to themselves using the tool.
But with a little effort we find the macOS diskutil
utility. This is also where we begin to see some the FreeBSD heritage in macOS as this is follows the FreeBSD “noun verb” UX for commands where you enter diskutil
followed by a number of verbs that do the work.
Let’s start with the list
verb. Issuing the command:
diskutil list
Gets you a listing of currently mounted disks, partitions, and mount points. This is fun as you get a lot more detail about the internals of how APFS is blatting stuff through your disk. For instance, on my machine I have /dev/disk0
as the physical disk with an APFS container disk in a partition. That logic disk is mounted as /dev/disk3
with the multiple volumes in the container. This is far more detailed information than what you get from the user interface.
The info
verb gets you the details for a specific disk. Again, lots of detail but good for troubleshooting. The umount
and umountDisk
verbs are for un-mounting partitions and disks out of a file system while mount
goes the other way. It’s important to understand that the eject
verb is for removable devices and is the same action as ejecting a drive in Finder.
All of the formatting and partition things you do in the GUI have corresponding verbs in the command-line tool. Do be careful as with great power comes with great responsibility. Think twice and then again before hitting that enter key.
The jobby-job thing that I do to pay the bills requires me to do a bunch of system administration things. So, I’m often needing to “burn” a Linux installer to a USB key. Here we can use a combination of the diskutil
and hdiutil
command-line tools to automate that process.
First, use the list verb to find the mount point for the USB device that’s your target device:
diskutil list
Now we can write a Bash script that will do the heavy lifting for us:
ISONAME=$1
DESTDISK=$2
TMPIMG=“~/tmp/copytarget.img”
hdiutil convert UDRW -o $TMPIMG $DESTDISK
diskutil unmountDisk /dev/$DESTDISK
dd if=$TMPIMG of=/dev/r$(DESTDISK) bs=1m
diskutil eject $DESTDISK
rm $TMPIMG
So, our little script takes two parameters: the filename of the Linux ISO and the base name of the disk mount point. This script first uses hdiutil
to convert the ISO into a macOS disk image. I keep a temp folder in my home folder for these sort of things. We then unmount the external device and use the classic UNIX dd
command to do a byte-by-byte copy to raw version of the mount point. After doing this, you need to eject the device.
And that’s a quick summary of diskutil
.
Selah.