October 30, 2009

Mount Disk Image Partition with Loop Device

I didn't have enough memory to start up an old Xen VM for a file restore, so I mounted the disk image through a loop device instead.

using just losetup and mount with simple partitions:
# losetup /dev/loop7 /var/lib/xen/images/vm01.img
# fdisk -lu /dev/loop7

Disk /dev/loop7: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/loop7p1 * 63 208844 104391 83 Linux
/dev/loop7p2 208845 205631999 102711577+ 83 Linux
/dev/loop7p3 205632000 209712509 2040255 82 Linux swap / Solaris

# mount -o ro,offset=$((208845 * 512)) /dev/loop7 /mnt
# losetup -d /dev/loop7
# umount /mnt

using kpartx for lvm and extended partitions:

# kpartx -v -a /var/lib/xen/images/vm01.img
add map loop1p1 : 0 208782 linear /dev/loop1 63
add map loop1p2 : 0 205423155 linear /dev/loop1 208845
add map loop1p3 : 0 4080510 linear /dev/loop1 205632000
# mount -o ro /dev/mapper/loop1p2 /mnt

further reading:

0 comments: