You are on page 1of 10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Guides

Ebooks

About

Membership

Follow

Contact

Search

Disk Management From the


Command-Line, Part 1
March 10, 2014

Win this free, limited edition t-shirt and wear


it proud. #DesignersAreFly

Highly Recommended
TextExpander 4

Disk Utility within Mac OS X provides a range of disk

Available for a limited time at just

management tools, from erasing and repartitioning

$16.99, 51% off it's usual price.

hard disks to restoring images and repairing volumes.


It's a simple way of interacting with attached storage
on your Mac.

Reader Support

Beyond this graphical front-end are some powerful

Help support The Instructional by

command-line tools that we can use directly. In this

becoming a member for just $2 per

series, we'll look at how to replicate the functionality

month.

of Disk Utility at the command-line.

Find out more...

The following guide will require the use of an external


hard drive which will be erased and partitioned.

Terminology
A partition is a logical storage unit located on a hard
disk. A hard disk can contain a single partition, making
use of all the space it contains, or it can be split into
multiple partitions.

The Instructional Weekly


Subscribe to a weekly digest of
everything we publish, delivered
straight to your inbox every Friday.

In order to store data on a partition, it needs a


filesystem. Once a partition has been formatted, this
combination of partition and filesystem is known as a
http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

1/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

volume.
Email Address

Join Mailing List

Categories
Highly Recommended
General
Offsite
Here's a USB hard drive that has been split into 16

iOS

partitions, all of which will display separately on the

Mac

Mac as separate volumes since they've been


formatted, though they are all on the same drive.
Imagine you have a loft apartment that's just four outer
walls. Think of partitioning as putting up dividing walls
to create additional rooms. The more walls you put up,

Archives
September 2014

the more rooms you'll have, but all limited to the total

August 2014

amount of space you first had available.

July 2014

But these rooms can't be used yet, not until you decide

June 2014

what each room will be. Formatting a disk partition is

May 2014

no different than deciding which room will be the

April 2014

bedroom or kitchen. At that point, it becomes a

March 2014

volume.

February 2014

With the introduction of OS X Lion, your Mac's hard disk


is split into two partitions with two corresponding
volumes. The first is hidden and named Recovery HD for
OS X Recovery, allowing you to reinstall OS X without
needing any physical media. The second is the more
familiar Macintosh HD.

Benefits of the Command-Line


Disk Utility is more than adequate to perform any form
http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

2/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

of disk management for most users. It's also safer than


the command-line, displaying warning dialogs before
proceeding with any potentially destructive functions.

For more experienced users, the command-line offers


a greater level of flexibility and control so that what
would normally require several different interactions
and mouse clicks can be done with just one command.

Disk Information with diskutil


The diskutilcommand provides many of the
features of Disk Utility, from verifying and repairing
volumes to changing partition information.
To view the full list of available options for the
command, enter the command diskutil.

Partition Information
Using the listoption will display some basic
information about all available volumes and drives
attached. Within Terminal, enter:
diskutil list
In the following screenshot, you can see both the
Recovery HD and Macintosh HD, both partitions
contained on the Mac's internal hard disk. An external
hard disk is also connected with a volume labeled
http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

3/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Untitled.

There are some hidden partitions (such as EFI) used for


the purposes of providing drivers and settings during
boot. These aren't volumes since they cannot be
mounted.
Depending on whether you have features such as
FileVault 2 or Fusion Drive, your partition layout might
differ slightly to what is pictured above.
For many of the options within diskutil, it's
necessary to use the disk or partition's Identifier. Using
listwill provide you with this information.
Should you have a number of disks and only want to
view information about a specific one, you can append
the disk identifier to the command:
diskutil list disk2

http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

4/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

The first number represents the physical disk


identifier. The number following the letter "s"
represents the partition number. If a disk has three
partitions, it would follow this convention:
disk2s1
disk2s2
disk2s3
In addition to list, you can also use infowith the
corresponding identifier to display even further
information, like so:
diskutil info disk2s1

Verifying and Repairing Volumes


As within Disk Utility, the diskutilcommand can
be used to verify or repair volumes of any errors and is
very straightforward to do using either
verifyVolumeor repairVolume. These options
don't need the disk identifier, just the volume's name:
diskutil verifyVolume /Volumes/{volume name}
If the feedback within Terminal looks familiar, that's
because it's the same information Disk Utility
provides.

