Ceph RBD Import/Export and More

Ceph rbd can import a block image and/or export a rbd image to a block image.

Create an ext4 block image

[code language=”bash”]

# dd if=/dev/zero of=/tmp/disk.img bs=1M count=1

# mkfs.ext4 /tmp/disk.img

[/code]

Import the block image to rbd pool

[code language=”bash”]

# rbd import /tmp/disk.img disk –pool kube

# rbd ls –pool kube

disk

foo

[/code]

Map rbd image to /dev/rbdX

[code language=”bash”]

# rbd map disk –pool kube

# rbd showmapped
id pool image snap device
0 kube foo – /dev/rbd0
1 kube disk – /dev/rbd1

[/code]

Mount /dev/rbdX and create a test file

[code language=”bash”]

#mount /dev/rbd1 /tmp/mount

# echo "test" > /tmp/mount/first
# ls /tmp/mount/
first lost+found

[/code]

Export the rbd image into a block image

[code language=”bash”]

# rbd export disk /tmp/export.img –pool kube
Exporting image: 100% complete…done.
# file /tmp/export.img
/tmp/export.img: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=3b1f22b1-48d3-4bdf-819d-d62fd7063321 (extents) (huge files)
#mount -o loop /tmp/export.img /tmp/mount
# ls /tmp/mount/
first lost+found

[/code]

There are more powerful use cases with import and export. One can simulate ZFS send/recv, a feature used by flocker, by just importing and exporting image diff. And recent Ceph Giant release also support parallelized import and export.

Leave a Reply