[clug] Accessing partitions on loop devices
davico at tpg.com.au
Thu Dec 16 01:20:08 GMT 2004
These devices (/dev/loop0p*) are only a naming convention used by fdisk,
they dont exist (and cant be created as they are not actually exported
as devices by the kernel/loop module).
You have 2 options:
1. Use the 'offset' option to losetup, to tell the loop device to begin
at the start of the partition. For example:
losetup -o 327680 /dev/loop0 image.dd
(BTW, you can do it with mount, then you dont have to delete the
loopback device yourself, it will happen for you when you unmount:
mount -o loop,offset=327680 image.dd /mnt/)
The problem with this is that the offset argument would appear to be a
signed integer, meaning that if any of you partitions begin after the
2GB mark, the offset will wrap and it will not work, which brings me to:
2. NASA has developed a replacement loop module without this
shortcoming. It even parses the partition table and exposes devices for
the partitions such that /dev/loop0p1 would be real and you could
actually mount it (you have to make the nodes, but the instructions tell
you how to do that). I know it works with DOS partition table, assuming
it uses the kernel to do the parsing, it will probably also work with
other partition tables supported by the kernel (sun, apple, bsd etc). I
dont have a link atm, you should be able to find it with google. I am
not sure it has been ported to kernel 2.6 either.
BTW, the block numbers you get from "fdisk -l" begin after the boot
sector and partition map. To get the correct values to give in the
'offset' parameter to loopback try 'fdisk -lu' or 'sfdisk -d'. For dos
disks, the first partition typically starts at sector 63, which is
63*512 bytes, so you would use 32256 as the offset option.
Maby there are other ways these days, device mapper etc??
Hope this helps,
On Thu, 2004-12-16 at 11:51 +1100, Andrew Pollock wrote:
> I'm dicking around with a file, which is actually a Sun disk image. I've
> used losetup to associate loop0 with this file, and if I use fdisk on it, I
> can see a couple of partitions inside.
> So how do I mount these partitions?
> apollock at debian:~$ sudo fdisk -l /dev/loop0
> Disk /dev/loop0 (Sun disk label): 1 heads, 640 sectors, 2048 cylinders
> Units = cylinders of 640 * 512 bytes
> Device Flag Start End Blocks Id System
> /dev/loop0p1 r 0 1 320 4 SunOS usr
> /dev/loop0p2 r 1 1768 565440 2 SunOS root
> /dev/loop0p3 1768 1776 2560 0 Empty
> /dev/loop0p4 1776 1784 2560 0 Empty
> /dev/loop0p5 1784 1792 2560 0 Empty
> /dev/loop0p6 1792 1800 2560 0 Empty
> It sounds like I need some more loop devices or something.
> linux.conf.au 2005 - http://lca2005.linux.org.au/ - Birthplace of Tux
> April 18th to 23rd - http://lca2005.linux.org.au/ - LINUX
> Canberra, Australia - http://lca2005.linux.org.au/ - Get bitten!
More information about the linux