← Back to DevBytes

macOS Disk Management: Disk Utility, APFS, CoreStorage

Introduction to macOS Disk Management

macOS disk management is the process of configuring, formatting, and maintaining storage devices on Apple computers. Whether you are setting up a new external drive, managing internal storage, or troubleshooting disk errors, understanding how macOS handles storage is crucial. Effective disk management ensures data integrity, optimizes performance, and provides the flexibility to run multiple operating systems or create secure, encrypted partitions.

Modern macOS relies on a combination of graphical tools and powerful command-line utilities to manage disks. At the heart of this system are the Apple File System (APFS) and the legacy CoreStorage logical volume manager. This tutorial will guide you through these technologies and show you how to manage them effectively using both Disk Utility and the terminal.

Understanding the Core Technologies

To effectively manage disks on macOS, you must first understand the underlying file systems and volume managers that the operating system uses to structure data.

APFS (Apple File System)

Introduced in macOS 10.13 High Sierra, APFS is the default file system for Mac computers. It was designed specifically for flash and solid-state drives, though it works perfectly on mechanical hard drives as well. APFS brings several modern features to macOS:

CoreStorage

CoreStorage is a logical volume manager introduced in Mac OS X Lion. It was primarily used to manage Fusion Drives (which combine an SSD and an HDD into a single logical volume) and to handle full-disk encryption via FileVault 2. With the transition to APFS, Apple largely deprecated CoreStorage. APFS now handles Fusion Drives and encryption natively. However, CoreStorage volumes still exist on older Macs that were upgraded to newer versions of macOS without being converted to APFS.

Using Disk Utility

Disk Utility is the built-in graphical application for managing disks. It allows users to format drives, create partitions, restore volumes, and verify disk health. While the GUI is user-friendly, macOS also includes a robust command-line equivalent called diskutil. The command-line tool offers advanced options not available in the GUI, making it essential for developers and system administrators.

Listing and Identifying Disks

Before modifying any disk, you must identify its identifier. The diskutil list command provides a tree view of all disks and their partitions.

# List all disks and partitions
diskutil list

If you are working with APFS, you can get a more detailed view of the containers and volumes using the APFS-specific command:

# List detailed APFS information
diskutil apfs list

Formatting a Disk as APFS

To erase and format a disk as APFS, you use the eraseDisk verb. Be extremely careful, as this will destroy all data on the target disk. In this example, disk4 is the target disk.

# Format disk4 as APFS with the name "MyExternalDrive"
diskutil eraseDisk APFS MyExternalDrive GPT /dev/disk4

Advanced Command-Line Disk Management

Working with APFS requires understanding the distinction between physical disks, containers, and volumes. A physical disk (e.g., /dev/disk0) hosts an APFS container (e.g., /dev/disk1). Inside the container, you create APFS volumes (e.g., /dev/disk1s1).

Working with APFS Containers

Because APFS uses space sharing, you typically create a container on a physical disk and then add multiple volumes to it. Here is how you can create a new APFS container on a specific partition.

# Create a new APFS container on disk2s1
diskutil apfs createContainer /dev/disk2s1

The command will output a new container identifier (e.g., 12345678-1234-1234-1234-123456789abc). You will use this identifier to add a new volume to the container.

# Add a new volume named "Development" to the container
diskutil apfs addVolume 12345678-1234-1234-1234-123456789abc APFS Development

Resizing APFS Volumes

One of the benefits of APFS is that you generally do not need to resize volumes because they share the container's free space. However, if you need to adjust the minimum or maximum reserve sizes, or if you are dealing with legacy partitions, you can use the resize commands.

# Resize an APFS container to a specific size (e.g., 100GB)
diskutil apfs resizeContainer /dev/disk1 100g

Managing Legacy CoreStorage

If you are managing an older Mac that still uses CoreStorage for FileVault or a Fusion Drive, you can inspect the logical volume groups using the coreStorage verb.

# List all CoreStorage logical volume groups
diskutil coreStorage list

If you want to upgrade a legacy CoreStorage volume to APFS, macOS usually handles this during an OS upgrade. However, you can manually unlock an encrypted CoreStorage volume from the command line if you are booted into Recovery Mode:

# Unlock a CoreStorage volume (replace UUID with your logical volume UUID)
diskutil coreStorage unlockVolume 12345678-1234-1234-1234-123456789abc

Best Practices for macOS Disk Management

Conclusion

Mastering macOS disk management requires a solid understanding of APFS, the legacy CoreStorage system, and the powerful diskutil command-line tool. By utilizing APFS containers and space sharing, developers and system administrators can create flexible, secure, and high-performance storage setups. While the Disk Utility GUI is sufficient for basic tasks, the terminal provides the granular control necessary for advanced configurations. Always remember to back up your data before making structural changes to your file system, and embrace APFS as the modern standard for macOS storage.

— Ad —

Google AdSense will appear here after approval

← Back to all articles