http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

5/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Disk permissions can also be verified and repaired


using two similar commands:
diskutil verifyPermissions /Volumes/{volume name}

Erasing Disks
Erasing disks from the command-line can be a
dangerous process as there aren't any warnings or
confirmations. One typo could lead to irreversible data
loss if there's no backup to restore from. If you're not
familiar with the command-line, Disk Utility is just as
capable.
You can either erase a whole disk which will remove
any partitions stored upon it, or individual volumes
without affecting others.
To erase an entire disk, you'll need the disk identifier,
enter the following, adjusting the disk identifier to suit:
diskutil eraseDisk JHFS+ Test /dev/{disk identifier}
You'll notice this command has a little more going on
than previous ones. The structure of the command is:
diskutil eraseDisk {filesystem} {Name to use} /dev/{disk identifier}
Erasing a whole disk will clear any partitions and create
a new, single partition, before formatting it as a
volume.

http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

6/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Filesystem
You can specify the filesystem to format the partition
in by using any that are supported. The most common
would be JHFS+ which is more commonly known as
Mac OS Extended (Journaled).
To find out which filesystems you can use, enter:
diskutil listFilesystems

Name
This simply refers to the name of the volume that will
be created. In this instance, I've just labelled the
volume as "Test".

Disk Identifier
Only the primary part of the identifier (i.e. disk1, disk2,
disk3...) is needed. The additional segment indicating
the partition number is omitted.

Erasing Volumes
http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

7/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Erasing volumes doesn't erase or affect the entire disk,


only the volume you specify.
Here is an external drive that's partitioned with two
volumes, FirstVolume and SecondVolume. To erase
SecondVolume, the command is:
diskutil eraseVolume JHFS+ New /Volumes/SecondVolume
The command's structure is almost identical to using
eraseDisk, only that you specify the volume rather
than disk. Should a disk contain multiple volumes, only
the one you specify is altered.

Reformatting Volumes
You'll notice that erasing a volume requires specifying
the filesystem and name. This can be a bit tedious if
you don't actually want to change either of these, but
simply want to erase the contents.
Instead, the reformatoption will erase the contents
of the volume without requiring the filesystem or
name, provided these are to remain unchanged.
diskutil reformat /Volumes/SecondVolume
Now, the volume will be erased but retain the existing
filesystem and name.

Renaming Volumes
Within the Finder, you can quite easily rename the
volume by selecting it on your desktop and pressing
the Return key, just like you would any file or folder.
Renaming volumes within the Terminal uses a
different method than the renaming of files and folder,
something accomplished by using the command:
diskutil rename "{current name of volume}" "{new name}"

Wrapping Up
http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

8/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

We've only scratched the surface of diskutilyet


covered quite a lot. While the graphical interface of
Disk Utility can be easier to interact with, a task that
would involve several steps can be accomplished with
just one single command.
In the next part of this series, we'll cover how to
manage partitioning and modify volumes.

You can purchase the complete guide to Disk


Management From the Command-Line that includes
Building an OS X Triage Drive as an ebook in ePub and
PDF format for just $0.99.
Permalink
Save:

Instapaper Pocket Readability

Disk Management From

Remote System

the Command-Line, Part 2

Monitoring With iStat for


iOS

Comments (2)

Newest First

Subscribe via e-mail

http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

9/10

9/11/2014

Disk Management From the Command-Line, Part 1 - The Instructional

Preview

Post Comme nt

adam deyo
4 weeks ago

Thanks for this post, it was very helpful. An


external hard drive that was partially formatted
(tried Mac OS X Extended (Journaled,
Encrypted) and it failed upon attempting to
initiate FileVault) could not be erased via the
Disk Utility UI. Terminal commands from your
post did the trick. Thanks again!

David Dingley
A month ago

Is there a way to totally wipe a drive? Using


DeployStudio, I have a EFI partition that is
messing up my workflows when I attempt to
reimage a machine again. EFI is at disk0s1, the
first partition where DS attempt to place a
image..
Is there a command to wipe EFI?
Thanks
~David

2014 Jordan Merrick

http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1

10/10

You might also like