Came across a situation where a Openstack instance needed to have its disk image repaired. I wanted to briefly share what I did here in hopes that it may help someone in the future.
First lets go ahead and make a snap of our image, then lets export it to local disk.
Next, we need to run
fdisk -l on our exported image to find 2 important things.
- Sector size
Units = sectors of 1 * 512 = 512 bytes
- List of Partitions, and their respective starting sectors
./recovery.img1 * 2048
After that we will calculate our offset for each partition we need to mount up.
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.
If you need to
fsck the disk, let do that now.
Finally, mount it up somewhere and write to it as normal!
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.
And thats it! If you have any questions, or just want to give thanks, feel free to email me at firstname.lastname@example.org.