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

May 13, 2013 - 64 Comments

Terminal in macOS

You can mount and unmount drives, volumes, and disks from the command line of MacOS and Mac OS X.

For many users, the easiest way to unmount a drive in Mac 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.

How to Unmount a Drive from Command Line on Mac

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
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
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
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
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 Mac OS X’s GUI.

How to Mount a Drive from the Command Line on Mac

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 Mac 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

How to Unmount & Remount a Drive / Volume in a Single Command

Terminal 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

.

Related articles:

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

64 Comments

» Comments RSS Feed

  1. Boris says:

    I have OS Monterey 12.1
    I removed all sticks and portable disks. I booted the Mac.
    If I go to /Volumes and key in ls, I get:
    Mydisk Macintosh HD

    How to remove Mydisk?

    Boris

  2. tfkh77 says:

    helpful, thanks..

  3. prix says:

    Thank you so much, saved my day!

  4. Karl says:

    My portable HD crashed my Mac, and when I restarted the Mac, my portable drive wasn’t mounted. I tried shutting down, disconnecting the HD, and restarting but when I plugged the HD back in, disk utility shows it unmounted. Disk repair fails, and when I follow the terminal command above to mount the drive again it gives me the following error:
    ‘Volume on disk4s2 timed out waiting to mount’
    Is there any other steps I can take to mount the drive again?

  5. terminal says:

    You can further simplify the steps with AWK, to grab the ID at the end of the list grep output, i.e.

    diskutil list | grep -i myvol |awk ‘{print $(NF)}’

    will return the mount ID for “myvol”, which could be accessed many ways, such as

    myvol=$(diskutil list | grep -i myvol |awk ‘{print $(NF)}’)
    mount “/dev/$myvol”

    [note i arbitrarily used myvol also as the variable name]

    then when done

    unmount “/dev/$myvol”

  6. Oleg says:

    Thank you for article! Helped!

    • Paul says:

      Apple ‘Superdrive’ could not be recognized by the Catalina OS. I plugged the USB drive into a Windows 7 laptop. Windows found the correct driver and automatically ejected the problem/stuck DVD.

      Windows 7. The irony never stops.

  7. Cees says:

    What is the exact commandline to (re)mount the main disk in a iMac?
    I see it in utilities suddenly named as “Media” but that’s it. It seems unmounted. Erasing not possible.
    So, I want to see if I can just mount it in Terminal and re-instal El Capitan again from scratch thx !

  8. BruceS says:

    Thanx! The grep tip within “diskutil list |grep OSXDaily” enabled me to identify the correct Identifier in the o/p. I used grep-i (easier than the Shift key). Anyway, worked perfectly. iMac, under hard restart—had to pull plug—recognized but refused to mount external exFAT drive.

    • Jamie says:

      I think it would be better to use && instead of ; when unmounting and re-mounting because the && will check that the unmount worked properly before executing the re-mount.

      Thanks for a very clear and helpful article, and thanks to the others for helpful comments too.

  9. UkeyD says:

    Thank you SO much! This is just what I needed! I couldn’t get it to unmount or mount but using both did the trick. Thanks again!

  10. Lee Maxwell says:

    I have noticed that when I attempt to mount an unmounted but connected [via USB] external hard drive using the following command in the Terminal:

    diskutil mountDrive /dev/disk2s4

    Terminal reports:

    “One or more volume(s) failed to mount”

    However, when I use:

    sudo diskutil mountDrive dev/disk2s4

    and type in my admin password, the external drive mounts.

    i am using macOS 10.13.6 on an iMac 27″ late 2009

    I’d like to be able to invoke this command without needing to type in an admin password. Can anyone suggest a way to do this?

  11. Nigel Pye says:

    Thank you so much, mounted my disc and able to copy everything off.

  12. bbb says:

    Too complicated! Can you be more specific, step by step & explain more of the tech vocabulary for us non-techies? We need help, too!!

    • tpom says:

      The command line approach to mounting and unmounting drives is intended for techies, of course it is complicated. If you’re not comfortable with the command line, don’t use it. There is no requirement to use the command line for anything at all on the Mac. Novice users can eject a disk through the Finder, or plug it into USB and mount it that way.

  13. Lalitha Sundararajan says:

    I have a macBook air. I did a list on the terminal command window and showed the following removable disks. I tried to dismount both of them, the reply I received I am copying below:

    /dev/disk2 (external, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: *1.0 TB disk2

    /dev/disk4 (external, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: *1.0 TB disk4

    Charus-Air:~ lsr$ diskutil unmount /dev/disk2
    disk2 was already unmounted or it has a partitioning scheme so use “diskutil unmountDisk” instead
    Charus-Air:~ lsr$ diskutil unmount /dev/disk4
    disk4 was already unmounted or it has a partitioning scheme so use “diskutil unmountDisk” instead
    Charus-Air:~ lsr$

    Is it advisable to do “diskutil unmountDisk”? I am afraid to do that because what will happen to the internal drives if I do the “diskutil unmountDisk”?
    Any help will be appreciated
    Thanks
    Lalitha

  14. Daniel says:

    This worked for me, thank you!
    My WD external hard drive wasn’t showing up in finder but worked in my PS4. I simply followed the instructions and it worked.

    diskutil list
    diskutil unmount /dev/disk2
    diskutil mountDrive /dev/disk2

  15. Ces says:

    I just had the same problem. Time machine external became unmountable in (running El Capitan) but I also tried it on a different mac running Leopard (yes,) still didn’t mount. Tried disk repair, tried First Aid. It would say all good, but the drive would NOT mount. I could see it in Disk Utility (on both OS’s). Even tried terminal, and force mount on terminal and it’d give me the whole try Read Only mount –also didn’t work. Called Apple and THEY couldn’t help either (after asking me if i tried everything -which I had) So I bit the bullet and bought DiskWarrior for $128 and crossed my fingers. IT WORKED. It could access the drive and instead of rebuilding the drive’s directory I made it copy my files to a new external. Doing it now. (SIGH…..) months and months of files saved.

    • Ces says:

      I should also add – DiskWarrior was the first program I tried. I read not so great reviews on others, but I’m glad the first one worked.

  16. Kelly says:

    If you connect a damaged disk, and the light indicates heavy activity but the OS does not immediately complain or appear to mount the disk, it is likely running fsck in the background.

    In my case, I noticed that fsck was going through an error/repair/recheck loop continuously, and not fixing the problem. However, after a very long time it would sometimes mount the disk in read-only mode, and tell me that the disk could not be repaired and I should copy files I needed as soon as possible.

    I found that if I killed the fsck process, it would skip right to mounting it as read-only (which, if you have a damaged disk, is probably the best you can hope for).

    To kill the fsck process, first find it by doing:

    ps waux | grep fsck

    Note the second column (a number) will be the process ID (e.g. 88888). Use that number (not 88888) to kill the process:

    sudo kill -9 88888

    Hopefully this helps someone, because I was looking for a way to cut off the useless repair process and just mount it read-only, but the “diskutil mount readOnly” wouldn’t work if fsck was busy operating on the disk.

    • DMurray says:

      Great advice – found the fsck process in Activity Monitor, killed it and very shortly after, the drive mounted.

    • camilla says:

      Hey!

      I have tried everything that has been mention on the above comments, and were now trying this but i am not sure what number i sould use? The disk that will not show up is the one reffered to as disk2s2, and i could see the fsck activity as you mentioned. When i ran the comando this came up:

      root 785 21,3 12,6 3510292 1053384 ?? U 11:56pm 1:21.46 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2
      *my name on the computer that i do not want on the internet* 855 0,0 0,0 2432804 1976 s000 S+ 12:00am 0:00.00 grep fsck

      I hope that you can help me!

  17. Ben says:

    If you want to fully automate the process of ejecting the disk based on a partition name, this should do the trick:

    diskutil list | grep PartitionNameOnDisk | tr ‘ ‘ ‘\n’ | grep disk | sed ‘s/s.$//g’ | xargs diskutil eject

  18. Chris says:

    To unmount you don’t need to find the /dev/disk… name: just use the /Volumes/whatever name.

    I have two simple shell scripts to make this easier because I can never remember the detail:
    unmountl.sh:
    #!/bin/sh
    hdiutil eject /Volumes/LaCie

    mountl.sh:
    #!/bin/sh
    set -e
    dv=`diskutil list | grep LaCie | sed -E ‘s/^.+(disk.+$)/\1/’`
    diskutil mount /dev/”$dv”

    • AJ says:

      Could you explain the second mount script and how it could may run in terminal.

      ” hdiutil eject /Volumes/LaCie ” works in terminal but I cant replicate the mount part.

  19. KP says:

    This definitely does work, it just takes some time. If the light on your hard drive is blinking or you can hear the motor spinning, that means you Mac is trying to read it. It may time out, so you have to continue to prompt the disk utility to unmount, even if it says that the disk is already unmounted. Mine finally unmounted after about ten tries. Then I typed the command to mount and it did. You have to be patient and stay at it. Remember that you are working with a machine.

  20. CL says:

    tried terminal command to mount disk that i cannot mount with disk utility. but looks like this is basically the same thing as using disk utility. basically same result: terminal says: “Unable to find disk for …” That disk is greyed out in Disk Utility. DU says to repair disk and then try mounting again. But repair returns/fixes no errors. but disk still wont mount. oddly, it was just mounted on a different computer. i shut that computer down, to move disk to a different computer; and suddenly it stopped mounting.

  21. JB says:

    In the “power cycling” part, instead of using ; at the end of the command, use &&, which makes sure that the previous command is successful before doing the next command(so you don’t mount the drive while it is already mounted, etc).

  22. lino says:

    Hi, thanks for this! when i type diskutil list, i see 2 hard drives and my ssd. I do not see the external dvd writer listed.

    I do see it under disc burning and I can see the player with toast but cannot mount anything, data or dvd discs.

    How can toast see it but not any other apps?

    disc burning: PIONEER BD-RW BDR-208D:

    I tried the csrutil disable but still dont get discs mounted.

    thanks for any suggestions!
    -l

  23. Devon says:

    Thanks man!
    This saved my Harddisk it wouldt come up at finder only disk utility.
    Now its reconized, going to make a big backup and send it back :)

    Many many thanks

  24. Sas says:

    Strange issue. Name of drive’s identifier does not appear! Help, anyone!

    /dev/disk2 (external, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *1.0 TB disk2
    1: EFI EFI 209.7 MB disk2s1
    2: Apple_HFS 999.9 GB disk2s2

    • kfl says:

      I can report about the same thing here. — 1 TB WD My Passport, + El Capitan.

      Greyed out, unmountable. No disk identifier!

      Is this one of the problems that I hear rumors about w/r/t El Capitan problems. Come to think of it, the other issue is with MOTU audio interfaces, so maybe there is a major USB issue?

  25. Sameh says:

    Hi in terminal reply comes that disk1 mounted “it is the 1st partition” in my external hard disk but it fails to mount the 2nd partition.
    also I don’t see the partitions in the disk utility, I want to format the 2nd partition OS X Journaled for time machine backup.
    would you please help ?

  26. Blaise says:

    I did the remount option and it says “Volume on disk2 failed to mount; if it has a partitioning scheme, use “diskutil mountDisk”
    If the volume is damaged, try the “readOnly” option”

    not sure what to do next.

    Also, it shows up in my disk utility in grey. Is there a way to at least get the files off of it if it is damaged?

    • Awais says:

      Hi , i got the same error by running this command:

      diskutil unmount /dev/disk3;diskutil mount /dev/disk3;echo “Remounted Volume”

      Result:
      disk3 was already unmounted or it has a partitioning scheme so use “diskutil unmountDisk” instead
      Volume on disk3 failed to mount; if it has a partitioning scheme, use “diskutil mountDisk”
      If the volume is damaged, try the “readOnly” option
      Remounted Volume

      Any idea how to fix this ?

  27. Wally says:

    My external drive is now greyed out in Disk Utility (though the repair function works and says the disk is OK). The disk permissions option is missing. How do you get “permission” to mount the disk. Nothing seems to work.

  28. Vijay says:

    Hi

    My situation is like, my disk got locked and tried to mint it and it’s giving me this msg disk0s2 is FileVault or fusion drive physical volume; use “disputing corestorage list” to find its logical volume, which you can then unlock and mount

    How I can unlock my disk please help me out
    M in very bad situation and my drive is a fusion drive

  29. Sara says:

    My external drive won’t unmount, says it’s busy?????

  30. Jesse says:

    For the trick with unmounting and remounting a drive, just in case anything were to go wrong in the process, it would be better to replace the inner semicolons with double-ampersands (that way, the remount is only attempted if the unmount were successful, and the success message would only be echoed if success actually occurred):
    diskutil unmount /dev/disk1s2 && diskutil mount /dev/disk1s2 && echo “Remounted Volume”

  31. Tom says:

    I needed to have the command and the redirect executed together so it had permissions to /etc/fstab:
    sudo sh -c ‘echo “LABEL=MYDRIVE none ntfs rw,auto,nobrowse” >> /etc/fstab’

  32. cyberpi 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 results say:

    /dev/disk0
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *160.0 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_HFS Macintosh HD 159.2 GB disk0s2
    3: Apple_Boot Recovery HD 650.0 MB disk0s3
    /dev/disk1
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *250.1 GB disk1
    1: EFI EFI 209.7 MB disk1s1
    2: Apple_HFS 249.2 GB disk1s2
    3: Apple_Boot Recovery HD 650.0 MB disk1s3
    $ diskutil mount /dev/disk1s2
    Volume on disk1s2 failed to mount
    $ diskutil unmount /dev/disk1s2
    disk1s2 was already unmounted
    $ diskutil mount /dev/disk1s2
    Volume on disk1s2 failed to mount

    What am I doing wrong or what is the issue? I need mount disk1s2. It is an external HDD with an Apple file system. I am trying to retrieve my personal data. It crashed due to the Yosemite upgrade.

  33. 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:

    /dev/disk2
    #: TYPE NAME SIZE IDENTIFIER
    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

    PLEASE HELP…

  34. 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
          /dev/disk0
          #: TYPE NAME SIZE IDENTIFIER
          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?

  35. 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.

    :)

  36. 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.

  37. Frank says:

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

  38. Nittn says:

    i am getting following reply – need help, thanks

    Volume LaCie on disk2s1 timed out while waiting to unmount

    • Will Kallhoff says:

      I am having the same issue. Did you find anything out?

    • Wendy says:

      Same thing. How did you resolve this?

    • xira says:

      me too!
      i got this message when i mount it :
      “Volume on disk1 timed out waiting to mount”
      please help !

    • xira says:

      me too ! please help :(

      • Raphael says:

        So I was trying various methods mentioned on this forum https://discussions.apple.com/thread/2706588?start=15&tstart=0

        My external HD was disconnected accidentally and it wouldn’t show up on my desktop, only on my disk utility while blinking rapidly. The HD under the indented section on the left panel would be in grey. When I ran “verify disk” and “repair” it said it couldn’t be repaired and needed to be repaired.

        the wd support (I have a wd passport 2tb) to no avail. I’ve tried
        -terminal (got the same message as you did)
        -disk utility as mentioned above
        -unplug, shut down the computer, restart
        -restart the computer while the external HD is plugged in, and repeat the disk utility step.
        -deleted finder plist

        Nothing worked until I tried the most crude method mentioned on the forum as my last resort: shut down the computer manually(close all apps, press down the power button until it shuts off) with the external HD still plugged in, then started it back up and it worked! Hope this is helpful.

  39. Bayesrisk says:

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

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

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

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site