mount & unmount drives from the command line in mac os x

4
► Mac OS X Disk ► Mac ► Mount Image ► External Drives 43% OFF beaTunes 3.5.16 Organize your music collection.

Upload: airton-miguel-junior

Post on 21-Oct-2015

47 views

Category:

Documents


5 download

DESCRIPTION

Montar drives em Unix

TRANSCRIPT

Page 1: Mount & Unmount Drives From the Command Line in Mac OS X

10/15/13 Mount & Unmount Drives from the Command Line in Mac OS X

osxdaily.com/2013/05/13/mount-unmount-drives-from-the-command-line-in-mac-os-x/ 1/4

May 13, 2013 - Leave a Comment

Mount & Unmount Drives from theCommand Line in Mac OS X

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 LineLet’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 DrivesThe 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

Follow @OSXDailyLike 28k

Shop at Amazon

Epson WorkForceWF­3540 WirelessAll...EpsonNew $139.99

WD My Passportfor Mac 1TBPortable ...Western Digital

Canon PIXMAMX922 WirelessColor Pho...Canon USANew $129.99

ARRIS / MotorolaSurfBoardSB6141 DO...ARRIS GeneralInst...

Microsoft WirelessMobile Mouse4000...MicrosoftNew $17.22

GoPro HERO3GoPro CameraNew $329.99

Privacy Information

Ad

Subscribe to OSXDaily

OSXDaily on Facebook

OS X Daily

Like

28,133 people like OS X Daily.

Facebook social plugin

OSXDaily on Google+

OSXDaily on  Follow

Shared on Facebook

SearchHome Mac OS X iPhone iPad Tips & Tricks Jailbreak Mountain Lion iOS

  ► Mac OS X Disk   ► Mac   ► Mount Image   ► External Drives

43%OFF

beaTunes 3.5.16

Organize yourmusic

collection.

   

Page 2: Mount & Unmount Drives From the Command Line in Mac OS X

10/15/13 Mount & Unmount Drives from the Command Line in Mac OS X

osxdaily.com/2013/05/13/mount-unmount-drives-from-the-command-line-in-mac-os-x/ 2/4

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 DriveStill 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 LineIf 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 MountIf 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 DriveTo 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.

Apple Sets Event Date for October 22, New iPadsComing135 people recommend this.

http://osxdaily.com/2013/07/19/disappearing-mouse-cursor-mac-os-x/One person recommends this.

How to Lock Orientation to Stop Screen Rotation iniOS 719 people recommend this.

Cut, Copy, & Paste Files Directly from Spotlight inMac OS X33 people recommend this.

Prevent Zip Clutter by Moving Archives AutomaticallyAfter Unzipping in Mac OS X26 people recommend this.

MacBook Pro 13″ gets dropped at 195mph… but waitit still boots!196 people recommend this.

Personal Hotspot Dropping Connections? Try ThisDHCP Client Fix40 people recommend this.

4 Simple Mac Maintenance Tips34 people recommend this.

Page 3: Mount & Unmount Drives From the Command Line in Mac OS X

10/15/13 Mount & Unmount Drives from the Command Line in Mac OS X

osxdaily.com/2013/05/13/mount-unmount-drives-from-the-command-line-in-mac-os-x/ 3/4

Unmount & Remount a Drive / Volume in a Single CommandWant 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

7

Related articles:Mount a DMG from the Command Line in Mac OS X

Easily Mount an ISO in Mac OS X

Access and Mount an SMB Share via Command Line

Burn an ISO Image from the Command Line

Download FreeSoftwaremobogenie.com/download­software

Download Free PC ManagerSoftware. Easy File Transfer.Download Now !

242

 

219

 

Page 4: Mount & Unmount Drives From the Command Line in Mac OS X

10/15/13 Mount & Unmount Drives from the Command Line in Mac OS X

osxdaily.com/2013/05/13/mount-unmount-drives-from-the-command-line-in-mac-os-x/ 4/4

OS X Daily

Email us: [email protected]

Write for us: [email protected]

Contact Us | Privacy Policy | Sitemap

This website is unrelated to Apple Inc

All trademarks and copyrights on this websiteare property of their respective owners.

« How to Open Zip Files & ExtractArchives on the iPhone & iPad

Generate Random Passwords on theiPhone with Siri »

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

Leave a Reply Name (required)

Mail (will not be published) (required)

Website

Submit Comment

Shop for Apple & Mac Deals on Amazon.com

© 2013 OS X Daily. All Rights Reserved. Reproduction without explicit permission is prohibited.