Look up a volume by UUID

Pierre Bernard picture Pierre Bernard · Feb 17, 2010 · Viewed 9.8k times · Source

I know the UUID of a volume - as found in Disk Utility.

How can I get additional information on the volume? Most importantly, I want to know its mount point.

Looking at /etc/fstab doesn't do the trick. This does not list the root volume. I would at least need to figure out the UUID of the root volume to verify my known UUID against it.

Answer

Peter Hosey picture Peter Hosey · Feb 17, 2010

You can use diskutil to look up the disk by its UUID, and the -plist option to get the output in a machine-parseable format:

% diskutil info /Volumes/RAM\ Disk | grep -F UUID
   Volume UUID:              EA20BE94-5F3C-3C02-901D-A213B5AB6831

% diskutil info -plist EA20BE94-5F3C-3C02-901D-A213B5AB6831
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <!--snip-->
    <key>MountPoint</key>
    <string>/Volumes/RAM Disk</string>
    <!--snip-->
</dict>
</plist>

You can use NSTask and NSPipe to run diskutil from within your program and capture the output.

Addendum: Not all volumes have UUIDs. My camera has a built-in read-only MS-DOS-formatted volume that has no UUID according to Disk Utility and diskutil. So, make sure your program can handle empty output from the above diskutil info … | grep pipeline.