RBD storing images in Ceph for the beginner

Ceph logo

Ceph is the open source Software Defined Storage (SDS) king. By default Ceph stores objects, how can you use it to store block devices such as virtual machines disks? For that purpose you can use RBD, let’s take a look.

I don’t have a Ceph cluster

Any sufficiently advanced technology is indistinguishable from magic.Arthur C. Clarke

Ceph is pretty complicated as it is, I highly suggest you to follow this guide with a Ceph test cluster beneath your keyboard.

Ceph pools and RBD

RBD (Rados Block Device) is a way to store block devices in a RADOS cluster. Block devices stored using RBD are often called RBD images or (sometimes) RBD devices. RBD is an abstraction layer built on RADOS, this means that RBD images stored in Ceph are still stored using objects.

To store RBD images you will need a Ceph pool dedicated to RBD, this is commonly referred to as “RBD pool“. You should never use a RBD pool for any other purpose. If you upload objects directly to an RBD pool you may experience incoherent behaviors.

Now that you know what RBD is and what it needs to work: let’s get started. You will need to have a Ceph keyring on the host you’re using. The fastest way to get started is to ssh into a monitor node. Once you have it you will need an empty Ceph pool dedicated to RBD.

I take NO responsibility of what you do with your machine; use this tutorial as a guide and remember you can possibly cause data loss if you touch things carelessly.

Initializing a RBD pool

The first thing in order to start using RBD is to initialize a pool:

$ rbd pool init <pool>

By default, in any rbd command, if you don’t specify the pool the system will assume the existence of a pool named “rbd“.

Creating an image

$ rbd create --size {megabytes} {pool-name}/{image-name}

Listing images in a pool

$ rbd ls {poolname}

Retrieving image information

$ rbd info {pool-name}/{image-name}

Removing an image

$ rbd rm {pool-name}/{image-name}

Increasing an image size

$ rbd resize --size <size> {pool-name}/{image-name}

Shrinking an image

$ rbd resize --size <size> {pool-name}/{image-name} --allow-shrink

Using trash

In RBD there’s a “trash bin” that you can use to delete images in a non-permanent way, much like the Windows trash can. The trash bin is not shared among the pools.

When an image is moved to trash it loses its name and can only be referred to using an id. You can retrieve the id using the listing command mentioned below.

Moving an image to trash

$ rbd trash mv {pool-name}/{image-name}

Listing images in trash

$ rbd trash ls {pool-name}

Restoring an image

$ rbd trash restore {pool-name}/{image-id}

Image courtesy of mark | marksei

You may also like...

2 Responses

  1. Rene Hernandez says:

    what happened if I have several pools with a lot of data, but no rbd images at all in the pools

    • mark says:

      Hello Rene, I haven’t really got what is your scenario. If you mean “does it harm to have no RBD images?” the answer is: “It is absolutely normal and not hurtful AT ALL.”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: