[TriLUG] Using Loop Device

Alan Porter porter at trilug.org
Mon Jan 28 14:08:23 EST 2008


> I have a dd file that I wish to extract some items. I was informed
> that using a loop device was the way to do this.

The important thing here is to know whether the image was made from
a PARTITION or a DISK.

If it was a DISK, then it contains a partition table and one or more
partitions.  If it was a partition, then it contains just one partition.

You can tell by doing a "file imagefile.img" and see whether it
contains a filesystem or a partition table (the words they use are
funny, but it'll say something like "x86 boot sector").

PARTITION

If you have a partition image, just do this:
   [aporter at sti]$ mount -o loop -t ext3 imagefile.img /mnt/image

The -o loop will set up the loop device for you.

DISK

If you have an entire disk image, just do this:

   [aporter at sti]$ /sbin/fdisk -u -l imagefile.img 2> /dev/null
   Disk image.usb: 0 MB, 0 bytes
   64 heads, 32 sectors/track, 0 cylinders, total 0 sectors
   Units = sectors of 1 * 512 = 512 bytes

   Device          Boot  Start   End      Blocks   Id  System
   imagefile.img1  *     32      1079295  539632   83  Linux

Make a note of the sector size ("Units") and the starting sector ("Start").

[aporter at sti]$ mount -t ext3 -o loop,offset=$((32*512)) imagefile.img /mnt/image


Hope this helps.


Alan





.







More information about the TriLUG mailing list