Macos Terminal Commands To Check Apfs Disk For Errors

Macos Terminal Commands To Check Apfs Disk For Errors Mac

Modifying this control will update this page automatically

All of the commands below should be used in Terminal app on macOS 10.13 (High Sierra) and macOS 10.14 (Mojave). Highlighted in bold parts should be replaced with your own respective volume name, disk.

Disk Utility User Guide

Disk Utility can fix certain disk problems—for example, multiple apps quit unexpectedly, a file is corrupted, an external device doesn’t work properly, or your computer won’t start up. Disk Utility can’t detect or repair all problems that a disk may have.

If you run First Aid on a disk, Disk Utility checks the partition maps on the disk and performs some additional checks, and then checks each volume. If you run First Aid on a volume, Disk Utility verifies all the contents of that volume only.

  1. In the Disk Utility app on your Mac, choose View > Show All Devices.

    Note: If you’re checking your startup disk or startup volume, restart your computer in macOS Recovery, select Disk Utility in the macOS Utilities window, then click Continue. If you check your startup volume (Macintosh HD), make sure you also check your data volume (Macintosh HD - Data).

  2. In the sidebar, select a disk or volume, then click the First Aid button .

    If Disk Utility tells you the disk is about to fail, back up your data and replace the disk—you can’t repair it. Otherwise, continue to the next step.

  3. Click Run, then click Continue.

    If Disk Utility reports that the disk appears to be OK or has been repaired, you’re done. You can click Show Details to see more information about the repairs. Otherwise, you may need to do one of the following.

    • If Disk Utility reports “overlapped extent allocation” errors, two or more files occupy the same space on your disk, and at least one of them is likely to be corrupted. You need to check each file in the list of affected files. Most of the files in the list have aliases in a DamagedFiles folder at the top level of your disk.

      • If you can replace a file or re-create it, delete it.

      • If it contains information you need, open it and examine its data to make sure it hasn’t been corrupted.

    • If Disk Utility can’t repair your disk, or you receive a report that the First Aid process failed, try to repair the disk or partition again. If that doesn’t work, back up as much of your data as possible, reformat the disk, reinstall macOS, then restore your backed-up data.

If your Mac has a Fusion Drive and you see a flashing question mark or alert, see the troubleshooting section of the Apple Support article About Fusion Drive, a storage option for some Mac computers.

If you continue to have problems with your disk or it can’t be repaired, it may be physically damaged and need to be replaced. For information about servicing your Mac, see Find out how to service or repair your Mac.

See alsoErase and reformat a storage device in Disk Utility on MacAdd, delete, or erase APFS volumes in Disk Utility on MacPartition a physical disk in Disk Utility on Mac

diskutil is the command line version of Disk Utility, the macOS application used to manage hard drives. Just like Disk Utility, you can use the command to format disks, erase drives and more. Once you’re familiar with it, you’ll find that the command is often more powerful and faster than Disk Utility, with more features to boot.

Getting Acquainted with diskutil

If you simply type diskutil into the command line and press Enter, you’ll receive a list of “verbs” that diskutil can operate on.

Just like in the English language, these verbs are things that diskutil can accomplish. The most basic verb for diskutil is list, which you’ll enter like so:


This command will list all the disks attached to your machine. It indicates information like partitions, format and, importantly, mount points. The mount points start with /dev/disk and are used to specify disk operations in diskutil. Partitions (called “volumes” in diskutil parlance) are specified by their identifier on the right.

Disk identifiers follow the format disk_s_, where the underscores are replaced with identifying numbers.

Terminal

Using verbs

We can use the other verbs to get more information about our drives and run specific operations.

The info verb gets more information about a specific disk (disk1, in this case). Use the mount point to specify the target disk to grab information on. You’ll see tons of stuff you might care about and a lot of stuff you won’t. This is the most information you can get about your disk in one place, and it’s helpful when troubleshooting drive problems.

Unmounting and Ejecting with diskutil

The umount verb unmounts a specified volume. Unmounting is just like ejecting a volume from Finder, but it can be done to internal disks. In this example, I’ve specified the volume I want to unmount with the disk identifier. You can also specify the volume using the partition name. Unmounted disks become inaccessible via Finder, but they can still be seen via diskutil list and manipulated with other diskutil commands. Also, note the command is umount, with no “n”.

The unmountDisk verb is similar to umount, but it unmounts an entire disk instead of one volume. Disks are specified with their mount point, as seen above. You can’t unmount your boot disk or volume, and you’ll get an error if you try to unmount a disk or drive that’s currently in use.

The eject verb is a lot like unmounting a drive, but only for removable disks. Removable disks are things like USB hard drives and flash drives. If it connects through an interface on the outside of your computer, it qualifies as a removable drive. Once a drive is ejected, it won’t appear in Finder or diskutil list until it’s physically unplugged and plugged in to its interface again.

The mount verb is the inverse of the umount verb. It mounts volumes on internal disks manually. Only unmounted volumes can be mounted, obviously. To mount all volumes on a disk, use diskutil mountDisk disk1, for example.

Fixing Problems with diskutil

The verifyVolume verb will run a verification pass on a specific volume. Verification involves checking the contents of the disk against the expected values. If any mismatches are found, the disk will be identified as in need of repair.

If it turns out that your volume needs to be repaired after you’ve verified it, you can run the repairVolume verb. This will run a repair pass on the volume and attempt to fix any problems found in the verification process.

Format and Erase Drives with diskutil

The eraseDisk verb handles reformatting disks, which erases all data and volumes on a single disk. The verb takes as inputs the format, new disk name and disk identifier, in that order. This example will erase disk2 and reformat it as journaled HFS+. The new disk will have one volume named

The reformat verb will erase a single volume on the disk while keeping the same name and format. It rewrites the same file system that the volume started with, resetting the volume to a blank state.

Partition Drives with diskutil

The partitionDisk verb runs an command-line version of Disk Utility, allowing you to create multiple partitions on a single disk. It’s a little complicated, but it follows this format for it’s arguments:

diskutil partitionDisk MountPoint[numberOfPartitions] [APM|MBR|GPT] [part1Format part1Name part1Size part2Format part2Name part2Sizepart3Format part3Name part3Size ...]

Partition sizes can be specified in gigabytes with the G suffix (2 G) or terabytes with the T suffix (2 T). My favorite way to specify partition sizes, however, is with percentages (25%, for example). The size of the final partition can be specified with “R” to indicate that it should take up the remainder of the disk.

For example, the following command will create three partitions:

They’ll be formatted with JHFS+, APFS and ExFAT, and named Volume1, Volume2 and Volume3 respectively. Volume1 and Volume2 will each take up 25 percent of the disk, and Volume3 will occupy the remainder. It will also use the GUID Partition Table (GPT) which is one of the more flexible partition table options.

You can see the results of the operation at the end of the Terminal window to determine everything went okay. Using partionDisk isn’t the easiest way to partition a disk, but if Disk Utility is complaining, its a good alternative.

You might also like:

Terminal Tips: Making Terminal More User-Friendly

Macos Terminal Commands To Check Apfs Disk For Errors Free

Getting Started with Terminal: Using Grep to Search Files

Macos Terminal Commands To Check Apfs Disk For Errors In Excel

Getting Started with Terminal: Must-Know macOS Terminal Commands