Mount a .img file

238 views
Skip to first unread message

Chaz

unread,
Sep 26, 2012, 4:08:10 PM9/26/12
to Linux Users Group
Hi,

I'm having trouble mounting two .img files.

I have tried mounting using "mount -oloop ...." and I have tried using
losetup but nothing seems to be happening.

I'm running OpenSUSE 12.1

If I run the "file" command on both of them, this is what I get..

CP_OS.img: x86 boot sector; partition 1: ID=0x63, active,
starthead 1, startsector 63, 71762292 sectors, code offset 0xc0
IMAGE_DATA.img: x86 boot sector, Microsoft Windows XP MBR, Serial
0xfc139932; partition 1: ID=0x63, active, starthead 1, startsector 63,
143556777 sectors, code offset 0xc0

As you can see, they are quite large files and I am desperate to get
the data from them

Does anybody have any ideas how I can get these mounted? I would
really appreciate it and may even buy you a drink, or some chocolates,
or whatever takes your fancy...!

Many thanks in advance

Daniel Eggleston

unread,
Sep 26, 2012, 6:13:08 PM9/26/12
to linuxus...@googlegroups.com
Hi, Chaz - you need to specify an offset. This is the boot sector getting in your way.

Run 'fdisk -ul' on your .img file.  It will show you where the partitions start:

fdisk -ul /dev/sda

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders, total 12582912 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 identifier: 0x000d4ee3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2         1026048    12582911     5778432   8e  Linux LVM
Partition 2 does not end on cylinder boundary.


That "Start" column is important.

Now, run "losetup -f -o $(( 512 * [offset] )) [file.img]" (don't copy those square brackets literally).  This will give you a loop device to the acutal partition you're interested in.

i.e.: losetup -f -o $(( 512 * 2048 )) /dev/sda

Now, you'll see:

losetup  -a
/dev/loop0: [0005]:6094 (/dev/sda), offset 1048576


A note: I did this on /dev/sda.  That's not going to do anything useful, since /dev/sda1 is now the same as /dev/loop0.  I could probably get myself into some fun problems with this setup.


--
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to linuxus...@googlegroups.com
To unsubscribe, send email to linuxusersgro...@googlegroups.com
For more options, visit our group at http://groups.google.com/group/linuxusersgroup
References can be found at: http://goo.gl/anqri
Please remember to abide by our list rules (http://tinyurl.com/LUG-Rules or http://cdn.fsdev.net/List-Rules.pdf)



--

           Daniel

Chaz

unread,
Oct 10, 2012, 6:13:06 AM10/10/12
to Linux Users Group
Thanks ever so for your help on this.

It still didn't work, I'm afraid, but in the end, I managed to mount
the actual disks onto an old server and got all the data I needed.

Thanks again.
Reply all
Reply to author
Forward
0 new messages