Mount and Unmount Drives on Mac OS Using Command Line

Learn how to easily manage your Mac’s drives with the command line. Follow these simple steps to mount and unmount drives and keep your system running smoothly.

This guide is about the Mount & Unmount Drives from the Command Line in Mac OS X. I will try my best so that you understand this guide very well. I hope you all like this guide Mount & Unmount Drives from the Command Line in Mac OS X.

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

For many users, the easiest way to remove a drive on a Mac is to either drag the volume to the Trash, use the Delete keys, remove the drive, or use some forced removal method. On the same line, if you want to reinstall the drive, you can usually just physically remove the drive and plug it back in. But what if you want to be able to mount, unmount, and install drives from the command line? This is exactly what we are covering here.

This trick works with external USB drives, hard drives, Firewire, Thunderbolt, DVDs, CDs, network drives, even USB flash drives, with literally any volume that can be installed and used with the incredibly useful diskutil command. When reinstalling a drive from the command line, the entire process can be performed remotely via SSH if necessary, and you never have to disconnect the drive from your Mac. This is extremely useful for troubleshooting situations, scripts, and automation, and is a great trick for those of us who just want to play in the Terminal.

Removing a drive from the command line on a Mac

Let’s first look at removing the drive. To do this, you need another volume that is connected or plugged into your Mac in one format or another, and then start the Terminal to start (sitting / Applications / Utilities /).

1: List all stations

The first thing you need to do is list the connected drives. This will list all the drives connected to your Mac that have been either installed and removed, as well as all the corresponding partitions. We do this so that we can get a drive ID, which is typically something like disk1s2 or disk2s2, etc.

diskutil list

The result looks 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_IZ GB disk11: EFI 209.7 MB disk1s12: Apple_HFS OSX daily 15.7 GB disk1s2

Because of this example, we’ll focus on a connected drive called bollyinside, which happens to be an external USB flash drive that appears last in the list. Note that the drive ID for that drive is “disk1s2”, and we’ll move it to the next script to remove and reinstall it.

It is probably worth mentioning that drives are always located in / dev / and thus / dev / is always appended to the prefix tag.

2: Remove the specified drive

We continue to use the diskutil command, assigning it to that drive for removal.

diskutil unmount / dev / disk1s2

This indicates that the named quantity and location have been removed, as follows:

$ diskutil unmount / dev / disk1s2Volume OSXDis of the day1s2 removed

That’s all there is to it. You’ll notice that the drive is no longer available in the Finder, but it will still appear through your disk account from the command line or from the more familiar Disk Utility application in the Mac OS X interface.

Installing a drive from the command line on a Mac

Of course, if you can remove the drive, you can also install or reinstall it. The script is very similar; find the volume and install the drive.

1: Find Drive to Mount

If you already know the location of the volume, you can ignore Part 1 and jump directly to Part 2, but in any case, retrieving the volume tag will be covered. This time, we shorten it a bit because we assume we know the name of the drive to be installed, so we just have to find the identifier. We do this by using a grep file to shorten the output of the diskutil command as follows:

$ diskutil list | grep bollyinside2: Apple_HFS bollyinside 15.7 GB disk1s2

This output is, of course, much shorter than the entire output of the diskutil list above.

In this example, the drive “bollyinside” is still located in / dev / disk1s2 and we will install it.

2: Install (or install) the drive

To install (or reinstall) a drive, we use the same diskutil command with a new flag and inputs, such as:

diskutil mount / dev / disk1s2

Using the same examples as elsewhere, the command and output look like this:

$ diskutil mount / dev / disk1s2Volume bollyinside has / dev / disk1s2 installed

This will apparently reinstall the drive, and it will also make the installed volume reappear in Mac OS X Finder and GUI-based applications in various Open or Save dialog boxes.

Install and remove drives from the command line in Mac OS X.

Removing and installing a drive / drive with a single command

Terminal Want to quickly unplug and install the same volume, mainly on a power wheel, that’s connectivity to a Mac? You can do this with a single command by tying the two together like this:

diskutil unmount / dev / disk1s2; diskutil mount / dev / disk1s2; echo “Reinstalled volume”

This looks like this when run:

$ diskutil unmount / dev / disk1s2; diskutil mount / dev / disk1s2; echo “Reinstalled Volume” Volume bollyinside Disk1s2 RemovableVolume bollyinside on / dev / disk1s2 InstalledRemounted Volume

If you happen to look at the volume in the Finder during this process, you will notice that it disappears for a moment and then appears almost immediately. The last echo section is optional, but it makes the whole command function even more precise.

Thanks to Nilesh for the tip inspiration

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

[wpsm_list type=”star”]

  • The Mount & Unmount Drives from the Command Line in Mac OS X guide is free to read.
  • We help many internet users follow up with interest in a convenient manner.
  • The price of the Mount & Unmount Drives from the Command Line in Mac OS X guide is free.

[/wpsm_list]

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

[wpsm_accordion]
[wpsm_accordion_section title=”Guide about Mount & Unmount Drives from the Command Line in Mac OS X”]
In this guide, I told you about the Mount & Unmount Drives from the Command Line in Mac OS X.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”How this Guide helping you?”]
In this guide, I discuss about the Mount & Unmount Drives from the Command Line in Mac OS X, which is very helpful.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”What are the supported devices for this guide?”]
Apple Devices only.
[/wpsm_accordion_section]
[wpsm_accordion_section title=”What are the supported Operating system?”]
mac OS or iOS
[/wpsm_accordion_section]
[/wpsm_accordion]
[wpsm_divider top=”2px” bottom=”15px” style=”fadeout”]

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

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

Editorial Staff
Editorial Staffhttps://www.bollyinside.com
The Bollyinside editorial staff is made up of tech experts with more than 10 years of experience Led by Sumit Chauhan. We started in 2014 and now Bollyinside is a leading tech resource, offering everything from product reviews and tech guides to marketing tips. Think of us as your go-to tech encyclopedia!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

Hubspot Service Hub review 2024: a comprehensive platform

When it comes to customer support operations, HubSpot Service Hub is an all-encompassing customer service platform that is meant to...
Read more
When players on Windows 11 or 10 try to log in to Steam, they may get the error code E87....
Users of Windows 11 or 10 may find it frustrating to deal with the error number 147-0 in Microsoft Office....
The Microsoft Store is an important part of the Windows operating system because it gives users a single place to...
It can be hard to find the right balance between usefulness, durability, and cost when it comes to kitchen storage....
Both AirDroid and Vysor are well-known tools that help Android users control their devices and mirror them. One of the...