Skip to content

Instantly share code, notes, and snippets.

@Raefael
Created June 12, 2013 07:34
Show Gist options
  • Save Raefael/5763462 to your computer and use it in GitHub Desktop.
Save Raefael/5763462 to your computer and use it in GitHub Desktop.
Deleting and merging a partition with diskutil from the command line OS X
/**
* diskutil list shows you the partitions currently connected to your unit
**/
imac:~ user$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 987.2 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
4: Apple_HFS eDrive 12.0 GB disk0s4
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk1
1: EFI 209.7 MB disk1s1
2: Apple_HFS Backup 999.9 GB disk1s2
imac:~ user$
/**
* to delete a partition you can also use diskutil eraseVolume followed by partition type, partition name and the path
**/
imac:~ user$ diskutil eraseVolume HFS+ eDrive /dev/disk0s4
/**
* to merge partitions use diskutil mergePartitions the syntax is nearly the same as above
* diskutil mergePartitions partition type, partition name and the the identifier of the partition you want to merge
* the first given partition in row will absorbing the space from the followed partitions and would be expanded
* BEWARE backup your files, all files on the used partitions will be deleted
*
* The example below merging the partitions disk0s2 disk03s disk04s to one partition disk02s named brandnew with the HFS+ filetype
**/
imac:~ user$ diskutil mergePartitions HFS+ brandnew disk0s2 disk03s disk04s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment