LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Image of a whole disk. Mounting one of its partitions. (https://www.linuxquestions.org/questions/linux-newbie-8/image-of-a-whole-disk-mounting-one-of-its-partitions-930039/)

stf92 02-18-2012 06:05 AM

Image of a whole disk. Mounting one of its partitions.
 
Kernel 2.6.21.5, Slackware 12.0

Hi:
I have disk.img, an image of a whole disk, comprising track 0, a FAT32 partition and an ext3 partition. Is it possible to mount one of these partitions? A command like 'mount ./disk.img /mnt -t<some_type> -o loop' will fail, because disk.img should be a filesystem and is not.

catkin 02-18-2012 06:20 AM

Should be doable by using mount ./disk.img /mnt -t<some_type> -o loop,offset=<some uint> where the offset uint could be found from the partition table?

unSpawn 02-18-2012 06:41 AM

...else try
Code:

losetup -o $[512*offset] /dev/loopn /path/to/disk.img
or
Code:

kpartx -a /path/to/disk.img
if you don't care mounting all partitions.

Doc CPU 02-18-2012 06:42 AM

Hi there,

Quote:

Originally Posted by catkin (Post 4605773)
Should be doable by using mount ./disk.img /mnt -t<some_type> -o loop,offset=<some uint> where the offset uint could be found from the partition table?

yes, true - but finding the correct offset is some tedious work. Of course, you could simply try multiples of the sector size (normally 512 bytes) until you get something reasonable.

But, you're right, that information is in the partition table, which is in the very first sector of the disk image. The actual starting sector for the first partition is the DWORD at offset 01C6h, for the second partition at 01D6h (see Explanation for details).
This assumes that you still use traditional partitioning; GPT is a bit more sophisticated.

[X] Doc CPU

stf92 02-18-2012 10:17 AM

Thank you all. A little shortsightedness of mine, so many times in mount manual and not having followed the losetup(8) reference!

I did:
Code:

# hexdump -C disk.img 

I got:

offset  id    sec
1C6      0C    0000003F
1D6      83    000234C9

Then

# losetup -f
/dev/loop0
# losetup -o <3F * 512> /dev/loop0 ./disk.img
# losetup -f
/dev/loop1
# losetup -o <234C9 * 512> /dev/loop1 ./disk.img
#
# mount -tvfat /dev/loop0 /mnt/win
# mount -text3 /dev/loop1 /mnt/lin

EDIT: I reread unSpawn's post and saw the command interpreter can do the math, even in hex.


All times are GMT -5. The time now is 04:30 PM.