[sclug] Mount whole-disk image?

Dickon Hood sclug at splurge.fluff.org
Sun Jan 27 00:42:02 UTC 2008


On Sat, Jan 26, 2008 at 22:18:20 +0000, John Stumbles wrote:
: I know if I make an image of a filesystem with
: 	dd if=/dev/sda1
: (say) I can then mount it loopback and access it as a filesystem. Can I 
: do something similar with an image of an entire disk, e.g. made with
: 	dd if=/dev/sda
: ?

Quick answer: yes, but.

Slightly longer answer: almost certainly, but it will require work.

Full monty: if you have put the filesystem on the disc without a partition
table, then this will work happily.  If you have a standard PC partition
table, or similar, on the front, then it won't.

Your problem is that mount wants a set of blocks to look at which define
a filesystem.  Normally, the kernel parses the partition table for you,
and creates a block device (and character devices on most other Unices)
corresponding to each partition.  However, with a loopback mount that
doesn't happen.

What you *can* do is parse the partition table yourself, and pass '-o
offset' to losetup manually.  That will allow you to setup a loopback
device that's an offset into the file you pass it.  When you 'mount
-oloop' (or let mount determine that itself) it does a lot of magic with
losetup that's hidden from you.

I might be wrong, as it's been a long time since I needed to do anything
like this, but I think that's your best bet.  fdisk on the file may
produce something useful.  A quick 'dd if=/dev/sda of=test; ^C; fdisk
./test;' gave me enough to locate the filesystem within the image, albeit
with some whingeing about cylinders.

-- 
Dickon Hood

Due to digital rights management, my .sig is temporarily unavailable.
Normal service will be resumed as soon as possible.  We apologise for the
inconvenience in the meantime.

No virus was found in this outgoing message as I didn't bother looking.



More information about the Sclug mailing list