Mount & Unmount Drives from the Command Line in Mac OS X

May 13, 2013 - 12 Comments

Terminal The easiest way to unmount a drive in OS X is to either just drag a volume into the Trash, use the eject keys, disconnect the drive, or use one of the force eject methods. Along the same lines, if you want to remount a drive you can usually just physically unplug the drive and plug it back again. But what if you want to be able to mount, unmount, and remount drives from the command line? That’s exactly what we’ll cover here.

This trick works with external USB disks, hard drives, Firewire, Thunderbolt, DVD’s, CD’s, network drives, even USB thumb drives, literally any volume that can be mounted and accessed through the incredibly helpful diskutil command. By using the command line to remount the drive, the entire process can be completed remotely if necessary through SSH, and without ever having to physically disconnect a drive from the Mac. This is infinitely useful for troubleshooting situations, for scripting and automation, and it’s a great trick for those of us who just like to tinker around in Terminal.

Unmount a Drive from the Command Line

Let’s first cover unmounting drives. To do this you’ll need another volume attached or connected to the Mac in some form or another, then launch Terminal to get started (sits in /Applications/Utilities/).

1: List All Drives

The first thing you’ll need to do is list the connected drives. This will provide a list of all drives that are attached to the Mac, that are either mounted and unmounted, and all of their respective partitions. We are doing this so we can get the drive identifier, which is typically something like disk1s2, or disk2s2, etc

diskutil list

The output will look something like this:

$ diskutil list
0: GUID_partition_scheme *121.3 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 120.5 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
0: GUID_partition_scheme *16.0 GB disk1
1: EFI 209.7 MB disk1s1
2: Apple_HFS OSXDaily 15.7 GB disk1s2

For the sake of this example, we’ll focus on the attached drive named “OSXDaily”, which happens to be an external USB thumb drive that appears last in the list. Note the identifier for that drive is “disk1s2″ and we’ll carry that to the next series of commands to unmount and remount it.

It’s probably worth mentioning that drives will always be located in /dev/ and thus /dev/ will always be prefixed to the identifier.

2: Unmount the Specified Drive

Still using the diskutil command, we’ll point it at the drive in question to unmount.

diskutil unmount /dev/disk1s2

This will report back the named volume and location has been unmounted, like so:

$ diskutil unmount /dev/disk1s2
Volume OSXDaily on disk1s2 unmounted

That’s all there is to it. You’ll notice the drive is no longer accessible in Finder, but it will still be visible through diskutil from the command line, or the more familiar Disk Utility app in OS X’s GUI.

Mount a Drive from the Command Line

If you can unmount a drive, of course you can mount or remount one too. The command sequence is very similar; locate the volume, then mount the drive.

1: Find the Drive to Mount

If you already know where the volume is located, you can ignore part 1 and jump straight to part 2, but let’s cover retrieving the volume identifier anyway. This time around we’ll shorten it a bit because we’ll assume we know the name of the drive to mount, thus we only need to locate the identifier. We’ll do this by using grep to shorten the output of the diskutil command like so:

$ diskutil list |grep OSXDaily
2: Apple_HFS OSXDaily 15.7 GB disk1s2

That output is obviously much shorter than the full output of diskutil list which we showed above.

For this example, the drive “OSXDaily” is still located at /dev/disk1s2 and that’s what we’ll mount.

2: Mount (or Remount) the Drive

To mount (or remount) a drive, we’ll use the same diskutil command with a new flag and inputs like so:

diskutil mount /dev/disk1s2

Using the same examples as elsewhere, here is what the command and the output will look like:

$ diskutil mount /dev/disk1s2
Volume OSXDaily on /dev/disk1s2 mounted

This obviously mounts the drive again, and it will also make the mounted volume visible again in the OS X Finder and to GUI-based apps in the various Open or Save dialog boxes.

Mount and unmount drives from the command line in Mac OS X

Unmount & Remount a Drive / Volume in a Single Command

Want to quickly unmount and remount the same volume, essentially power cycling it’s connectivity to the Mac? You can do that in a single command by stringing the two together like so:

diskutil unmount /dev/disk1s2;diskutil mount /dev/disk1s2;echo "Remounted Volume"

This would look like the following when executed:

$ diskutil unmount /dev/disk1s2;diskutil mount /dev/disk1s2;echo "Remounted Volume"
Volume OSXDaily on disk1s2 unmounted
Volume OSXDaily on /dev/disk1s2 mounted
Remounted Volume

If you happened to be watching the volume in the Finder during this process, you would find it to disappear briefly, then reappear almost immediately. The last echo portion is optional but it makes the entire command action even more verbose.

Thanks to Nilesh for the tip inspiration

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks


» Comments RSS Feed

  1. Bayesrisk says:

    Pretty good help. I need the next step, though.

  2. Nittn says:

    i am getting following reply – need help, thanks

    Volume LaCie on disk2s1 timed out while waiting to unmount

  3. Frank says:

    Thanks! My HD won’t sleep after unmount. To achive that I used diskutil eject /dev/disk1s2 or even diskutileject MyHDsVolumenName

  4. Phillip Lovgren says:

    I’m able to mount my external OWC FW800 drives using Apple’s Disk Utility. It seems to unmount a mount my USB3.0 thumb drive also.

  5. M. Mossman says:

    OMG. This is the best tip I’ve found. I would have died if I lost everything on my external hard drive. You saved my HD many times because of this tip alone. I’ve have people pull out my HD without ejecting it properly…sometimes I do too…and my Adata HD always unmounts itself.
    Thank you thank you thank you.


  6. Garrett Blair says:

    Hi there

    What if the disk fails to mount?

    • volkansal says:

      diskutil unmount /dev/disk1s2;diskutil mount /dev/disk1s2;echo “Remounted Volume”
      Unmount failed for /dev/disk1s2
      Unable to find disk for /dev/disk1s2

      can you help me?

      • ph says:

        Use diskutil list to see where the drive is mounted, its not mounting because it can’t be found, you’re pointing it at the wrong thing.

        • So then says:

          When I do diskutil list, it only comes up with:

          $ diskutil list
          0: GUID_partition_scheme *500.1 GB disk0
          1: EFI EFI 209.7 MB disk0s1
          2: Apple_HFS Macintosh HD 499.2 GB disk0s2
          3: Apple_Boot Recovery HD 650.0 MB disk0s3

          Therefore, I have no idea what to be pointing it at…any ideas?

  7. Jeet says:

    Hi my external HDD is not getting mounted. Its visible in the disk utility but can’t be verified or repaired. I followed the above command line to mount the HDD but it still couldn’t be mounted. this is what the result says:

    0: FDisk_partition_scheme *2.0 TB disk2
    1: Windows_NTFS Yaanus Movies 2.0 TB disk2s1

    $ diskutil unmount /dev/disk2s1
    disk2s1 was already unmounted

    diskutil mount /dev/disk2s1
    Volume on disk2s1 failed to mount


Leave a Reply


Shop for Apple & Mac Deals on

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates