Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.
The Disk Utility application is a powerful tool for keeping the drives that are connected to your Mac happy and healthy. But there are situations in which it may not be available. As an example, connecting to a remote computer via SSH, or Disk Utility simply refusing to launch.
In this tutorial, I’ll show you how to:
- Find a disk that may have an error
- Verify a disk from the command line
- Repair that disk (if need be) from the command line
Before I take you any further, you need to understand a couple of things:
- I will be working on an SD Card I have inserted into my mac. If you need to target your Mac's hard drive, make sure you substitute the word Macintosh HD for SD in any of the commands I am showing in this article.
- These instructions are not meant for novice Mac users. If you aren't at least a bit comfortable in Terminal, you may want to stick to the graphical user interface applications like Disk Utility.
Locating the Disk
All of the disks that are attached to the Mac are located within the Volumes directory in Terminal. This directory is located one step away from the root of the Mac. The command used to switch from directory to directory is
cd. In the terminal a
/is known as the root, or lowest level, directory.
So to switch to the Volumes directory, open Terminal and type or paste in this command:
cd /Volumes. The Terminal window should now look very similar to this:
ls and press Return. You’ll be shown a list of disks attached to your Mac.
Verify the Disk
Once you have the list of disks, you can target one or many of them for verification and repair. To start the verification process, type the following command, while being sure to substitute the
[drive identifier] portion for the actual name of the drive.
diskutil verifyVolume [drive identifier]
If you are targeting the Mac's hard drive you can also simply use a
/. You will see something that looks like this:
This test came back successful. So I can be confident in the drive and its ability to store data. If there was an error I would see a message that reads:
The volume [volume tested] was found corrupt and needs to be repaired.
Repairing the Disk
Assume, for a moment, that the disk did come back with an error or needing repair. To repair a disk from the command line, type or paste the following command into terminal:
diskutil repairvolume /Volumes/[drive identifier]/ and press Return.
Just as before, I’ll use
SD as my drive identifier. If you wish to target a different drive, insert the name of that drive instead of
SD. You may also use
/ as the identifier for your Mac's hard drive. Your Terminal window should now look similar to this:
Congratulations! Your disk has now been verified and repaired entirely from the command line.
The Terminal may sometimes feel like an unfamiliar or scary application to use. But it can also be a great place to go when you are in a pinch. In many cases, it may be your only option. So the next time you need to repair a disk, give this method a shot!