LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Mounting/accessing individual partitions within a dd image? (http://www.linuxquestions.org/questions/linux-general-1/mounting-accessing-individual-partitions-within-a-dd-image-743930/)

jessica6 07-30-2009 10:34 AM

Mounting/accessing individual partitions within a dd image?
 
I found a thread from 2008.02 regarding this at http://www.linuxquestions.org/questi...-image-618939/ but I will refrain from "necroposting".

When I attempt to follow the instructions:

==
# fdisk -l /media/disk/files.img
Note the device name, start and where it says "512 = n bytes".
If an ext3 partition is /media/disk/files.img2 starting at 660 with n = 8225280 you could 'losetup -o$[660*8225280] /dev/loop0 /media/disk/files.img' and then 'mount /dev/loop0 -t ext3 /mnt/somemountpoint'.
==

I run into some problems. Here's my output:

root@box:/var/misc# fdisk -l image.dd
You must set cylinders.
You can do this from the extra functions menu.

Disk image.dd: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
image.dd1 * 1 22 176683+ 83 Linux
image.dd2 2430 2491 498015 82 Linux swap
Partition 2 has different physical/logical beginnings (non-Linux?):
phys=(1023, 254, 63) logical=(2429, 0, 1)
Partition 2 has different physical/logical endings:
phys=(1023, 254, 63) logical=(2490, 254, 63)
image.dd3 23 2429 19334227+ 5 Extended
Partition 3 has different physical/logical endings:
phys=(1023, 254, 63) logical=(2428, 254, 63)
image.dd5 23 508 3903763+ 83 Linux
image.dd6 509 630 979933+ 83 Linux
image.dd7 631 752 979933+ 83 Linux
image.dd8 753 874 979933+ 83 Linux
image.dd9 875 2429 12490506 83 Linux

Partition table entries are not in disk order
root@box:/var/misc#

(I want to access image.dd6, which should be hda6)

root@box:/var/misc# losetup -o$[509*8225280] /dev/loop0 image.dd

root@box:/var/misc# mount /dev/loop0 -t ext2 /mnt2
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

From syslog:
Jul 30 15:21:30 box kernel: VFS: Can't find an ext2 filesystem on dev loop0.

On the running system from which this dd was made, I can verify it is ext2 using cfdisk:

cfdisk 2.12p

Disk Drive: /dev/hda
Size: 20491075584 bytes, 20.4 GB
Heads: 255 Sectors per Track: 63 Cylinders: 2491

Name Flags Part Type FS Type [Label] Size (MB)
------------------------------------------------------------------------
hda1 Boot Primary Linux ext3 180.96
hda5 Logical Linux ext2 3997.49
hda6 Logical Linux ext2 1003.49
hda7 Logical Linux ext2 1003.49
hda8 Logical Linux ext2 1003.49
hda9 Logical Linux ext2 12790.32
hda2 Primary Linux swap 509.97

#

Any help/ideas would be great.

Thanks!

GrapefruiTgirl 07-30-2009 10:44 AM

Quote:

(I want to access image.dd6, which should be hda6)

root@box:/var/misc# losetup -o$[509*8225280] /dev/loop0 image.dd

root@box:/var/misc# mount /dev/loop0 -t ext2 /mnt2
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

From syslog:
Jul 30 15:21:30 box kernel: VFS: Can't find an ext2 filesystem on dev loop0.
Is it possible this is as simple as a typo? Note the bold text above; should that not read image.dd6?

Sasha

EDIT - I think I am wrong; I did not fully understand that ALL of the dd# images are INSIDE the image.dd file.

unSpawn 07-30-2009 11:42 AM

Quote:

Originally Posted by jessica6 (Post 3625597)
I found a thread from 2008.02 (..) I will refrain from "necroposting".

Thanks. So fdisk doesn't recognise the image and therefore mounting the partition fails. I can see two options: 'losetup /dev/loop0 /media/disk/files.img && kpartx -va /dev/loop0 && mount /dev/mapper/loop0p6 /some/mountpoint' or, since there's no tools to adjust BIOS-level representation of disks-on-file* (as far as I know but hey, what do I know) use virtualisation: qemu-img convert the image to VMware VMDK, add it to your VM guest, in the VMware BIOS tweak the C/H/S then boot the guest with a (HELIX or KNOPPIX?) LiveCD/ISO and see if you can mount the partition.

* OK, tools like testdisk accept custom C/H/S but they won't allow you to "export" it as a Live system to use with other tools AFAIK.

David the H. 07-30-2009 12:25 PM

It's not usually necessary to use a separate losetup step. You can add the loop and offset options to your mount command, and it will pass them to losetup and configure a loop device automatically. See the loopback section in "man mount" for more.

Also, in bash at least, arithmetic expansion is now done with the $(()) expression (though it looks like the older $[] still works).

Finally, I believe the number is supposed to be [block size] x [starting block], with block size usually being 512.

So I think your command should be:

Code:

mount -t ext2 -o loop,offset=$((512*509)) /path/to/diskimage /mountpoint

allend 07-30-2009 12:53 PM

I think the offset is ((509-1)*8225280) + (63*512) = 4178474496.

When you have an image of an entire disk, you need to account for the first track containing the MBR and partition table.

jessica6 07-30-2009 05:01 PM

Ok, I pieced something together which worked. A single command:

# mount -t ext2 -o loop,offset=$[(509-1)*8225280+63*512] /var/misc/image.dd /mnt2

Thanks everyone!


All times are GMT -5. The time now is 10:02 AM.