Planet Ceph

Aggregated news from external sources

August 22, 2017

Recovering data from a RBD image

Drawing

Recovering data from a RBD image

First lets go ahead and make a snap of our image, then lets export it to local disk.

1
2
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
1
2
3
4
5
6
7
8
9
10
11
12
13
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.

1
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.

1
root> losetup -o 2672820224 /dev/loop0 recovery.img

If you need to fsck the disk, let do that now.

1
root> fsck -fv /dev/loop0

Finally, mount it up somewhere and write to it as normal!

1
2
3
4
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.

1
2
3
root> unmount /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.

Source: Stephen McElroy (Recovering data from a RBD image)

Careers