16

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.

  • As you've already found out, the mount command cannot use UUID or LABEL and must use the Disk Identifier, e.g. /dev/disk0s4. Additionally as perhapsmaybeharry pointed out that the OS X method is to use diskutil. To address your update... However fstab can use the UUID or LABEL, just look at the examples in the man page for fstab. In a Terminal type fstab and then right-click on fstab and select Open man Page, then read it in its entirety! :) – user3439894 May 2 '16 at 11:32
  • @user3439894 I tried a line in fstab like this: UUID=<volume_uuid> /mount/point auto, and ran sudo mount -a. The same error happened: ... mount_hfs: No such file or directory – biocyberman May 2 '16 at 12:02
  • The second field, (fs_file), the mount point, has to already exist, does it? – user3439894 May 2 '16 at 12:04
  • Yes, it does exist. – biocyberman May 2 '16 at 12:06
  • I have no problems using fstab, however I always use at least the first four fields. I see your missing the third field, (fs_vfstype), in your comment. Are you omitting it in fstab? You should edit your question and show exactly what you've tried in fstab and which editor you've used. That said, none of my mount points are other then the default /Volumes for which none is set. I'll test once I see your edit and the mount point you're attempting. – user3439894 May 2 '16 at 12:16
16
+25

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.

  • Thanks for the answer, could you check the update section in my question and address it? – biocyberman May 2 '16 at 10:03
  • @biocyberman updated my answer. If it does not address your addition appropriately, please let me know – perhapsmaybeharry May 2 '16 at 10:16
2

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 used SSD_Music.
  • Use sudo vifs to edit the fstab 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 the UUID= 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 called local.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!

0

I'm combining some of my comment into an answer as I believe it address the fstab issue.

As you've already found out, the mount command cannot use UUID or LABEL and must use the Disk Identifier, e.g. /dev/disk0s4. Additionally as perhapsmaybeharry pointed out that the OS X method is to use diskutil. To address your update... However fstab can use the UUID or LABEL, just look at the examples in the man page for fstab. In a Terminal type fstab and then right-click on fstab and select Open man Page. Read it in its entirety! :)

I have no problems using fstab, however I always use at least the first four fields. I see you'er missing the third field, (fs_vfstype), in your comment. Are you omitting it in fstab? You should edit your question and show exactly what you've tried in fstab and which editor you've used.

Try: UUID=1738336E-68DD-46B1-997E-57469CF0472D /mount/point hfs rw,auto where /mount/point is a preexisting directory.

I've tested this on my system using my UUID, it's your UUID in the line I'm suggesting you try above.

Note: It would only mount to the defined mount point if I included the third field, (fs_vfstype), otherwise it mounted in /Volumes even though the second field, (fs_file), existed.

  • I've tested this previously and I got two identical volumes mounted with UUID=... /mount/point hfs rw,auto in El Capitan: 1. /mount/point and 2. /Volumes. – klanomath May 2 '16 at 13:15
  • @klanomath, Not sure what you're trying to say, other then maybe it works as I've said in my answer? Or are you saying it mounts twice no matter what? BTW I'm running OS X 10.8.5. – user3439894 May 2 '16 at 13:24
  • @klanomath, I've edited it, hopefully it's clearer. Now back to your first comment, are you saying that under OS X 10.11 it will mount to a custom mount point but it also mounts a second mount point at the default /Volumes too, with just one line added to fstab? – user3439894 May 2 '16 at 13:32
  • Yes that was my experience. I wrote a similar answer but then I realized that the volume was shown twice: on the Desktop (which is /Volumes) and at the mount point defined in fstab (which was /Users/user/test) – klanomath May 2 '16 at 13:35
  • @klanomath, I never saw your answer, I guess you deleted it before I saw this question. Since I'm running OS X 10.8.5 and do not have an OS X 10.11.x machine to test, there's not much more I can do other then to delete my answer too. – user3439894 May 2 '16 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .