How to Use Mac Diskutil Commands to Manage Disks/Partitions

Cassie Xie
Last updated: Sep 21, 2023
Summary: In this post, you will learn some useful diskutil commands to do operations to disks and partitions.

Diskutil is a command-line utility that lets you manage disks or partitions in macOS. You can use this tool to view, create, unmount, resize, format, repair disks, etc. This post mainly introduces how to use diskutil commands to realize these tasks. Check the details below.

diskutil commands

How to Use Mac Diskutil Commands to Manage Disks

To access the Diskutil tool in macOS, you need to open the Mac Terminal app first. You can search for Terminal via Spotlight or go to Finder > Applications > Utilities to easily launch Terminal.

After opening Terminal, you can use the diskutil commands. Below are some commonly used commands. Check how to use them to perform various disk tasks.

note
Running command lines may be dangerous since the actions cannot be undone. You should be very careful with using these Mac diskutil commands. Making mistakes may result in data loss. It’s highly advised you back up all your data on the disk before you continue to avoid data loss.

diskutil list

Type diskutil list command and press Enter to view a list of all detected disks and partitions on your Mac. It will display information about the drives and their partitions including the drive identifier, type, and size.

If you want to view the detailed information of a particular disk or partition, you can type the command diskutil list /dev/[disk or partition identifier], for instance, diskutil list /dev/disk0s1.

diskutil partition

To create a new partition on a disk, you can type the command diskutil partition <Disk Identifier> <Name> <Format> <Size>. Replace “Disk Identifier” with the actual identifier of the disk. Replace “Name” with the desired name of the new partition.

For instance, type diskutil partition disk0s3 MyPartitionName APFS 30%. Press Enter and it will create a new APFS partition named MyPartitionName using 30% of the available space on disk0s3.

diskutil resizeVolume

To resize an existing partition, type the command diskutil resizeVolume <Identifier> <Size>, for example, diskutil resizeVolume disk0s3 100g. It will resize the disk0s3 partition to 100 GB.

diskutil unmount

To unmount a disk from your Mac, you can type sudo diskutil unmount /Volumes/diskname. Replace “/Volumes/diskname” with the actual directory of the disk.

Or you can type the command sudo diskutil unmount /dev/diskX. Replace “diskX” with the exact identifier of the disk. You can check it with the “diskutil list” command.

If you can’t eject an external hard drive from your Mac, you can type sudo diskutil unmount force /dev/diskX. Replace “diskX” with the exact identifier of the disk. Press Enter to force unmount the drive on your Mac.

Related: 10 Tips to Fix External Hard Drive Not Mounting on Mac

diskutil verifyVolume/diskutil repairVolume

You can type the command diskutil verifyVolume [drive name] to check the file system data structure of a partition. For an external hard drive, you can type diskutil verifyVolume /Volumes/drive name/.

If it finds errors, you can type the command diskutil repairVolume [drive name] to fix the disk errors. For an external hard drive, type diskutil repairVolume /Volumes/drive name/. Replace “drive name” in these command lines with the real name of the drive.

Alternatively, you can type diskutil verifyVolume or diskutil repairVolume with the identifier of the disk to check and repair the disk errors.

diskutil eraseVolume

To format a partition to a specific file system format, you can type the command diskutil eraseVolume <Format> <Name> <Identifier>. For example, diskutil eraseVolume ExFAT MyVolumeName disk0s2.

Alternative to Mac Diskutil Commands

If you are not familiar with diskutil commands, you can use an alternative way to manage disks and partitions on your Mac. Mac comes with a built-in Disk Utility app. You can use it to easily perform different operations on your disk or partition, e.g., mount/unmount the hard drive, create/delete volume, erase/format disk, check and repair disk errors, etc.

Best Way to Free Up Disk Space on Your Mac

To make your Mac run faster and have more free space, you can use a professional Mac cleaner tool like BuhoCleaner.

BuhoCleaner lets you flash clean your Mac to release much free space. It also allows you to uninstall apps without leftovers, find and delete large files or duplicate files, manage startup items on Mac, free up RAM, and more.

DownloadFor macOS 10.10 and above
100,000+ Satisfied Users Worldwide
Clean Mac with BuhoCleaner

Bottom Line

This post mainly introduces how to use diskutil commands on Mac to manage disks and partitions. For other Mac tips and tricks, you may visit our official website: https://www.drbuho.com/.

Cassie has been writing about technology for her entire career life - over 5 years. She enjoys diving into how Apple products work and then breaking it down in a way anyone can understand.