diskutil

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.

     info | information device
		Get information on a disk or volume.

     unmount	[force] device
		Unmount a single volume.   Force will force unmount the vol-
		ume.

     unmountDisk [force] device
		Unmount an entire disk (all volumes).  Force will force
		unmount the volumes.

     eject device
		Eject a disk.

     mount device
		Mount a single volume.

     mountDisk device
		Mount an entire disk (all mountable volumes).

     rename name device
		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.

     verifyDisk device
		Verify the disk structure of a volume.	Ownership of the
		affected disk is required.

     repairDisk device
		Repair the structure of a volume.  Ownership of the affected
		disk is required.

     verifyPermissions device
		Verify the permissions of a Mac OS X boot volume.

     repairPermissions device
		Repair the permissions of a Mac OS X boot volume.  Root per-
		missions are required.

     repairOS9Permissions
		Repair the permissions of the user selected Classic System and
		Applications folder.

     eraseDisk format name [OS9Drivers] device
		Erase an existing disk, removing all volumes.  Format dis-
		cussed below.  Ownership of the affected disk is required.

     eraseVolume format name device
		Erase an existing volume.  Format discussed below.  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 num-
		ber of times to write random information.  Ownership of the
		affected disk is required.

     partitionDisk device numberOfPartitions [OS9Drivers] [MBRFormat]
		<part1format part1name part1size> <part2format part2name
		part2size> <part3format part3name part3size> ...
		(re)Partition a disk, removing all volumes.  All volumes on
		this disk will be destroyed.  Format is the specific filesys-
		tem name you want to erase it as. (HFS+, etc.)	MBRFormat
		specifies that the partition map should be written in DOS com-
		patible format.	 (OS9Drivers will be ignored in this case)
		Valid sizes are B(ytes), K(ilobytes), M(egabytes), G(iga-
		bytes), T(erabytes) Example: 10G (10 gigabytes), 4.23T (4.23
		terabytes), 5M (5 megabytes) You cannot partition the boot
		disk.	Ownership of the affected disk is required.

     createRAID mirror|stripe setName format device device ...
		Create a RAID set on multiple disks.  Ownership of the
		affected disks is required.

     destroyRAID device
		Destroy an existing RAID set.  Ownership of the affected disks
		is required.

     checkRAID device
		Print out the list of available RAID sets.

     enableRAID mirror device
		Convert single filesystem disk into a unpaired mirror RAID
		set.  Ownership of the affected disks is required.

     repairMirror device sliceNumber fromDisk toDisk
		Repair a failed mirror.	 Supply the slice number to replace
		(from the checkRAID information).  Supply the valid slice disk
		identifier as the second to last parameter.  Supply the new
		disk as the last parameter of the request. fromDisk and toDisk
		are only Device Nodes or Disk Identifiers.  Ownership of the
		affected disk is required.

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)

FORMAT
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/Contents/Info.plist
Some examples include: HFS+, HFS, JournaledHFS+, UFS, MS-DOS, etc.

EXAMPLES

List the disk device names and partition identifiers:

$ diskutil list

/dev/disk0
#: 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 MirrorDisk HFS+ disk disk2

Destroy a RAID
$ diskutil destroyRAID /dev/disk3

Repair a damaged RAID
$ diskutil repairMirror disk3 2 disk1 disk2

DEVICES

A device parameter to any of the above commands (except where explicitly defined otherwise) is any of the following
The device node entry. Any entry of the form of /dev/disk*
ex. /dev/disk2
The disk identifier. Any entry of the form of disk* ex. disk1s9
The volume mount point. Any entry of the form of /Volumes/Mountpoint
ex. /Volumes/Untitled

"What you want, what you're hanging around in the world waiting for, is for something to occur to you" - Robert Frost

Related:
authopen(1)
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
diskarbitrationd(8)
hdid(8)
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)



Back to the Top

© Copyright SS64.com 1999-2010
Some rights reserved