How to mount an OpenBSD hard disk image on Linux

filesystemsmountopenbsd

First, I'll start by explaining how I got my problem, this will help me get across what I need.

A few months ago, my laptop hard disk broke. I had no quick replacement, but I needed that laptop the next day, so all I could do was to rip the 2.5" drive out from my router. The router was actually an ATX PC, running OpenBSD 4.9. Now, since I needed that drive very quickly, I created an image with dd on my desktop computer, put the drive into the laptop and installed Fedora.

OK, now I have a replacement hard drive for my laptop, and before I start installing stuff on the hard drive that is going back into the router, I was asking myself, how I could mount the image that I made when I started…

The point is, I could make a fresh install of the latest OpenBSD and then just use things like config files from the image. The only thing I know of that I can do now, is simply write the image back to the disk with dd. This should work and all that, but I'd like to use the opportunity to upgrade the system as well.

I tried mounting the OpenBSD partitions before making the image, but it didn't work, and I had very little time (only a couple of hours on this one evening). Should I write back the image to disk, then try to mount it, recover the files I need and then install the latest OpenBSD?

Best Answer

The reason why you cannot just mount the partitions is because you have a disc image not images of individual partitions. You would need the offsets of the different partitions and use those when mount using its the loop and offset options.

In your case I would play back the image and then upgrade, but you don't indicate how you connected the 2.5" to you desktop computer, or how you are going to do that now. If you are going to use USB, then upgrading before playback is probably faster (but a bit more work), assuming the image is on an internal SATA drive. Because of the USB 2.0 vs SATA speed differences the upgrading is going to take longer. The playback of the image (upgraded or not) will take the same time.

If you want to upgrade before playback, then use parted to find the start of the images. parted hd.img will give you a list of partition numbers, start and end. With the start information e.g 12345 you can mount a partition in the disk image:

mount -o loop,ro,offset=12345 hd.img /mnt/tmp

You might need to specify the partition type as well if your desktop does not recognise it. You can then update your fresh install with that info, remount the partition rw clean out the partition and write things back. The only thing I am not sure about is if that would consfuse the ATX board's bootloader, but upgrading a system restored to disk would have the same problem.

Related Question