Notice
This document is for a development version of Ceph.
Creating and Mounting a Block Device
This procedure creates a Ceph Block Device (RBD) image, maps it on a Linux client, and mounts a file system on it. Use it to try block storage on a new cluster. For day-to-day image management, see Ceph Block Device.
Prerequisites
A running Ceph cluster that reports
HEALTH_OK.A Linux client host that has the
ceph-commonpackage installed, and a copy of/etc/ceph/ceph.confand of a keyring that is allowed to use the cluster. On a cephadm bootstrap host both files are in/etc/ceph; the keyring isceph.client.admin.keyring.A client host that is not also a host of the Ceph cluster, unless the client is a virtual machine. Mapping a block device with the kernel client on a host that runs Ceph daemons can cause a deadlock.
Procedure
On a cluster host, inside
cephadm shell, create a pool for block device images. This example uses the pool namerbd1701:ceph osd pool create rbd1701The command prints
pool 'rbd1701' created.Initialize the pool for use by RBD:
rbd pool init rbd1701The command prints nothing on success.
On the client host, create a 1 GB image:
rbd create rbd1701/image1701 --size 1GThe command prints nothing.
rbd ls rbd1701listsimage1701.Map the image to a block device:
rbd map rbd1701/image1701The command prints the device name, for example
/dev/rbd0. The next steps use the link/dev/rbd/rbd1701/image1701that theceph-commonudev rule creates. If that link does not exist, use the/dev/rbdNname instead.Create a file system on the device:
mkfs.ext4 /dev/rbd/rbd1701/image1701The output ends with
Writing superblocks and filesystem accounting information: done.Create a mount point:
mkdir /mnt/ceph-block-deviceMount the file system:
mount /dev/rbd/rbd1701/image1701 /mnt/ceph-block-deviceThe command prints nothing on success.
Verification
List the mapped images:
rbd device listThe output shows
image1701in poolrbd1701and the device that it is mapped to.Confirm that the file system is mounted:
df -h /mnt/ceph-block-deviceThe output shows the
/dev/rbddevice mounted on/mnt/ceph-block-devicewith about 1 GB of space.
Troubleshooting
If
rbd mapreportsRBD image feature set mismatch, the kernel on the client does not support every feature that is enabled on the image. Run therbd feature disablecommand that the error message suggests, then map the image again.If
rbd mapreportsrbd: map failed: (2) No such file or directoryormodprobe: FATAL: Module rbd not found, the client kernel has norbdmodule. Runmodprobe rbd, then map the image again.If
mkfs.ext4ormountreportsNo such file or directoryfor/dev/rbd/rbd1701/image1701, the udev link was not created. Use the/dev/rbdNdevice name thatrbd mapprinted.If
rbdcommands hang or report an authentication error, check that/etc/ceph/ceph.confand the keyring on the client are copies of the files on the cluster. Then check that the client can reach the Monitors over the network.
Next Steps
Map the image automatically at boot. See the rbdmap manpage.
Create a Ceph user for block device clients instead of using the
adminuser. See Basic Block Device Commands.
Additional Resources
Brought to you by the Ceph Foundation
The Ceph Documentation is a community resource funded and hosted by the non-profit Ceph Foundation. If you would like to support this and our other efforts, please consider joining now.