/
_diskutil
276 lines (267 loc) · 14.1 KB
/
_diskutil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#compdef diskutil
# -----------------------------------------------------------------------------
# The BSD-3-Clause License
#
# Copyright (c) 2016, Koichi Shiraishi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of que nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
function _diskutil() {
local context curcontext=$curcontext state line ret=1
declare -A opt_args
local -a commands
commands=(
'list:List the partitions of a disk'
'info:Get information on a specific disk or partition'
'information:Get information on a specific disk or partition'
'listFilesystems:List file systems available for formatting'
'activity:Continuous log of system-wide disk arbitration'
'umount:Unmount a single volume'
'unmount:Unmount a single volume'
'unmountDisk:Unmount an entire disk (all volumes)'
'eject:Eject a disk'
'mount:Mount a single volume'
'mountDisk:Mount an entire disk (all mountable volumes)'
'enableJournal:Enable HFS+ journaling on a mounted HFS+ volume'
'disableJournal:Disable HFS+ journaling on a mounted HFS+ volume'
'moveJournal:Move the HFS+ journal onto another volume'
'enableOwnership:Exact on-disk User/Group IDs on a mounted volume'
'disableOwnership:Ignore on-disk User/Group IDs on a mounted volume'
'rename:Rename a volume'
'renameVolume:Rename a volume'
'verifyVolume:Verify the file system data structures of a volume'
'repairVolume:Repair the file system data structures of a volume'
'verifyDisk:Verify the components of a partition map of a disk'
'repairDisk:Repair the components of a partition map of a disk'
'eraseDisk:Erase an existing disk, removing all volumes'
'eraseVolume:Erase an existing volume'
'reformat:Erase an existing volume with same name and type'
'eraseOptical:Erase 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'
'partitionDisk:(re)Partition a disk, removing all volumes'
'resizeVolume:Resize a volume, increasing or decreasing its size'
'splitPartition:Split an existing partition into two or more'
'mergePartitions:Combine two or more existing partitions into one'
'appleRAID:Perform additional verbs related to AppleRAID'
'coreStorage:Perform additional verbs related to CoreStorage'
'apfs:Perform additional verbs related to APFS'
)
_arguments -C \
"1: :{_describe 'diskutil subcommand' commands}" \
'*:: :->args' \
&& ret=0
case $state in
args)
case $words[1] in
apfs)
local -a apfs_cmds
apfs_cmds=(
'list:Show status of all current APFS Containers'
'create:Create a new APFS Container with one APFS Volume'
'createContainer:Create a new empty APFS Container'
'deleteContainer:Delete an APFS Container and reformat old disks to HFS'
'resizeContainer:Resize an APFS Container and its disk space usage'
'addVolume:Export a new APFS Volume from an APFS Container'
'deleteVolume:Remove an APFS Volume from its APFS Container'
'eraseVolume:Erase contents of, but keep, an APFS Volume'
{chrole,changeVolumeRole}:'Change the Role metadata bits of an APFS Volume'
)
_arguments -C \
"1: :{_describe 'apfs subcommand' apfs_cmds}" \
'*:: :->args' \
&& ret=0
case $words[1] in
list)
_arguments -C \
'-plist[property list will be emitted instead of the normal user-readable output]'\
&& ret=0
;;
create)
# Usage: diskutil apfs create <disk> <name>
# where <disk> = MountPoint|DiskIdentifier|DeviceNode
# <name> = a volume name
# Create an empty APFS Container and add one unencrypted space-sharing APFS
# Volume with the given name to it. This verb is a limited combination of the
# diskutil apfs createContainer and diskutil apfs addVolume verbs.
# Ownership of the affected disks is required.
# Example: diskutil apfs create disk0s2 MyTestVolume
_arguments -C \
'1:where MountPoint|DiskIdentifier|DeviceNode' \
'2:name' \
&& ret=0
;;
createContainer)
# Usage: diskutil apfs createContainer <disk>
# where <disk> = MountPoint|DiskIdentifier|DeviceNode
# Create an empty APFS Container. You can then add APFS Volumes with the
# diskutil apfs addVolume verb.
# Ownership of any affected disks is required.
# Example: diskutil apfs createContainer disk0s2
_arguments -C \
'1:where MountPoint|DiskIdentifier|DeviceNode' \
&& ret=0
;;
deleteContainer)
# Usage: diskutil apfs deleteContainer <containerRefDisk> [<name>]
# diskutil apfs deleteContainer <physicalStoreDisk> [<name>]
# where <containerRefDisk> = Container Reference DiskIdentifier
# <name> = a new name (base) for the old Physical Store(s)
# <physicalStoreDisk> = DiskIdentifier to use if Container damaged
# Delete an APFS Container. All of its APFS Volumes will be deleted, and all of
# its former APFS Physical Store disks will be reformatted as HFS. Data on all
# APFS Volumes will be lost. You can optionally specify a new name, or else
# "Untitled" will be chosen. If there are multiple Physical Stores, a space
# and a number suffix is added for each.
# Ownership of the affected disks is required.
# Example: apfs deleteContainer disk5
_arguments -C \
'1:<containerRefDisk> Container Reference DiskIdentifier' \
'2:<name> new name (base) for the old Physical Store(s)' \
'3:<physicalStoreDisk> DiskIdentifier to use if Container damaged' \
&& ret=0
;;
resizeContainer)
# Usage: diskutil APFS resizeContainer <physicalStoreDisk> <newSize> [<triple>*]
# where <physicalStoreDisk> = A Physical Store disk backing the Container
# <newSize> = The desired new on-disk size for that Physical Store
# <triple> = A { fileSystemPersonality, name, size } tuple
# Resize an APFS Container. The Container's Physical Store disk which you specify
# will be resized, and therefore its Container will be resized by an equal
# amount. If the requested new size is smaller than the existing size, you may
# specify ordered triples in the same manner as diskutil partitionDisk, etc, to
# fill the partition map's free space gap that would otherwise result.
# Ownership of the affected disks is required.
# Example: diskutil apfs resizeContainer disk0s2 40g
# diskutil apfs resizeContainer disk0s2 30g jhfs+ foo 10g ms-dos BAR r
_arguments -C \
'1:<physicalStoreDisk> A Physical Store disk backing the Container' \
'2:<newSize> The desired new on-disk size for that Physical Store' \
'3:<triple> A { fileSystemPersonality, name, size } tuple' \
&& ret=0
;;
addVolume)
# Usage: diskutil apfs addVolume <containerRefDisk> <fs> <name>
# [-reserve <reserveSize>] [-quota <quotaSize>]
# [-en[crypt]ion | -[eff]aceable] [-role <roles>]
# [-nomount | -mountpoint <mountPoint>]
# where <containerRefDisk> = Container Reference DiskIdentifier
# <fs> = an APFS personality: specify "APFS"
# <name> = a volume name
# <reserveSize> = optional minimum guaranteed file data capacity
# <quotaSize> = optional maximum file data usage limit
# -encryption = enable per-file encryption
# -effaceable = enable O(1)-time cryptographic erase
# <roles> = one or more of 0|B|U|S|R|V; see changeVolumeRole
# <mountPoint> = a custom mount point (path must already exist)
# Add a new APFS Volume to an existing APFS Container.
# Ownership of the affected disks is required.
# Example: diskutil apfs addVolume disk5 APFS VirtualSpaceVolume
# diskutil apfs addVolume disk5 APFS Fixed -quota 10g -reserve 10g
# diskutil apfs addVolume disk5 APFS QuickErasableShared -eff
# diskutil apfs addVolume disk5 APFS CryptoLimited -crypt -quota 5g
# diskutil apfs addVolume disk5 APFS System -role S
_arguments -C \
'-reserve[optional minimum guaranteed file data capacity]:reserveSize' \
'-quota[optional maximum file data usage limit]:quotaSize' \
(-fileencryption -encryption -crypt){-fileencryption,-encryption,-crypt}'[enable per-file encryption]' \
'-effaceable[enable O(1)-time cryptographic erase]' \
'-role[one or more of 0|B|U|S|R|V; see changeVolumeRole]:roles' \
'-nomount[nomount]' \
'-mountpoint[]:mountPoint' \
'1:<physicalStoreDisk> A Physical Store disk backing the Container' \
'2:<newSize> The desired new on-disk size for that Physical Store' \
'3:<triple> A { fileSystemPersonality, name, size } tuple' \
&& ret=0
;;
deleteVolume)
# Usage: diskutil apfs deleteVolume <apfsVolumeDisk>
# where <apfsVolumeDisk> = APFS Volume DiskIdentifier
# Remove the given APFS Volume from its APFS Container, losing all of its data.
# Ownership of the affected disks is required.
# Example: diskutil apfs deleteVolume disk5s1
_arguments -C \
'1:<apfsVolumeDisk> APFS Volume DiskIdentifier' \
&& ret=0
;;
eraseVolume)
# Usage: diskutil apfs eraseVolume <apfsVolumeDisk>
# where <apfsVolumeDisk> = APFS Volume DiskIdentifier
# Erase the contents of the given APFS Volume, losing all of its data. Unlike
# deleteVolume, the APFS Volume is not removed from its APFS Container. The new
# APFS Volume will inherit format, name, size, and crypto attributes from the old
# APFS Volume.
# Ownership of the affected disks is required.
# Example: diskutil apfs eraseVolume disk5s1
_arguments -C \
'1:<apfsVolumeDisk> APFS Volume DiskIdentifier' \
&& ret=0
;;
(chrole|changeVolumeRole)
# Usage: diskutil apfs changeVolumeRole|chrole <apfsVolumeDisk> <roles>
# where <apfsVolumeDisk> = APFS Volume DiskIdentifier
# <roles> = one or more of 0|clear|b|u|s|r|v|B|U|S|R|V
# Change the role metadata flag bits of the existing APFS Volume. Unspecified
# bits are left alone; lower case clears a bit; upper case sets a bit; clear
# clears all bits; 0 is ignored. You should not make any assumptions about the
# usage or legal combinations of role bits.
# Ownership of the affected disks is required.
# Example: diskutil apfs changeVolumeRole disk5s1 U
_arguments -C \
'1:<apfsVolumeDisk> APFS Volume DiskIdentifier' \
'2:<roles> one or more of 0|clear|b|u|s|r|v|B|U|S|R|V' \
&& ret=0
;;
esac
;;
list)
_arguments \
'-plist[output user-readable property list]'
'*:devices:__devices'
;;
info)
_arguments \
'-plist[output user-readable property list]' \
'-all[output the all disks whole disks and their partitions]'
'*:devices:__devices'
;;
activity)
_arguments \
;;
listFilesystems)
_arguments \
'-plist[output user-readable property list]'
;;
esac
;;
esac
return ret
}
_diskutil "$@"
# vim:ft=zsh:et:sts=2:sw=2