How to format SSD in Mac terminal?

Solid-state drives (SSDs) are a type of computer storage device that uses flash memory rather than a spinning hard disk to store data. SSDs have no moving parts and provide much faster read/write speeds and access times compared to traditional hard drives. However, out of the box, SSDs usually come formatted in a way that is optimized for Windows computers. To take full advantage of an SSD’s performance on a Mac, it is recommended to reformat the drive using the Mac’s native file system.

There are a few key reasons why you may want to format an SSD for use with Mac:

  • Faster performance – The Mac native APFS file system is optimized for flash storage like SSDs.
  • Compatibility – APFS ensures full compatibility with latest macOS features and Time Machine backups.
  • Encryption – APFS supports full disk encryption to better protect sensitive data.
  • Space efficiency – APFS uses space more efficiently than older Mac file systems.

By reformatting the SSD drive, you can unlock its full potential speed and usability on a Mac system.

Prerequisites

Before formatting your SSD in Mac terminal, it’s important to complete a few prerequisites. This ensures you don’t lose any important data during the formatting process.

You’ll need administrative access on your Mac in order to format the SSD [1]. This allows you to make changes to your storage devices.

It’s also crucial that you back up any data you want to keep before formatting the SSD [2]. Formatting will erase all data, so make sure it’s backed up externally or on another drive.

Some other things to do before formatting include [2]:

  • Make a list of installed apps and licenses
  • Back up settings and configuration files
  • Save any widgets, snippets or plugins you want to keep
  • Clean up unused files to simplify the backup process

Completing these steps ensures you don’t lose any important data or customizations during the formatting process.

Launch Terminal

The Terminal app is built into every Mac computer and provides access to the command line interface. Here are a few ways to launch Terminal on your Mac:

Use the Finder to navigate to Applications > Utilities and double click on Terminal to launch it. Alternatively, you can use Spotlight search by hitting Command+Spacebar and typing “Terminal”, then hit Enter.

The fastest method is to use the keyboard shortcut Command+Spacebar then type “terminal” then hit Enter. This will immediately launch a new Terminal window.

You can also configure a custom keyboard shortcut for Terminal. Go to System Preferences > Keyboard > Shortcuts tab, then select App Shortcuts. Click the + button, type “Terminal” for the Application, type a keyboard shortcut like “Ctrl+T”, then click Add.

If you frequently use Terminal, drag it to your Dock for one-click access. Just launch Terminal, then drag the icon from the title bar down to the Dock.

Terminal can also be launched from various IDEs and text editors like Visual Studio Code. Check their documentation for details on integrating their built-in terminal.

No matter how you launch it, the Terminal provides command line access where you can manage files, configure settings, install software and more in macOS.

Unmount SSD

Before formatting the SSD drive, it needs to be unmounted first. This can be done using the diskutil unmount command in Terminal. According to the Apple Discussions thread “unmount disk from terminal”, you can view all mounted drives by running diskutil list. The SSD will likely be at /dev/disk1 or higher. Once you’ve identified the disk, run diskutil unmountDisk /dev/diskX (replace X with the disk number). This will unmount the SSD drive and prepare it for formatting.[1]

List Disks

To view all disks connected to your Mac, including both volumes and drives, you can use the diskutil list command in Terminal. This will display a list of the device nodes for all disks, along with information like the disk’s name, type, size, and partitions.

For example, running diskutil list may display something like:

/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         251.0 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         250.7 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +250.7 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            224.9 GB   disk1s1
   2:                APFS Volume Preboot                 45.3 MB    disk1s2
   3:                APFS Volume Recovery                1.1 GB     disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4

This shows two disks – an internal 250GB drive (/dev/disk0) partitioned with EFI, Apple_APFS and a synthesized APFS container disk (/dev/disk1). The diskutil list output will include all drives connected to your Mac that you can then identify.

Source: https://osxdaily.com/2009/12/01/list-all-mounted-drives-and-their-partitions-from-the-terminal/

Select SSD

The first step in formatting an SSD on Mac is to identify which disk is the SSD. There are a couple ways to do this in Terminal:

List all disks with the command diskutil list. SSDs will typically have “SSD” in the name or description. For example:

/dev/disk2 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:                 Apple_APFS Container disk3         250.8 GB   disk2s2

Here “SSD” is in the physical description, indicating this is the SSD.

You can also use system_profiler SPNVMeDataType to list only NVMe SSD disks. The disk identifier will be shown here.

Once you’ve identified the SSD disk, take note of the disk number (e.g. disk2) to use when formatting.

Format SSD

To format the SSD from the command line, we’ll use the diskutil eraseDisk command. This allows erasing and reformatting a disk from the terminal. The basic syntax is:

diskutil eraseDisk FORMAT DISKNAME

Where FORMAT is the format type like APFS, HFS+, etc. And DISKNAME is the name of the disk you want to format. To find the disk name, you can run diskutil list first.

For example, to format an SSD named “Untitled” to APFS:

diskutil eraseDisk APFS Untitled

This will immediately erase and reformat the disk to APFS. You’ll see a progress indicator as it formats (source).

Be very careful when selecting the disk name, as this will erase all data. Make absolutely sure you have the correct drive selected before executing the command.

Confirm Formatting

Before proceeding with the format, it is crucial to double check that you have selected the correct disk to format. Formatting will erase all data on the disk, so accidentally selecting the wrong disk can lead to catastrophic data loss.

In the Disk Utility sidebar, verify that the disk you intend to format is highlighted. The name, size, and format should match the SSD you want to erase. Also confirm that the volume you are erasing does not contain any important files or the operating system drive.

If you accidentally began formatting the wrong disk, immediately click Cancel in the Disk Utility toolbar. This should stop the formatting process before too much data is lost. However, it is still possible some data has been erased already. To minimize risk, carefully verify your disk selection before clicking Erase in Disk Utility.

For additional precaution, some recommend physically disconnecting any other disks before formatting an SSD. This prevents accidentally selecting and erasing the wrong drive. After formatting is complete, reconnect any other disks.

Format Progress

As the SSD formatting proceeds, you can monitor the status in real time. The progress bar in Disk Utility will show the percentage completed so far. Formatting a drive can take some time depending on the drive size and options selected. For a quick format, it may take 5-10 minutes for a 250GB SSD. For a full format with zeroing out data, it could take several hours.

While the formatting is in progress, don’t disconnect the SSD or shut down the Mac as this can lead to data corruption. Let the process run to completion. You’ll know it’s done when the progress bar reaches 100% and you see a message that the formatting was successful.

If the formatting seems to be taking an excessively long time, you can check for issues like drive errors in Disk Utility. But in most cases, it’s best to just let it continue. Get a cup of coffee and check back later once it’s had sufficient time to complete.

Remount SSD

After formatting the SSD in Disk Utility, you may need to remount the drive to access it in Finder. To remount the SSD, first list the available disks again using the diskutil list command in Terminal. Identify the disk identifier for your SSD from the list. Then use the diskutil mountDisk command along with the disk identifier to remount the disk (source: Apple Support):

For example:

diskutil mountDisk disk2

This will remount the SSD with the disk identifier disk2. After remounting, you should be able to access the SSD normally in Finder.