Kyle Pericak

"It works in my environment"

Created: 2020-03-05Updated: 2020-03-05

Ceph Reference Page

Quick reference for Ceph storage commands: pool replica management, RBD volume create/map/delete, snapshot rollback, and exporting RBD images to files.

Table of Contents

Commands

Modify Pool Replica Count

Show and modify the replica count (size) in a given pool.

You can do the same with min_size if needed.

# Show the current replica count
#   ceph osd pool get <pool name> size
ceph osd pool get images size

# Set the replica count for a given pool
#   ceph osd pool set <pool name> size <number of replicas>
ceph osd pool set images size 2

Show current space used

ceph df

Show status

# Show the status right now
ceph -s

# Show the status and watch it
ceph -w

List, create and delete volumes

# LIST
# rbd ls -p <pool name>
rbd ls -p volumes

# CREATE
#   rbd create --size <size in gb> <pool>/<volume id>
rbd create --size 10 volumes/myVolume

# DELETE
#   rbd rm <pool>/<volume id>
rbd rm volumes/myVolume

Presenting a volume to this host

# PRESENT TO HOST
#   rbd map <pool>/<volume id>
rbd map volumes/myVolume

# LIST MAPPED
rbd showmapped

# REMOVE FROM HOST
#   rbd unmap <pool>/<volume id>
rbd unmap volumes/myVolume

Once you've presented the volume you can use it like this:

mkfs.ext4 /dev/rbd0
mkdir /data
mount /dev/rbd0 /data

Snapshots

# LIST SNAPSHOTS
#   rbd snap ls <pool>/<volume id>
rbd snap ls volumes/myVolume

# REVERT TO SNAPSHOT
# rbd snap rollback <pool>/<volume id>@<snapshot id>
rbd snap rollback volumes/myVolume@sampleSnapshot

# DELETE SNAPSHOT
#   rbd snap rm <pool>/<volume id>@<snap id>
rbd snap rm volumes/myVolume@sampleSnapshot

Save RBD as file

#   rbd export <pool>/<volume> <filename>
rbd export volumes/myVolume myVolume.raw

Python Automation

To automate any of the above from Python, the rados and rbd libraries wrap the same operations. See Python Ceph Examples for pool management, volume creation, and snapshot handling via the Python API.