Partition From Xen Instance
How to mount partition from xen instance
This below describes the way to mount an LVM partition that exists within a partition from a multi-partition disk image.
Let assume our image is called System.img
We will need losetup, kpartx and vgscan,vgchange commands.
With losetup -f you will identify free loopback devices. let say this is loop6.
losetup /dev/loop6 ./System.img
This will mount the disk image in the loop device.
You can see partition info with
fdisk -l /dev/loop6
Disk /dev/loop6: 82.6 GB, 82678120448 bytes
255 heads, 63 sectors/track, 10051 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/loop6p1 * 1 66 524288 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/loop6p2 66 10051 80209345+ 8e Linux LVM
You could possibly remove the loopback mount and remount only the partition you want from the total disk by using the offset ‘’’-o’’’ option.
losetup -d /dev/loop6
offset is the start cylinder multiplied by the size of each, here 512, so (start of p2) 66* (512 bytes) 512 = offset is 33792
losetup /dev/loop6 System.img -o 33792
However, we will not use that option.
Instead:
kpartx -a /dev/loop6
which will create the /dev/mapper/loopXpY devices for all partitions of image
vgscan
this will show the volume groups that exists in all the devices (so eventually search those created above). In our example it returned (in addition to others) the vg_apol
vgchange -ay vg_apol
This creates the /dev/<vgroup>/<logical_volume> devices so we can mount.
- finally mount the one we need
mount /dev/vg_apol/lv_root ./second/
After doing what we want with the mounted filesystem, we need to do reverse order, so
umount /dev/vg_apol/lv_root unmount volume
vgchange -an vg_apol remove logical volume devices 0 logical volume(s) in volume group “vg_apol” now active
kpartx -d /dev/loop6 remove /dev mapper partitions
losetup -d /dev/loop6 “dettach” the loopback device