Chapter 8. The rbd kernel module
As a storage administrator, you can access Ceph block devices through the rbd
kernel module. You can map and unmap a block device, and displaying those mappings. Also, you can get a list of images through the rbd
kernel module.
Kernel clients on Linux distributions other than Red Hat Enterprise Linux (RHEL) are permitted but not supported. If issues are found in the storage cluster when using these kernel clients, Red Hat will address them, but if the root cause is found to be on the kernel client side, the issue will have to be addressed by the software vendor.
Prerequisites
- A running Red Hat Ceph Storage cluster.
8.1. Create a Ceph Block Device and use it from a Linux kernel module client Copy linkLink copied to clipboard!
As a storage administrator, you can create a Ceph Block Device for a Linux kernel module client in the Red Hat Ceph Storage Dashboard. As a system administrator, you can map that block device on a Linux client, and partition, format, and mount it, using the command line. After this, you can read and write files to it.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- A Red Hat Enterprise Linux client.
8.1.1. Creating a Ceph block device for a Linux kernel module client using dashboard Copy linkLink copied to clipboard!
You can create a Ceph block device specifically for a Linux kernel module client using the dashboard web interface by enabling only the features it supports.
Kernel module client supports features like Deep flatten, Layering, Exclusive lock, Object map, and Fast diff.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- A replicated RBD pool created and enabled.
Procedure
- From the Block drop-down menu, select Images.
- Click Create.
In the Create RBD window, enter a image name, select the RBD enabled pool, select the supported features:
- Click Create RBD.
Verification
- You will get a notification that the image is created successfully.
8.1.2. Map and mount a Ceph Block Device on Linux using the command line Copy linkLink copied to clipboard!
You can map a Ceph Block Device from a Red Hat Enterprise Linux client using the Linux rbd
kernel module. After mapping it, you can partition, format, and mount it, so you can write files to it.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- A Ceph block device for a Linux kernel module client using the dashboard is created.
- A Red Hat Enterprise Linux client.
Procedure
On the Red Hat Enterprise Linux client node, enable the Red Hat Ceph Storage 7 Tools repository:
subscription-manager repos --enable=rhceph-7-tools-for-rhel-9-x86_64-rpms
[root@rbd-client ~]# subscription-manager repos --enable=rhceph-7-tools-for-rhel-9-x86_64-rpms
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
ceph-common
RPM package:dnf install ceph-common
[root@rbd-client ~]# dnf install ceph-common
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the Ceph configuration file from a Monitor node to the Client node:
Syntax
scp root@MONITOR_NODE:/etc/ceph/ceph.conf /etc/ceph/ceph.conf
scp root@MONITOR_NODE:/etc/ceph/ceph.conf /etc/ceph/ceph.conf
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
scp root@cluster1-node2:/etc/ceph/ceph.conf /etc/ceph/ceph.conf
[root@rbd-client ~]# scp root@cluster1-node2:/etc/ceph/ceph.conf /etc/ceph/ceph.conf root@192.168.0.32's password: ceph.conf 100% 497 724.9KB/s 00:00 [root@client1 ~]#
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the key file from a Monitor node to the Client node:
Syntax
scp root@MONITOR_NODE:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring
scp root@MONITOR_NODE:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
scp root@cluster1-node2:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring
[root@rbd-client ~]# scp root@cluster1-node2:/etc/ceph/ceph.client.admin.keyring /etc/ceph/ceph.client.admin.keyring root@192.168.0.32's password: ceph.client.admin.keyring 100% 151 265.0KB/s 00:00 [root@client1 ~]#
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Map the image:
Syntax
rbd map --pool POOL_NAME IMAGE_NAME --id admin
rbd map --pool POOL_NAME IMAGE_NAME --id admin
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
rbd map --pool block-device-pool image1 --id admin
[root@rbd-client ~]# rbd map --pool block-device-pool image1 --id admin /dev/rbd0 [root@client1 ~]#
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a partition table on the block device:
Syntax
parted /dev/MAPPED_BLOCK_DEVICE mklabel msdos
parted /dev/MAPPED_BLOCK_DEVICE mklabel msdos
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
parted /dev/rbd0 mklabel msdos
[root@rbd-client ~]# parted /dev/rbd0 mklabel msdos Information: You may need to update /etc/fstab.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a partition for an XFS file system:
Syntax
parted /dev/MAPPED_BLOCK_DEVICE mkpart primary xfs 0% 100%
parted /dev/MAPPED_BLOCK_DEVICE mkpart primary xfs 0% 100%
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
parted /dev/rbd0 mkpart primary xfs 0% 100%
[root@rbd-client ~]# parted /dev/rbd0 mkpart primary xfs 0% 100% Information: You may need to update /etc/fstab.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Format the partition:
Syntax
mkfs.xfs /dev/MAPPED_BLOCK_DEVICE_WITH_PARTITION_NUMBER
mkfs.xfs /dev/MAPPED_BLOCK_DEVICE_WITH_PARTITION_NUMBER
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a directory to mount the new file system on:
Syntax
mkdir PATH_TO_DIRECTORY
mkdir PATH_TO_DIRECTORY
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
mkdir /mnt/ceph
[root@rbd-client ~]# mkdir /mnt/ceph
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the file system:
Syntax
mount /dev/MAPPED_BLOCK_DEVICE_WITH_PARTITION_NUMBER PATH_TO_DIRECTORY
mount /dev/MAPPED_BLOCK_DEVICE_WITH_PARTITION_NUMBER PATH_TO_DIRECTORY
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
mount /dev/rbd0p1 /mnt/ceph/
[root@rbd-client ~]# mount /dev/rbd0p1 /mnt/ceph/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the file system is mounted and showing the correct size:
Syntax
df -h PATH_TO_DIRECTORY
df -h PATH_TO_DIRECTORY
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
df -h /mnt/ceph/
[root@rbd-client ~]# df -h /mnt/ceph/ Filesystem Size Used Avail Use% Mounted on /dev/rbd0p1 10G 105M 9.9G 2% /mnt/ceph
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional Resources
- For more information, see Creating a Ceph Block Device for a Linux kernel module client using Dashboard.
- For more information, see Managing file systems for Red Hat Enterprise Linux 8.
- For more information, see Storage Administration Guide for Red Hat Enterprise Linux 7.
8.2. Mapping a block device Copy linkLink copied to clipboard!
Use rbd
to map an image name to a kernel module. You must specify the image name, the pool name and the user name. rbd
will load the RBD kernel module if it is not already loaded.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- Root-level access to the node.
Procedure
Return a list of the images:
Example
rbd list
[root@rbd-client ~]# rbd list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Following are the two options to map the image:
Map an image name to a kernel module:
Syntax
rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME
rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
rbd device map rbd/myimage --id admin
[root@rbd-client ~]# rbd device map rbd/myimage --id admin
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Specify a secret when using
cephx
authentication by either the keyring or a file containing the secret:Syntax
rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME --keyring PATH_TO_KEYRING
[root@rbd-client ~]# rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME --keyring PATH_TO_KEYRING
Copy to Clipboard Copied! Toggle word wrap Toggle overflow or
rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME --keyfile PATH_TO_FILE
[root@rbd-client ~]# rbd device map POOL_NAME/IMAGE_NAME --id USER_NAME --keyfile PATH_TO_FILE
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
8.3. Displaying mapped block devices Copy linkLink copied to clipboard!
You can display which block device images are mapped to the kernel module with the rbd
command.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- Root-level access to the node.
Procedure
Display the mapped block devices:
rbd device list
[root@rbd-client ~]# rbd device list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
8.4. Unmapping a block device Copy linkLink copied to clipboard!
You can unmap a block device image with the rbd
command, by using the unmap
option and providing the device name.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- Root-level access to the node.
- An image that is mapped.
Procedure
Get the specification of the device.
Example
rbd device list
[root@rbd-client ~]# rbd device list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Unmap the block device image:
Syntax
rbd device unmap /dev/rbd/POOL_NAME/IMAGE_NAME
rbd device unmap /dev/rbd/POOL_NAME/IMAGE_NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
rbd device unmap /dev/rbd/pool1/image1
[root@rbd-client ~]# rbd device unmap /dev/rbd/pool1/image1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
8.5. Segregating images within isolated namespaces within the same pool Copy linkLink copied to clipboard!
When using Ceph Block Devices directly without a higher-level system, such as OpenStack or OpenShift Container Storage, it was not possible to restrict user access to specific block device images. When combined with CephX capabilities, users can be restricted to specific pool namespaces to restrict access to the images.
You can use RADOS namespaces, a new level of identity to identify an object, to provide isolation between rados clients within a pool. For example, a client can only have full permissions on a namespace specific to them. This makes using a different RADOS client for each tenant feasible, which is particularly useful for a block device where many different tenants are accessing their own block device images.
You can segregate block device images within isolated namespaces within the same pool.
Prerequisites
- A running Red Hat Ceph Storage cluster.
- Upgrade all the kernels to 4x and to librbd and librados on all clients.
- Root-level access to the monitor and client nodes.
Procedure
Create an
rbd
pool:Syntax
ceph osd pool create POOL_NAME PG_NUM
ceph osd pool create POOL_NAME PG_NUM
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# ceph osd pool create mypool 100 pool 'mypool' created
[ceph: root@host01 /]# ceph osd pool create mypool 100 pool 'mypool' created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Associate the
rbd
pool with the RBD application:Syntax
ceph osd pool application enable POOL_NAME rbd
ceph osd pool application enable POOL_NAME rbd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# ceph osd pool application enable mypool rbd enabled application 'rbd' on pool 'mypool'
[ceph: root@host01 /]# ceph osd pool application enable mypool rbd enabled application 'rbd' on pool 'mypool'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Initialize the pool with the RBD application:
Syntax
rbd pool init -p POOL_NAME
rbd pool init -p POOL_NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# rbd pool init -p mypool
[ceph: root@host01 /]# rbd pool init -p mypool
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create two namespaces:
Syntax
rbd namespace create --namespace NAMESPACE
rbd namespace create --namespace NAMESPACE
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Provide access to the namespaces for two users:
Syntax
ceph auth get-or-create client.USER_NAME mon 'profile rbd' osd 'profile rbd pool=rbd namespace=NAMESPACE' -o /etc/ceph/client.USER_NAME.keyring
ceph auth get-or-create client.USER_NAME mon 'profile rbd' osd 'profile rbd pool=rbd namespace=NAMESPACE' -o /etc/ceph/client.USER_NAME.keyring
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# ceph auth get-or-create client.testuser mon 'profile rbd' osd 'profile rbd pool=rbd namespace=namespace1' -o /etc/ceph/client.testuser.keyring [ceph: root@host01 /]# ceph auth get-or-create client.newuser mon 'profile rbd' osd 'profile rbd pool=rbd namespace=namespace2' -o /etc/ceph/client.newuser.keyring
[ceph: root@host01 /]# ceph auth get-or-create client.testuser mon 'profile rbd' osd 'profile rbd pool=rbd namespace=namespace1' -o /etc/ceph/client.testuser.keyring [ceph: root@host01 /]# ceph auth get-or-create client.newuser mon 'profile rbd' osd 'profile rbd pool=rbd namespace=namespace2' -o /etc/ceph/client.newuser.keyring
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the key of the clients:
Syntax
ceph auth get client.USER_NAME
ceph auth get client.USER_NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the block device images and use the pre-defined namespace within a pool:
Syntax
rbd create --namespace NAMESPACE IMAGE_NAME --size SIZE_IN_GB
rbd create --namespace NAMESPACE IMAGE_NAME --size SIZE_IN_GB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# rbd create --namespace namespace1 image01 --size 1G [ceph: root@host01 /]# rbd create --namespace namespace2 image02 --size 1G
[ceph: root@host01 /]# rbd create --namespace namespace1 image01 --size 1G [ceph: root@host01 /]# rbd create --namespace namespace2 image02 --size 1G
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Get the details of the namespace and the associated image:
Syntax
rbd --namespace NAMESPACE ls --long
rbd --namespace NAMESPACE ls --long
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the Ceph configuration file from the Ceph Monitor node to the client node:
scp /etc/ceph/ceph.conf root@CLIENT_NODE:/etc/ceph/
scp /etc/ceph/ceph.conf root@CLIENT_NODE:/etc/ceph/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# scp /etc/ceph/ceph.conf root@host02:/etc/ceph/ root@host02's password: ceph.conf 100% 497 724.9KB/s 00:00
[ceph: root@host01 /]# scp /etc/ceph/ceph.conf root@host02:/etc/ceph/ root@host02's password: ceph.conf 100% 497 724.9KB/s 00:00
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the admin keyring from the Ceph Monitor node to the client node:
Syntax
scp /etc/ceph/ceph.client.admin.keyring root@CLIENT_NODE:/etc/ceph
scp /etc/ceph/ceph.client.admin.keyring root@CLIENT_NODE:/etc/ceph
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# scp /etc/ceph/ceph.client.admin.keyring root@host02:/etc/ceph/ root@host02's password: ceph.client.admin.keyring 100% 151 265.0KB/s 00:00
[ceph: root@host01 /]# scp /etc/ceph/ceph.client.admin.keyring root@host02:/etc/ceph/ root@host02's password: ceph.client.admin.keyring 100% 151 265.0KB/s 00:00
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the keyrings of the users from the Ceph Monitor node to the client node:
Syntax
scp /etc/ceph/ceph.client.USER_NAME.keyring root@CLIENT_NODE:/etc/ceph/
scp /etc/ceph/ceph.client.USER_NAME.keyring root@CLIENT_NODE:/etc/ceph/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
[ceph: root@host01 /]# scp /etc/ceph/client.newuser.keyring root@host02:/etc/ceph/ [ceph: root@host01 /]# scp /etc/ceph/client.testuser.keyring root@host02:/etc/ceph/
[ceph: root@host01 /]# scp /etc/ceph/client.newuser.keyring root@host02:/etc/ceph/ [ceph: root@host01 /]# scp /etc/ceph/client.testuser.keyring root@host02:/etc/ceph/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Map the block device image:
Syntax
rbd map --name NAMESPACE IMAGE_NAME -n client.USER_NAME --keyring /etc/ceph/client.USER_NAME.keyring
rbd map --name NAMESPACE IMAGE_NAME -n client.USER_NAME --keyring /etc/ceph/client.USER_NAME.keyring
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This does not allow access to users in the other namespaces in the same pool.
Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the device:
Example
[ceph: root@host01 /]# rbd showmapped id pool namespace image snap device 0 rbd namespace1 image01 - /dev/rbd0 1 rbd namespace2 image02 - /dev/rbd1
[ceph: root@host01 /]# rbd showmapped id pool namespace image snap device 0 rbd namespace1 image01 - /dev/rbd0 1 rbd namespace2 image02 - /dev/rbd1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow