Get the best SMM Services at the most unbeatable prices Get Now!

Mac Terminal diskutil Command Examples

 The diskutil command operates on disk partitions: mounting and unmounting, getting information, renaming, erasing, and more. Read-only operations can be done by any user, but writing and mounting require an administrator. For example, if you have a portable USB drive mounted:

$ df -h /Volumes/MyUSB
Filesystem      Size   Used  Avail Capacity  Mounted on
/dev/disk1s2   1.8Ti  813Mi  1.8Ti     1%    /Volumes/MyUSB

you can unmount it with either of these diskutil commands, by providing the directory where it’s mounted:

$ sudo diskutil unmount /Volumes/MyUSB
Volume MyUSB on disk1s2 unmounted

or the associated device in the /dev directory:

$ sudo diskutil unmount /dev/disk1s2
Volume MyUSB on disk1s2 unmounted

Finding out about disks in your system

For information on all available disks and their partitioning, use:

$ diskutil list

For more detailed information on a particular disk or partition, use:

$ diskutil info [disk or partition]

The default Apple partitioning scheme uses the last physical partition on a disk for storing data. Here is sample output from diskutil list showing a hard disk and a CD. The UNIX device name is shown first, along with the contents of each partition:

$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         121.1 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +121.1 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD - Data     62.5 GB    disk1s1
   2:                APFS Volume Preboot                 404.5 MB   disk1s2
   3:                APFS Volume Recovery                1.1 GB     disk1s3
   4:                APFS Volume VM                      5.4 GB     disk1s4
   5:                APFS Volume Macintosh HD            15.8 GB    disk1s5
   6:              APFS Snapshot com.apple.os.update-... 15.8 GB    disk1s5s1

Here is sample output from diskutil info on a particular disk:

$ diskutil list /dev/disk0s2
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         121.1 GB   disk0s2

Checking partitions for integrity and fixing them

You can use diskutil to check the file system data structure of a partition (e.g., /dev/disk0s3) with:

$ diskutil verifyVolume partition

If errors are you found, you can fix them with:

$ diskutil repairVolume partition

Checking partitions for UNIX permission problems and repairing them

You can use diskutil to check the UNIX permissions on a partition with:

$ diskutil verifyPermissions partition

If errors are you found, you can fix them with:

$ diskutil repairPermissions partition

If permissions get accidentally changed on some system files, it could cause strange behavior or disable certain features of the system.

Finding out about RAID sets

RAID is usually used in servers to provide additional protection from hard disk failure. For information on RAID sets, use:

$ diskutil listRAID

Other diskutil options

In addition to the options listed above, diskutil can be used to reformat disks or partitions, erase writable CDs/DVDs, securely erase data, etc. Here are some of the other features:

  • u[n]mount – Unmount a single volume
  • unmountDisk – Unmount an entire disk (all volumes)
  • eject – Eject a removable disk
  • mount – Mount a single volume
  • mountDisk – Mount an entire disk (all mountable volumes)
  • eraseDisk – Erase an existing disk, removing all volumes
  • eraseVolume – Erase an existing volume
  • reformat – Reformat an existing volume
  • eraseOptical – Erase an optical media (CD/RW, DVD/RW, etc.)
  • zeroDisk – Erase a disk, writing zeros to the media
  • randomDisk – Erase a disk, writing random data to the media
  • secureErase – Securely erase a disk or freespace on a volume
  • resizeVolume – Resize a volume, increasing or decreasing its size

Other Examples

1. renaming a partition:

$ sudo diskutil rename /dev/disk1s2 OtherName
Volume on disk1s2 renamed to OtherName

2. Checking its internal structure for errors:

$ sudo diskutil verifyVolume /dev/disk1s2
Started filesystem verification on disk1s2 MyUSB
Checking Journaled HFS Plus volume
Checking extents overflow file
...

3. List the available filesystems.

$ diskutil listFilesystems
PERSONALITY                     USER VISIBLE NAME                               
-------------------------------------------------
ExFAT                           ExFAT
MS-DOS FAT32                    MS-DOS (FAT32)
HFS+                            Mac OS Extended
...

4. Erase a filesystem:

$ diskutil erase HFS+ CoolDisk /dev/disk1s2
Started erase on disk1s2 CoolDisk ...

See the man page for even more!

# man diskutil
Tags

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !