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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
=============================
Basic Block Device Commands
=============================
.. index:: Ceph Block Device; image management
The ``rbd`` command enables you to create, list, introspect and remove block
device images. You can also use it to clone images, create snapshots,
rollback an image to a snapshot, view a snapshot, etc. For details on using
the ``rbd`` command, see `RBD – Manage RADOS Block Device (RBD) Images`_ for
details.
.. important:: To use Ceph Block Device commands, you must have access to
a running Ceph cluster.
Create a Block Device Pool
==========================
#. Use the ``ceph`` tool to `create a pool`_.
#. Use the ``rbd`` tool to initialize the pool for use by RBD:
.. prompt:: bash $
rbd pool init <pool-name>
.. note:: The ``rbd`` tool assumes a default pool name of 'rbd' if no pool
name is specified in the command.
Create a Block Device User
==========================
Unless otherwise specified, the ``rbd`` command uses the Ceph user ID ``admin``
to access the Ceph cluster. The ``admin`` Ceph user ID allows full
administrative access to the cluster. We recommend that you acess the Ceph
cluster with a Ceph user ID that has fewer permissions than the ``admin`` Ceph
user ID does. We call this non-``admin`` Ceph user ID a "block device user" or
"Ceph user".
To `create a Ceph user`_, use the ``ceph auth get-or-create`` command to
specify the Ceph user ID name, monitor caps (capabilities), and OSD caps
(capabilities):
.. prompt:: bash $
ceph auth get-or-create client.{ID} mon 'profile rbd' osd 'profile {profile name} [pool={pool-name}][, profile ...]' mgr 'profile rbd [pool={pool-name}]'
For example: to create a Ceph user ID named ``qemu`` that has read-write access
to the pool ``vms`` and read-only access to the pool ``images``, run the
following command:
.. prompt:: bash $
ceph auth get-or-create client.qemu mon 'profile rbd' osd 'profile rbd pool=vms, profile rbd-read-only pool=images' mgr 'profile rbd pool=images'
The output from the ``ceph auth get-or-create`` command is the keyring for the
specified Ceph user ID, which can be written to
``/etc/ceph/ceph.client.{ID}.keyring``.
.. note:: Specify the Ceph user ID by providing the ``--id {id} argument when
using the ``rbd`` command. This argument is optional.
Creating a Block Device Image
=============================
Before you can add a block device to a node, you must create an image for it in
the :term:`Ceph Storage Cluster`. To create a block device image, run a command of this form:
.. prompt:: bash $
rbd create --size {megabytes} {pool-name}/{image-name}
For example, to create a 1GB image named ``bar`` that stores information in a
pool named ``swimmingpool``, run this command:
.. prompt:: bash $
rbd create --size 1024 swimmingpool/bar
If you don't specify a pool when you create an image, then the image will be
stored in the default pool ``rbd``. For example, if you ran this command, you
would create a 1GB image named ``foo`` that is stored in the default pool
``rbd``:
.. prompt:: bash $
rbd create --size 1024 foo
.. note:: You must create a pool before you can specify it as a source. See
`Storage Pools`_ for details.
Listing Block Device Images
===========================
To list block devices in the ``rbd`` pool, run the following command:
.. prompt:: bash $
rbd ls
.. note:: ``rbd`` is the default pool name, and ``rbd ls`` lists the commands
in the default pool.
To list block devices in a particular pool, run the following command, but
replace ``{poolname}`` with the name of the pool:
.. prompt:: bash $
rbd ls {poolname}
For example:
.. prompt:: bash $
rbd ls swimmingpool
To list "deferred delete" block devices in the ``rbd`` pool, run the
following command:
.. prompt:: bash $
rbd trash ls
To list "deferred delete" block devices in a particular pool, run the
following command, but replace ``{poolname}`` with the name of the pool:
.. prompt:: bash $
rbd trash ls {poolname}
For example:
.. prompt:: bash $
rbd trash ls swimmingpool
Retrieving Image Information
============================
To retrieve information from a particular image, run the following command, but
replace ``{image-name}`` with the name for the image:
.. prompt:: bash $
rbd info {image-name}
For example:
.. prompt:: bash $
rbd info foo
To retrieve information from an image within a pool, run the following command,
but replace ``{image-name}`` with the name of the image and replace
``{pool-name}`` with the name of the pool:
.. prompt:: bash $
rbd info {pool-name}/{image-name}
For example:
.. prompt:: bash $
rbd info swimmingpool/bar
.. note:: Other naming conventions are possible, and might conflict with the
naming convention described here. For example, ``userid/<uuid>`` is a
possible name for an RBD image, and such a name might (at the least) be
confusing.
Resizing a Block Device Image
=============================
:term:`Ceph Block Device` images are thin provisioned. They don't actually use
any physical storage until you begin saving data to them. However, they do have
a maximum capacity that you set with the ``--size`` option. If you want to
increase (or decrease) the maximum size of a Ceph Block Device image, run one
of the following commands:
Increasing the Size of a Block Device Image
-------------------------------------------
.. prompt:: bash $
rbd resize --size 2048 foo
Decreasing the Size of a Block Device Image
-------------------------------------------
.. prompt:: bash $
rbd resize --size 2048 foo --allow-shrink
Removing a Block Device Image
=============================
To remove a block device, run the following command, but replace
``{image-name}`` with the name of the image you want to remove:
.. prompt:: bash $
rbd rm {image-name}
For example:
.. prompt:: bash $
rbd rm foo
Removing a Block Device from a Pool
-----------------------------------
To remove a block device from a pool, run the following command but replace
``{image-name}`` with the name of the image to be removed, and replace
``{pool-name}`` with the name of the pool from which the image is to be
removed:
.. prompt:: bash $
rbd rm {pool-name}/{image-name}
For example:
.. prompt:: bash $
rbd rm swimmingpool/bar
"Defer Deleting" a Block Device from a Pool
-------------------------------------------
To defer delete a block device from a pool (which entails moving it to the
"trash" and deleting it later), run the following command but replace
``{image-name}`` with the name of the image to be moved to the trash and
replace ``{pool-name}`` with the name of the pool:
.. prompt:: bash $
rbd trash mv {pool-name}/{image-name}
For example:
.. prompt:: bash $
rbd trash mv swimmingpool/bar
Removing a Deferred Block Device from a Pool
--------------------------------------------
To remove a deferred block device from a pool, run the following command but
replace ``{image-}`` with the ID of the image to be removed, and replace
``{pool-name}`` with the name of the pool from which the image is to be
removed:
.. prompt:: bash $
rbd trash rm {pool-name}/{image-}
For example:
.. prompt:: bash $
rbd trash rm swimmingpool/2bf4474b0dc51
.. note::
* You can move an image to the trash even if it has snapshot(s) or is
actively in use by clones. However, you cannot remove it from the trash
under those conditions.
* You can use ``--expires-at`` to set the deferment time (default is
``now``). If the deferment time has not yet arrived, you cannot remove the
image unless you use ``--force``.
Restoring a Block Device Image
==============================
To restore a deferred delete block device in the rbd pool, run the
following command but replace ``{image-id}`` with the ID of the image:
.. prompt:: bash $
rbd trash restore {image-id}
For example:
.. prompt:: bash $
rbd trash restore 2bf4474b0dc51
Restoring a Block Device Image in a Specific Pool
-------------------------------------------------
To restore a deferred delete block device in a particular pool, run the
following command but replace ``{image-id}`` with the ID of the image and
replace ``{pool-name}`` with the name of the pool:
.. prompt:: bash $
rbd trash restore {pool-name}/{image-id}
For example:
.. prompt:: bash $
rbd trash restore swimmingpool/2bf4474b0dc51
Renaming an Image While Restoring It
------------------------------------
You can also use ``--image`` to rename the image while restoring it.
For example:
.. prompt:: bash $
rbd trash restore swimmingpool/2bf4474b0dc51 --image new-name
.. _create a pool: ../../rados/operations/pools/#create-a-pool
.. _Storage Pools: ../../rados/operations/pools
.. _RBD – Manage RADOS Block Device (RBD) Images: ../../man/8/rbd/
.. _create a Ceph user: ../../rados/operations/user-management#add-a-user
|