diskutil

From RaySoft

diskutil manipulates the volume-level structure of local disks. It provides information about, and allows the administration of, the partitioning scheme of disks, optical discs, and 'AppleRAID' sets.[1]

Documentation

Subcommands & Parameters

enableOwnership DEVICE
Enable ownership of a volume. The on-root-disk Volume Database at /var/db/volinfo.database is manipulated such that the User and Group ID settings of files, directories, and links on the target volume are taken into account.
This setting for a particular volume is persistent across ejects and injects of that volume as seen by the current OS, even across reboots of that OS, because of the entries in this OS's Volume Database.
NOTE:
The setting is not kept on the target disk, nor is it in-memory.
See also the vsdbutil command.
disableOwnership DEVICE
Disable ownership of a volume. See enableOwnership above.
eraseDisk FORMAT NAME DEVICE
Erase an existing disk, removing all volumes and writing out a new partitioning scheme containing one new empty file system volume. If the partitioning scheme is not specified, then an appropriate one for the current machine is chosen.
NOTE:
Ownership of the affected disk is required.
list [internal | external] [physical | virtual] [DEVICE]
List disks, including internal and external disks, whole disks and partitions, and various kinds of virtual or offline disks.
If no argument is given, then all whole disks and their partitions are listed.
secureErase [freespace] LEVEL DEVICE
Securely erase a disk or freespace on a mounted DEVICE. Ownership of the affected disk is required. LEVEL should be one of the following:
  • 0 for Single-pass zero-fill erase.
  • 1 for Single-pass random-fill erase.
  • 2 for US DoD 7-pass secure erase.
  • 3 for Gutmann algorithm 35-pass secure erase.
  • 4 for US DoE algorithm 3-pass secure erase.
unmountDisk [force] DEVICE
Unmount an entire DEVICE.

Examples

Create an ISO image from a CD or DVD on macOS

Show all external physical devices to find the correct device

diskutil list 'external' 'physical'

Unmount the CD or DVD

diskutil unmountDisk '/dev/disk3'

Create the ISO image

dd if='/dev/disk3s0' of="${HOME}/tmp/cd-image.iso"
Overwrite free space on device '/dev/disk0s2' with random data
diskutil secureErase freespace 1 '/dev/disk0s2'
Format a USB flash drive for use with Windows

Show all external physical devices to find the correct device

diskutil list 'external' 'physical'

Format the USB flash drive

diskutil eraseDisk 'FAT32' 'DRIVE_NAME' '/dev/disk3'
Create a bootable USB flash drive from a ISO image on macOS

Show all external physical devices to find the correct device

diskutil list 'external' 'physical'

Format the USB flash drive with FAT32

sudo diskutil eraseDisk 'FAT32' 'DRIVE_NAME' 'MBR' '/dev/disk3'

Umount the USB flash drive

sudo diskutil unmountDisk '/dev/disk3'

Copy the ISO image to the USB flash drive

sudo dd if='image.iso' of='/dev/disk3' bs='4M' status='progress'

Eject the USB flash drive

sudo diskutil eject '/dev/disk3'

References

  1. man 8 'diskutil'