disk management from the command-line, part 1 - the instructional

Upload: scribd-123

Post on 02-Mar-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    1/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    Disk Management From theCommand-Line, Part 1March 10, 2014

    Disk Utility within Mac OS X provides a range of disk

    management tools, from erasing and repartitioning

    hard disks to restoring images and repairing volumes.

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

    Beyond this graphical front-end are some powerful

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

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

    of Disk Utility at the command-line.

    The following guide will require the use of an external

    hard drive which will be erased and partitioned.

    Terminology

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

    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

    Win this free, limited edition t-shirt and wear

    it proud. #DesignersAreFly

    Highly Recommended

    TextExpander 4

    Available for a limited time at just

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

    Reader Support

    Help support The Instructional by

    becoming a member for just $2 per

    month.

    Find out more...

    The Instructional Weekly

    Subscribe to a weekly digest of

    everything we publish, delivered

    straight to your inbox every Friday.

    Guides Ebooks About Membership Follow Contact

    http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.theinstructional.com/http://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://www.theinstructional.com/contact/http://www.theinstructional.com/subscribe/http://www.theinstructional.com/membership/http://www.theinstructional.com/about/http://www.theinstructional.com/ebooks/http://www.theinstructional.com/http://www.theinstructional.com/membershiphttp://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://srv.buysellads.com/ads/click/x/GTND423JCTBDV5QYCTBLYKQWC6YDV2QNCTYD6Z3JCEYIT23NC6SDVKQKC6BD4K3WCWYI6K3EHJNCLSIZ?segment=placement:theinstructionalcomhttp://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.theinstructional.com/
  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    2/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    volume.

    Here's a USB hard drive that has been split into 16

    partitions, all of which will display separately on the

    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,

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

    amount of space you first had available.

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

    what each room will be. Formatting a disk partition is

    no different than deciding which room will be the

    bedroom or kitchen. At that point, it becomes a

    volume.

    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 HDfor

    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 Uti lity is more than adequate to perform any form

    Join Mailing List

    Email Address

    Categories

    Highly Recommended

    General

    Offsite

    iOS

    Mac

    Archives

    September 2014August 2014

    July 2014

    June 2014

    May 2014

    April 2014

    March 2014

    February 2014

    http://www.theinstructional.com/guides/?month=february-2014&view=calendarhttp://www.theinstructional.com/guides/?month=march-2014&view=calendarhttp://www.theinstructional.com/guides/?month=april-2014&view=calendarhttp://www.theinstructional.com/guides/?month=may-2014&view=calendarhttp://www.theinstructional.com/guides/?month=june-2014&view=calendarhttp://www.theinstructional.com/guides/?month=july-2014&view=calendarhttp://www.theinstructional.com/guides/?month=august-2014&view=calendarhttp://www.theinstructional.com/guides/?month=september-2014&view=calendarhttp://www.theinstructional.com/guides/?category=Machttp://www.theinstructional.com/guides/?category=iOShttp://www.theinstructional.com/guides/?category=Offsitehttp://www.theinstructional.com/guides/?category=Generalhttp://www.theinstructional.com/guides/?category=Highly+Recommended
  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    3/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

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

    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 HDand Macintosh HD, both partitions

    contained on the Mac's internal hard disk. An external

    hard disk is also connected with a volume labeled

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    4/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    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

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    5/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    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

    disk2s2disk2s3

    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

    verifyVolumeorrepairVolume. These options

    don't need the disk identifier, just the volume's name:

    If the feedback within Terminal looks familiar, that's

    because it's the same information Disk Utility

    provides.

    diskutil verifyVolume /Volumes/{volum

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    6/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    Disk permissions can also be verified and repaired

    using two similar commands:

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

    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:

    You'll notice this command has a little more going on

    than previous ones. The structure of the command is:

    Erasing a whole disk will clear any partitions and createa new, single partition, before formatting it as a

    volume.

    diskutil verifyPermissions /Volumes/{

    diskutil eraseDisk JHFS+ Test /dev/{d

    diskutil eraseDisk {filesystem} {Name

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    7/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    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

    NameThis 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

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    8/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    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, FirstVolumeand SecondVolume. To erase

    SecondVolume, the command is:

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

    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:

    Wrapping Up

    diskutil eraseVolume JHFS+ New /Volum

    diskutil reformat /Volumes/SecondVolu

    diskutil rename "{current name of vol

  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    9/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

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

    Disk Management From

    the Command-Line, Part 2

    Remote System

    Monitoring With iStat for

    iOS

    Comments (2) Subscribe via e-mail

    Permalink

    Save: Instapaper Pocket Readability

    We've only scratched the surface ofdiskutilyet

    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 tomanage partitioning and modify volumes.

    You can purchase the complete guide to Disk

    Management From the Command-Linethat includes

    Building an OS X Triage Driveas an ebook in ePub and

    PDF format for just $0.99.

    Newest First

    http://www.theinstructional.com/ebooks/os-x-disk-management-from-the-command-linehttp://www.readability.com/save?url=http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1https://getpocket.com/save?url=http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.instapaper.com/hello2?url=http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.theinstructional.com/guides/disk-management-from-the-command-line-part-1http://www.theinstructional.com/guides/remote-system-monitoring-with-istat-for-ioshttp://www.theinstructional.com/guides/disk-management-from-the-command-line-part-2
  • 7/26/2019 Disk Management From the Command-Line, Part 1 - The Instructional

    10/10

    9/11/2014 Disk Management From the Command-Line, Part 1 - The Instructional

    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!

    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

    Preview Post Comment

    adam deyo

    4 weeks ago

    David Dingley

    A month ago

    2014 Jordan Merrick

    https://plus.google.com/+Theinstructionalhttps://www.facebook.com/theinstructionalhttps://alpha.app.net/theinstructionalhttps://twitter.com/_instructionalhttp://www.theinstructional.com/rss