How to mount disk by UUID or LABEL in OS X El Capitan?
I get the UUID and label of a disk from diskutil info disk0s4
diskutil info disk0s4
Device Identifier: disk0s4
Device Node: /dev/disk0s4
Whole: No
Part of Whole: disk0
Device / Media Name: Untitled
Volume Name: Data
Mounted: No
File System Personality: HFS+
Type (Bundle): hfs
Name (User Visible): Mac OS Extended
Journal: Unknown (not mounted)
Owners: Disabled
Partition Type: Apple_HFS
OS Can Be Installed: No
Media Type: Generic
Protocol: PCI
SMART Status: Verified
Volume UUID: F8C88B2D-5412-343B-8969-254F3AC559B8
Disk / Partition UUID: 1738336E-68DD-46B1-997E-57469CF0472D
Total Size: 338.0 GB (337984569344 Bytes) (exactly 660126112 512-Byte-Units)
Volume Free Space: 0 B (0 Bytes) (exactly 0 512-Byte-Units)
Device Block Size: 512 Bytes
Read-Only Media: No
Read-Only Volume: Not applicable (not mounted)
Device Location: Internal
Removable Media: No
Solid State: Yes
mount
using the volume label does not work:
$ sudo mount -t hfs LABEL=Data /Users/user/test
GetMasterBlock: Error 2 opening LABEL=Data
GetMasterBlock: Error 2 opening LABEL=Data
mount_hfs: error on mount(): error = -1.
mount_hfs: No such file or directory
mount
using the volume UUID does not work with or without quotes:
$ sudo mount -t hfs uuid=F8C88B2D-5412-343B-8969-254F3AC559B8 /Users/user/test
GetMasterBlock: Error 2 opening uuid=F8C88B2D-5412-343B-8969-254F3AC559B8
GetMasterBlock: Error 2 opening uuid=F8C88B2D-5412-343B-8969-254F3AC559B8
mount_hfs: error on mount(): error = -1.
mount_hfs: No such file or directory
$ sudo mount -t hfs UUID="F8C88B2D-5412-343B-8969-254F3AC559B8" /Users/user/test
GetMasterBlock: Error 2 opening UUID=F8C88B2D-5412-343B-8969-254F3AC559B8
GetMasterBlock: Error 2 opening UUID=F8C88B2D-5412-343B-8969-254F3AC559B8
mount_hfs: error on mount(): error = -1.
mount_hfs: No such file or directory
mount
using the volume identifier works
mymac:~ user$ sudo mount -t hfs /dev/disk0s4 /Users/user/test
Update:
My goal is to put the mount
line in /etc/fstab
as I want to mount a volume to a custom mountpoint.
When using OS X, it's usually more advisable to use diskutil
for disk-related activities.
TL;DR:
To mount a volume/disk by identifier:
diskutil mount /dev/diskXsY # mounts just that volume
diskutil mountDisk /dev/diskX # mounts the whole disk
To mount a volume by UUID:
diskutil mount [Volume/Partition UUID]
To mount a volume by label:
diskutil mount [label]
Explanation
With diskutil
, node identifiers (/dev/diskXsY
) are interchangeable with UUIDs: in any diskutil
operation (such as eject
), a UUID can be specified instead of a node identifier. From the man page:
DEVICES
A device parameter to any of the above commands (except where explicitly required otherwise) can usually be any of the following:
o The disk identifier (see below). Any entry of the form of disk*, e.g. disk1s9.
o The device node entry containing the disk identifier. Any entry of the form of /dev/disk*, e.g. /dev/disk2.
o The volume mount point. Any entry of the form of /Volumes/*, e.g. /Volumes/Untitled. In most cases, a "custom" mount point e.g. /your/custom/mountpoint/here is also accepted.
o The URL form of any of the volume mount point forms described above. E.g. file:///Volumes/Untitled or file:///.
o A UUID. Any entry of the form of e.g. 11111111-2222-3333-4444-555555555555. The UUID can be a "media" UUID which IOKit places in an IOMedia node as derived from e.g. a GPT map's partition UUID, or it can be an AppleRAID (or CoreStorage) set (LV) or member (PV) UUID.
From
man diskutil
, section 'Devices'.
Obtaining these identifiers/UUIDs/labels are simple, with either of the following commands:
diskutil list # lists all connected volumes and their identifiers
diskutil info /dev/diskXsY | grep UUID # gets the UUID of a connected volume
The returned values from these commands should look something like the following:
$ 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_HFS Macintosh SSD 499.4 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
$ diskutil info /dev/diskXsY | grep UUID
Volume UUID: 1F340CD7-G071-4218-98DG-2D08G89CC57C
Disk / Partition UUID: 76E7G531-G6C3-5E37-C11B-BCEEC67D12G4
As shown above, the identifier can be found from the IDENTIFIER
column, the label from the NAME
column, and the UUID from either UUID
field (either UUID will mount the volume).
By label:
$ diskutil mount Recovery\ HD
Volume Recovery HD on Recovery HD mounted
By UUID:
$ diskutil mount 67EG87EB-CB01-4ED9-082D-303F63CF6394
Volume Recovery HD on 67EG87EB-CB01-4ED9-082D-303F63CF6394 mounted
By disk identifier:
$ diskutil mount /dev/disk0s3
Volume Recovery HD on /dev/disk0s3 mounted
addition for edit to OP's question: mounting to a custom path
You can do this with diskutil mount
and the -mountPoint
option. From the man page:
mount [readOnly] [-mountPoint path] device
Mount a single volume. If readOnly is specified, then the file system is mounted read-only, even if the volume's underlying file system and/or device and/or media supports writing; even the super-user may not write to it; this is the same as the rdonly option to mount (8). If a -mountPoint is specified, then that path, rather than the standard path of /Volumes/VolumeName, will be used as the view into the volume file con- tent; a directory at that path must already exist.
From
man diskutil
, section 'Verbs'.
The syntax to mount to a custom mountpoint is as follows:
diskutil mount -mountPoint /path/to/custom/mountpoint [volume (identifier/UUID/label)]
Bear in mind that /path/to/custom/mountpoint
must be a directory, just like with mount
, and that your identifier/UUID/label are specific to the volume (i.e. /dev/diskXsY
not /dev/diskX
). Mounting to a custom mountpoint cannot be done with diskutil mountDisk
, and only works with a single volume at a time.
Here is what I've been using to mount an external SSD into my Music folder that contains my iTunes media files automatically whenever I log in. You didn't say exactly what the purpose of the external mount is so some of these bits might not be what you need but then again, it might be exactly what you are trying to do.
As mentioned in your question and in @perhapsmaybeharry's answer, the mount
command doesn't support UUIDs so diskutil
is the recommended utility. However, the fstab
file does support UUIDs so you can store the mount parameters in fstab
then diskutil
will read the parameters from fstab
to mount your drive.
- In
~/Music/iTunes/
, create a folder to be used for the mountpoint. I usedSSD_Music
. -
Use
sudo vifs
to edit thefstab
file, add the following as a single line (editing for the UUID and USERNAME as appropriate) then save/exit.UUID=F8C88B2D-5412-343B-8969-254F3AC559B8 /Users/USERNAME/Music/iTunes/SSD_Music hfs rw,noauto,noowners,nobrowse 0 0
- noauto = don't mount the drive during boot. I've encountered times where the drive was mounted as root instead of as me so it is better to wait until you log in.
- noowners = Ignore ownership on the volume. Permissions will be inherited from the mountpoint. If I didn't use this, the mounted volume was owned by root but subdirectories were owned by me.
- nobrowse = Don't show the disk in the Finder sidebar or Desktop.
- Perform the mount with
diskutil mount F8C88B2D-5412-343B-8969-254F3AC559B8
(Note: Do not include theUUID=
prefix in this command. - Hopefully it mounted without errors. Check it with
mount
which should show something like/dev/disk2s2 on /Users/USERNAME/Music/iTunes/SSD_Music (hfs, local, nodev, nosuid, journaled, noowners, nobrowse)
- If you are doing this for iTunes, you need to create an alias for the
iTunes Media
folder to point to the folder on the mounted disk.- Quit iTunes if it is running
cd ~/Music/iTunes/
mv 'iTunes Media' 'iTunes Media-bak'
ln -s 'SSD_Music/iTunes Media' 'iTunes Media'
-
ditto 'iTunes Media-bak' 'iTunes Media'
to copy your media to the new drive. Skip this if you have already copied it over.
- Unmount the disk with
diskutil unmount ~/Music/iTunes/SSD_Music
Now that you can mount the drive by UUID, let's automate it when you log in.
- In
~/Library/LaunchAgents/
, create a new file calledlocal.mount_SSD_Music.plist
-
Copy/Paste the following XML into the new file then save/exit.
<?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> <key>Disabled</key> <false/> <key>KeepAlive</key> <false/> <key>Label</key> <string>local.mount_SSD_Music</string> <key>ProcessType</key> <string>Background</string> <key>ProgramArguments</key> <array> <string>/usr/sbin/diskutil</string> <string>mount</string> <string>F8C88B2D-5412-343B-8969-254F3AC559B8</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Make sure the drive is unmounted
- Test the mounting using the new LaunchAgent plist with
launchctl load ~/Library/LaunchAgents/local.mount_SSD_Music.plist
. Hopefully it mounted without errors again.
So now if you reboot, the external drive will be automatically mounted when you log in.
Hope this helps!