How to Repair Hard Disks with fsck on macOS

When your hard drive starts to fail, Disk Utility offers some useful disk repair tools. But if they don’t get it done for you, you might want to turn to one of the big guns: fsck. fsck, which stands for “File System Consistency Check,” is a command-line tool that reviews and repairs the underlying structure of a hard drive. And while we all hope we never have to use it, here’s a brief introduction into its functionality.

Note: the fsck tool in Mac is the same as the one found in Linux. This article is written with a focus on Mac’s user interface.

Before you can run fsck, you’ll need to find the device node and identifier of the disk you want to target. We’ll use Terminal’s diskutil command to accomplish that.

1. Open Terminal (/Applications/Utilities/Terminal.app)

2. Type the following command, then press “Enter.”

diskutil list

terminal-diskutil-list

3. This will produce a list of all the currently connect drives, both mounted and unmounted.

terminal-diskutil-list-result

4. Locate the disk you want to run fsck on and find its device identifier. It will look like /dev/disk1, and you’ll find this information along the left margin of the Terminal window. Write this information down somewhere since you’ll need it in the next steps.

terminal-diskutil-list-result-2

fsck is a powerful utility, but macOS won’t let you run it from inside the operating system. You might think you can run fsck on a non-booting disk, but you’d be wrong: fsck is basically non-functional while in macOS’s userland. You’ll need to reboot into Single User mode, which is a stripped-down, text-only, superuser interface for macOS.

1. Restart your computer.

fsck-restart-mac

2. Hold down “Command + S” while your computer restarts. You can release the keys once you see white text start to appear on the startup screen.

3. Some white text will scroll by quickly. When it stops, you’ll see a command prompt at the bottom of the screen that says root#.

fsck-single-user-mode-1

If the text stops scrolling but you don’t see this prompt, press the “Enter” key once to reveal it.

4. To repair the boot disk, type in the following command, then press “Enter.”

/sbin/fsck -fy

fsck-single-user-mode-2

This runs fsck with the -f flag which forces it to check journaled file systems like HFS+, as well as the -y flag, which automatically says “yes” to any prompts that fsck might encounter. Keep in mind that the -y flag can be a little dangerous: as the fsck’s man page points out, “this should be used with great caution, as this is a free license to continue after essentially unlimited trouble has been encountered.

5. You can also use fsck to repair non-boot disks, but you’ll need to know the filesystem type. For example, if I wanted to run fsck on “/dev/disk2.” I might use the following command:

/sbin/fsck_hfs -fy /dev/disk2

fsck-single-user-mode-3

That command will run the HFS sub-version of fsck on that drive. Other available filesystems include fsck_msdos, which runs on FAT file systems; fsck_exfat, which examines ExFAT filesystems; and fsck_udf, which looks at UDF file systems.

4. fsck will check the file system and attempt to repair any damage that it finds. If it finds no damage, it will exit with “OK.”

5. When fsck is finished checking and repairing the filesystem, type reboot into the command prompt and press “Enter.”

fsck on the Mac isn’t as powerful as fsck on Linux, but it can still be a lifesaver if you end up with a corrupted boot disk or damaged hard drive.

Leave a Reply

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.