Ceph - Recovering data from a RBD image
This allowed me recover a VM in Openstack, and I wanted to share what I did. For anyone using Ceph I hope this helps.
First lets go ahead and make a snap of our image, then lets export it to local disk.
root> rbd snap create volumes/openstackRBD_disk@recovery.snap
root> rbd export volumes/openstackRBD_disk@recovery.snap /tmp/recovery.img
Next, we need to run fdisk -l on our exported image to find 2 important things. 1. Sector size Units = sectors of 1 * 512 = 512 bytes 2. List of Partitions, and their respective starting sectors ./recovery.img1 * 2048
root> fdisk -l /tmp/recovery.img
Disk ./recovery.img: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000248cc
Device Boot Start End Blocks Id System
./recovery.img1 * 2048 1026047 512000 83 Linux
./recovery.img2 1026048 5220351 2097152 82 Linux swap / Solaris
./recovery.img3 5220352 20971519 7875584 83 Linux
After that we will calculate our offset for each partition we need to mount up.
recovery.img3: 5220352 * 512 = 2672820224
Next, we will take that offset number and use it to mount our image to a loop device. For those who don’t know, a loop device basically lets you mount a file that acts as a block-based device.
root> losetup -o 2672820224 /dev/loop0 recovery.img
If you need to fsck the disk, let do that now.
root> fsck -fv /dev/loop0
Finally, mount it up somewhere and write to it as normal!
root> mount /dev/loop1 /mnt/recovery/
root> ls
bin boot dev etc export home lib lib64 mnt sys tmp usr var
root>
Now once you’re done making any repairs or changes, feel free to unmount the image and reimport it back into your pool. Remember if your original image is there and you plan on replacing it with this new image, you must delete it and all of its snaps.
root> umount /mnt/recovery/
root> rbd rm volumes/openstackRBD_disk
root> rbd import recovery.img volumes/openstackRBD_disk
And thats it! If you have any questions, or just want to give thanks, feel free to email me at magusnebula@gmail.com.
Man Ceph is awesome.