Mounting LVM Parition inside an image file

As I am working on a project which required me to extract a script from an image file which was backup using dd tool.

It is possible to mount the image file on a linux server.

1) you need to scan the image file and see partition

[root@c10 sax]# kpartx -v IPC-2Sep2015.img
loop0p1 : 0 409600 /dev/loop0 2048
loop0p2 : 0 1024000 /dev/loop0 411648
loop0p3 : 0 123621376 /dev/loop0 1435648

2) add the partitionto the system

[root@c10 sax]# kpartx -a -v IPC-2Sep2015.img
add map loop0p1 (253:3): 0 409600 linear /dev/loop0 2048
add map loop0p2 (253:4): 0 1024000 linear /dev/loop0 411648
add map loop0p3 (253:5): 0 123621376 linear /dev/loop0 1435648

3) Now use pvscan to scan for the LVM partition

[root@c10 sax]# pvscan
PV /dev/sdb2 VG vg_cdp10 lvm2 [2.73 TiB / 0 free]
PV /dev/mapper/loop0p3 VG centos lvm2 [58.95 GiB / 64.00 MiB free]
Total: 2 [2.79 TiB] / in use: 2 [2.79 TiB] / in no VG: 0 [0 ]

4) You need to activate the LVM so it can be active based on the VG name above

[root@c10 sax]# vgchange -a y centos
3 logical volume(s) in volume group "centos" now active

5) Now, let’s mount the LVM

[root@c10 sax]# mount /dev/centos/root /mnt
[root@c10 sax]#

Clean up:

umount /mnt
vgchange -a n centos
kpartx -d -v IPC-2Sep2015.img

You are good to go now! Hope this helps someone out there.