Mount & Unmount Drives from Command Line on Mac OS

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

So after a lot of requests from our users here is a guide about Mount & Unmount Drives from the Command Line in Mac OS X.

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 on the Mac is by either dragging a volume to the trash, using the eject keys, unmounting the drive, or using one of the forced eject methods. Likewise, if you want to reattach a drive, you can usually just physically disconnect and reconnect the drive. 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 drives, hard drives, Firewire, Thunderbolt, DVDs, CDs, network drives, even USB sticks, literally any volume that can be mounted and accessed via the incredibly handy diskutil command. By using the command line to remount the drive, the whole process can be completed remotely via SSH if needed, and without ever having to physically disconnect a drive from the Mac. This is infinitely useful for troubleshooting, scripting and automation, and it’s great trick for those of us who just like to tinker in Terminal.

How to Unmount a drive from the command line on the Mac

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

1: List of all disks

The first thing to do is list the connected drives. This will list all the drives connected to the Mac, which are mounted and unmounted, and all of their respective partitions. We do this so that we can get the drive ID, 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 IDENTIFIER0: GUID_partition_scheme * 121.3 GB disk01: EFI 209.7 MB disk0s12: Apple_HFS Macintosh HD 120.5 GB disk0s23: Apple_Boot Recovery HD 650.0 MB disk0s3 / dev / disk1 #: TYPE NAME SIZE IDENTIFIER part: TYPE NAME SIZE IDENTIFIER * 16.0 GB disk11: EFI 209.7 MB disk1s12: Apple_HFS OSXDaily 15.7 GB disk1s2

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

It’s probably worth noting that disks will always be in / dev /, so / dev / will always be preceded by the identifier.

2: Unmount the specified drive

We’re still using the diskutil command, we’ll point it to the disk in question to unmount.

diskutil unmount / dev / disk1s2

This reports the named volume and location has been unmounted, as follows:

$ diskutil unmount / dev / disk1s2Volume OSXDaily on disk1s2 unmount

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

How to Mount a drive from the command line on the Mac

Of course, if you can unmount a drive, you can mount or relink one as well. The order of the commands is very similar; find the volume and then mount the disk.

1: Find the drive you want to mount

If you already know where the volume is, you can ignore part 1 and go straight to part 2, but let’s see how to get the volume ID anyway. This time we’ll shorten it a bit as we assume we know the name of the drive to be mounted, so we just need to locate the identifier. We do this by using grep to shorten the output of the diskutil command like this:

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

Obviously, that output is much shorter than the full output of the diskutil list we showed above.

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

2: Mount (or remount) the disc

To mount (or remount) a disk, we use the same diskutil command with a new flag and enter as follows:

diskutil mount / dev / disk1s2

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

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

This will of course mount the drive back in, and it also makes the mounted volume visible again in the Mac OS X Finder and for 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 and remount a disk / volume in a single command

Terminal Want to quickly unmount and re-mount the same volume, essentially powering the connection to the Mac? You can do that in a single command by stringing the two together like this:

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

This would look like this:

$ diskutil unmount / dev / disk1s2; diskutil mount / dev / disk1s2; echo “Remounted Volume” Volume OSXDaily on disk1s2 unmountedVolume OSXDaily on / dev / disk1s2 mountedRemounted Volume

If you looked at the volume in the Finder during this process, you would notice it disappear for a moment and then reappear almost immediately. The final echo portion is optional, but it makes the whole command action even more elaborate.

Thanks to Nilesh for the tip inspiration

Mount & Unmount Drives from the Command Line in Mac OS X Guide is free?

Starting from: Free
This guide is a free model
Free Trial: May be included, please check on the official site, we mentioned above.
The Mount & Unmount Drives from the Command Line in Mac OS X tutorial price is Free or Freemium. This means you can truly enjoy the Mount & Unmount Drives from the Command Line in Mac OS X guide.

The Mount & Unmount Drives from the Command Line in Mac OS X guide gives you an easy-to-use and efficient management and Mount & Unmount Drives from the Command Line in Mac OS X allows you to focus on the most important things. It’s friendly guide to use maybe you will love it and Mount & Unmount Drives from the Command Line in Mac OS X tutorial can be used on Linux, Windows or android devices.

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

  • The Mount & Unmount Drives from the Command Line in Mac OS X tutorial is free .
  • Helps many users follow up with interest in a timely manner.
  • The price of the Mount & Unmount Drives from the Command Line in Mac OS X guide is free.

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

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

In this guide, we told you about Mount & Unmount Drives from the Command Line in Mac OS X; please read all steps so that you understand Mount & Unmount Drives from the Command Line in Mac OS X in case if you need any assistance from us, then contact us.

How this tutorial helping you?

So in this guide, we discuss the Mount & Unmount Drives from the Command Line in Mac OS X, which undoubtedly helps you.

What is actual time in which this method complete?

The time to complete the Mount & Unmount Drives from the Command Line in Mac OS X tutorial is 10+ minutes.

What are the supported Device?

Apple

What are the supported Operating system?

mac OS


Mount & Unmount Drives from the Command Line in Mac OS X Tutorial: final note

For our visitors: If you have any queries regards the Mount & Unmount Drives from the Command Line in Mac OS X, then please ask us through the comment section below or directly contact us.
Education: This guide or tutorial is just for educational purposes.
Misinformation: If you want to correct any misinformation about the guide “Mount & Unmount Drives from the Command Line in Mac OS X”, then kindly contact us.
Want to add an alternate method: If anyone wants to add the more methods to the guide Mount & Unmount Drives from the Command Line in Mac OS X, then kindly contact us.
Our Contact: Kindly use our contact page regards any help. You may also use our social and accounts by following the Whatsapp, Facebook, and Twitter for your questions. We always love to help you. We answer your questions within 24-48 hours (Weekend off).
Channel: If you want the latest software updates and discussion about any software in your pocket, then here is our Telegram channel.

Compsmag
Logo