How to Use Mac Diskutil Commands to Manage Disks/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.
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.
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.
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.
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 100GB.
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.
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.
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.
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/.