rbdmap is a shell script that automates rbdmap and rbdunmap operations on one or more RBD (RADOS Block
Device) images. While the script can be run manually by the system administrator at any time, the
principal use case is automatic mapping/mounting of RBD images at boot time (and unmounting/unmapping at
shutdown), as triggered by the init system (a systemd unit file, rbdmap.service is included with the
ceph-common package for this purpose).
The script takes a single argument, which can be either "map" or "unmap". In either case, the script
parses a configuration file (defaults to /etc/ceph/rbdmap, but can be overridden via an environment
variable RBDMAPFILE). Each line of the configuration file corresponds to an RBD image which is to be
mapped, or unmapped.
The configuration file format is:
IMAGESPEC RBDOPTS
where IMAGESPEC should be specified as POOLNAME/IMAGENAME (the pool name, a forward slash, and the image
name), or merely IMAGENAME, in which case the POOLNAME defaults to "rbd". RBDOPTS is an optional list of
parameters to be passed to the underlying rbdmap command. These parameters and their values should be
specified as a comma-separated string:
PARAM1=VAL1,PARAM2=VAL2,...,PARAMN=VALN
This will cause the script to issue an rbdmap command like the following:
rbd map POOLNAME/IMAGENAME --PARAM1 VAL1 --PARAM2 VAL2
(See the rbd manpage for a full list of possible options.) For parameters and values which contain
commas or equality signs, a simple apostrophe can be used to prevent replacing them.
When run as rbdmapmap, the script parses the configuration file, and for each RBD image specified
attempts to first map the image (using the rbdmap command) and, second, to mount the image.
When run as rbdmapunmap, images listed in the configuration file will be unmounted and unmapped.
rbdmapunmap-all attempts to unmount and subsequently unmap all currently mapped RBD images, regardless
of whether or not they are listed in the configuration file.
If successful, the rbdmap operation maps the image to a /dev/rbdX device, at which point a udev rule is
triggered to create a friendly device name symlink, /dev/rbd/POOLNAME/IMAGENAME, pointing to the real
mapped device.
In order for mounting/unmounting to succeed, the friendly device name must have a corresponding entry in
/etc/fstab.
When writing /etc/fstab entries for RBD images, it's a good idea to specify the "noauto" (or "nofail")
mount option. This prevents the init system from trying to mount the device too early - before the device
in question even exists. (Since rbdmap.service executes a shell script, it is typically triggered quite
late in the boot sequence.)