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?

  • Would help if you included the commands used for dd and mount + actual error messages. Also output of fdisk -l backup.img would be nice. Have posted one answer, – comment if any problems.
    – Runium
    Jun 19, 2013 at 6:00

2 Answers 2


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.

  • Thanks. Once I got the hint of "demuxing" a whole disk image, I worked from there.
    – polemon
    Aug 27, 2013 at 6:51

This worked for me:

losetup -r -P /dev/loop1 openbsd.dsk

However losetup(8) comes from:

# losetup --version
losetup from util-linux 2.22.2

and has -P option:

   -P, --partscan
          force kernel to scan partition table on newly created loop device

I can see the partitions, in dmesg(1) and in /proc:

# dmesg
[43126.359869]  loop1: p4
 p4: <openbsd: p5 p6 p7 p8 p9 p10 p11 >

# grep -e loop1 /proc/partitions
   7        1  419430400 loop1
 259        0  419424988 loop1p4
 259        1     208845 loop1p5
 259        2     265041 loop1p6
 259        3     160650 loop1p7
 259        4    1052240 loop1p8
 259        5    4192960 loop1p9
 259        6     522112 loop1p10
 259        7  413023104 loop1p11

Older version of losetup(8) don't support -P option.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .