Disk utilities - Format, Verify, Repair (local disks.) This includes options not available in the Disk utility GUI.
Syntax diskutil verb [options] VERBS Each verb is listed with its description and individual arguments. list [device] List the partitions of a disk or all disks. If no device is listed, than all partitions on all disks will be displayed. list [plist] Print a property list A script could interpret the results of the diskutil -plist output
and use diskutil info on each entry for detailed information. info | information device Get information on a disk or volume. unmount [force] device Unmount a single volume. Force will force unmount the volume. unmountDisk [force] device Unmount an entire disk (all volumes). Force will force unmount the volumes. eject device Eject a disk. mount [readOnly] device Mount a single volume. If readOnly is specified, then the file system is
mounted read-only, even if the volume's underlying file system and/or device
and/or media supports writing. Even the super-user can not write to it. This
is the same as the rdonly option to mount mountDisk device Mount an entire disk (all mountable volumes). rename | renameVolume device name Rename a volume. enableJournal device Enable HFS+ journaling on a mounted HFS+ volume. Ownership of the affected disk is required. disableJournal device Disable HFS+ journaling on a mounted HFS+ volume. Ownership of the affected disk is required. verifyVolume | verifyDisk device Verify the data structure of a volume (e.g. fsck). Ownership of the affected disk is required. The synonym "verifyDisk" is allowed but deprecated. repairVolume | repairDisk device Repair the data structure of a volume (e.g. fsck). Ownership of the affected disk is required. The synomym "repairDisk" is allowed but deprecated. verifyPermissions [-plist] device Verify the permissions of a Mac OS X boot volume. repairPermissions [-plist] device Repair the permissions of a Mac OS X boot volume. Ownership of the affected disk is required. repairOS9Permissions Repair the permissions of the user selected Classic System and Applications folder. eraseDisk format name [OS9Drivers | APMFormat | MBRFormat | GPTFormat] device Erase an existing disk, removing all volumes. Format is discussed below in the section for the partitionDisk verb. Ownership of the affected disk is required. eraseVolume format name device Erase an existing volume. Format is discussed below in the section for the partitionDisk verb. Ownership of the affected disk is required. reformat device Reformat an existing device in the same name and format. Ownership of the affected disk is required. eraseOptical [quick] device Erase an optical media (CD/RW, DVD/RW, etc.). Quick specifies whether the disc recording stack should do a full erase or a quick erase. Ownership of the affected disk is required. zeroDisk device Erase a disk, writing zeros to the media. Ownership of the affected disk is required. randomDisk [times] device Erase a disk, writing random data to the media. Times is number of times to write random information. Ownership of the affected disk is required. secureErase [freespace] level device Securely erase a disk or freespace on a mounted volume. Ownership of the affected disk is required. Level should be one of the following: 1 - Single pass randomly erase the disk. 2 - US DoD 7 pass secure erase. 3 - Gutmann algorithm 35 pass secure erase. partitionDisk device [numberOfPartitions] [OS9Drivers | APMFormat | MBRFormat | GPTFormat] [part1Format part1Name part1Size part2Format part2Name part2Size part3Format part3Name part3Size ...] (re)Partition a disk, removing all volumes. All volumes on this disk will be destroyed. The device parameter specifies which whole disk is to be parti- tioned. The optional numberOfPartitions parameter specifies the number of partitions to create; if given then the number of parameter triplets (see below) is expected to match; else, the number of triplets alone given will determine the number of partitions created. The optional partitioning scheme parameter forces a particular partitioning scheme; if not specified, a suitable default is chosen. They are: o APMFormat specifies that an Apple Partition Map scheme should be used. This is the traditional Apple partitioning scheme used to start up a PowerPC-based Macintosh computer, to use the disk as a non-startup disk with any Mac, or to create a multiplatform compati- ble startup disk. o MBRFormat specifies that a Master Boot Record scheme should be used. This is the DOS/Windows-compatible partitioning scheme. o GPTFormat specifies that a GUID Partitioning Table scheme should be used. This is the partitioning scheme used to start up an Intel- based Macintosh computer. o OS9Drivers is a special partitioning scheme parameter that implies APMFormat (and is not to be combined together with the other scheme format parameters); it specifies that an Apple Partition Map scheme should be used (others not supported), and laid out in a manner com- patible with Mac OS 9. For each partition, a triplet of the desired filesystem format, volume name, and size must be specified. Several other diskutil verbs allow these triplets as well (and for them, the numberOfPartitions parameter is also optional). The triplets must be as follows: o Format names are of the form HFS+, MS-DOS, etc.; a list of available filesystems is printed as part of the usage text when invoking diskutil partitionDisk with no parameters. Format guides both what partition type to set for the partitions (slices) as well as what filesystem structures to lay down therein, e.g. with newfs (8). o Names are the initial volume names; they must conform to filesystem- specific restrictions. If a name of %noformat% is specified, then the partition is left blank such that the partition space is carved out, the partition type is set according to the filesystem format name, the partition space is partially erased, but a filesystem structure is not laid down; this is useful in certain cases e.g. when setting up ZFS pools. o Sizes are floating point numbers followed by B(ytes), S(512-byte- blocks), K(ilobytes), M(egabytes), G(igabytes), T(erabytes), P(etabytes), or %(percent of the whole disk size), e.g. 10G (10 gigabytes), 4.23T (4.23 terabytes), 5M (5 megabytes), 25.4% (25.4 percent of whole disk size). The S, K, M, G, T, P suffix multipli- ers are powers of 2. The last partition will be lengthened to the end of the disk; to specify an exact size for the last usable partition, specify an additional partition with a format name of Free Space. Ownership of the affected disk is required. resizeVolume device size [numberOfPartitions] [part1Format part1Name part1Size part2Format part2Name part2Size part3Format part3Name part3Size ...] Non-destructively resize a volume. You can increase or decrease its size. A size of limits will print the range of valid values for the current filesys- tem. When decreasing the size, new partitions can optionally be created to fill the newly-freed space. To do this, specify the numberOfPartitions, format, name, and size parameters in the same manner as the triplet description for the partitionDisk verb. Resizing a volume that is currently set as the computer's startup disk will invalidate that setting; use the Startup Disk System Preferences panel or bless (8) to reset the resized volume as the startup disk. Device refers to a volume; the volume's file system must be journaled HFS+. Valid sizes are a number followed by a capital letter multiplier or percent sign suffix as described in the section for the partitionDisk verb. Ownership of the affected disk is required. splitPartition device [numberOfPartitions] [part1Format part1Name part1Size part2Format part2Name part2Size part3Format part3Name part3Size ...] Destructively split a volume into multiple partitions. You must supply a list of new partitions to create in the space of the old partition; specify these with the numberOfPartitions, format, name, and size parameters in the same manner as the triplet description for the partitionDisk verb above. Device refers to a volume. Ownership of the affected disk is required. mergePartitions [force] format name fromDevice toDevice Merge two or more partitions on a disk. All data on merged partitions other than the first will be lost. The first will be erased if it doesn't have a resizable type (e.g. JHFS+) or if the force argument is given. Format and name apply only when the first partition is being erased. Merged partitions are required to be ordered sequentially on disk (see diskutil list for the actual on-disk ordering). Ownership of the affected disk is required.
The following diskutil verbs can be used to create, manipulate and destroy AppleRAID volumes (Software RAID). AppleRAID supports three basic types of RAID sets:
"stripe" - Striped Volume (RAID 0) "mirror" - Mirrored Volume (RAID 1) "concat" - Concatenated Volume (Spanning)
Of these three basic types, only the "mirror" type increases fault-tolerance. Mirrors
may have more than two disks to further increase their fault-tolerance. Striped and concatentated volumes are, in fact, more vulnerable to faults than single disk volumes.
From these basic types, "stacked" or "nested" RAID volumes can be created. Stacked RAID sets that make use of mirrored RAID sets are fault-tolerant. For example, these are some of the more common combinations of stacked RAID sets:
When creating new RAID sets or adding disks, if possible, it is better to specify the
entire disk instead of a partition on that disk. This allows the software to reformat
the entire disk using the most current partition layouts. When using whole disks, the
type of partitioning used is selected based on the platform type (PPC = APMFormat, Intel
= GPTFormat). GPT and APM partition formats cannot be mixed in the same RAID set.
In addition to whole disk and partition device names, AppleRAID uses UUIDs to refer to existing RAID sets and their members. Existing RAID sets can also be specified by mount point (e.g. /Volume/raidset). In many cases, using the UUID for the device argument is preferred because disk device names can change over time when disks are added, disks are removed or when the system is rebooted. If RAID members have been physically disconnected from the system or are no longer responding, you must use the member's UUID as the command argument. Messages in the system log will refer to RAID sets and their member disks by UUID. For more information on specifying device arguments see the "DEVICES"
AppleRAID is not a replacement for backing up your data. Backups should be always be performed on a regular basis and before modifying any RAID set using these commands.
APPLERAID VERBS listRAID [UUID] Display AppleRAID volumes with current status and associated member disks. If UUID is specified, only list that RAID. createRAID mirror|stripe|concat setName format devices ... Create a new RAID set consisting of multiple disks and/or RAID sets. setName is used for both the name of the created RAID volume and the RAID set itself (as displayed in listRAID). e.g. 'diskutil createRAID stripe MyArray JHFS+ disk1 disk2 disk3 disk4'. Ownership of the affected disks is required. destroyRAID raidVolume Destroy an existing RAID set. If the RAID set is a mirror, destroyRAID will attempt to convert each of the member partitions back into a non-RAID volume while retaining the contained filesystem. For concatenated RAID sets, destroyRAID will attempt to shrink the filesystem to fit on the first member partition and convert that to a non-RAID volume. Ownership of the affected disks is required. repairMirror raidVolume newDevice Repair a degraded mirror by replacing a broken or missing member. Broken devices in the mirrored set can also be rebuilt by specifying newDevice. When replacing members of a mirrored set, the new disk must be the same size or larger than the existing disks in the RAID set. Ownership of the affected disk is required. addToRAID type newDevice raidVolume Add a new member or hot spare to an existing RAID set. Type can be either member or spare. New disks are added live, the RAID volume does not need to be unmounted. Mirrored volumes support adding both members and hot spares, concatenated volumes only support adding members. When adding to a mirrored RAID set, the new disk must be the same size or larger than the existing disks in the RAID set. Adding a hot spare to a mirror will enable autorebuilding for that mirror. Adding a new member to a concatenated RAID set appends the member and expands the RAID volume. Ownership of the affected disk is required. removeFromRAID oldDevice raidVolume Remove a member or spare from an existing RAID set. Old disks are removed live, the RAID volume does not need to be unmounted. For missing devices, oldDevice must be the device's UUID. Online mirror members will be coverted non-RAID volumes, spare and offline members will be marked free. For concate- nated RAID sets, only the last member can be removed. RemoveFromRAID will first attempt to shrink the concatenated RAID set so that the filesystem fits on the remaining disks. Ownership of the affected disk is required. enableRAID mirror|concat device Convert a non-RAID disk partition containing a resizable filesystem (like JHFS+) into an unpaired mirror or single disk concatenated RAID set. Disks that were originally partitioned on Mac OS X 10.2 Jaguar or earlier or were partitioned to be Mac OS 9 compatible might not be resizable. Ownership of the affected disk is required. updateRAID key value raidVolume Update the key value parameters of an existing RAID set. Valid keys are: o AutoRebuild - If true, the system attempts to rebuild degraded mir- rored volumes automatically. When looking for devices for rebuild, AppleRAID first looks for hot spares and then degraded members. Use a value of "1" for true and "0" for false. o SetTimeout - Controls how long the system waits (in seconds) for a missing device before degrading a mirrored raid set. Also controls the amount of time you have to disconnect all devices from an unmounted mirror without degrading it. Ownership of the affected disk is required. convertRAID device Convert an AppleRAID version 1.x set (built on Mac OS X 10.3 Panther or ear- lier) into an AppleRAID version 2.x set (Tiger or later). RAID sets must be converted prior to using diskutil verbs other than listRAID and destroyRAID. Depending on how the original RAID was created the converted RAID set might not be bootable. Ownership of the affected disks is required. DEVICES A device parameter to any of the above commands (except where explicitly defined other- wise) is any of the following: o The device node entry. Any entry of the form of /dev/disk*, e.g. /dev/disk2. o The disk identifier. Any entry of the form of disk*, e.g. disk1s9. o The volume mount point. Any entry of the form of /Volumes/*, e.g. /Volumes/Untitled. o The Universally Unique Identifier or UUID. Any entry of the form of e.g. 11111111-2222-3333-4444-555555555555.
OS X does not guarantee assigning the same device id to the same disk at each boot.
Diskutil replaces the disktool utility found in earlier versions of OS X. (disktool is now deprecated)
The format parameter of erase and partitioning (and RAID creation) is the filesystems name. You can determine this name by looking in /System/Library/Filesystems/<fs>.fs/Contents/Info.plist
Some examples include: HFS+, HFS, JournaledHFS+, UFS, MS-DOS, etc.
List the disk device names and partition identifiers:
$ diskutil list
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *298.1 Gi disk0
1: EFI 200.0 Mi disk0s1
2: Apple_HFS Macintosh HD 297.8 Gi disk0s2
Get the Volume UUID (disk must already be mounted)
$ diskutil info disk0s2
Get the Volume ID of an IPOD
$ diskutil list |grep "IPOD" |grep -o '\(disk[0-9s]*\)'
Mount a disk using its Volume ID
$ diskutil mount Disk1
Mount a disk using its UUID
$ diskutil mount B172F107-06D4-39E3-9F7C-57466CD6489B
Erase a disk
$ diskutil eraseDisk UFS UntitledUFS disk3
Erase a volume
$ diskutil eraseVolume HFS+ UntitledHFS /Volumes/SomeDisk
Partition a disk
# create 3 partitions: # one partition as HFS+, one as UFS and one as MS-DOS: $ sudo diskutil partitionDisk /Volumes/disk7 3 HFS+ SimonsHFSPtn 20G UFS SimonsUFSPtn 20G MS-DOS SimonsDOS 10G # create 2 partitions on an intel machine, # one partition as Journaled HFS+ and one partition as UFS 30G: $ sudo diskutil partitionDisk /Volumes/xxxx GPTFormat 2 JournaledHFS+ SimonsbootPtn 20G UFS SimonsUFSPtn 30G Important: you cannot create non-HFS partitions on a disk if you intend to boot OS X on it. Use these partitioning commands on a second (or third) disk that you mount after booting.
Create a RAID
$ diskutil createRAID mirror MirroredVolume JHFS+ disk disk2
Destroy a RAID
$ diskutil destroyRAID /Volumes/MirroredVolume
Repair a damaged RAID
$ diskutil repairMirror /Volumes/MirroredVolume disk3
“What you want, what you're hanging around in the world waiting for, is for something to occur to you” - Robert Frost
diskutil man page - Apple.com
asr - Apple Software Restore
iMac seagate drive failures - apple support
bless - Set volume bootability and startup disk options.
drutil - Interact with CD/DVD burners
Disk Utility (GUI) - The 'Info' button displays the disk identifier, UUID etc
hdiutil - Manipulate iso disk images
hfs.util - HFS/HFS+ file system utility (Mount/unmount)
mount - Mount a file system
ntfs.util - NTFS file system utility
ufs.util - UFS file system utility (Mount/unmount)
SetFile(1) - Set extended attributes (Developer Tools)