logo

Home page
Articles for Windows, Linux, OS X
Mac tips and articles
Mac tips
Windows 8 tips and articles
Windows 7 tips and articles
Vista Tips
XP Tips
Linux tips and articles
Read the blog
Online store
Windows, Linux, OS X programs
Links
About

Repair and manage disk drives using Diskutil on the Mac

Disk Utility is a useful tool in OS X on the Mac and you can use it to format disks, partition them, erase them and repair them. However, it is not the only utility that is able to do this and there is a command prompt tool called diskutil that can perform all this and more. It has a lot of functions, but learning a few key ones could help in certain situations, such as when you can't run Disk Utility. Here's an introduction to diskutil to get you started.

Diskutil only works from a command prompt, so go to the Utilities folder and run Terminal. In the terminal window type diskutil. This displays all the help information and you will need to use the scrollbar to scroll up and down to view it all because there is quite a lot of information.

The simplest command and the most essential, is list. Type diskutil list to see a list of the disks and partitions that are available. Here is the result on a Mac with a single disk drive running OS X Lion.

Diskutil in OS XLook at the identifier column on the right. The first item is disk0, which is the internal hard disk drive in this Mac. The items below are the partitions on it and disk0s1, called EFI, is used for booting the Mac and is essential. The next partition is disk0s2 and this is called Apple_HFS Macintosh HD. It is 118.5Gb and this is the main boot disk containing OS X and all the files and applications. The third item, disk0s3, is Apple_Boot Recovery HD and it is OS X Lion's recovery partition.

Suppose you want to get detailed information about one of the partitions, such as disk0s2. You would enter diskutil info disk0s2 and a long and detailed report is displayed. Use the scrollbars to scroll up and down to view it all.

Format and erase

Diskutil can be used for format disks and to see what file systems are supported, enter diskutil listfilesystems. Disks or partitions can be erased and you might want to do this for security purposes. You can't erase the internal disk when you're running OS X from it of course, but if you have a large disk with extra partitions or an external drive then enter diskutil zerodisk [disk] where [disk] is the disk identifier - disk0s2 for example, as reported by the list function.

You can also use diskutil randomdisk [disk] to write random data all over the disk, or diskutil secureErase [level] [disk] to securely erase the disk data, where [level] is 0 (single pass, zero written), 1 (single pass random data), 2 (7-pass secure erase), 3 (Gutmann 35-pass) and 4 (US DoE 3-pass).

Don't actually do these unless you are absolutely sure you have selected the right partition. For example, disk0s2 in the screen shot is the partition with OS X on and it wouldn't be a good idea to erase it!

Verify and repair the disk

Here are a couple of commands that are safe to use, diskutil verifyvolume disk0s2 and diskutil verifypermissions disk0s2 - replace disk0s2 with whatever disk you want to check. If there are problems then use diskutil repairvolume disk0s2 and diskutil repairpermissions disk0s2.

More information on diskutil

I have only covered the easy uses of diskutil here and there are many more useful functions that it can perform. However, it does get a bit more complicated and erasing, repairing and formatting are probably all most people need. Get more information on diskutil at the online manual.

Related articles

Securely erase disks with Disk Utility
Use the Lion Recovery Disk
Check your Mac's disk drive for errors
Check for disk faults
Partition your USB disk
Burn ISO images using Disk Utility



copyright