Chapter 2. Block Device Commands
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, and so on.
2.1. Prerequisites Copy linkLink copied to clipboard!
There are two prerequisites that you must meet before you can use the Ceph Block Devices and the rbd command:
- You must have access to a running Ceph Storage Cluster. For details, see the Red Hat Ceph Storage 3 Installation Guide for Red Hat Enterprise Linux or Installation Guide for Ubuntu.
- You must install the Ceph Block Device client. For details, see the Red Hat Ceph Storage 3 Installation Guide for Red Hat Enterprise Linux or Installation Guide for Ubuntu.
The Manually Installing Ceph Block Device chapter also provides information on mounting and using Ceph Block Devices on client nodes. Execute these steps on client nodes only after creating an image for the Block Device in the Ceph Storage Cluster. See Section 2.4, “Creating Block Device Images” for details.
2.2. Displaying Help Copy linkLink copied to clipboard!
Use the rbd help command to display help for a particular rbd command and its subcommand:
rbd help <command> <subcommand>
[root@rbd-client ~]# rbd help <command> <subcommand>
Example
To display help for the snap list command:
rbd help snap list
[root@rbd-client ~]# rbd help snap list
The -h option still displays help for all available commands.
2.3. Creating Block Device Pools Copy linkLink copied to clipboard!
Before using the block device client, ensure a pool for rbd exists and is enabled and initialized. To create an rbd pool, execute the following:
ceph osd pool create {pool-name} {pg-num} {pgp-num}
ceph osd pool application enable {pool-name} rbd
rbd pool init -p {pool-name}
[root@rbd-client ~]# ceph osd pool create {pool-name} {pg-num} {pgp-num}
[root@rbd-client ~]# ceph osd pool application enable {pool-name} rbd
[root@rbd-client ~]# rbd pool init -p {pool-name}
You MUST create a pool first before you can specify it as a source. See the Pools chapter in the Storage Strategies guide for Red Hat Ceph Storage 3 for additional details.
2.4. Creating Block Device Images Copy linkLink copied to clipboard!
Before adding a block device to a node, create an image for it in the Ceph storage cluster. To create a block device image, execute the following command:
rbd create <image-name> --size <megabytes> --pool <pool-name>
[root@rbd-client ~]# rbd create <image-name> --size <megabytes> --pool <pool-name>
For example, to create a 1GB image named data that stores information in a pool named stack, run:
rbd create data --size 1024 --pool stack
[root@rbd-client ~]# rbd create data --size 1024 --pool stack
- NOTE
-
Ensure a pool for
rbdexists before creating an image. See Creating Block Device Pools for additional details.
2.5. Listing Block Device Images Copy linkLink copied to clipboard!
To list block devices in the rbd pool, execute the following (rbd is the default pool name):
rbd ls
[root@rbd-client ~]# rbd ls
To list block devices in a particular pool, execute the following, but replace {poolname} with the name of the pool:
rbd ls {poolname}
[root@rbd-client ~]# rbd ls {poolname}
For example:
rbd ls swimmingpool
[root@rbd-client ~]# rbd ls swimmingpool
2.6. Retrieving Image Information Copy linkLink copied to clipboard!
To retrieve information from a particular image, execute the following, but replace {image-name} with the name for the image:
rbd --image {image-name} info
[root@rbd-client ~]# rbd --image {image-name} info
For example:
rbd --image foo info
[root@rbd-client ~]# rbd --image foo info
To retrieve information from an image within a pool, execute the following, but replace {image-name} with the name of the image and replace {pool-name} with the name of the pool:
rbd --image {image-name} -p {pool-name} info
[root@rbd-client ~]# rbd --image {image-name} -p {pool-name} info
For example:
rbd --image bar -p swimmingpool info
[root@rbd-client ~]# rbd --image bar -p swimmingpool info
2.7. Resizing Block Device Images Copy linkLink copied to clipboard!
Ceph block device images are thin provisioned. They do not 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.
To increase or decrease the maximum size of a Ceph block device image:
rbd resize --image <image-name> --size <size>
[root@rbd-client ~]# rbd resize --image <image-name> --size <size>
2.8. Removing Block Device Images Copy linkLink copied to clipboard!
To remove a block device, execute the following, but replace {image-name} with the name of the image you want to remove:
rbd rm {image-name}
[root@rbd-client ~]# rbd rm {image-name}
For example:
rbd rm foo
[root@rbd-client ~]# rbd rm foo
To remove a block device from a pool, execute the following, but replace {image-name} with the name of the image to remove and replace {pool-name} with the name of the pool:
rbd rm {image-name} -p {pool-name}
[root@rbd-client ~]# rbd rm {image-name} -p {pool-name}
For example:
rbd rm bar -p swimmingpool
[root@rbd-client ~]# rbd rm bar -p swimmingpool
2.9. Moving Block Device Images to the Trash Copy linkLink copied to clipboard!
RADOS Block Device (RBD) images can be moved to the trash using the rbd trash command. This command provides more options than the rbd rm command.
Once an image is moved to the trash, it can be removed from the trash at a later time. This helps to avoid accidental deletion.
To move an image to the trash execute the following:
rbd trash move {image-spec}
[root@rbd-client ~]# rbd trash move {image-spec}
Once an image is in the trash, it is assigned a unique image ID. You will need this image ID to specify the image later if you need to use any of the trash options. Execute the rbd trash list for a list of IDs of the images in the trash. This command also returns the image’s pre-deletion name.
In addition, there is an optional --image-id argument that can be used with rbd info and rbd snap commands. Use --image-id with the rbd info command to see the properties of an image in the trash, and with rbd snap to remove an image’s snapshots from the trash.
Remove an Image from the Trash
To remove an image from the trash execute the following:
rbd trash remove [{pool-name}/] {image-id}
[root@rbd-client ~]# rbd trash remove [{pool-name}/] {image-id}
Once an image is removed from the trash, it cannot be restored.
Delay Trash Removal
Use the --delay option to set an amount of time before an image can be removed from the trash. Execute the following, except replace {time} with the number of seconds to wait before the image can be removed (defaults to 0):
rbd trash move [--delay {time}] {image-spec}
[root@rbd-client ~]# rbd trash move [--delay {time}] {image-spec}
Once the --delay option is enabled, an image cannot be removed from the trash within the specified timeframe unless forced.
Restore an Image from the Trash
As long as an image has not been removed from the trash, it can be restored using the rbd trash restore command.
Execute the rbd trash restore command to restore the image:
rbd trash restore [{pool-name}/] {image-id}
[root@rbd-client ~]# rbd trash restore [{pool-name}/] {image-id}
2.10. Enabling and Disabling Image Features Copy linkLink copied to clipboard!
You can enable or disable image features, such as fast-diff, exclusive-lock, object-map, or journaling, on already existing images.
To enable a feature:
rbd feature enable <pool-name>/<image-name> <feature-name>
[root@rbd-client ~]# rbd feature enable <pool-name>/<image-name> <feature-name>
To disable a feature:
rbd feature disable <pool-name>/<image-name> <feature-name>
[root@rbd-client ~]# rbd feature disable <pool-name>/<image-name> <feature-name>
Examples
To enable the
exclusive-lockfeature on theimage1image in thedatapool:rbd feature enable data/image1 exclusive-lock
[root@rbd-client ~]# rbd feature enable data/image1 exclusive-lockCopy to Clipboard Copied! Toggle word wrap Toggle overflow To disable the
fast-difffeature on theimage2image in thedatapool:rbd feature disable data/image2 fast-diff
[root@rbd-client ~]# rbd feature disable data/image2 fast-diffCopy to Clipboard Copied! Toggle word wrap Toggle overflow
After enabling the fast-diff and object-map features, rebuild the object map:
rbd object-map rebuild <pool-name>/<image-name>
[root@rbd-client ~]# rbd object-map rebuild <pool-name>/<image-name>
The deep flatten feature can be only disabled on already existing images but not enabled. To use deep flatten, enable it when creating images.
2.11. Working with Image Metadata Copy linkLink copied to clipboard!
Ceph supports adding custom image metadata as key-value pairs. The pairs do not have any strict format.
Also, by using metadata, you can set the RBD configuration parameters for particular images. See Overriding the Default Configuration for Particular Images for details.
Use the rbd image-meta commands to work with metadata.
Setting Image Metadata
To set a new metadata key-value pair:
rbd image-meta set <pool-name>/<image-name> <key> <value>
[root@rbd-client ~]# rbd image-meta set <pool-name>/<image-name> <key> <value>
Example
To set the
last_updatekey to the2016-06-06value on thedatasetimage in thedatapool:rbd image-meta set data/dataset last_update 2016-06-06
[root@rbd-client ~]# rbd image-meta set data/dataset last_update 2016-06-06Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Removing Image Metadata
To remove a metadata key-value pair:
rbd image-meta remove <pool-name>/<image-name> <key>
[root@rbd-client ~]# rbd image-meta remove <pool-name>/<image-name> <key>
Example
To remove the
last_updatekey-value pair from thedatasetimage in thedatapool:rbd image-meta remove data/dataset last_update
[root@rbd-client ~]# rbd image-meta remove data/dataset last_updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Getting a Value for a Key
To view a value of a key:
rbd image-meta get <pool-name>/<image-name> <key>
[root@rbd-client ~]# rbd image-meta get <pool-name>/<image-name> <key>
Example
To view the value of the
last_updatekey:rbd image-meta get data/dataset last_update
[root@rbd-client ~]# rbd image-meta get data/dataset last_updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Listing Image Metadata
To show all metadata on an image:
rbd image-meta list <pool-name>/<image-name>
[root@rbd-client ~]# rbd image-meta list <pool-name>/<image-name>
Example
To list metadata set on the
datasetimage in thedatapool:rbd data/dataset image-meta list
[root@rbd-client ~]# rbd data/dataset image-meta listCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Overriding the Default Configuration for Particular Images
To override the RBD image configuration settings set in the Ceph configuration file for a particular image, set the configuration parameters with the conf_ prefix as image metadata:
rbd image-meta set <pool-name>/<image-name> conf_<parameter> <value>
[root@rbd-client ~]# rbd image-meta set <pool-name>/<image-name> conf_<parameter> <value>
Example
To disable the RBD cache for the
datasetimage in thedatapool:rbd image-meta set data/dataset conf_rbd_cache false
[root@rbd-client ~]# rbd image-meta set data/dataset conf_rbd_cache falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
See Block Device Configuration Reference for a list of possible configuration options.