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


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

# mkfs.ext4 /tmp/disk.img

Import the block image to rbd pool


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

# rbd ls --pool kube

disk

foo

Map rbd image to /dev/rbdX


# rbd map disk --pool kube

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

Mount /dev/rbdX and create a test file


#mount /dev/rbd1 /tmp/mount

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

Export the rbd image into a block image


# 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

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s