[ale] Loopback mounting of disk images with LVM

brian at polibyte.com brian at polibyte.com
Fri Sep 18 17:01:14 EDT 2009


Hi,

I have a file that's a disk image of a standard RHEL4 install. In this file
are two partitions. The second partition contains a logical volume. I'd
like to access the filesystem in that logical volume. I'm trying to create
a loopback device that refers to the second partition so that I can use the
standard lvm tools to set it up. I can't use the max_part option for the
loopback module since my kernel is too old. Therefore, I think I have to
manually calculate the offset of the second partition in the file and pass
that to losetup. However, I get some warnings from fdisk when I'm trying to
figure out the offset, and after I set up the loopback device the lvm tools
don't detect anything. Anyone have any suggestions? More details are below.

# First, set up the "flat" file to represent the disk.

$ vmware-mount -f thedisk.vmdk /mnt/vm1/

# Next, get details about the partitions.

$ fdisk -l /mnt/vm1/flat
last_lba(): I don't know how to handle files with mode 8180
You must set cylinders.
You can do this from the extra functions menu.

Disk /mnt/vm1/flat: 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
/mnt/vm1/flat1   *           1          13      104391   83  Linux
/mnt/vm1/flat2              14        4177    33447330   8e  Linux LVM
Partition 2 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(4176, 254, 63)

# Multiply the start of the lvm partition by the units to get the offset.
8225280 * 14 is 115153920, so I try to mount the loopback device with
that offset.

$ losetup /dev/loop0 /mnt/vm1/flat -o 115153920

# However, when I run pvscan or vgscan loop0 isn't recognized.

#device/dev-io.c:486         Opened /dev/loop0 RO
#device/dev-io.c:260       /dev/loop0: size is 66883954 sectors
#device/dev-io.c:532         Closed /dev/loop0
#device/dev-io.c:260       /dev/loop0: size is 66883954 sectors
#device/dev-io.c:486         Opened /dev/loop0 RW O_DIRECT
#device/dev-io.c:134         /dev/loop0: block size is 1024 bytes
#device/dev-io.c:532         Closed /dev/loop0
#filters/filter-composite.c:31         Using /dev/loop0
#device/dev-io.c:486         Opened /dev/loop0 RW O_DIRECT
#device/dev-io.c:134         /dev/loop0: block size is 1024 bytes
#label/label.c:184       /dev/loop0: No label detected
#device/dev-io.c:532         Closed /dev/loop0

All the best,
Brian Pitts


More information about the Ale mailing list